From cca7ac6a26d7db67ae05e640f3607656148fd511 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 23 Dec 2021 12:11:37 -0500 Subject: [PATCH] Fix .gitignore --- .gitignore | 2 +- .../mapping/xml/asset/assets/AssetXML.ts | 61 +++++++++++++++++ .../mapping/xml/asset/assets/AssetsXML.ts | 41 +++++++++++ .../mapping/xml/asset/assets/PaletteXML.ts | 68 +++++++++++++++++++ src/common/mapping/xml/asset/assets/index.ts | 3 + 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/common/mapping/xml/asset/assets/AssetXML.ts create mode 100644 src/common/mapping/xml/asset/assets/AssetsXML.ts create mode 100644 src/common/mapping/xml/asset/assets/PaletteXML.ts create mode 100644 src/common/mapping/xml/asset/assets/index.ts diff --git a/.gitignore b/.gitignore index e005d9d..55ea89f 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ Thumbs.db *.as *.bin .env -assets/ +/assets # Nitro /src/configuration.json diff --git a/src/common/mapping/xml/asset/assets/AssetXML.ts b/src/common/mapping/xml/asset/assets/AssetXML.ts new file mode 100644 index 0000000..9c9fd16 --- /dev/null +++ b/src/common/mapping/xml/asset/assets/AssetXML.ts @@ -0,0 +1,61 @@ +export class AssetXML +{ + private readonly _name: string; + private readonly _source: string; + private readonly _x: number; + private readonly _y: number; + private readonly _flipH: boolean; + private readonly _flipV: boolean; + private readonly _usesPalette: boolean; + + constructor(asset: any) + { + const attributes = asset.$; + + if(attributes !== undefined) + { + if(attributes.name !== undefined) this._name = attributes.name; + if(attributes.source !== undefined) this._source = attributes.source; + if(attributes.x !== undefined) this._x = parseInt(attributes.x); + if(attributes.x !== undefined) this._y = parseInt(attributes.y); + if(attributes.flipH !== undefined) this._flipH = (attributes.flipH === '1'); + if(attributes.flipV !== undefined) this._flipV = (attributes.flipV === '1'); + if(attributes.usesPalette !== undefined) this._usesPalette = (attributes.usesPalette === '1'); + } + } + + public get name(): string + { + return this._name; + } + + public get source(): string + { + return this._source; + } + + public get x(): number + { + return this._x; + } + + public get y(): number + { + return this._y; + } + + public get flipH(): boolean + { + return this._flipH; + } + + public get flipV(): boolean + { + return this._flipV; + } + + public get usesPalette(): boolean + { + return this._usesPalette; + } +} diff --git a/src/common/mapping/xml/asset/assets/AssetsXML.ts b/src/common/mapping/xml/asset/assets/AssetsXML.ts new file mode 100644 index 0000000..94c3599 --- /dev/null +++ b/src/common/mapping/xml/asset/assets/AssetsXML.ts @@ -0,0 +1,41 @@ +import { AssetXML } from './AssetXML'; +import { PaletteXML } from './PaletteXML'; + +export class AssetsXML +{ + private readonly _assets: AssetXML[]; + private readonly _palettes: PaletteXML[]; + + constructor(xml: any) + { + if(xml.asset !== undefined) + { + if(Array.isArray(xml.asset)) + { + this._assets = []; + + for(const asset of xml.asset) this._assets.push(new AssetXML(asset)); + } + } + + if(xml.palette !== undefined) + { + if(Array.isArray(xml.palette)) + { + this._palettes = []; + + for(const palette of xml.palette) this._palettes.push(new PaletteXML(palette)); + } + } + } + + public get assets(): AssetXML[] + { + return this._assets; + } + + public get palettes(): PaletteXML[] + { + return this._palettes; + } +} diff --git a/src/common/mapping/xml/asset/assets/PaletteXML.ts b/src/common/mapping/xml/asset/assets/PaletteXML.ts new file mode 100644 index 0000000..d0bae8d --- /dev/null +++ b/src/common/mapping/xml/asset/assets/PaletteXML.ts @@ -0,0 +1,68 @@ +export class PaletteXML +{ + private readonly _id: number; + private readonly _source: string; + private readonly _master: boolean; + private readonly _tags: string[]; + private readonly _breed: number; + private readonly _colorTag: number; + private readonly _color1: string; + private readonly _color2: string; + + constructor(xml: any) + { + const attributes = xml.$; + + if(attributes) + { + if(attributes.id !== undefined) this._id = parseInt(attributes.id); + if(attributes.source !== undefined) this._source = attributes.source; + if(attributes.master !== undefined) this._master = (attributes.master === 'true') ? true : false; + if(attributes.tags !== undefined) this._tags = attributes.tags.split(','); + if(attributes.breed !== undefined) this._breed = parseInt(attributes.breed); + if(attributes.colortag !== undefined) this._colorTag = parseInt(attributes.colortag); + if(attributes.color1 !== undefined) this._color1 = attributes.color1; + if(attributes.color2 !== undefined) this._color2 = attributes.color2; + } + } + + public get id(): number + { + return this._id; + } + + public get source(): string + { + return this._source; + } + + public get master(): boolean + { + return this._master; + } + + public get tags(): string[] + { + return this._tags; + } + + public get breed(): number + { + return this._breed; + } + + public get colorTag(): number + { + return this._colorTag; + } + + public get color1(): string + { + return this._color1; + } + + public get color2(): string + { + return this._color2; + } +} diff --git a/src/common/mapping/xml/asset/assets/index.ts b/src/common/mapping/xml/asset/assets/index.ts new file mode 100644 index 0000000..433c955 --- /dev/null +++ b/src/common/mapping/xml/asset/assets/index.ts @@ -0,0 +1,3 @@ +export * from './AssetsXML'; +export * from './AssetXML'; +export * from './PaletteXML';