diff --git a/src/controllers/EffectMap.ts b/src/controllers/EffectMap.ts new file mode 100644 index 0000000..847cf28 --- /dev/null +++ b/src/controllers/EffectMap.ts @@ -0,0 +1,20 @@ +import type { IEffectMap, IXML } from '../types' + +export class EffectMap { + public effects: IEffectMap['effects'] = [] + + constructor(XML: IXML) { + this.parseLibrairies(XML.map.effect) + } + + private parseLibrairies(effects: any[]): void { + for (const libraryXML of effects) { + this.effects.push({ + id: Number(libraryXML.id), + lib: libraryXML.lib, + type: libraryXML.type, + revision: Number(libraryXML.revision) + }) + } + } +} diff --git a/src/controllers/FigureData.ts b/src/controllers/FigureData.ts new file mode 100644 index 0000000..0411a25 --- /dev/null +++ b/src/controllers/FigureData.ts @@ -0,0 +1,85 @@ +import type { + IFigureData, + IFigureDataColor, + IFigureDataPalette, + IFigureDataSet, + IFigureDataSetType, + IXML +} from '../types' + +export class FigureData { + public data: IFigureData = { palettes: [], setTypes: [] } + + constructor(XML: IXML) { + this.parsePalettes(XML.figuredata.colors.palette) + this.parseSetTypes(XML.figuredata.sets.settype) + } + + private parsePalettes(palettes: any[]): void { + for (const paletteXML of palettes) { + const palette: IFigureDataPalette = { id: Number(paletteXML.id), color: [] } + + for (const colorXML of paletteXML.color) { + palette.color.push({ + id: Number(colorXML.id), + index: Number(colorXML.index), + club: Number(colorXML.club), + selectable: Boolean(colorXML.selectable), + hexCode: String(colorXML['#text' as keyof IFigureDataColor]) + }) + } + + this.data.palettes.push(palette) + } + } + + private parseSetTypes(setTypes: any[]): void { + for (const setTypeXML of setTypes) { + const settype: IFigureDataSetType = { + type: setTypeXML.type, + paletteId: Number(setTypeXML.paletteid), + mandatoryF0: Boolean(setTypeXML.mand_f_0), + mandatoryF1: Boolean(setTypeXML.mand_f_1), + mandatoryM0: Boolean(setTypeXML.mand_m_0), + mandatoryM1: Boolean(setTypeXML.mand_m_1), + sets: [] + } + + for (const setXML of setTypeXML.set) { + const setType: IFigureDataSet = { + id: Number(setXML.id), + gender: setXML.gender, + club: Number(setXML.club), + colorable: Boolean(setXML.colorable), + selectable: Boolean(setXML.selectable), + preselectable: Boolean(setXML.preselectable), + sellable: Boolean(setXML.sellable), + parts: [], + hiddenLayers: [] + } + + for (const partXML of Array.isArray(setXML.part) ? setXML.part : [setXML.part]) { + setType.parts.push({ + id: Number(partXML.id), + type: partXML.type, + colorable: Boolean(partXML.colorable), + index: Number(partXML.index), + colorindex: Number(partXML.colorindex) + }) + } + + if (setXML.hiddenLayers != null) { + for (const hiddenLayerXML of Array.isArray(setXML.hiddenLayers) + ? setXML.hiddenLayers + : [setXML.hiddenLayers]) { + setType.hiddenLayers.push({ partType: hiddenLayerXML.partType }) + } + } + + settype.sets.push(setType) + } + + this.data.setTypes.push(setTypeXML) + } + } +} diff --git a/src/controllers/FigureMap.ts b/src/controllers/FigureMap.ts new file mode 100644 index 0000000..f62c98e --- /dev/null +++ b/src/controllers/FigureMap.ts @@ -0,0 +1,24 @@ +import type { IFigureMap, IFigureMapLibrary, IXML } from '../types' + +export class FigureMap { + public data: IFigureMap = { libraries: [] } + + constructor(XML: IXML) { + this.parseLibrairies(XML.map.lib) + } + + private parseLibrairies(librairies: any[]): void { + for (const libraryXML of librairies) { + const library: IFigureMapLibrary = { id: libraryXML.id, revision: Number(libraryXML.revision), part: [] } + + for (const libraryPart of Array.isArray(libraryXML.part) ? libraryXML.part : [libraryXML.part]) { + library.part.push({ id: Number(libraryPart.id), type: libraryPart.type }) + } + + this.data.libraries.push(library) + } + } + + // maybe + /* public get classNamesAndRevisions(data: IFigureData): { [index: string]: string } {} */ +} diff --git a/src/controllers/FurniData.ts b/src/controllers/FurniData.ts new file mode 100644 index 0000000..e2b1121 --- /dev/null +++ b/src/controllers/FurniData.ts @@ -0,0 +1,45 @@ +import type { IFurni, IFurniData, IXML, KeyValuePairs } from '../types' + +export class FurniData { + public data: IFurniData = { roomItemTypes: [], wallItemTypes: [] } + + constructor(data: IXML) { + this.parseRoomItemTypes(data.roomitemtypes.furnitype) + this.parseWallItemTypes(data.roomitemtypes.furnitype) + } + + private parseRoomItemTypes(roomItems: IFurni[]): void { + for (const roomItem of roomItems) { + this.data.roomItemTypes.push(roomItem) + } + } + + private parseWallItemTypes(wallItems: IFurni[]): void { + for (const wallItem of wallItems) { + this.data.wallItemTypes.push(wallItem) + } + } + + private getClassNameRevision(itemType: IFurni): { className: string; revision: number } { + const className = itemType.classname.split('*')[0] + const revision = itemType.revision + + return { className, revision } + } + + public get classNamesAndRevisions(): KeyValuePairs { + const entries: KeyValuePairs = {} + + for (const roomItem of this.data.roomItemTypes) { + const { className, revision } = this.getClassNameRevision(roomItem) + entries[className] = String(revision) + } + + for (const wallItem of this.data.wallItemTypes) { + const { className, revision } = this.getClassNameRevision(wallItem) + entries[className] = String(revision) + } + + return entries + } +} diff --git a/src/controllers/index.ts b/src/controllers/index.ts new file mode 100644 index 0000000..b92fd54 --- /dev/null +++ b/src/controllers/index.ts @@ -0,0 +1,4 @@ +export * from './EffectMap' +export * from './FigureMap' +export * from './FigureData' +export * from './FurniData'