refactor(controllers): add data parser

This commit is contained in:
Walid 2023-04-23 23:27:49 +01:00
parent 51ba8d4fcb
commit 4f6b2045f2
Signed by: Walidoux
GPG Key ID: CCF21881FE8BEBAF
4 changed files with 30 additions and 6 deletions

View File

@ -1,15 +1,21 @@
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 effects: IEffectMap['effects'] = [] public data: IEffectMap = { effects: [] }
constructor(XML: IXML) { constructor(XML: IXML, fileName: string) {
this.parseLibrairies(XML.map.effect) this.parseLibrairies(XML.map.effect)
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => {
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.effects.push({ this.data.effects.push({
id: Number(libraryXML.id), id: Number(libraryXML.id),
lib: libraryXML.lib, lib: libraryXML.lib,
type: libraryXML.type, type: libraryXML.type,

View File

@ -1,3 +1,4 @@
import { parseData } from '../tools/parseData'
import type { import type {
IFigureData, IFigureData,
IFigureDataColor, IFigureDataColor,
@ -6,13 +7,18 @@ import type {
IFigureDataSetType, IFigureDataSetType,
IXML IXML
} from '../types' } from '../types'
import { Convertion } from '../config/Convertion'
export class FigureData { export class FigureData {
public data: IFigureData = { palettes: [], setTypes: [] } public data: IFigureData = { palettes: [], setTypes: [] }
constructor(XML: IXML) { constructor(XML: IXML, fileName: string) {
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 {

View File

@ -1,10 +1,16 @@
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: [] }
constructor(XML: IXML) { constructor(XML: IXML, fileName: string) {
this.parseLibrairies(XML.map.lib) this.parseLibrairies(XML.map.lib)
parseData(Convertion.gamedataConfigDir, fileName, this.data).catch((error) => {
return console.error(error)
})
} }
private parseLibrairies(librairies: any[]): void { private parseLibrairies(librairies: any[]): void {

View File

@ -1,11 +1,17 @@
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: [] }
constructor(data: IXML) { constructor(data: IXML, fileName: string) {
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 {