From 0dcb984a9ed8ee89e74aa667f429f251d379361b Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Wed, 15 Mar 2023 17:06:40 +0100 Subject: [PATCH 1/2] feat: show song info in inventory --- src/api/inventory/GroupItem.ts | 64 +++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/src/api/inventory/GroupItem.ts b/src/api/inventory/GroupItem.ts index 8569321eb..f4c31f06b 100644 --- a/src/api/inventory/GroupItem.ts +++ b/src/api/inventory/GroupItem.ts @@ -1,4 +1,5 @@ -import { IObjectData, IRoomEngine } from '@nitrots/nitro-renderer'; +import { IObjectData, IRoomEngine, SongDataEntry, TraxSongInfoMessageEvent } from '@nitrots/nitro-renderer'; +import { GetNitroInstance } from '../nitro'; import { LocalizeText } from '../utils'; import { FurniCategory } from './FurniCategory'; import { FurnitureItem } from './FurnitureItem'; @@ -19,6 +20,7 @@ export class GroupItem private _selected: boolean; private _hasUnseenItems: boolean; private _items: FurnitureItem[]; + private _traxSongInfoEvent: TraxSongInfoMessageEvent; constructor(type: number = -1, category: number = -1, roomEngine: IRoomEngine = null, stuffData: IObjectData = null, extra: number = -1) { @@ -35,6 +37,12 @@ export class GroupItem this._selected = false; this._hasUnseenItems = false; this._items = []; + + if (this._category === FurniCategory.TRAX_SONG) + { + this._traxSongInfoEvent = new TraxSongInfoMessageEvent(this.onTraxSongInfoMessageEvent.bind(this)); + GetNitroInstance().communication.connection.addMessageEvent(this._traxSongInfoEvent); + } } public clone(): GroupItem @@ -67,7 +75,7 @@ export class GroupItem public dispose(): void { - + this.clearTraxSongInfoEvent(); } public getItemByIndex(index: number): FurnitureItem @@ -322,7 +330,11 @@ export class GroupItem key = (('poster_' + k.stuffData.getLegacyString()) + '_name'); break; case FurniCategory.TRAX_SONG: - this._name = 'SONG_NAME'; + const songInfo = (GetNitroInstance().soundManager.musicController.getSongInfo(k.extra) as SongDataEntry); + if(songInfo == null) break; + // remove the event if we already know the song + this.clearTraxSongInfoEvent(); + this._name = songInfo.creator; return; default: if(this.isWallItem) @@ -340,6 +352,28 @@ export class GroupItem private setDescription(): void { + const k = this.getLastItem(); + + if(!k) + { + this._description = ''; + + return; + } + + switch(this._category) + { + case FurniCategory.TRAX_SONG: + const songInfo = (GetNitroInstance().soundManager.musicController.getSongInfo(k.extra) as SongDataEntry); + if(songInfo == null) break; + // remove the event if we already know the song + this.clearTraxSongInfoEvent(); + this._description = songInfo.name; + return; + default: + break; + } + this._description = ''; } @@ -458,4 +492,26 @@ export class GroupItem { this._items = items; } -} + + private clearTraxSongInfoEvent(): void + { + GetNitroInstance().communication.connection.removeMessageEvent(this._traxSongInfoEvent); + } + + private onTraxSongInfoMessageEvent(event: TraxSongInfoMessageEvent): void + { + const k = this.getLastItem(); + if(!k)return; + + const parser = event.getParser(); + + for(const song of parser.songs) + { + if (k.extra !== song.id) continue; + this._name = song.creator; + this._description = song.name; + } + + if(this._name) this.clearTraxSongInfoEvent(); + } +} \ No newline at end of file From 198ecab5ed0ca002d748f0947e0dc5404e9c9698 Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Wed, 15 Mar 2023 17:11:24 +0100 Subject: [PATCH 2/2] feat: added description to inventory view --- .../inventory/views/furniture/InventoryFurnitureView.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/inventory/views/furniture/InventoryFurnitureView.tsx b/src/components/inventory/views/furniture/InventoryFurnitureView.tsx index 52e670fec..9ecd6e8cf 100644 --- a/src/components/inventory/views/furniture/InventoryFurnitureView.tsx +++ b/src/components/inventory/views/furniture/InventoryFurnitureView.tsx @@ -128,7 +128,10 @@ export const InventoryFurnitureView: FC = props => { selectedItem && - { selectedItem.name } + + { selectedItem.name } + { selectedItem.description } + { !!roomSession &&