You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-20 07:26:18 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { IFigureDataPart, IFigurePart } from '@nitrots/api';
|
||||
|
||||
export class FigurePart implements IFigurePart
|
||||
{
|
||||
private _id: number;
|
||||
private _type: string;
|
||||
private _breed: number;
|
||||
private _index: number;
|
||||
private _colorLayerIndex: number;
|
||||
private _paletteMapId: number;
|
||||
|
||||
constructor(data: IFigureDataPart)
|
||||
{
|
||||
if(!data) throw new Error('invalid_data');
|
||||
|
||||
this._id = data.id;
|
||||
this._type = data.type;
|
||||
this._index = data.index;
|
||||
this._colorLayerIndex = data.colorindex;
|
||||
this._paletteMapId = -1;
|
||||
this._breed = -1;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get breed(): number
|
||||
{
|
||||
return this._breed;
|
||||
}
|
||||
|
||||
public get index(): number
|
||||
{
|
||||
return this._index;
|
||||
}
|
||||
|
||||
public get colorLayerIndex(): number
|
||||
{
|
||||
return this._colorLayerIndex;
|
||||
}
|
||||
|
||||
public get paletteMap(): number
|
||||
{
|
||||
return this._paletteMapId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { IFigureDataSet, IFigurePart, IFigurePartSet } from '@nitrots/api';
|
||||
import { FigurePart } from './FigurePart';
|
||||
|
||||
export class FigurePartSet implements IFigurePartSet
|
||||
{
|
||||
private _id: number;
|
||||
private _type: string;
|
||||
private _gender: string;
|
||||
private _clubLevel: number;
|
||||
private _isColorable: boolean;
|
||||
private _isSelectable: boolean;
|
||||
private _parts: IFigurePart[];
|
||||
private _hiddenLayers: string[];
|
||||
private _isPreSelectable: boolean;
|
||||
private _isSellable: boolean;
|
||||
|
||||
constructor(type: string, data: IFigureDataSet)
|
||||
{
|
||||
if(!type || !data) throw new Error('invalid_data');
|
||||
|
||||
this._id = data.id;
|
||||
this._type = type;
|
||||
this._gender = data.gender;
|
||||
this._clubLevel = data.club;
|
||||
this._isColorable = data.colorable;
|
||||
this._isSelectable = data.selectable;
|
||||
this._parts = [];
|
||||
this._hiddenLayers = [];
|
||||
this._isPreSelectable = data.preselectable;
|
||||
this._isSellable = data.sellable;
|
||||
|
||||
for(const part of data.parts)
|
||||
{
|
||||
const newPart = new FigurePart(part);
|
||||
const partIndex = this.getPartIndex(newPart);
|
||||
|
||||
if(partIndex !== -1) this._parts.splice(partIndex, 0, newPart);
|
||||
else this._parts.push(newPart);
|
||||
}
|
||||
|
||||
if(data.hiddenLayers)
|
||||
{
|
||||
for(const hiddenLayer of data.hiddenLayers) this._hiddenLayers.push(hiddenLayer.partType);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._parts = null;
|
||||
this._hiddenLayers = null;
|
||||
}
|
||||
|
||||
private getPartIndex(part: FigurePart): number
|
||||
{
|
||||
const totalParts = this._parts.length;
|
||||
|
||||
if(!totalParts) return -1;
|
||||
|
||||
for(let i = 0; i < totalParts; i++)
|
||||
{
|
||||
const existingPart = this._parts[i];
|
||||
|
||||
if(!existingPart) continue;
|
||||
|
||||
if(existingPart.type !== part.type || existingPart.index > part.index) continue;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public getPart(k: string, _arg_2: number): IFigurePart
|
||||
{
|
||||
for(const part of this._parts)
|
||||
{
|
||||
if((part.type !== k) || (part.id !== _arg_2)) continue;
|
||||
|
||||
return part;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get gender(): string
|
||||
{
|
||||
return this._gender;
|
||||
}
|
||||
|
||||
public get clubLevel(): number
|
||||
{
|
||||
return this._clubLevel;
|
||||
}
|
||||
|
||||
public get isColorable(): boolean
|
||||
{
|
||||
return this._isColorable;
|
||||
}
|
||||
|
||||
public get isSelectable(): boolean
|
||||
{
|
||||
return this._isSelectable;
|
||||
}
|
||||
|
||||
public get parts(): IFigurePart[]
|
||||
{
|
||||
return this._parts;
|
||||
}
|
||||
|
||||
public get hiddenLayers(): string[]
|
||||
{
|
||||
return this._hiddenLayers;
|
||||
}
|
||||
|
||||
public get isPreSelectable(): boolean
|
||||
{
|
||||
return this._isPreSelectable;
|
||||
}
|
||||
|
||||
public get isSellable(): boolean
|
||||
{
|
||||
return this._isSellable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { IAdvancedMap, IFigureDataPalette, IPalette, IPartColor } from '@nitrots/api';
|
||||
import { AdvancedMap } from '@nitrots/utils';
|
||||
import { PartColor } from './PartColor';
|
||||
|
||||
export class Palette implements IPalette
|
||||
{
|
||||
private _id: number;
|
||||
private _colors: IAdvancedMap<string, IPartColor>;
|
||||
|
||||
constructor(data: IFigureDataPalette)
|
||||
{
|
||||
if(!data) throw new Error('invalid_data');
|
||||
|
||||
this._id = data.id;
|
||||
this._colors = new AdvancedMap();
|
||||
|
||||
this.append(data);
|
||||
}
|
||||
|
||||
public append(data: IFigureDataPalette): void
|
||||
{
|
||||
for(const color of data.colors)
|
||||
{
|
||||
const newColor = new PartColor(color);
|
||||
|
||||
this._colors.add(color.id.toString(), newColor);
|
||||
}
|
||||
}
|
||||
|
||||
public getColor(id: number): IPartColor
|
||||
{
|
||||
if((id === undefined) || id < 0) return null;
|
||||
|
||||
return (this._colors.getValue(id.toString()) || null);
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get colors(): IAdvancedMap<string, IPartColor>
|
||||
{
|
||||
return this._colors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { IFigureDataColor, IPartColor } from '@nitrots/api';
|
||||
|
||||
export class PartColor implements IPartColor
|
||||
{
|
||||
private _id: number;
|
||||
private _index: number;
|
||||
private _clubLevel: number;
|
||||
private _isSelectable: boolean;
|
||||
private _rgb: number;
|
||||
|
||||
constructor(data: IFigureDataColor)
|
||||
{
|
||||
if(!data) throw new Error('invalid_data');
|
||||
|
||||
this._id = data.id;
|
||||
this._index = data.index;
|
||||
this._clubLevel = (data.club || 0);
|
||||
this._isSelectable = data.selectable;
|
||||
this._rgb = parseInt('0x' + data.hexCode, 16);
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get index(): number
|
||||
{
|
||||
return this._index;
|
||||
}
|
||||
|
||||
public get clubLevel(): number
|
||||
{
|
||||
return this._clubLevel;
|
||||
}
|
||||
|
||||
public get isSelectable(): boolean
|
||||
{
|
||||
return this._isSelectable;
|
||||
}
|
||||
|
||||
public get rgb(): number
|
||||
{
|
||||
return this._rgb;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { IAdvancedMap, IFigureDataSetType, IFigurePartSet, ISetType } from '@nitrots/api';
|
||||
import { AdvancedMap } from '@nitrots/utils';
|
||||
import { FigurePartSet } from './FigurePartSet';
|
||||
|
||||
export class SetType implements ISetType
|
||||
{
|
||||
private _type: string;
|
||||
private _paletteId: number;
|
||||
private _isMandatory: { [index: string]: boolean[] };
|
||||
private _partSets: IAdvancedMap<string, IFigurePartSet>;
|
||||
|
||||
constructor(data: IFigureDataSetType)
|
||||
{
|
||||
if(!data) throw new Error('invalid_data');
|
||||
|
||||
this._type = data.type;
|
||||
this._paletteId = data.paletteId;
|
||||
this._isMandatory = {};
|
||||
this._isMandatory['F'] = [data.mandatory_f_0, data.mandatory_f_1];
|
||||
this._isMandatory['M'] = [data.mandatory_m_0, data.mandatory_m_1];
|
||||
this._partSets = new AdvancedMap();
|
||||
|
||||
this.append(data);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
for(const set of this._partSets.getValues())
|
||||
{
|
||||
const partSet = set as FigurePartSet;
|
||||
|
||||
partSet.dispose();
|
||||
}
|
||||
|
||||
this._partSets = null;
|
||||
}
|
||||
|
||||
public cleanUp(data: IFigureDataSetType): void
|
||||
{
|
||||
for(const set of data.sets)
|
||||
{
|
||||
const setId = set.id.toString();
|
||||
const partSet = (this._partSets.getValue(setId) as FigurePartSet);
|
||||
|
||||
if(partSet)
|
||||
{
|
||||
partSet.dispose();
|
||||
|
||||
this._partSets.remove(setId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public append(setType: IFigureDataSetType): void
|
||||
{
|
||||
if(!setType || !setType.sets) return;
|
||||
|
||||
for(const set of setType.sets) this._partSets.add(set.id.toString(), new FigurePartSet(this._type, set));
|
||||
}
|
||||
|
||||
public getDefaultPartSet(gender: string): IFigurePartSet
|
||||
{
|
||||
for(const set of this._partSets.getValues())
|
||||
{
|
||||
if(!set) continue;
|
||||
|
||||
if((set.clubLevel === 0) && ((set.gender === gender) || (set.gender === 'U'))) return set;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getPartSet(k: number): IFigurePartSet
|
||||
{
|
||||
return this._partSets.getValue(k.toString());
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get paletteID(): number
|
||||
{
|
||||
return this._paletteId;
|
||||
}
|
||||
|
||||
public isMandatory(k: string, _arg_2: number): boolean
|
||||
{
|
||||
return this._isMandatory[k.toUpperCase()][Math.min(_arg_2, 1)];
|
||||
}
|
||||
|
||||
public optionalFromClubLevel(k: string): number
|
||||
{
|
||||
const _local_2 = this._isMandatory[k.toUpperCase()];
|
||||
|
||||
return _local_2.indexOf(false);
|
||||
}
|
||||
|
||||
public get partSets(): IAdvancedMap<string, IFigurePartSet>
|
||||
{
|
||||
return this._partSets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from './FigurePart';
|
||||
export * from './FigurePartSet';
|
||||
export * from './Palette';
|
||||
export * from './PartColor';
|
||||
export * from './SetType';
|
||||
Reference in New Issue
Block a user