From e303acc3bae420941267a448467159690232b459 Mon Sep 17 00:00:00 2001 From: jankuss Date: Fri, 8 Jan 2021 11:39:41 -0800 Subject: [PATCH] Fix valid directions for furniture --- src/objects/furniture/BaseFurniture.tsx | 18 ++++++++++++++---- .../AnimatedFurnitureVisualization.ts | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/objects/furniture/BaseFurniture.tsx b/src/objects/furniture/BaseFurniture.tsx index 368c11d7..29040948 100644 --- a/src/objects/furniture/BaseFurniture.tsx +++ b/src/objects/furniture/BaseFurniture.tsx @@ -21,6 +21,7 @@ import { Shroom } from "../Shroom"; import { IFurnitureVisualization } from "./IFurnitureVisualization"; import { FurnitureSprite } from "./FurnitureSprite"; import { AnimatedFurnitureVisualization } from "./visualization/AnimatedFurnitureVisualization"; +import { getDirectionForFurniture } from "./util/getDirectionForFurniture"; const highlightFilter = new HighlightFilter(0x999999, 0xffffff); @@ -63,6 +64,7 @@ export class BaseFurniture implements IFurnitureEventHandlers { private _unknownSprite: FurnitureSprite | undefined; private _clickHandler = new ClickHandler(); private _loadFurniResultPromise: Promise; + private _validDirections: number[] | undefined; private _resolveLoadFurniResult: (result: LoadFurniResult) => void = () => {}; private _visualization: IFurnitureVisualization | undefined; @@ -76,8 +78,6 @@ export class BaseFurniture implements IFurnitureEventHandlers { private _alpha: number = 1; private _destroyed: boolean = false; - private _frameCount: number | undefined; - private _maskNodes: MaskNode[] = []; private _cancelTicker: (() => void) | undefined = undefined; private _getMaskId: MaskIdGetter; @@ -264,7 +264,7 @@ export class BaseFurniture implements IFurnitureEventHandlers { public set direction(value) { this._direction = value; - this.visualization.updateDirection(this.direction); + this._updateDirection(); } public get animation() { @@ -301,6 +301,14 @@ export class BaseFurniture implements IFurnitureEventHandlers { } }; + private _updateDirection() { + if (this._validDirections != null) { + this.visualization.updateDirection( + getDirectionForFurniture(this.direction, this._validDirections) + ); + } + } + private _updateSprites(cb: (element: FurnitureSprite) => void) { this._sprites.forEach(cb); @@ -432,8 +440,10 @@ export class BaseFurniture implements IFurnitureEventHandlers { }); this.visualization.update(this); + this._validDirections = loadFurniResult.directions; + + this._updateDirection(); - this.visualization.updateDirection(this.direction); this.visualization.updateAnimation(this.animation); this.visualization.updateFrame(this.dependencies.animationTicker.current()); } diff --git a/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts b/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts index 421926ac..a0f3f7e9 100644 --- a/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts +++ b/src/objects/furniture/visualization/AnimatedFurnitureVisualization.ts @@ -109,7 +109,7 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization { newAnimation ); - this._disableTransitions = this._changeAnimationCount === 0; + this._disableTransitions = false; this._changeAnimationCount++; } @@ -216,6 +216,7 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization { const frameCount = this._animationFrameCount ?? 1; this._sprites.forEach((sprite) => (sprite.visible = false)); + this._furnitureDrawDefintion?.parts.forEach((part) => { if (this.modifier != null) { part = this.modifier(part); @@ -237,6 +238,7 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization { } const sprite = this.view.createSprite(part, frameIndex); + if (sprite != null) { this._sprites.add(sprite); sprite.visible = true;