feat(session): live furnidata reload via mergeFurnitureDataFromUrl

Add SessionDataManager.mergeFurnitureDataFromUrl() + FurnitureDataLoader.mergeFromUrl()
to merge a single furnidata chunk (e.g. a custom tier) into the live floor/wall maps at
runtime, returning the added entries so callers can also refresh the RoomContentLoader.
Lets newly added furniture appear without a full client reload.
This commit is contained in:
medievalshell
2026-06-03 23:27:50 +02:00
committed by medievalshell
parent 6c07cf8677
commit e83468563d
3 changed files with 59 additions and 4 deletions
@@ -9,6 +9,7 @@ export interface ISessionDataManager
{
init(): Promise<void>;
getAllFurnitureData(): IFurnitureData[];
mergeFurnitureDataFromUrl(url: string): Promise<IFurnitureData[]>;
applyFurnitureDataOverrides(url: string): Promise<void>;
clearFurnitureDataOverrides(): void;
getFloorItemData(id: number): IFurnitureData;
@@ -224,6 +224,21 @@ export class SessionDataManager implements ISessionDataManager
];
}
// Mergia a runtime un chunk furnidata (es. custom/imported.json5) nelle Map
// esistenti, SENZA reload del client. Ritorna gli entry aggiunti cosi il
// chiamante puo' aggiornare anche il RoomContentLoader. Fa comparire i furni
// appena importati nel catalogo in tempo reale.
public async mergeFurnitureDataFromUrl(url: string): Promise<IFurnitureData[]>
{
if(!url || !url.length) return [];
const added = await this._furnitureData.mergeFromUrl(url);
if(added && added.length) GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SESSION_DATA_UPDATED));
return added;
}
public async applyFurnitureDataOverrides(url: string): Promise<void>
{
if(!url || !url.length)
@@ -37,9 +37,38 @@ export class FurnitureDataLoader
if(responseData.wallitemtypes) this.parseWallItems(responseData.wallitemtypes);
}
private parseFloorItems(data: any): void
// Ri-carica un singolo chunk furnidata (es. custom/imported.json5) e
// mergia i suoi entry nelle Map esistenti. Ritorna gli entry aggiunti/aggiornati
// cosi il chiamante puo' aggiornare anche il RoomContentLoader senza reload.
public async mergeFromUrl(url: string): Promise<IFurnitureData[]>
{
if(!data || !data.furnitype) return;
if(!url || !url.length) return [];
let responseData: any;
try
{
responseData = await loadGamedata(url);
}
catch(err)
{
return [];
}
const added: IFurnitureData[] = [];
if(responseData.roomitemtypes) added.push(...this.parseFloorItems(responseData.roomitemtypes));
if(responseData.wallitemtypes) added.push(...this.parseWallItems(responseData.wallitemtypes));
return added;
}
private parseFloorItems(data: any): IFurnitureData[]
{
const added: IFurnitureData[] = [];
if(!data || !data.furnitype) return added;
for(const furniture of data.furnitype)
{
@@ -76,13 +105,19 @@ export class FurnitureDataLoader
this._floorItems.set(furnitureData.id, furnitureData);
added.push(furnitureData);
this.updateLocalizations(furnitureData);
}
return added;
}
private parseWallItems(data: any): void
private parseWallItems(data: any): IFurnitureData[]
{
if(!data || !data.furnitype) return;
const added: IFurnitureData[] = [];
if(!data || !data.furnitype) return added;
for(const furniture of data.furnitype)
{
@@ -93,8 +128,12 @@ export class FurnitureDataLoader
this._wallItems.set(furnitureData.id, furnitureData);
added.push(furnitureData);
this.updateLocalizations(furnitureData);
}
return added;
}
private updateLocalizations(furniture: FurnitureData): void