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

View File

@ -1,38 +1,27 @@
import { parseData } from '../tools/parseData' import type { IFigureData, IFigureDataPalette, IFigureDataSet, IFigureDataSetType, IXML } from '../types'
import type {
IFigureData,
IFigureDataColor,
IFigureDataPalette,
IFigureDataSet,
IFigureDataSetType,
IXML
} from '../types'
import { Convertion } from '../config/Convertion'
export class FigureData { export class FigureData {
public data: IFigureData = { palettes: [], setTypes: [] } public data: IFigureData = { palettes: [], setTypes: {} }
public fileName: string
constructor(XML: IXML, fileName: string) { constructor(XML: IXML, fileName: string) {
this.fileName = fileName
this.parsePalettes(XML.figuredata.colors.palette) this.parsePalettes(XML.figuredata.colors.palette)
this.parseSetTypes(XML.figuredata.sets.settype) this.parseSetTypes(XML.figuredata.sets.settype)
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => {
return console.error(error)
})
} }
private parsePalettes(palettes: any[]): void { private parsePalettes(palettes: any[]): void {
for (const paletteXML of palettes) { for (const paletteXML of palettes) {
const palette: IFigureDataPalette = { id: Number(paletteXML.id), color: [] } const palette = {} as IFigureDataPalette
for (const colorXML of paletteXML.color) { for (const colorXML of paletteXML.color) {
palette.color.push({ palette[Number(colorXML.id)] = {
id: Number(colorXML.id),
index: Number(colorXML.index), index: Number(colorXML.index),
club: Number(colorXML.club), club: Number(colorXML.club),
selectable: Boolean(colorXML.selectable), selectable: Boolean(colorXML.selectable),
hexCode: String(colorXML['#text' as keyof IFigureDataColor]) color: '#' + String(colorXML['#text'])
}) }
} }
this.data.palettes.push(palette) this.data.palettes.push(palette)
@ -42,24 +31,22 @@ export class FigureData {
private parseSetTypes(setTypes: any[]): void { private parseSetTypes(setTypes: any[]): void {
for (const setTypeXML of setTypes) { for (const setTypeXML of setTypes) {
const settype: IFigureDataSetType = { const settype: IFigureDataSetType = {
type: setTypeXML.type,
paletteId: Number(setTypeXML.paletteid), paletteId: Number(setTypeXML.paletteid),
mandatoryF0: Boolean(setTypeXML.mand_f_0), mandatoryF0: Boolean(Number(setTypeXML.mand_f_0)),
mandatoryF1: Boolean(setTypeXML.mand_f_1), mandatoryF1: Boolean(Number(setTypeXML.mand_f_1)),
mandatoryM0: Boolean(setTypeXML.mand_m_0), mandatoryM0: Boolean(Number(setTypeXML.mand_m_0)),
mandatoryM1: Boolean(setTypeXML.mand_m_1), mandatoryM1: Boolean(Number(setTypeXML.mand_m_1)),
sets: [] sets: {}
} }
for (const setXML of setTypeXML.set) { for (const setXML of setTypeXML.set) {
const setType: IFigureDataSet = { const setType: IFigureDataSet = {
id: Number(setXML.id),
gender: setXML.gender, gender: setXML.gender,
club: Number(setXML.club), club: Number(setXML.club),
colorable: Boolean(setXML.colorable), colorable: Boolean(Number(setXML.colorable)),
selectable: Boolean(setXML.selectable), selectable: Boolean(Number(setXML.selectable)),
preselectable: Boolean(setXML.preselectable), preselectable: Boolean(Number(setXML.preselectable)),
sellable: Boolean(setXML.sellable), sellable: setXML.sellable != null ? Boolean(Number(setXML.sellable)) : undefined,
parts: [], parts: [],
hiddenLayers: [] hiddenLayers: []
} }
@ -68,7 +55,7 @@ export class FigureData {
setType.parts.push({ setType.parts.push({
id: Number(partXML.id), id: Number(partXML.id),
type: partXML.type, type: partXML.type,
colorable: Boolean(partXML.colorable), colorable: Boolean(Number(partXML.colorable)),
index: Number(partXML.index), index: Number(partXML.index),
colorindex: Number(partXML.colorindex) colorindex: Number(partXML.colorindex)
}) })
@ -78,14 +65,14 @@ export class FigureData {
for (const hiddenLayerXML of Array.isArray(setXML.hiddenLayers) for (const hiddenLayerXML of Array.isArray(setXML.hiddenLayers)
? setXML.hiddenLayers ? 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' import type { IFigureMap, IFigureMapLibrary, IXML } from '../types'
export class FigureMap { export class FigureMap {
public data: IFigureMap = { libraries: [] } public data: IFigureMap = { libraries: [], parts: {} }
public fileName: string
constructor(XML: IXML, fileName: string) { constructor(XML: IXML, fileName: string) {
this.parseLibrairies(XML.map.lib) this.fileName = fileName
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => { this.parseLibrairies(XML.map.lib)
return console.error(error)
})
} }
private parseLibrairies(librairies: any[]): void { private parseLibrairies(librairies: any[]): void {
for (const libraryXML of librairies) { 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]) { 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) 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 type { IFurni, IFurniData, IXML, KeyValuePairs } from '../types'
import { Convertion } from '../config/Convertion'
export class FurniData { export class FurniData {
public data: IFurniData = { roomItemTypes: [], wallItemTypes: [] } public data: IFurniData = { roomItemTypes: [], wallItemTypes: [] }
public fileName: string
constructor(data: IXML, fileName: string) { constructor(data: IXML, fileName: string) {
this.fileName = fileName
this.parseRoomItemTypes(data.roomitemtypes.furnitype) this.parseRoomItemTypes(data.roomitemtypes.furnitype)
this.parseWallItemTypes(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 { private parseRoomItemTypes(roomItems: IFurni[]): void {
@ -33,8 +30,8 @@ export class FurniData {
return { className, revision } return { className, revision }
} }
public get classNamesAndRevisions(): KeyValuePairs { public get classNamesAndRevisions(): KeyValuePairs<string, string> {
const entries: KeyValuePairs = {} const entries: KeyValuePairs<string, string> = {}
for (const roomItem of this.data.roomItemTypes) { for (const roomItem of this.data.roomItemTypes) {
const { className, revision } = this.getClassNameRevision(roomItem) const { className, revision } = this.getClassNameRevision(roomItem)