mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-22 23:50:52 +01:00
added figuredata converter
This commit is contained in:
parent
44cf84ea72
commit
ac3bd7fbb0
@ -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)
|
||||
|
@ -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"
|
||||
}
|
||||
|
102
src/converters/figuredata/FigureDataConverter.ts
Normal file
102
src/converters/figuredata/FigureDataConverter.ts
Normal file
@ -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<void>
|
||||
{
|
||||
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<IFigureData>
|
||||
{
|
||||
if(!xml) return null;
|
||||
|
||||
const output: IFigureData = {};
|
||||
|
||||
FigureDataMapper.mapXML(xml, output);
|
||||
return output;
|
||||
}
|
||||
}
|
32
src/converters/figuredata/FigureDataDownloader.ts
Normal file
32
src/converters/figuredata/FigureDataDownloader.ts
Normal file
@ -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<void>): Promise<void>
|
||||
{
|
||||
const figureData = await this.parseFigureData();
|
||||
|
||||
if(!figureData) throw new Error('invalid_figure_data');
|
||||
|
||||
callback(figureData);
|
||||
}
|
||||
|
||||
public async parseFigureData(): Promise<string>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
8
src/mapping/json/figuredata/IFigureData.ts
Normal file
8
src/mapping/json/figuredata/IFigureData.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { IFigureDataPalette } from './IFigureDataPalette';
|
||||
import { IFigureDataSetType } from './IFigureDataSetType';
|
||||
|
||||
export interface IFigureData
|
||||
{
|
||||
palettes?: IFigureDataPalette[];
|
||||
sets?: IFigureDataSetType[];
|
||||
}
|
8
src/mapping/json/figuredata/IFigureDataColor.ts
Normal file
8
src/mapping/json/figuredata/IFigureDataColor.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export interface IFigureDataColor
|
||||
{
|
||||
id?: number;
|
||||
index?: number;
|
||||
club?: boolean;
|
||||
selectable?: boolean;
|
||||
hexCode?: string;
|
||||
}
|
7
src/mapping/json/figuredata/IFigureDataPalette.ts
Normal file
7
src/mapping/json/figuredata/IFigureDataPalette.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IFigureDataColor } from './IFigureDataColor';
|
||||
|
||||
export interface IFigureDataPalette
|
||||
{
|
||||
id?: number;
|
||||
colors?: IFigureDataColor[];
|
||||
}
|
8
src/mapping/json/figuredata/IFigureDataPart.ts
Normal file
8
src/mapping/json/figuredata/IFigureDataPart.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export interface IFigureDataPart
|
||||
{
|
||||
id?: number;
|
||||
type?: string;
|
||||
colorable?: boolean;
|
||||
index?: number;
|
||||
colorindex?: number;
|
||||
}
|
12
src/mapping/json/figuredata/IFigureDataSet.ts
Normal file
12
src/mapping/json/figuredata/IFigureDataSet.ts
Normal file
@ -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[];
|
||||
}
|
12
src/mapping/json/figuredata/IFigureDataSetType.ts
Normal file
12
src/mapping/json/figuredata/IFigureDataSetType.ts
Normal file
@ -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[];
|
||||
}
|
6
src/mapping/json/figuredata/index.ts
Normal file
6
src/mapping/json/figuredata/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from './IFigureData';
|
||||
export * from './IFigureDataColor';
|
||||
export * from './IFigureDataPalette';
|
||||
export * from './IFigureDataPart';
|
||||
export * from './IFigureDataSet';
|
||||
export * from './IFigureDataSetType';
|
@ -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';
|
||||
|
166
src/mapping/mappers/FigureDataMapper.ts
Normal file
166
src/mapping/mappers/FigureDataMapper.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
export * from './asset';
|
||||
export * from './EffectMapMapper';
|
||||
export * from './FigureDataMapper';
|
||||
export * from './FigureMapMapper';
|
||||
export * from './FurnitureDataMapper';
|
||||
|
45
src/mapping/xml/figuredata/FigureDataColorXML.ts
Normal file
45
src/mapping/xml/figuredata/FigureDataColorXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
39
src/mapping/xml/figuredata/FigureDataPaletteXML.ts
Normal file
39
src/mapping/xml/figuredata/FigureDataPaletteXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
44
src/mapping/xml/figuredata/FigureDataPartXML.ts
Normal file
44
src/mapping/xml/figuredata/FigureDataPartXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
74
src/mapping/xml/figuredata/FigureDataSetTypeXML.ts
Normal file
74
src/mapping/xml/figuredata/FigureDataSetTypeXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
74
src/mapping/xml/figuredata/FigureDataSetXML.ts
Normal file
74
src/mapping/xml/figuredata/FigureDataSetXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
55
src/mapping/xml/figuredata/FigureDataXML.ts
Normal file
55
src/mapping/xml/figuredata/FigureDataXML.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
6
src/mapping/xml/figuredata/index.ts
Normal file
6
src/mapping/xml/figuredata/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from './FigureDataColorXML';
|
||||
export * from './FigureDataPaletteXML';
|
||||
export * from './FigureDataPartXML';
|
||||
export * from './FigureDataSetTypeXML';
|
||||
export * from './FigureDataSetXML';
|
||||
export * from './FigureDataXML';
|
@ -1,4 +1,5 @@
|
||||
export * from './asset';
|
||||
export * from './effectmap';
|
||||
export * from './figuredata';
|
||||
export * from './figuremap';
|
||||
export * from './furnituredata';
|
||||
|
Loading…
Reference in New Issue
Block a user