Skip to content

Commit

Permalink
Fix valid directions for furniture
Browse files Browse the repository at this point in the history
  • Loading branch information
jankuss committed Jan 8, 2021
1 parent 187afad commit e303acc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/objects/furniture/BaseFurniture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -63,6 +64,7 @@ export class BaseFurniture implements IFurnitureEventHandlers {
private _unknownSprite: FurnitureSprite | undefined;
private _clickHandler = new ClickHandler();
private _loadFurniResultPromise: Promise<LoadFurniResult>;
private _validDirections: number[] | undefined;
private _resolveLoadFurniResult: (result: LoadFurniResult) => void = () => {};

private _visualization: IFurnitureVisualization | undefined;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization {
newAnimation
);

this._disableTransitions = this._changeAnimationCount === 0;
this._disableTransitions = false;
this._changeAnimationCount++;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit e303acc

Please sign in to comment.