feat(controllers): integrate EffectMap/FigureData/FigureMap/FurniData
This commit is contained in:
parent
63d9921dd5
commit
052ad1c6ab
20
src/controllers/EffectMap.ts
Normal file
20
src/controllers/EffectMap.ts
Normal file
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
85
src/controllers/FigureData.ts
Normal file
85
src/controllers/FigureData.ts
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
24
src/controllers/FigureMap.ts
Normal file
24
src/controllers/FigureMap.ts
Normal file
@ -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 } {} */
|
||||
}
|
45
src/controllers/FurniData.ts
Normal file
45
src/controllers/FurniData.ts
Normal file
@ -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
|
||||
}
|
||||
}
|
4
src/controllers/index.ts
Normal file
4
src/controllers/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './EffectMap'
|
||||
export * from './FigureMap'
|
||||
export * from './FigureData'
|
||||
export * from './FurniData'
|
Loading…
Reference in New Issue
Block a user