Move to Renderer V2

This commit is contained in:
duckietm
2024-04-03 09:27:56 +02:00
parent 110c3ad393
commit b3134ce50b
4080 changed files with 115593 additions and 66375 deletions
@@ -0,0 +1,57 @@
import { IActionDefinition, IFigureSetData } from '@nitrots/api';
import { AnimationAction } from './animation';
export class AvatarAnimationData implements IFigureSetData
{
private _actions: Map<string, AnimationAction>;
constructor()
{
this._actions = new Map();
}
public parse(data: any): boolean
{
if(data && (data.length > 0))
{
for(const animation of data)
{
if(!animation) continue;
const newAnimation = new AnimationAction(animation);
this._actions.set(newAnimation.id, newAnimation);
}
}
return true;
}
public appendJSON(k: any): boolean
{
for(const _local_2 of k.action)
{
this._actions.set(_local_2.id, new AnimationAction(_local_2));
}
return true;
}
public getAction(action: IActionDefinition): AnimationAction
{
const existing = this._actions.get(action.id);
if(!existing) return null;
return existing;
}
public getFrameCount(k: IActionDefinition): number
{
const animationAction = this.getAction(k);
if(!animationAction) return 0;
return animationAction.frameCount;
}
}
@@ -0,0 +1,47 @@
import { AvatarScaleType } from '@nitrots/api';
import { Point } from 'pixi.js';
export class AvatarCanvas
{
private _id: string;
private _width: number;
private _height: number;
private _offset: Point;
private _regPoint: Point;
constructor(k: any, _arg_2: string)
{
this._id = k.id;
this._width = k.width;
this._height = k.height;
this._offset = new Point(k.dx, k.dy);
if(_arg_2 == AvatarScaleType.LARGE) this._regPoint = new Point(((this._width - 64) / 2), 0);
else this._regPoint = new Point(((this._width - 32) / 2), 0);
}
public get width(): number
{
return this._width;
}
public get height(): number
{
return this._height;
}
public get offset(): Point
{
return this._offset;
}
public get id(): string
{
return this._id;
}
public get regPoint(): Point
{
return this._regPoint;
}
}
@@ -0,0 +1,129 @@
import { IFigureData, IFigurePartSet, IFigureSetData, IPalette, ISetType, IStructureData } from '@nitrots/api';
import { Palette, SetType } from './figure';
export class FigureSetData implements IFigureSetData, IStructureData
{
private _palettes: Map<string, Palette>;
private _setTypes: Map<string, SetType>;
constructor()
{
this._palettes = new Map();
this._setTypes = new Map();
}
public dispose(): void
{
}
public parse(data: IFigureData): boolean
{
if(!data) return false;
for(const palette of data.palettes)
{
const newPalette = new Palette(palette);
if(!newPalette) continue;
this._palettes.set(newPalette.id.toString(), newPalette);
}
for(const set of data.setTypes)
{
const newSet = new SetType(set);
if(!newSet) continue;
this._setTypes.set(newSet.type, newSet);
}
return true;
}
public injectJSON(data: IFigureData): void
{
for(const setType of data.setTypes)
{
const existingSetType = this._setTypes.get(setType.type);
if(existingSetType) existingSetType.cleanUp(setType);
else this._setTypes.set(setType.type, new SetType(setType));
}
this.appendJSON(data);
}
public appendJSON(data: IFigureData): boolean
{
if(!data) return false;
for(const palette of data.palettes)
{
const id = palette.id.toString();
const existingPalette = this._palettes.get(id);
if(!existingPalette) this._palettes.set(id, new Palette(palette));
else existingPalette.append(palette);
}
for(const setType of data.setTypes)
{
const type = setType.type;
const existingSetType = this._setTypes.get(type);
if(!existingSetType) this._setTypes.set(type, new SetType(setType));
else existingSetType.append(setType);
}
return false;
}
public getMandatorySetTypeIds(k: string, _arg_2: number): string[]
{
const types: string[] = [];
for(const set of this._setTypes.values())
{
if(!set || !set.isMandatory(k, _arg_2)) continue;
types.push(set.type);
}
return types;
}
public getDefaultPartSet(type: string, gender: string): IFigurePartSet
{
const setType = this._setTypes.get(type);
if(!setType) return null;
return setType.getDefaultPartSet(gender);
}
public getSetType(k: string): ISetType
{
return (this._setTypes.get(k) || null);
}
public getPalette(k: number): IPalette
{
return (this._palettes.get(k.toString()) || null);
}
public getFigurePartSet(k: number): IFigurePartSet
{
for(const set of this._setTypes.values())
{
const partSet = set.getPartSet(k);
if(!partSet) continue;
return partSet;
}
return null;
}
}
@@ -0,0 +1,118 @@
import { IActionDefinition, IFigureSetData } from '@nitrots/api';
import { ActionDefinition } from '../actions';
import { ActivePartSet, PartDefinition } from './parts';
export class PartSetsData implements IFigureSetData
{
private _parts: Map<string, PartDefinition>;
private _activePartSets: Map<string, ActivePartSet>;
constructor()
{
this._parts = new Map();
this._activePartSets = new Map();
}
public parse(data: any): boolean
{
if(data.partSet && (data.partSet.length > 0))
{
for(const part of data.partSet)
{
if(!part) continue;
this._parts.set(part.setType, new PartDefinition(part));
}
}
if(data.activePartSets && (data.activePartSets.length > 0))
{
for(const activePart of data.activePartSets)
{
if(!activePart) continue;
this._activePartSets.set(activePart.id, new ActivePartSet(activePart));
}
}
return true;
}
public appendJSON(data: any): boolean
{
if(data.partSet && (data.partSet.length > 0))
{
for(const part of data.partSet)
{
if(!part) continue;
this._parts.set(part.setType, new PartDefinition(part));
}
}
if(data.activePartSets && (data.activePartSets.length > 0))
{
for(const activePart of data.activePartSets)
{
if(!activePart) continue;
this._activePartSets.set(activePart.id, new ActivePartSet(activePart));
}
}
return false;
}
public getActiveParts(k: IActionDefinition): string[]
{
const activePartSet = this._activePartSets.get(k.activePartSet);
if(!activePartSet) return [];
return activePartSet.parts;
}
public getPartDefinition(part: string): PartDefinition
{
const existing = this._parts.get(part);
if(!existing) return null;
return existing;
}
public addPartDefinition(k: any): PartDefinition
{
const _local_2 = k.setType as string;
let existing = this._parts.get(_local_2);
if(!existing)
{
existing = new PartDefinition(k);
this._parts.set(_local_2, existing);
}
return existing;
}
public getActivePartSet(k: ActionDefinition): ActivePartSet
{
const existing = this._activePartSets.get(k.activePartSet);
if(!existing) return null;
return existing;
}
public get parts(): Map<string, PartDefinition>
{
return this._parts;
}
public get activePartSets(): Map<string, ActivePartSet>
{
return this._activePartSets;
}
}
@@ -0,0 +1,138 @@
import { Point } from 'pixi.js';
import { AnimationActionPart } from './AnimationActionPart';
export class AnimationAction
{
public static DEFAULT_OFFSET: Point = new Point(0, 0);
private _id: string;
private _actionParts: Map<string, AnimationActionPart>;
private _bodyPartOffsets: Map<number, Map<number, Map<string, Point>>>;
private _frameCount: number;
private _frameIndexes: number[];
constructor(data: any)
{
this._id = data.id;
this._actionParts = new Map();
this._bodyPartOffsets = new Map();
this._frameCount = 0;
this._frameIndexes = [];
if(data.parts && (data.parts.length > 0))
{
for(const part of data.parts)
{
if(!part) continue;
const newPart = new AnimationActionPart(part);
this._actionParts.set(part.setType, newPart);
this._frameCount = Math.max(this._frameCount, newPart.frames.length);
}
}
if(data.offsets && data.offsets.frames && (data.offsets.frames.length > 0))
{
for(const frame of data.offsets.frames)
{
if(!frame) continue;
const frameId = frame.id;
this._frameCount = Math.max(this._frameCount, frameId);
const directions: Map<number, Map<string, Point>> = new Map();
this._bodyPartOffsets.set(frameId, directions);
if(frame.directions && (frame.directions.length > 0))
{
for(const direction of frame.directions)
{
if(!direction) continue;
const directionId = direction.id;
const offsets: Map<string, Point> = new Map();
directions.set(directionId, offsets);
if(direction.bodyParts && (direction.bodyParts.length > 0))
{
for(const part of direction.bodyParts)
{
if(!part) continue;
const partId = part.id;
let dx = 0;
let dy = 0;
if(part.dx !== undefined) dx = part.dx;
if(part.dy !== undefined) dy = part.dy;
offsets.set(partId, new Point(dx, dy));
}
}
}
}
this._frameIndexes.push(frameId);
if(frame.repeats !== undefined)
{
let repeats = frame.repeats || 0;
if(repeats > 1) while(--repeats > 0) this._frameIndexes.push(frameId);
}
}
}
}
public getPart(type: string): AnimationActionPart
{
if(!type) return null;
const existing = this._actionParts.get(type);
if(!existing) return null;
return existing;
}
public getFrameBodyPartOffset(frameId: number, frameCount: number, partId: string): Point
{
const frameIndex = (frameCount % this._frameIndexes.length);
const frameNumber = this._frameIndexes[frameIndex];
const offsets = this._bodyPartOffsets.get(frameNumber);
if(!offsets) return AnimationAction.DEFAULT_OFFSET;
const frameOffset = offsets.get(frameId);
if(!frameOffset) return AnimationAction.DEFAULT_OFFSET;
const offset = frameOffset.get(partId);
if(!offset) return AnimationAction.DEFAULT_OFFSET;
return offset;
}
public get id(): string
{
return this._id;
}
public get parts(): Map<string, AnimationActionPart>
{
return this._actionParts;
}
public get frameCount(): number
{
return this._frameCount;
}
}
@@ -0,0 +1,30 @@
import { AvatarAnimationFrame } from './AvatarAnimationFrame';
export class AnimationActionPart
{
private _frames: AvatarAnimationFrame[];
constructor(data: any)
{
this._frames = [];
if(data.frames && (data.frames.length > 0))
{
for(const frame of data.frames)
{
if(!frame) continue;
this._frames.push(new AvatarAnimationFrame(frame));
let repeats = frame.repeats || 0;
if(repeats > 1) while(--repeats > 0) this._frames.push(this._frames[(this._frames.length - 1)]);
}
}
}
public get frames(): AvatarAnimationFrame[]
{
return this._frames;
}
}
@@ -0,0 +1,21 @@
export class AvatarAnimationFrame
{
private _number: number;
private _assetPartDefinition: string;
constructor(data: any)
{
this._number = data.number;
this._assetPartDefinition = data.assetPartDefinition || null;
}
public get number(): number
{
return this._number;
}
public get assetPartDefinition(): string
{
return this._assetPartDefinition;
}
}
@@ -0,0 +1,3 @@
export * from './AnimationAction';
export * from './AnimationActionPart';
export * from './AvatarAnimationFrame';
@@ -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';
+7
View File
@@ -0,0 +1,7 @@
export * from './AvatarAnimationData';
export * from './AvatarCanvas';
export * from './FigureSetData';
export * from './PartSetsData';
export * from './animation';
export * from './figure';
export * from './parts';
@@ -0,0 +1,26 @@
export class ActivePartSet
{
private _id: string;
private _parts: string[];
constructor(data: any)
{
this._id = data.id;
this._parts = [];
if(data.activeParts && (data.activeParts.length > 0))
{
for(const part of data.activeParts)
{
if(!part) continue;
this._parts.push(part.setType);
}
}
}
public get parts(): string[]
{
return this._parts;
}
}
@@ -0,0 +1,64 @@
export class PartDefinition
{
private _setType: string;
private _flippedSetType: string;
private _removeSetType: string;
private _appendToFigure: boolean;
private _staticId: number;
constructor(data: any)
{
if(!data) throw new Error('invalid_data');
this._setType = data.setType;
this._flippedSetType = data.flippedSetType || null;
this._removeSetType = data.removeSetType || null;
this._appendToFigure = false;
this._staticId = -1;
}
public hasStaticId(): boolean
{
return this._staticId >= 0;
}
public get staticId(): number
{
return this._staticId;
}
public set staticId(k: number)
{
this._staticId = k;
}
public get setType(): string
{
return this._setType;
}
public get flippedSetType(): string
{
return this._flippedSetType;
}
public set flippedSetType(type: string)
{
this._flippedSetType = type;
}
public get removeSetType(): string
{
return this._removeSetType;
}
public get appendToFigure(): boolean
{
return this._appendToFigure;
}
public set appendToFigure(flag: boolean)
{
this._appendToFigure = flag;
}
}
@@ -0,0 +1,2 @@
export * from './ActivePartSet';
export * from './PartDefinition';