Update mannequins

This commit is contained in:
billsonnn 2024-03-30 19:58:03 -04:00
parent ebf481419f
commit 2a7e7e8864
2 changed files with 46 additions and 72 deletions

View File

@ -1,35 +1,20 @@
import { AvatarSetType, IAvatarImageListener, IObjectVisualizationData, RoomObjectVariable } from '@nitrots/api';
import { AvatarSetType, IAvatarImage, IAvatarImageListener, IGraphicAsset, IObjectVisualizationData, RoomObjectVariable } from '@nitrots/api';
import { Texture } from 'pixi.js';
import { FurnitureMannequinVisualizationData } from './FurnitureMannequinVisualizationData';
import { FurnitureVisualization } from './FurnitureVisualization';
export class FurnitureMannequinVisualization extends FurnitureVisualization implements IAvatarImageListener
{
private static AVATAR_IMAGE_SPRITE_TAG: string = 'avatar_image';
private _mannequinScale: number;
private _figure: string;
private _gender: string;
private _dynamicAssetName: string;
private _needsUpdate: boolean;
private _placeHolderFigure: string;
private _disposed: boolean;
constructor()
{
super();
this._mannequinScale = -1;
this._figure = null;
this._gender = null;
this._dynamicAssetName = null;
this._needsUpdate = false;
this._placeHolderFigure = 'hd-99999-99998';
this._disposed = false;
}
private _mannequinScale: number = -1;
private _figure: string = null;
private _gender: string = null;
private _avatarImage: IAvatarImage = null;
private _avatarWidth: number = 90;
private _avatarHeight: number = 130;
private _needsUpdate: boolean = false;
private _placeHolderFigure: string = 'hd-99999-99998';
private _disposed: boolean = false;
public initialize(data: IObjectVisualizationData): boolean
{
@ -44,11 +29,11 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
this._disposed = true;
if(this._dynamicAssetName && this.asset)
if(this._avatarImage)
{
this.asset.disposeAsset(this._dynamicAssetName);
this._avatarImage.dispose();
this._dynamicAssetName = null;
this._avatarImage = null;
}
super.dispose();
@ -81,7 +66,7 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
if(figure)
{
this._figure = (figure + '.' + this._placeHolderFigure);
this._figure = `${ figure }.${ this._placeHolderFigure }`;
this._gender = (this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_MANNEQUIN_GENDER) || null);
this.updateAvatar();
@ -95,60 +80,30 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
return updateModel;
}
private updateAvatar(forceUpdate: boolean = false): void
private updateAvatar(): void
{
if(!this.avatarExists() || forceUpdate)
if(this._avatarImage)
{
const avatarImage = this.data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this);
this._avatarImage.dispose();
if(avatarImage)
{
avatarImage.setDirection(AvatarSetType.FULL, this.direction);
if(this._dynamicAssetName) this.asset.disposeAsset(this._dynamicAssetName);
this.asset.addAsset(this.getAvatarAssetName(), avatarImage.getImage(AvatarSetType.FULL, false, 1, false), true);
this._dynamicAssetName = this.getAvatarAssetName();
this._needsUpdate = true;
avatarImage.dispose();
}
this._avatarImage = null;
}
}
private avatarExists(): boolean
{
return (this._figure && (this.getAsset(this.getAvatarAssetName()) !== null));
}
private getAvatarAssetName(): string
{
return (((((('mannequin_' + this._figure) + '_') + this._mannequinScale) + '_') + this.direction) + '_') + this.object.id;
this._avatarImage = this.data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this);
}
public resetFigure(figure: string): void
{
if(figure === this._figure) this.updateAvatar(true);
}
this.updateAvatar();
protected getSpriteAssetName(scale: number, layerId: number): string
{
const tag = this.getLayerTag(scale, this.direction, layerId);
if(this._figure && (tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists())
{
return this.getAvatarAssetName();
}
return super.getSpriteAssetName(scale, layerId);
this._needsUpdate = true;
}
protected getLayerXOffset(scale: number, direction: number, layerId: number): number
{
const tag = this.getLayerTag(scale, direction, layerId);
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists()) return (-(this.getSprite(layerId).width) / 2);
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage) return (-(this._avatarWidth) / 3);
return super.getLayerXOffset(scale, direction, layerId);
}
@ -157,11 +112,25 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
{
const tag = this.getLayerTag(scale, direction, layerId);
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists()) return -(this.getSprite(layerId).height);
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage) return (-(this._avatarHeight) / 3);
return super.getLayerYOffset(scale, direction, layerId);
}
public getTexture(scale: number, layerId: number, asset: IGraphicAsset): Texture
{
const tag = this.getLayerTag(scale, this.direction, layerId);
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage)
{
this._avatarImage.setDirection(AvatarSetType.FULL, this.direction);
return this._avatarImage.processAsTexture(AvatarSetType.FULL, false);
}
return super.getTexture(scale, layerId, asset);
}
public get disposed(): boolean
{
return this._disposed;

View File

@ -1,5 +1,5 @@
import { AlphaTolerance, IGraphicAsset, IObjectVisualizationData, IRoomGeometry, IRoomObjectSprite, RoomObjectVariable, RoomObjectVisualizationType } from '@nitrots/api';
import { BLEND_MODES } from 'pixi.js';
import { BLEND_MODES, Texture } from 'pixi.js';
import { RoomObjectSpriteVisualization } from '../RoomObjectSpriteVisualization';
import { ColorData, LayerData } from '../data';
import { FurnitureVisualizationData } from './FurnitureVisualizationData';
@ -279,11 +279,11 @@ export class FurnitureVisualization extends RoomObjectSpriteVisualization
{
const assetData = this.getAsset(assetName, layerId);
if(assetData && assetData.texture)
if(assetData)
{
sprite.visible = true;
sprite.type = this._type;
sprite.texture = assetData.texture;
sprite.texture = this.getTexture(scale, layerId, assetData);
sprite.flipH = assetData.flipH;
sprite.flipV = assetData.flipV;
sprite.direction = this._direction;
@ -577,6 +577,11 @@ export class FurnitureVisualization extends RoomObjectSpriteVisualization
return this.asset.getAsset(name);
}
public getTexture(scale: number, layerId: number, asset: IGraphicAsset): Texture
{
return asset?.texture ?? null;
}
protected get direction(): number
{
return this._direction;