From ac3bd7fbb021ee031a2de09c115726d6325d17c5 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Tue, 3 Aug 2021 02:15:05 -0500 Subject: [PATCH] added figuredata converter --- src/Main.ts | 4 +- src/configuration.json.example | 4 +- .../figuredata/FigureDataConverter.ts | 102 +++++++++++ .../figuredata/FigureDataDownloader.ts | 32 ++++ src/mapping/json/figuredata/IFigureData.ts | 8 + .../json/figuredata/IFigureDataColor.ts | 8 + .../json/figuredata/IFigureDataPalette.ts | 7 + .../json/figuredata/IFigureDataPart.ts | 8 + src/mapping/json/figuredata/IFigureDataSet.ts | 12 ++ .../json/figuredata/IFigureDataSetType.ts | 12 ++ src/mapping/json/figuredata/index.ts | 6 + src/mapping/json/index.ts | 1 + src/mapping/mappers/FigureDataMapper.ts | 166 ++++++++++++++++++ src/mapping/mappers/index.ts | 1 + .../xml/figuredata/FigureDataColorXML.ts | 45 +++++ .../xml/figuredata/FigureDataPaletteXML.ts | 39 ++++ .../xml/figuredata/FigureDataPartXML.ts | 44 +++++ .../xml/figuredata/FigureDataSetTypeXML.ts | 74 ++++++++ .../xml/figuredata/FigureDataSetXML.ts | 74 ++++++++ src/mapping/xml/figuredata/FigureDataXML.ts | 55 ++++++ src/mapping/xml/figuredata/index.ts | 6 + src/mapping/xml/index.ts | 1 + 22 files changed, 707 insertions(+), 2 deletions(-) create mode 100644 src/converters/figuredata/FigureDataConverter.ts create mode 100644 src/converters/figuredata/FigureDataDownloader.ts create mode 100644 src/mapping/json/figuredata/IFigureData.ts create mode 100644 src/mapping/json/figuredata/IFigureDataColor.ts create mode 100644 src/mapping/json/figuredata/IFigureDataPalette.ts create mode 100644 src/mapping/json/figuredata/IFigureDataPart.ts create mode 100644 src/mapping/json/figuredata/IFigureDataSet.ts create mode 100644 src/mapping/json/figuredata/IFigureDataSetType.ts create mode 100644 src/mapping/json/figuredata/index.ts create mode 100644 src/mapping/mappers/FigureDataMapper.ts create mode 100644 src/mapping/xml/figuredata/FigureDataColorXML.ts create mode 100644 src/mapping/xml/figuredata/FigureDataPaletteXML.ts create mode 100644 src/mapping/xml/figuredata/FigureDataPartXML.ts create mode 100644 src/mapping/xml/figuredata/FigureDataSetTypeXML.ts create mode 100644 src/mapping/xml/figuredata/FigureDataSetXML.ts create mode 100644 src/mapping/xml/figuredata/FigureDataXML.ts create mode 100644 src/mapping/xml/figuredata/index.ts diff --git a/src/Main.ts b/src/Main.ts index 8be1930..6ed14a6 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -5,6 +5,7 @@ import { IConverter } from './common/converters/IConverter'; import { EffectConverter } from './converters/effect/EffectConverter'; import { ExternalTextsConverter } from './converters/externaltexts/ExternalTextsConverter'; import { FigureConverter } from './converters/figure/FigureConverter'; +import { FigureDataConverter } from './converters/figuredata/FigureDataConverter'; import { FurnitureConverter } from './converters/furniture/FurnitureConverter'; import { PetConverter } from './converters/pet/PetConverter'; import { ProductDataConverter } from './converters/productdata/ProductDataConverter'; @@ -21,7 +22,8 @@ import { ProductDataConverter } from './converters/productdata/ProductDataConver FigureConverter, EffectConverter, FurnitureConverter, - PetConverter + PetConverter, + FigureDataConverter ]; for(const converterClass of converters) diff --git a/src/configuration.json.example b/src/configuration.json.example index 8ce9e62..739a6b8 100644 --- a/src/configuration.json.example +++ b/src/configuration.json.example @@ -3,6 +3,7 @@ "flash.client.url": "", "furnidata.load.url": "", "productdata.load.url": "", + "figuredata.load.url": "https://www.habbo.com/gamedata/figuredata/1", "figuremap.load.url": "${flash.client.url}figuremap.xml", "effectmap.load.url": "${flash.client.url}effectmap.xml", "dynamic.download.pet.url": "${flash.client.url}%className%.swf", @@ -17,5 +18,6 @@ "convert.figure": "1", "convert.effect": "1", "convert.furniture": "1", - "convert.pet": "1" + "convert.pet": "1", + "convert.figuredata": "1" } diff --git a/src/converters/figuredata/FigureDataConverter.ts b/src/converters/figuredata/FigureDataConverter.ts new file mode 100644 index 0000000..a2fcc19 --- /dev/null +++ b/src/converters/figuredata/FigureDataConverter.ts @@ -0,0 +1,102 @@ +import { writeFile } from 'fs/promises'; +import * as ora from 'ora'; +import { singleton } from 'tsyringe'; +import { parseStringPromise } from 'xml2js'; +import { Configuration } from '../../common/config/Configuration'; +import { Converter } from '../../common/converters/Converter'; +import { FigureDataMapper } from '../../mapping/mappers/FigureDataMapper'; +import File from '../../utils/File'; +import { Logger } from '../../utils/Logger'; +import { IFigureData } from './../../mapping/json/figuredata/IFigureData'; +import { FigureDataDownloader } from './FigureDataDownloader'; + +@singleton() +export class FigureDataConverter extends Converter +{ + constructor( + private readonly _figureDataDownloader: FigureDataDownloader, + private readonly _configuration: Configuration, + private readonly _logger: Logger) + { + super(); + } + + public async convertAsync(): Promise + { + if(!this._configuration.getBoolean('convert.figuredata')) return; + + return new Promise((resolve, reject) => + { + const now = Date.now(); + + const spinner = ora('Preparing FigureData').start(); + + const directory = this.getDirectory(); + + try + { + this._figureDataDownloader.download(async (content: string) => + { + spinner.text = 'Parsing FigureData'; + + spinner.render(); + + let figureDataString = content; + + if(!figureDataString.startsWith('{')) + { + const xml = await parseStringPromise(figureDataString); + + const figureData = await this.mapXML2JSON(xml); + + figureDataString = JSON.stringify(figureData); + } + + const path = directory.path + '/FigureData.json'; + + await writeFile(path, figureDataString, 'utf8'); + + this._configuration.setValue('figuredata.load.url', path); + + spinner.succeed(`FigureData finished in ${ Date.now() - now }ms`); + + resolve(); + }); + } + + catch (error) + { + spinner.fail('FigureData failed: ' + error.message); + + reject(error); + } + }); + } + + private getDirectory(): File + { + const baseFolder = new File(this._configuration.getValue('output.folder')); + + if(!baseFolder.isDirectory()) baseFolder.mkdirs(); + + const gameDataFolder = new File(baseFolder.path + '/gamedata'); + + if(!gameDataFolder.isDirectory()) gameDataFolder.mkdirs(); + + const jsonFolder = new File(gameDataFolder.path + '/json'); + + if(!jsonFolder.isDirectory()) jsonFolder.mkdirs(); + + return jsonFolder; + } + + private async mapXML2JSON(xml: any): Promise + { + if(!xml) return null; + + const output: IFigureData = {}; + + FigureDataMapper.mapXML(xml, output); + return output; + } +} diff --git a/src/converters/figuredata/FigureDataDownloader.ts b/src/converters/figuredata/FigureDataDownloader.ts new file mode 100644 index 0000000..7b49005 --- /dev/null +++ b/src/converters/figuredata/FigureDataDownloader.ts @@ -0,0 +1,32 @@ +import { singleton } from 'tsyringe'; +import { Configuration } from '../../common/config/Configuration'; +import { FileUtilities } from '../../utils/FileUtilities'; + +@singleton() +export class FigureDataDownloader +{ + constructor(private readonly _configuration: Configuration) + {} + + public async download(callback: (content: string) => Promise): Promise + { + const figureData = await this.parseFigureData(); + + if(!figureData) throw new Error('invalid_figure_data'); + + callback(figureData); + } + + public async parseFigureData(): Promise + { + const url = this._configuration.getValue('figuredata.load.url'); + + if(!url || !url.length) return null; + + const content = await FileUtilities.readFileAsString(url); + + if(!content || !content.length) return null; + + return content; + } +} diff --git a/src/mapping/json/figuredata/IFigureData.ts b/src/mapping/json/figuredata/IFigureData.ts new file mode 100644 index 0000000..98a332a --- /dev/null +++ b/src/mapping/json/figuredata/IFigureData.ts @@ -0,0 +1,8 @@ +import { IFigureDataPalette } from './IFigureDataPalette'; +import { IFigureDataSetType } from './IFigureDataSetType'; + +export interface IFigureData +{ + palettes?: IFigureDataPalette[]; + sets?: IFigureDataSetType[]; +} diff --git a/src/mapping/json/figuredata/IFigureDataColor.ts b/src/mapping/json/figuredata/IFigureDataColor.ts new file mode 100644 index 0000000..325dabc --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataColor.ts @@ -0,0 +1,8 @@ +export interface IFigureDataColor +{ + id?: number; + index?: number; + club?: boolean; + selectable?: boolean; + hexCode?: string; +} diff --git a/src/mapping/json/figuredata/IFigureDataPalette.ts b/src/mapping/json/figuredata/IFigureDataPalette.ts new file mode 100644 index 0000000..f83fa06 --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataPalette.ts @@ -0,0 +1,7 @@ +import { IFigureDataColor } from './IFigureDataColor'; + +export interface IFigureDataPalette +{ + id?: number; + colors?: IFigureDataColor[]; +} diff --git a/src/mapping/json/figuredata/IFigureDataPart.ts b/src/mapping/json/figuredata/IFigureDataPart.ts new file mode 100644 index 0000000..99e89f2 --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataPart.ts @@ -0,0 +1,8 @@ +export interface IFigureDataPart +{ + id?: number; + type?: string; + colorable?: boolean; + index?: number; + colorindex?: number; +} diff --git a/src/mapping/json/figuredata/IFigureDataSet.ts b/src/mapping/json/figuredata/IFigureDataSet.ts new file mode 100644 index 0000000..c17941a --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataSet.ts @@ -0,0 +1,12 @@ +import { IFigureDataPart } from './IFigureDataPart'; + +export interface IFigureDataSet +{ + id?: number; + gender?: string; + club?: boolean; + colorable?: boolean; + selectable?: boolean; + preselectable?: boolean; + parts?: IFigureDataPart[]; +} diff --git a/src/mapping/json/figuredata/IFigureDataSetType.ts b/src/mapping/json/figuredata/IFigureDataSetType.ts new file mode 100644 index 0000000..ab87638 --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataSetType.ts @@ -0,0 +1,12 @@ +import { IFigureDataSet } from './IFigureDataSet'; + +export interface IFigureDataSetType +{ + type?: string; + paletteId?: number; + mandatory_m_0?: boolean; + mandatory_f_0?: boolean; + mandatory_m_1?: boolean; + mandatory_f_1?: boolean; + sets?: IFigureDataSet[]; +} diff --git a/src/mapping/json/figuredata/index.ts b/src/mapping/json/figuredata/index.ts new file mode 100644 index 0000000..192b5ec --- /dev/null +++ b/src/mapping/json/figuredata/index.ts @@ -0,0 +1,6 @@ +export * from './IFigureData'; +export * from './IFigureDataColor'; +export * from './IFigureDataPalette'; +export * from './IFigureDataPart'; +export * from './IFigureDataSet'; +export * from './IFigureDataSetType'; diff --git a/src/mapping/json/index.ts b/src/mapping/json/index.ts index f23311b..fb85944 100644 --- a/src/mapping/json/index.ts +++ b/src/mapping/json/index.ts @@ -1,6 +1,7 @@ export * from './asset'; export * from './effectmap'; export * from './externaltexts'; +export * from './figuredata'; export * from './figuremap'; export * from './furnituredata'; export * from './productdata'; diff --git a/src/mapping/mappers/FigureDataMapper.ts b/src/mapping/mappers/FigureDataMapper.ts new file mode 100644 index 0000000..f986f4e --- /dev/null +++ b/src/mapping/mappers/FigureDataMapper.ts @@ -0,0 +1,166 @@ +import { IFigureDataPalette } from '../json/figuredata/IFigureDataPalette'; +import { IFigureDataSet } from '../json/figuredata/IFigureDataSet'; +import { FigureDataColorXML } from '../xml/figuredata/FigureDataColorXML'; +import { FigureDataPaletteXML } from '../xml/figuredata/FigureDataPaletteXML'; +import { FigureDataXML } from '../xml/figuredata/FigureDataXML'; +import { IFigureData } from './../json/figuredata/IFigureData'; +import { IFigureDataColor } from './../json/figuredata/IFigureDataColor'; +import { IFigureDataPart } from './../json/figuredata/IFigureDataPart'; +import { IFigureDataSetType } from './../json/figuredata/IFigureDataSetType'; +import { FigureDataPartXML } from './../xml/figuredata/FigureDataPartXML'; +import { FigureDataSetTypeXML } from './../xml/figuredata/FigureDataSetTypeXML'; +import { FigureDataSetXML } from './../xml/figuredata/FigureDataSetXML'; +import { Mapper } from './asset/Mapper'; + +export class FigureDataMapper extends Mapper +{ + public static mapXML(xml: any, output: IFigureData): void + { + if(!xml || !output) return; + + if(xml.figuredata !== undefined) FigureDataMapper.mapFigureDataXML(new FigureDataXML(xml.figuredata), output); + } + + private static mapFigureDataXML(xml: FigureDataXML, output: IFigureData): void + { + if(!xml || !output) return; + + if(xml.colorPalettes !== undefined) + { + if(xml.colorPalettes.length) + { + output.palettes = []; + + FigureDataMapper.mapFigureDataColorPalettesXML(xml.colorPalettes, output.palettes); + } + } + + if(xml.sets !== undefined) + { + if(xml.sets.length) + { + output.sets = []; + + FigureDataMapper.mapFigureDataSetTypes(xml.sets, output.sets); + } + } + } + + private static mapFigureDataColorPalettesXML(xml: FigureDataPaletteXML[], output: IFigureDataPalette[]): void + { + if(!xml || !xml.length || !output) return; + + for(const paletteXML of xml) + { + const palette: IFigureDataPalette = {}; + + if(paletteXML.id !== undefined) palette.id = paletteXML.id; + + if(paletteXML.colors !== undefined) + { + if(paletteXML.colors.length) + { + palette.colors = []; + + FigureDataMapper.mapFigureDataPaletteColorsXML(paletteXML.colors, palette.colors); + } + } + + output.push(palette); + } + } + + private static mapFigureDataPaletteColorsXML(xml: FigureDataColorXML[], output: IFigureDataColor[]): void + { + if(!xml || !xml.length || !output) return; + + for(const colorXML of xml) + { + const color: IFigureDataColor = {}; + + if(colorXML.id !== undefined) color.id = colorXML.id; + if(colorXML.index !== undefined) color.index = colorXML.index; + if(colorXML.club !== undefined) color.club = colorXML.club; + if(colorXML.selectable !== undefined) color.selectable = colorXML.selectable; + if(colorXML.hexCode !== undefined) color.hexCode = colorXML.hexCode; + + output.push(color); + } + } + + private static mapFigureDataSetTypes(xml: FigureDataSetTypeXML[], output: IFigureDataSetType[]): void + { + if(!xml || !xml.length || !output) return; + + for(const setTypeXML of xml) + { + const setType: IFigureDataSetType = {}; + + if(setTypeXML.type !== undefined) setType.type = setTypeXML.type; + if(setTypeXML.paletteId !== undefined) setType.paletteId = setTypeXML.paletteId; + if(setTypeXML.mandatoryF0 !== undefined) setType.mandatory_f_0 = setTypeXML.mandatoryF0; + if(setTypeXML.mandatoryF1 !== undefined) setType.mandatory_f_1 = setTypeXML.mandatoryF1; + if(setTypeXML.mandatoryM0 !== undefined) setType.mandatory_m_0 = setTypeXML.mandatoryM0; + if(setTypeXML.mandatoryM1 !== undefined) setType.mandatory_m_1 = setTypeXML.mandatoryM1; + + if(setTypeXML.sets !== undefined) + { + if(setTypeXML.sets.length) + { + setType.sets = []; + + FigureDataMapper.mapFigureDataSets(setTypeXML.sets, setType.sets); + } + } + + output.push(setType); + } + } + + private static mapFigureDataSets(xml: FigureDataSetXML[], output: IFigureDataSet[]): void + { + if(!xml || !xml.length || !output) return; + + for(const setXML of xml) + { + const setType: IFigureDataSet = {}; + + if(setXML.id !== undefined) setType.id = setXML.id; + if(setXML.gender !== undefined) setType.gender = setXML.gender; + if(setXML.club !== undefined) setType.club = setXML.club; + if(setXML.colorable !== undefined) setType.colorable = setXML.colorable; + if(setXML.selectable !== undefined) setType.selectable = setXML.selectable; + if(setXML.preselectable !== undefined) setType.preselectable = setXML.preselectable; + + if(setXML.parts !== undefined) + { + if(setXML.parts.length) + { + setType.parts = []; + + FigureDataMapper.mapFigureDataParts(setXML.parts, setType.parts); + } + } + + output.push(setType); + } + } + + private static mapFigureDataParts(xml: FigureDataPartXML[], output: IFigureDataPart[]): void + { + if(!xml || !xml.length || !output) return; + + for(const partXML of xml) + { + const part: IFigureDataPart = {}; + + if(partXML.id !== undefined) part.id = partXML.id; + if(partXML.type !== undefined) part.type = partXML.type; + if(partXML.colorable !== undefined) part.colorable = partXML.colorable; + if(partXML.index !== undefined) part.index = partXML.index; + if(partXML.colorIndex !== undefined) part.colorindex = partXML.colorIndex; + + output.push(part); + } + } +} diff --git a/src/mapping/mappers/index.ts b/src/mapping/mappers/index.ts index 5629e41..4478190 100644 --- a/src/mapping/mappers/index.ts +++ b/src/mapping/mappers/index.ts @@ -1,4 +1,5 @@ export * from './asset'; export * from './EffectMapMapper'; +export * from './FigureDataMapper'; export * from './FigureMapMapper'; export * from './FurnitureDataMapper'; diff --git a/src/mapping/xml/figuredata/FigureDataColorXML.ts b/src/mapping/xml/figuredata/FigureDataColorXML.ts new file mode 100644 index 0000000..6161d19 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataColorXML.ts @@ -0,0 +1,45 @@ +export class FigureDataColorXML +{ + private _id: number; + private _index: number; + private _club: boolean; + private _selectable: boolean; + private _hexCode: string; + + constructor(xml: any) + { + const attributes = xml.$; + + this._id = ((attributes && parseInt(attributes.id)) || 0); + this._index = ((attributes && parseInt(attributes.index)) || 0); + this._club = ((attributes && parseInt(attributes.club) === 1) || false); + this._selectable = ((attributes && parseInt(attributes.selectable) === 1) || false); + + this._hexCode = ((xml && xml._) || ''); + } + + public get id(): number + { + return this._id; + } + + public get index(): number + { + return this._index; + } + + public get club(): boolean + { + return this._club; + } + + public get selectable(): boolean + { + return this._selectable; + } + + public get hexCode(): string + { + return this._hexCode; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataPaletteXML.ts b/src/mapping/xml/figuredata/FigureDataPaletteXML.ts new file mode 100644 index 0000000..6be509c --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataPaletteXML.ts @@ -0,0 +1,39 @@ +import { FigureDataColorXML } from './FigureDataColorXML'; + +export class FigureDataPaletteXML +{ + private _id: number; + private _colors: FigureDataColorXML[]; + + constructor(xml: any) + { + if(xml.color !== undefined) + { + if(Array.isArray(xml.color)) + { + this._colors = []; + + for(const col in xml.color) + { + const color = xml.color[col]; + + this._colors.push(new FigureDataColorXML(color)); + } + } + } + + const attributes = xml.$; + + this._id = ((attributes && parseInt(attributes.id)) || 0); + } + + public get id(): number + { + return this._id; + } + + public get colors(): FigureDataColorXML[] + { + return this._colors; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataPartXML.ts b/src/mapping/xml/figuredata/FigureDataPartXML.ts new file mode 100644 index 0000000..2194b27 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataPartXML.ts @@ -0,0 +1,44 @@ +export class FigureDataPartXML +{ + private _id: number; + private _type: string; + private _colorable: boolean; + private _index: number; + private _colorindex: number; + + constructor(xml: any) + { + const attributes = xml.$; + + this._id = ((attributes && parseInt(attributes.id)) || 0); + this._type = ((attributes && attributes.type) || ''); + this._colorable = ((attributes && parseInt(attributes.colorable) === 1) || false); + this._index = ((attributes && parseInt(attributes.index)) || 0); + this._colorindex = ((attributes && parseInt(attributes.colorindex)) || 0); + } + + public get id(): number + { + return this._id; + } + + public get type(): string + { + return this._type; + } + + public get colorable(): boolean + { + return this._colorable; + } + + public get index(): number + { + return this._index; + } + + public get colorIndex(): number + { + return this._colorindex; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataSetTypeXML.ts b/src/mapping/xml/figuredata/FigureDataSetTypeXML.ts new file mode 100644 index 0000000..40368c0 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataSetTypeXML.ts @@ -0,0 +1,74 @@ +import { FigureDataSetXML } from './FigureDataSetXML'; + +export class FigureDataSetTypeXML +{ + private _type: string; + private _paletteId: number; + private _mandatory_m_0: boolean; + private _mandatory_f_0: boolean; + private _mandatory_m_1: boolean; + private _mandatory_f_1: boolean; + private _sets: FigureDataSetXML[]; + + constructor(xml: any) + { + const attributes = xml.$; + + this._type = ((attributes && attributes.type) || ''); + this._paletteId = ((attributes && parseInt(attributes.paletteid)) || 1); + this._mandatory_m_0 = ((attributes && parseInt(attributes.mand_m_0) == 1) || false); + this._mandatory_f_0 = ((attributes && parseInt(attributes.mand_f_0) == 1) || false); + this._mandatory_m_1 = ((attributes && parseInt(attributes.mand_m_1) == 1) || false); + this._mandatory_f_1 = ((attributes && parseInt(attributes.mand_f_1) == 1) || false); + + if(xml.set !== undefined) + { + if(Array.isArray(xml.set)) + { + this._sets = []; + + for(const index in xml.set) + { + const set = xml.set[index]; + + this._sets.push(new FigureDataSetXML(set)); + } + } + } + } + + public get type(): string + { + return this._type; + } + + public get paletteId(): number + { + return this._paletteId; + } + + public get mandatoryM0(): boolean + { + return this._mandatory_m_0; + } + + public get mandatoryM1(): boolean + { + return this._mandatory_m_1; + } + + public get mandatoryF0(): boolean + { + return this._mandatory_f_0; + } + + public get mandatoryF1(): boolean + { + return this._mandatory_f_1; + } + + public get sets(): FigureDataSetXML[] + { + return this._sets; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataSetXML.ts b/src/mapping/xml/figuredata/FigureDataSetXML.ts new file mode 100644 index 0000000..ca65f24 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataSetXML.ts @@ -0,0 +1,74 @@ +import { FigureDataPartXML } from './FigureDataPartXML'; + +export class FigureDataSetXML +{ + private _id: number; + private _gender: string; + private _club: boolean; + private _colorable: boolean; + private _selectable: boolean; + private _preselectable: boolean; + private _parts: FigureDataPartXML[]; + + constructor(xml: any) + { + const attributes = xml.$; + + this._id = ((attributes && parseInt(attributes.id)) || 0); + this._gender = ((attributes && attributes.gender) || ''); + this._club = ((attributes && parseInt(attributes.club) === 1) || false); + this._colorable = ((attributes && parseInt(attributes.colorable) === 1) || false); + this._selectable = ((attributes && parseInt(attributes.selectable) === 1) || false); + this._preselectable = ((attributes && parseInt(attributes.preselectable) === 1) || false); + + if(xml.part !== undefined) + { + if(Array.isArray(xml.part)) + { + this._parts = []; + + for(const index in xml.part) + { + const part = xml.part[index]; + + this._parts.push(new FigureDataPartXML(part)); + } + } + } + } + + public get id(): number + { + return this._id; + } + + public get gender(): string + { + return this._gender; + } + + public get club(): boolean + { + return this._club; + } + + public get colorable(): boolean + { + return this._colorable; + } + + public get selectable(): boolean + { + return this._selectable; + } + + public get preselectable(): boolean + { + return this._preselectable; + } + + public get parts(): FigureDataPartXML[] + { + return this._parts; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataXML.ts b/src/mapping/xml/figuredata/FigureDataXML.ts new file mode 100644 index 0000000..d5a0414 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataXML.ts @@ -0,0 +1,55 @@ +import { FigureDataPaletteXML } from './FigureDataPaletteXML'; +import { FigureDataSetTypeXML } from './FigureDataSetTypeXML'; + +export class FigureDataXML +{ + private _colorPalettes: FigureDataPaletteXML[]; + private _sets: FigureDataSetTypeXML[]; + + constructor(xml: any) + { + if(xml.colors !== undefined && xml.colors[0].palette !== undefined) + { + const paletteArr = xml.colors[0].palette; + + if(Array.isArray(paletteArr)) + { + this._colorPalettes = []; + + for(const pal in paletteArr) + { + const palette = paletteArr[pal]; + + this._colorPalettes.push(new FigureDataPaletteXML(palette)); + } + } + } + + if(xml.sets !== undefined && xml.sets[0].settype !== undefined) + { + const setTypeArr = xml.sets[0].settype; + + if(Array.isArray(setTypeArr)) + { + this._sets = []; + + for(const set in setTypeArr) + { + const setType = setTypeArr[set]; + + this._sets.push(new FigureDataSetTypeXML(setType)); + } + } + } + } + + public get colorPalettes(): FigureDataPaletteXML[] + { + return this._colorPalettes; + } + + public get sets(): FigureDataSetTypeXML[] + { + return this._sets; + } +} diff --git a/src/mapping/xml/figuredata/index.ts b/src/mapping/xml/figuredata/index.ts new file mode 100644 index 0000000..bbafa13 --- /dev/null +++ b/src/mapping/xml/figuredata/index.ts @@ -0,0 +1,6 @@ +export * from './FigureDataColorXML'; +export * from './FigureDataPaletteXML'; +export * from './FigureDataPartXML'; +export * from './FigureDataSetTypeXML'; +export * from './FigureDataSetXML'; +export * from './FigureDataXML'; diff --git a/src/mapping/xml/index.ts b/src/mapping/xml/index.ts index 8a7330a..cd405d0 100644 --- a/src/mapping/xml/index.ts +++ b/src/mapping/xml/index.ts @@ -1,4 +1,5 @@ export * from './asset'; export * from './effectmap'; +export * from './figuredata'; export * from './figuremap'; export * from './furnituredata';