From ac3bd7fbb021ee031a2de09c115726d6325d17c5 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Tue, 3 Aug 2021 02:15:05 -0500 Subject: [PATCH 1/6] 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'; From 759bc72cebd437c4b3d5980238f562d10a3c25a1 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Tue, 3 Aug 2021 02:22:41 -0500 Subject: [PATCH 2/6] rename settype array --- src/mapping/json/figuredata/IFigureData.ts | 2 +- src/mapping/mappers/FigureDataMapper.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mapping/json/figuredata/IFigureData.ts b/src/mapping/json/figuredata/IFigureData.ts index 98a332a..86e7901 100644 --- a/src/mapping/json/figuredata/IFigureData.ts +++ b/src/mapping/json/figuredata/IFigureData.ts @@ -4,5 +4,5 @@ import { IFigureDataSetType } from './IFigureDataSetType'; export interface IFigureData { palettes?: IFigureDataPalette[]; - sets?: IFigureDataSetType[]; + setTypes?: IFigureDataSetType[]; } diff --git a/src/mapping/mappers/FigureDataMapper.ts b/src/mapping/mappers/FigureDataMapper.ts index f986f4e..43392f1 100644 --- a/src/mapping/mappers/FigureDataMapper.ts +++ b/src/mapping/mappers/FigureDataMapper.ts @@ -39,9 +39,9 @@ export class FigureDataMapper extends Mapper { if(xml.sets.length) { - output.sets = []; + output.setTypes = []; - FigureDataMapper.mapFigureDataSetTypes(xml.sets, output.sets); + FigureDataMapper.mapFigureDataSetTypes(xml.sets, output.setTypes); } } } From 245c2683d67b8f3649f85ca5c59f056960cbf457 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Tue, 3 Aug 2021 02:29:11 -0500 Subject: [PATCH 3/6] add script for single-run no watch to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a6046ac..46b55de 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "scripts": { + "start": "ts-node-transpile-only src/Main.ts", "start:dev": "ts-node-dev --respawn --transpile-only src/Main.ts" }, "author": "", From 3127b33eb50a999dcd8d21dd187fd7323e3626dc Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 3 Aug 2021 12:17:21 -0400 Subject: [PATCH 4/6] Fix club level --- src/converters/figuredata/FigureDataConverter.ts | 1 + src/mapping/json/figuredata/IFigureDataColor.ts | 2 +- src/mapping/xml/figuredata/FigureDataColorXML.ts | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/converters/figuredata/FigureDataConverter.ts b/src/converters/figuredata/FigureDataConverter.ts index a2fcc19..04f7335 100644 --- a/src/converters/figuredata/FigureDataConverter.ts +++ b/src/converters/figuredata/FigureDataConverter.ts @@ -97,6 +97,7 @@ export class FigureDataConverter extends Converter const output: IFigureData = {}; FigureDataMapper.mapXML(xml, output); + return output; } } diff --git a/src/mapping/json/figuredata/IFigureDataColor.ts b/src/mapping/json/figuredata/IFigureDataColor.ts index 325dabc..76a65fd 100644 --- a/src/mapping/json/figuredata/IFigureDataColor.ts +++ b/src/mapping/json/figuredata/IFigureDataColor.ts @@ -2,7 +2,7 @@ export interface IFigureDataColor { id?: number; index?: number; - club?: boolean; + club?: number; selectable?: boolean; hexCode?: string; } diff --git a/src/mapping/xml/figuredata/FigureDataColorXML.ts b/src/mapping/xml/figuredata/FigureDataColorXML.ts index 6161d19..292d34f 100644 --- a/src/mapping/xml/figuredata/FigureDataColorXML.ts +++ b/src/mapping/xml/figuredata/FigureDataColorXML.ts @@ -2,7 +2,7 @@ export class FigureDataColorXML { private _id: number; private _index: number; - private _club: boolean; + private _club: number; private _selectable: boolean; private _hexCode: string; @@ -12,7 +12,7 @@ export class FigureDataColorXML this._id = ((attributes && parseInt(attributes.id)) || 0); this._index = ((attributes && parseInt(attributes.index)) || 0); - this._club = ((attributes && parseInt(attributes.club) === 1) || false); + this._club = ((attributes && parseInt(attributes.club)) || 0); this._selectable = ((attributes && parseInt(attributes.selectable) === 1) || false); this._hexCode = ((xml && xml._) || ''); @@ -28,7 +28,7 @@ export class FigureDataColorXML return this._index; } - public get club(): boolean + public get club(): number { return this._club; } From e6a7f3dde5cf7b11d3ccb27a82c6cd7f040e47b6 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 3 Aug 2021 14:07:45 -0400 Subject: [PATCH 5/6] Add stuff skelly missed --- .vscode/settings.json | 1 + .../json/figuredata/IFigureDataColor.ts | 10 +++--- .../json/figuredata/IFigureDataHiddenLayer.ts | 4 +++ .../json/figuredata/IFigureDataPart.ts | 10 +++--- src/mapping/json/figuredata/IFigureDataSet.ts | 17 +++++---- .../json/figuredata/IFigureDataSetType.ts | 14 ++++---- src/mapping/json/figuredata/index.ts | 1 + src/mapping/mappers/FigureDataMapper.ts | 27 ++++++++++++++ .../figuredata/FigureDataHiddenLayerXML.ts | 16 +++++++++ .../xml/figuredata/FigureDataSetXML.ts | 35 +++++++++++++++++-- src/mapping/xml/figuredata/index.ts | 1 + 11 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 src/mapping/json/figuredata/IFigureDataHiddenLayer.ts create mode 100644 src/mapping/xml/figuredata/FigureDataHiddenLayerXML.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 7b328b8..98e959b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "typescript.format.placeOpenBraceOnNewLineForFunctions": true, "editor.codeActionsOnSave": { "source.fixAll": true, + "source.fixAll.sortJSON": false, "source.organizeImports": true, }, "emmet.showExpandedAbbreviation": "never", diff --git a/src/mapping/json/figuredata/IFigureDataColor.ts b/src/mapping/json/figuredata/IFigureDataColor.ts index 76a65fd..535dead 100644 --- a/src/mapping/json/figuredata/IFigureDataColor.ts +++ b/src/mapping/json/figuredata/IFigureDataColor.ts @@ -1,8 +1,8 @@ export interface IFigureDataColor { - id?: number; - index?: number; - club?: number; - selectable?: boolean; - hexCode?: string; + id?: number; + index?: number; + club?: number; + selectable?: boolean; + hexCode?: string; } diff --git a/src/mapping/json/figuredata/IFigureDataHiddenLayer.ts b/src/mapping/json/figuredata/IFigureDataHiddenLayer.ts new file mode 100644 index 0000000..80f42e6 --- /dev/null +++ b/src/mapping/json/figuredata/IFigureDataHiddenLayer.ts @@ -0,0 +1,4 @@ +export interface IFigureDataHiddenLayer +{ + partType?: string; +} diff --git a/src/mapping/json/figuredata/IFigureDataPart.ts b/src/mapping/json/figuredata/IFigureDataPart.ts index 99e89f2..e57ef47 100644 --- a/src/mapping/json/figuredata/IFigureDataPart.ts +++ b/src/mapping/json/figuredata/IFigureDataPart.ts @@ -1,8 +1,8 @@ export interface IFigureDataPart { - id?: number; - type?: string; - colorable?: boolean; - index?: number; - colorindex?: number; + 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 index c17941a..f3c89d9 100644 --- a/src/mapping/json/figuredata/IFigureDataSet.ts +++ b/src/mapping/json/figuredata/IFigureDataSet.ts @@ -1,12 +1,15 @@ +import { IFigureDataHiddenLayer } from './IFigureDataHiddenLayer'; import { IFigureDataPart } from './IFigureDataPart'; export interface IFigureDataSet { - id?: number; - gender?: string; - club?: boolean; - colorable?: boolean; - selectable?: boolean; - preselectable?: boolean; - parts?: IFigureDataPart[]; + id?: number; + gender?: string; + club?: number; + colorable?: boolean; + selectable?: boolean; + preselectable?: boolean; + sellable?: boolean; + parts?: IFigureDataPart[]; + hiddenLayers?: IFigureDataHiddenLayer[]; } diff --git a/src/mapping/json/figuredata/IFigureDataSetType.ts b/src/mapping/json/figuredata/IFigureDataSetType.ts index ab87638..d9a2d97 100644 --- a/src/mapping/json/figuredata/IFigureDataSetType.ts +++ b/src/mapping/json/figuredata/IFigureDataSetType.ts @@ -2,11 +2,11 @@ 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[]; + 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 index 192b5ec..579987b 100644 --- a/src/mapping/json/figuredata/index.ts +++ b/src/mapping/json/figuredata/index.ts @@ -1,5 +1,6 @@ export * from './IFigureData'; export * from './IFigureDataColor'; +export * from './IFigureDataHiddenLayer'; export * from './IFigureDataPalette'; export * from './IFigureDataPart'; export * from './IFigureDataSet'; diff --git a/src/mapping/mappers/FigureDataMapper.ts b/src/mapping/mappers/FigureDataMapper.ts index 43392f1..8b50a40 100644 --- a/src/mapping/mappers/FigureDataMapper.ts +++ b/src/mapping/mappers/FigureDataMapper.ts @@ -1,5 +1,7 @@ +import { IFigureDataHiddenLayer } from '../json'; import { IFigureDataPalette } from '../json/figuredata/IFigureDataPalette'; import { IFigureDataSet } from '../json/figuredata/IFigureDataSet'; +import { FigureDataHiddenLayerXML } from '../xml'; import { FigureDataColorXML } from '../xml/figuredata/FigureDataColorXML'; import { FigureDataPaletteXML } from '../xml/figuredata/FigureDataPaletteXML'; import { FigureDataXML } from '../xml/figuredata/FigureDataXML'; @@ -131,6 +133,7 @@ export class FigureDataMapper extends Mapper 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.sellable !== undefined) setType.sellable = setXML.sellable; if(setXML.parts !== undefined) { @@ -142,6 +145,16 @@ export class FigureDataMapper extends Mapper } } + if(setXML.hiddenLayers !== undefined) + { + if(setXML.hiddenLayers.length) + { + setType.hiddenLayers = []; + + FigureDataMapper.mapFigureDataHiddenLayers(setXML.hiddenLayers, setType.hiddenLayers); + } + } + output.push(setType); } } @@ -163,4 +176,18 @@ export class FigureDataMapper extends Mapper output.push(part); } } + + private static mapFigureDataHiddenLayers(xml: FigureDataHiddenLayerXML[], output: IFigureDataHiddenLayer[]): void + { + if(!xml || !xml.length || !output) return; + + for(const hiddenLayerXML of xml) + { + const hiddenLayer: IFigureDataHiddenLayer = {}; + + if(hiddenLayerXML.partType !== undefined) hiddenLayer.partType = hiddenLayerXML.partType; + + output.push(hiddenLayer); + } + } } diff --git a/src/mapping/xml/figuredata/FigureDataHiddenLayerXML.ts b/src/mapping/xml/figuredata/FigureDataHiddenLayerXML.ts new file mode 100644 index 0000000..bbba173 --- /dev/null +++ b/src/mapping/xml/figuredata/FigureDataHiddenLayerXML.ts @@ -0,0 +1,16 @@ +export class FigureDataHiddenLayerXML +{ + private _partType: string; + + constructor(xml: any) + { + const attributes = xml.$; + + this._partType = ((attributes && attributes.parttype) || ''); + } + + public get partType(): string + { + return this._partType; + } +} diff --git a/src/mapping/xml/figuredata/FigureDataSetXML.ts b/src/mapping/xml/figuredata/FigureDataSetXML.ts index ca65f24..b4bc094 100644 --- a/src/mapping/xml/figuredata/FigureDataSetXML.ts +++ b/src/mapping/xml/figuredata/FigureDataSetXML.ts @@ -1,14 +1,17 @@ +import { FigureDataHiddenLayerXML } from './FigureDataHiddenLayerXML'; import { FigureDataPartXML } from './FigureDataPartXML'; export class FigureDataSetXML { private _id: number; private _gender: string; - private _club: boolean; + private _club: number; private _colorable: boolean; private _selectable: boolean; private _preselectable: boolean; + private _sellable: boolean; private _parts: FigureDataPartXML[]; + private _hiddenLayers: FigureDataHiddenLayerXML[]; constructor(xml: any) { @@ -16,10 +19,11 @@ export class FigureDataSetXML this._id = ((attributes && parseInt(attributes.id)) || 0); this._gender = ((attributes && attributes.gender) || ''); - this._club = ((attributes && parseInt(attributes.club) === 1) || false); + this._club = ((attributes && parseInt(attributes.club)) || 0); this._colorable = ((attributes && parseInt(attributes.colorable) === 1) || false); this._selectable = ((attributes && parseInt(attributes.selectable) === 1) || false); this._preselectable = ((attributes && parseInt(attributes.preselectable) === 1) || false); + this._sellable = ((attributes && parseInt(attributes.sellable) === 1) || false); if(xml.part !== undefined) { @@ -35,6 +39,21 @@ export class FigureDataSetXML } } } + + if(xml.hiddenlayers !== undefined) + { + this._hiddenLayers = []; + + for(const hiddenLayer of xml.hiddenlayers) + { + const layers = hiddenLayer.layer; + + if(layers !== undefined) + { + if(Array.isArray(layers)) for(const layer of layers) this._hiddenLayers.push(new FigureDataHiddenLayerXML(layer)); + } + } + } } public get id(): number @@ -47,7 +66,7 @@ export class FigureDataSetXML return this._gender; } - public get club(): boolean + public get club(): number { return this._club; } @@ -67,8 +86,18 @@ export class FigureDataSetXML return this._preselectable; } + public get sellable(): boolean + { + return this._sellable; + } + public get parts(): FigureDataPartXML[] { return this._parts; } + + public get hiddenLayers(): FigureDataHiddenLayerXML[] + { + return this._hiddenLayers; + } } diff --git a/src/mapping/xml/figuredata/index.ts b/src/mapping/xml/figuredata/index.ts index bbafa13..9a4ab5e 100644 --- a/src/mapping/xml/figuredata/index.ts +++ b/src/mapping/xml/figuredata/index.ts @@ -1,4 +1,5 @@ export * from './FigureDataColorXML'; +export * from './FigureDataHiddenLayerXML'; export * from './FigureDataPaletteXML'; export * from './FigureDataPartXML'; export * from './FigureDataSetTypeXML'; From df4d9bda98f64ac0cc39c9437d265d6bb02b5126 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 3 Aug 2021 14:17:03 -0400 Subject: [PATCH 6/6] More updates --- README.md | 4 +++- src/Main.ts | 1 + src/configuration.json.example | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 80ddc34..0ac3c73 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ The converter currently supports the following files: - furnidata.xml +- figuredata.xml - figuremap.xml - effectmap.xml - external_texts.txt @@ -40,6 +41,7 @@ You may set any of the urls to a local path on your system or a remote url. A lo | convert.productdata | Either `0` to skip or `1` to run | | convert.externaltexts | Either `0` to skip or `1` to run | | convert.figure | Either `0` to skip or `1` to run | +| convert.figuredata | Either `0` to skip or `1` to run | | convert.effect | Either `0` to skip or `1` to run | | convert.furniture | Either `0` to skip or `1` to run | | convert.pet | Either `0` to skip or `1` to run | @@ -50,6 +52,6 @@ To run the converter open a new terminal / console window in the main converter **Make sure you run ``npm i`` before first use.** -Type `npm run start:dev` and the converter will start running, only errors will be outputted in the console. +Type `npm start` and the converter will start running, only errors will be outputted in the console. The converter will skip any assets that already exist but will always reconvert your XMLs / copy your JSONS to the ``gamedata`` folder to ensure you always have the latest copy. diff --git a/src/Main.ts b/src/Main.ts index 6ed14a6..c4aa86c 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -13,6 +13,7 @@ import { ProductDataConverter } from './converters/productdata/ProductDataConver (async () => { checkNodeVersion(); + const config = container.resolve(Configuration); await config.init(); diff --git a/src/configuration.json.example b/src/configuration.json.example index 739a6b8..cd6fd92 100644 --- a/src/configuration.json.example +++ b/src/configuration.json.example @@ -16,8 +16,8 @@ "convert.productdata": "1", "convert.externaltexts": "1", "convert.figure": "1", + "convert.figuredata": "1", "convert.effect": "1", "convert.furniture": "1", - "convert.pet": "1", - "convert.figuredata": "1" + "convert.pet": "1" }