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,220 @@
|
||||
import { IActionDefinition } from '@nitrots/api';
|
||||
import { ActionType } from './ActionType';
|
||||
|
||||
export class ActionDefinition implements IActionDefinition
|
||||
{
|
||||
private _id: string;
|
||||
private _state: string;
|
||||
private _precedence: number;
|
||||
private _activePartSet: string;
|
||||
private _assetPartDefinition: string;
|
||||
private _lay: string;
|
||||
private _geometryType: string;
|
||||
private _isMain: boolean;
|
||||
private _isDefault: boolean;
|
||||
private _isAnimation: boolean;
|
||||
private _startFromFrameZero: boolean;
|
||||
private _prevents: string[];
|
||||
private _preventHeadTurn: boolean;
|
||||
private _types: Map<number, ActionType> = new Map();
|
||||
private _params: Map<string, string> = new Map();
|
||||
private _defaultParameterValue: string = '';
|
||||
private _canvasOffsets: Map<string, Map<number, number[]>> = new Map();
|
||||
|
||||
constructor(data: any)
|
||||
{
|
||||
this._id = data.id;
|
||||
this._state = data.state;
|
||||
this._precedence = data.precedence;
|
||||
this._activePartSet = data.activePartSet;
|
||||
this._assetPartDefinition = data.assetPartDefinition;
|
||||
this._lay = data.lay;
|
||||
this._geometryType = data.geometryType;
|
||||
this._isMain = data.main || false;
|
||||
this._isDefault = data.isDefault || false;
|
||||
this._isAnimation = data.animation || false;
|
||||
this._startFromFrameZero = data.startFromFrameZero || false;
|
||||
this._prevents = data.prevents || [];
|
||||
this._preventHeadTurn = data.preventHeadTurn || false;
|
||||
|
||||
if(data.params && (data.params.length > 0))
|
||||
{
|
||||
for(const param of data.params)
|
||||
{
|
||||
if(!param) continue;
|
||||
|
||||
if(param.id === 'default') this._defaultParameterValue = param.value;
|
||||
else this._params.set(param.id, param.value);
|
||||
}
|
||||
}
|
||||
|
||||
if(data.types && (data.types.length > 0))
|
||||
{
|
||||
for(const type of data.types)
|
||||
{
|
||||
if(!type) continue;
|
||||
|
||||
const action = new ActionType(type);
|
||||
|
||||
this._types.set(action.id, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setOffsets(k: string, _arg_2: number, _arg_3: number[]): void
|
||||
{
|
||||
if(!this._canvasOffsets) this._canvasOffsets = new Map();
|
||||
|
||||
let existing = this._canvasOffsets.get(k);
|
||||
|
||||
if(!existing)
|
||||
{
|
||||
existing = new Map();
|
||||
|
||||
this._canvasOffsets.set(k, existing);
|
||||
}
|
||||
|
||||
existing.set(_arg_2, _arg_3);
|
||||
}
|
||||
|
||||
public getOffsets(k: string, _arg_2: number): number[]
|
||||
{
|
||||
if(!this._canvasOffsets) return null;
|
||||
|
||||
const existing = this._canvasOffsets.get(k);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing.get(_arg_2);
|
||||
}
|
||||
|
||||
public getType(id: string): ActionType
|
||||
{
|
||||
if(!id) return null;
|
||||
|
||||
const existing = this._types.get(parseInt(id));
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getParameterValue(id: string): string
|
||||
{
|
||||
if(!id) return '';
|
||||
|
||||
const existing = this._params.get(id);
|
||||
|
||||
if(!existing) return this._defaultParameterValue;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getPrevents(type: string): string[]
|
||||
{
|
||||
return this._prevents.concat(this.getTypePrevents(type));
|
||||
}
|
||||
|
||||
private getTypePrevents(type: string): string[]
|
||||
{
|
||||
if(!type) return [];
|
||||
|
||||
const existing = this._types.get(parseInt(type));
|
||||
|
||||
if(!existing) return [];
|
||||
|
||||
return existing.prevents;
|
||||
}
|
||||
|
||||
public getPreventHeadTurn(k: string): boolean
|
||||
{
|
||||
if(!k) return this._preventHeadTurn;
|
||||
|
||||
const type = this.getType(k);
|
||||
|
||||
if(!type) return this._preventHeadTurn;
|
||||
|
||||
return type.preventHeadTurn;
|
||||
}
|
||||
|
||||
public isAnimated(k: string): boolean
|
||||
{
|
||||
if(!k) return true;
|
||||
|
||||
const type = this.getType(k);
|
||||
|
||||
if(!type) return true;
|
||||
|
||||
return type.isAnimated;
|
||||
}
|
||||
|
||||
public get id(): string
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get state(): string
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
|
||||
public get precedence(): number
|
||||
{
|
||||
return this._precedence;
|
||||
}
|
||||
|
||||
public get activePartSet(): string
|
||||
{
|
||||
return this._activePartSet;
|
||||
}
|
||||
|
||||
public get assetPartDefinition(): string
|
||||
{
|
||||
return this._assetPartDefinition;
|
||||
}
|
||||
|
||||
public get lay(): string
|
||||
{
|
||||
return this._lay;
|
||||
}
|
||||
|
||||
public get geometryType(): string
|
||||
{
|
||||
return this._geometryType;
|
||||
}
|
||||
|
||||
public get isMain(): boolean
|
||||
{
|
||||
return this._isMain;
|
||||
}
|
||||
|
||||
public get isDefault(): boolean
|
||||
{
|
||||
return this._isDefault;
|
||||
}
|
||||
|
||||
public get isAnimation(): boolean
|
||||
{
|
||||
return this._isAnimation;
|
||||
}
|
||||
|
||||
public get startFromFrameZero(): boolean
|
||||
{
|
||||
return this._startFromFrameZero;
|
||||
}
|
||||
|
||||
public get prevents(): string[]
|
||||
{
|
||||
return this._prevents;
|
||||
}
|
||||
|
||||
public get preventHeadTurn(): boolean
|
||||
{
|
||||
return this._preventHeadTurn;
|
||||
}
|
||||
|
||||
public get params(): Map<string, string>
|
||||
{
|
||||
return this._params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
export class ActionType
|
||||
{
|
||||
private _id: number;
|
||||
private _value: number;
|
||||
private _prevents: string[];
|
||||
private _preventHeadTurn: boolean;
|
||||
private _isAnimated: boolean;
|
||||
|
||||
constructor(data: any)
|
||||
{
|
||||
this._id = parseInt(data.id);
|
||||
this._value = parseInt(data.id);
|
||||
this._prevents = data.prevents || [];
|
||||
this._preventHeadTurn = data.preventHeadTurn || false;
|
||||
this._isAnimated = true;
|
||||
|
||||
if((data.animated !== undefined) && (data.animated === false)) this._isAnimated = false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get value(): number
|
||||
{
|
||||
return this._value;
|
||||
}
|
||||
|
||||
public get prevents(): string[]
|
||||
{
|
||||
return this._prevents;
|
||||
}
|
||||
|
||||
public get preventHeadTurn(): boolean
|
||||
{
|
||||
return this._preventHeadTurn;
|
||||
}
|
||||
|
||||
public get isAnimated(): boolean
|
||||
{
|
||||
return this._isAnimated;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { IActionDefinition, IActiveActionData } from '@nitrots/api';
|
||||
|
||||
export class ActiveActionData implements IActiveActionData
|
||||
{
|
||||
private _actionType: string;
|
||||
private _actionParameter: string;
|
||||
private _definition: IActionDefinition;
|
||||
private _startFrame: number;
|
||||
private _overridingAction: string;
|
||||
|
||||
constructor(action: string, parameter: string = '', startFrame: number = 0)
|
||||
{
|
||||
this._actionType = action || '';
|
||||
this._actionParameter = parameter || '';
|
||||
this._definition = null;
|
||||
this._startFrame = startFrame || 0;
|
||||
this._overridingAction = null;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._actionType = null;
|
||||
this._actionParameter = null;
|
||||
this._definition = null;
|
||||
}
|
||||
|
||||
public get id(): string
|
||||
{
|
||||
if(!this._definition) return '';
|
||||
|
||||
return this._definition.id + '_' + this._actionParameter;
|
||||
}
|
||||
|
||||
public get actionType(): string
|
||||
{
|
||||
return this._actionType;
|
||||
}
|
||||
|
||||
public get actionParameter(): string
|
||||
{
|
||||
return this._actionParameter;
|
||||
}
|
||||
|
||||
public set actionParameter(parameter: string)
|
||||
{
|
||||
this._actionParameter = parameter;
|
||||
}
|
||||
|
||||
public get definition(): IActionDefinition
|
||||
{
|
||||
return this._definition;
|
||||
}
|
||||
|
||||
public set definition(definition: IActionDefinition)
|
||||
{
|
||||
this._definition = definition;
|
||||
}
|
||||
|
||||
public get startFrame(): number
|
||||
{
|
||||
return this._startFrame;
|
||||
}
|
||||
|
||||
public get overridingAction(): string
|
||||
{
|
||||
return this._overridingAction;
|
||||
}
|
||||
|
||||
public set overridingAction(action: string)
|
||||
{
|
||||
this._overridingAction = action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import { IActiveActionData, IAssetManager } from '@nitrots/api';
|
||||
import { ActionDefinition } from './ActionDefinition';
|
||||
|
||||
export class AvatarActionManager
|
||||
{
|
||||
private _assets: IAssetManager;
|
||||
private _actions: Map<string, ActionDefinition>;
|
||||
private _defaultAction: ActionDefinition;
|
||||
|
||||
constructor(k: IAssetManager, data: any)
|
||||
{
|
||||
this._assets = k;
|
||||
this._actions = new Map();
|
||||
this._defaultAction = null;
|
||||
|
||||
this.updateActions(data);
|
||||
}
|
||||
|
||||
public updateActions(data: any): void
|
||||
{
|
||||
if(!data) return;
|
||||
|
||||
for(const action of data.actions)
|
||||
{
|
||||
if(!action || !action.state) continue;
|
||||
|
||||
const definition = new ActionDefinition(action);
|
||||
|
||||
this._actions.set(definition.state, definition);
|
||||
}
|
||||
|
||||
if(data.actionOffsets) this.parseActionOffsets(data.actionOffsets);
|
||||
}
|
||||
|
||||
private parseActionOffsets(offsets: any): void
|
||||
{
|
||||
if(!offsets || !offsets.length) return;
|
||||
|
||||
for(const offset of offsets)
|
||||
{
|
||||
const action = this._actions.get(offset.action);
|
||||
|
||||
if(!action) continue;
|
||||
|
||||
for(const canvasOffset of offset.offsets)
|
||||
{
|
||||
const size = (canvasOffset.size || '');
|
||||
const direction = canvasOffset.direction;
|
||||
|
||||
if((size === '') || (direction === undefined)) continue;
|
||||
|
||||
const x = (canvasOffset.x || 0);
|
||||
const y = (canvasOffset.y || 0);
|
||||
const z = (canvasOffset.z || 0);
|
||||
|
||||
action.setOffsets(size, direction, [x, y, z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getActionDefinition(id: string): ActionDefinition
|
||||
{
|
||||
if(!id) return null;
|
||||
|
||||
for(const action of this._actions.values())
|
||||
{
|
||||
if(!action || (action.id !== id)) continue;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getActionDefinitionWithState(state: string): ActionDefinition
|
||||
{
|
||||
const existing = this._actions.get(state);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getDefaultAction(): ActionDefinition
|
||||
{
|
||||
if(this._defaultAction) return this._defaultAction;
|
||||
|
||||
for(const action of this._actions.values())
|
||||
{
|
||||
if(!action || !action.isDefault) continue;
|
||||
|
||||
this._defaultAction = action;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getCanvasOffsets(k: IActiveActionData[], _arg_2: string, _arg_3: number): number[]
|
||||
{
|
||||
let canvasOffsets: number[] = [];
|
||||
|
||||
for(const activeAction of k)
|
||||
{
|
||||
if(!activeAction) continue;
|
||||
|
||||
const action = this._actions.get(activeAction.actionType);
|
||||
const offsets = action && action.getOffsets(_arg_2, _arg_3);
|
||||
|
||||
if(offsets) canvasOffsets = offsets;
|
||||
}
|
||||
|
||||
return canvasOffsets;
|
||||
}
|
||||
|
||||
public sortActions(actions: IActiveActionData[]): IActiveActionData[]
|
||||
{
|
||||
if(!actions) return null;
|
||||
|
||||
actions = this.filterActions(actions);
|
||||
|
||||
const validatedActions: IActiveActionData[] = [];
|
||||
|
||||
for(const action of actions)
|
||||
{
|
||||
if(!action) continue;
|
||||
|
||||
const definition = this._actions.get(action.actionType);
|
||||
|
||||
if(!definition) continue;
|
||||
|
||||
action.definition = definition;
|
||||
|
||||
validatedActions.push(action);
|
||||
}
|
||||
|
||||
validatedActions.sort(this.sortByPrecedence);
|
||||
|
||||
return validatedActions;
|
||||
}
|
||||
|
||||
private filterActions(actions: IActiveActionData[]): IActiveActionData[]
|
||||
{
|
||||
let preventions: string[] = [];
|
||||
const activeActions: IActiveActionData[] = [];
|
||||
|
||||
for(const action of actions)
|
||||
{
|
||||
if(!action) continue;
|
||||
|
||||
const localAction = this._actions.get(action.actionType);
|
||||
|
||||
if(localAction) preventions = preventions.concat(localAction.getPrevents(action.actionParameter));
|
||||
}
|
||||
|
||||
for(const action of actions)
|
||||
{
|
||||
if(!action) continue;
|
||||
|
||||
let actionType = action.actionType;
|
||||
|
||||
if(action.actionType === 'fx') actionType = (actionType + ('.' + action.actionParameter));
|
||||
|
||||
if(preventions.indexOf(actionType) >= 0) continue;
|
||||
|
||||
activeActions.push(action);
|
||||
}
|
||||
|
||||
return activeActions;
|
||||
}
|
||||
|
||||
private sortByPrecedence(actionOne: IActiveActionData, actionTwo: IActiveActionData): number
|
||||
{
|
||||
if(!actionOne || !actionTwo) return 0;
|
||||
|
||||
const precedenceOne = actionOne.definition.precedence;
|
||||
const precedenceTwo = actionTwo.definition.precedence;
|
||||
|
||||
if(precedenceOne < precedenceTwo) return 1;
|
||||
|
||||
if(precedenceOne > precedenceTwo) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './ActionDefinition';
|
||||
export * from './ActionType';
|
||||
export * from './ActiveActionData';
|
||||
export * from './AvatarActionManager';
|
||||
Reference in New Issue
Block a user