From 4f6b2045f2264c2f9c2acd41c277dbe962b92619 Mon Sep 17 00:00:00 2001 From: Walidoux Date: Sun, 23 Apr 2023 23:27:49 +0100 Subject: [PATCH] refactor(controllers): add data parser --- src/controllers/EffectMap.ts | 12 +++++++++--- src/controllers/FigureData.ts | 8 +++++++- src/controllers/FigureMap.ts | 8 +++++++- src/controllers/FurniData.ts | 8 +++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/controllers/EffectMap.ts b/src/controllers/EffectMap.ts index 847cf28..f8775ea 100644 --- a/src/controllers/EffectMap.ts +++ b/src/controllers/EffectMap.ts @@ -1,15 +1,21 @@ +import { Convertion } from '../config/Convertion' +import { parseData } from '../tools/parseData' import type { IEffectMap, IXML } from '../types' export class EffectMap { - public effects: IEffectMap['effects'] = [] + public data: IEffectMap = { effects: [] } - constructor(XML: IXML) { + constructor(XML: IXML, fileName: string) { this.parseLibrairies(XML.map.effect) + + parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => { + return console.error(error) + }) } private parseLibrairies(effects: any[]): void { for (const libraryXML of effects) { - this.effects.push({ + this.data.effects.push({ id: Number(libraryXML.id), lib: libraryXML.lib, type: libraryXML.type, diff --git a/src/controllers/FigureData.ts b/src/controllers/FigureData.ts index 0411a25..8a8c470 100644 --- a/src/controllers/FigureData.ts +++ b/src/controllers/FigureData.ts @@ -1,3 +1,4 @@ +import { parseData } from '../tools/parseData' import type { IFigureData, IFigureDataColor, @@ -6,13 +7,18 @@ import type { IFigureDataSetType, IXML } from '../types' +import { Convertion } from '../config/Convertion' export class FigureData { public data: IFigureData = { palettes: [], setTypes: [] } - constructor(XML: IXML) { + constructor(XML: IXML, fileName: string) { this.parsePalettes(XML.figuredata.colors.palette) this.parseSetTypes(XML.figuredata.sets.settype) + + parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => { + return console.error(error) + }) } private parsePalettes(palettes: any[]): void { diff --git a/src/controllers/FigureMap.ts b/src/controllers/FigureMap.ts index f62c98e..e088177 100644 --- a/src/controllers/FigureMap.ts +++ b/src/controllers/FigureMap.ts @@ -1,10 +1,16 @@ +import { Convertion } from '../config/Convertion' +import { parseData } from '../tools/parseData' import type { IFigureMap, IFigureMapLibrary, IXML } from '../types' export class FigureMap { public data: IFigureMap = { libraries: [] } - constructor(XML: IXML) { + constructor(XML: IXML, fileName: string) { this.parseLibrairies(XML.map.lib) + + parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => { + return console.error(error) + }) } private parseLibrairies(librairies: any[]): void { diff --git a/src/controllers/FurniData.ts b/src/controllers/FurniData.ts index e2b1121..bb83cd6 100644 --- a/src/controllers/FurniData.ts +++ b/src/controllers/FurniData.ts @@ -1,11 +1,17 @@ +import { parseData } from '../tools/parseData' import type { IFurni, IFurniData, IXML, KeyValuePairs } from '../types' +import { Convertion } from '../config/Convertion' export class FurniData { public data: IFurniData = { roomItemTypes: [], wallItemTypes: [] } - constructor(data: IXML) { + constructor(data: IXML, fileName: string) { this.parseRoomItemTypes(data.roomitemtypes.furnitype) this.parseWallItemTypes(data.roomitemtypes.furnitype) + + parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => { + return console.error(error) + }) } private parseRoomItemTypes(roomItems: IFurni[]): void {