refactor(controllers): classes and parse libraries, sets and palettes

- Refactored several classes in controllers directory and modified parsing of libraries, sets and palettes.
This commit is contained in:
Walid 2023-04-28 14:41:16 +01:00
parent a25d278115
commit fbf1a5dc7b
Signed by: Walidoux
GPG Key ID: CCF21881FE8BEBAF
4 changed files with 40 additions and 68 deletions

View File

@ -1,26 +1,19 @@
import { Convertion } from '../config/Convertion'
import { parseData } from '../tools/parseData'
import type { IEffectMap, IXML } from '../types'
export class EffectMap {
public data: IEffectMap = { effects: [] }
public data: IEffectMap = {}
public fileName: string
constructor(XML: IXML, fileName: string) {
this.parseLibrairies(XML.map.effect)
this.fileName = fileName
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => {
return console.error(error)
})
this.parseLibrairies(XML.map.effect)
}
private parseLibrairies(effects: any[]): void {
for (const libraryXML of effects) {
this.data.effects.push({
id: Number(libraryXML.id),
lib: libraryXML.lib,
type: libraryXML.type,
revision: Number(libraryXML.revision)
})
this.data[libraryXML.type] == null && (this.data[libraryXML.type] = {})
this.data[libraryXML.type][libraryXML.id] = libraryXML.lib
}
}
}

View File

@ -1,38 +1,27 @@
import { parseData } from '../tools/parseData'
import type {
IFigureData,
IFigureDataColor,
IFigureDataPalette,
IFigureDataSet,
IFigureDataSetType,
IXML
} from '../types'
import { Convertion } from '../config/Convertion'
import type { IFigureData, IFigureDataPalette, IFigureDataSet, IFigureDataSetType, IXML } from '../types'
export class FigureData {
public data: IFigureData = { palettes: [], setTypes: [] }
public data: IFigureData = { palettes: [], setTypes: {} }
public fileName: string
constructor(XML: IXML, fileName: string) {
this.fileName = fileName
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 {
for (const paletteXML of palettes) {
const palette: IFigureDataPalette = { id: Number(paletteXML.id), color: [] }
const palette = {} as IFigureDataPalette
for (const colorXML of paletteXML.color) {
palette.color.push({
id: Number(colorXML.id),
palette[Number(colorXML.id)] = {
index: Number(colorXML.index),
club: Number(colorXML.club),
selectable: Boolean(colorXML.selectable),
hexCode: String(colorXML['#text' as keyof IFigureDataColor])
})
color: '#' + String(colorXML['#text'])
}
}
this.data.palettes.push(palette)
@ -42,24 +31,22 @@ export class FigureData {
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: []
mandatoryF0: Boolean(Number(setTypeXML.mand_f_0)),
mandatoryF1: Boolean(Number(setTypeXML.mand_f_1)),
mandatoryM0: Boolean(Number(setTypeXML.mand_m_0)),
mandatoryM1: Boolean(Number(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),
colorable: Boolean(Number(setXML.colorable)),
selectable: Boolean(Number(setXML.selectable)),
preselectable: Boolean(Number(setXML.preselectable)),
sellable: setXML.sellable != null ? Boolean(Number(setXML.sellable)) : undefined,
parts: [],
hiddenLayers: []
}
@ -68,7 +55,7 @@ export class FigureData {
setType.parts.push({
id: Number(partXML.id),
type: partXML.type,
colorable: Boolean(partXML.colorable),
colorable: Boolean(Number(partXML.colorable)),
index: Number(partXML.index),
colorindex: Number(partXML.colorindex)
})
@ -78,14 +65,14 @@ export class FigureData {
for (const hiddenLayerXML of Array.isArray(setXML.hiddenLayers)
? setXML.hiddenLayers
: [setXML.hiddenLayers]) {
setType.hiddenLayers.push({ partType: hiddenLayerXML.partType })
setType.hiddenLayers?.push(hiddenLayerXML.partType)
}
}
settype.sets.push(setType)
settype.sets[Number(setXML.id)] = setType
}
this.data.setTypes.push(setTypeXML)
this.data.setTypes[String(setTypeXML.type)] = settype
}
}
}

View File

@ -1,30 +1,25 @@
import { Convertion } from '../config/Convertion'
import { parseData } from '../tools/parseData'
import type { IFigureMap, IFigureMapLibrary, IXML } from '../types'
export class FigureMap {
public data: IFigureMap = { libraries: [] }
public data: IFigureMap = { libraries: [], parts: {} }
public fileName: string
constructor(XML: IXML, fileName: string) {
this.parseLibrairies(XML.map.lib)
this.fileName = fileName
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => {
return console.error(error)
})
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: [] }
const library: IFigureMapLibrary = { id: libraryXML.id, revision: Number(libraryXML.revision) }
for (const libraryPart of Array.isArray(libraryXML.part) ? libraryXML.part : [libraryXML.part]) {
library.part.push({ id: Number(libraryPart.id), type: libraryPart.type })
this.data.parts[libraryPart.type] == null && (this.data.parts[libraryPart.type] = {})
this.data.parts[libraryPart.type][Number(libraryPart.id)] = librairies.indexOf(libraryXML)
}
this.data.libraries.push(library)
}
}
// maybe
/* public get classNamesAndRevisions(data: IFigureData): { [index: string]: string } {} */
}

View File

@ -1,17 +1,14 @@
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: [] }
public fileName: string
constructor(data: IXML, fileName: string) {
this.fileName = fileName
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 {
@ -33,8 +30,8 @@ export class FurniData {
return { className, revision }
}
public get classNamesAndRevisions(): KeyValuePairs {
const entries: KeyValuePairs = {}
public get classNamesAndRevisions(): KeyValuePairs<string, string> {
const entries: KeyValuePairs<string, string> = {}
for (const roomItem of this.data.roomItemTypes) {
const { className, revision } = this.getClassNameRevision(roomItem)