Skip to content

Commit

Permalink
Merge pull request #117 from jankuss/various-fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
jankuss authored Jan 25, 2021
2 parents e2123d9 + b7017fe commit 9f2dcbb
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/objects/furniture/BaseFurniture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ export class BaseFurniture implements IFurnitureEventHandlers {
this.visualization.updateFrame(frame);
}
);
this.visualization.update(this);
this.visualization.updateFrame(
this.dependencies.animationTicker.current()
);
Expand All @@ -671,6 +672,8 @@ export class BaseFurniture implements IFurnitureEventHandlers {
) {
this._cancelTicker();
this._cancelTicker = undefined;

this.visualization.update(this);
this.visualization.updateFrame(
this.dependencies.animationTicker.current()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class AnimatedFurnitureVisualization extends FurnitureVisualization {
this._update(true);
}

isAnimated() {
return true;
}

private _getCurrentProgress(frame: number) {
if (this._animationQueueStartFrame == null) {
return 0;
Expand Down
9 changes: 0 additions & 9 deletions src/objects/furniture/visualization/FurnitureVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export abstract class FurnitureVisualization
}

isAnimated(animation = "0"): boolean {
const frameCount = this._view?.furniture.visualizationData.getFrameCountWithoutRepeat(
64,
Number(animation)
);

if (frameCount != null) {
return frameCount > 1;
}

return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/objects/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ export class Room
destroy() {
super.destroy();
this.roomObjects.forEach((object) => this.removeRoomObject(object));

this._visualization.destroy();
}

private _getObjectPositionWithOffset(roomX: number, roomY: number) {
Expand Down
11 changes: 10 additions & 1 deletion src/objects/room/RoomModelVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ export class RoomModelVisualization
return this._wallLayer;
}

destroy() {
super.destroy();
this._destroyAllSprites();
}

addMask(id: string, element: PIXI.Sprite): MaskNode {
/*
const existing = this._masks.get(id);
Expand Down Expand Up @@ -385,14 +390,18 @@ export class RoomModelVisualization
return this.parsedTileMap.largestDiff * 32 + this._wallHeight;
}

private _updateHeightmap() {
private _destroyAllSprites() {
[...this._tileCursors, ...this._tiles, ...this._walls].forEach((part) =>
part.destroy()
);

this._tileCursors = [];
this._tiles = [];
this._walls = [];
}

private _updateHeightmap() {
this._destroyAllSprites();

for (let y = 0; y < this.parsedTileMap.parsedTileTypes.length; y++) {
for (let x = 0; x < this.parsedTileMap.parsedTileTypes[y].length; x++) {
Expand Down
1 change: 1 addition & 0 deletions src/objects/room/parts/Stair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class Stair extends PIXI.Container implements IRoomPart {

destroy() {
super.destroy();
this.removeChildren();
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/objects/room/parts/StairCorner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ export class StairCorner extends PIXI.Container implements IRoomPart {
this._container?.destroy();
}

destroyed(): void {
destroy() {
super.destroy();
this.destroySprites();
}

registered(): void {
this.updateSprites();
}

private _createStairBoxFront(index: number): PIXI.DisplayObject[] {
const baseXLeft = +stairBase * index;
const baseYLeft = -stairBase * index * 1.5;
Expand Down
5 changes: 5 additions & 0 deletions src/objects/room/parts/Tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export class Tile extends PIXI.Container implements IRoomPart {
this._updateSprites();
}

destroy() {
super.destroy();
this._destroySprites();
}

private _destroySprites() {
this._sprites.forEach((sprite) => sprite.destroy());
this._sprites = [];
Expand Down
2 changes: 1 addition & 1 deletion src/objects/room/parts/TileCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export class TileCursor extends PIXI.Container implements HitDetectionElement {

destroy() {
super.destroy();

this._node.remove();
this._graphics.destroy();
}

private _createGraphics() {
Expand Down
6 changes: 6 additions & 0 deletions src/objects/room/parts/WallLeft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export class WallLeft extends PIXI.Container implements IRoomPart {
this._update();
}

destroy() {
super.destroy();
this._hitAreaElement?.destroy();
this.removeChildren();
}

protected _update() {
if (this._hitAreaElement != null) {
this.props.hitAreaContainer.removeChild(this._hitAreaElement);
Expand Down
43 changes: 34 additions & 9 deletions storybook/stories/Furniture.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ export function LoadTest() {
}
});

obj.onClick = (event) => {
console.log("Clicked");
};

room.addRoomObject(obj);
});
});
Expand All @@ -1034,24 +1038,45 @@ export function LoadTest() {
type: "bed_budget",
});

const avatar = new Avatar({
room.x = application.screen.width / 2 - room.roomWidth / 2;
room.y = application.screen.height / 2 - room.roomHeight / 2;
room.addRoomObject(furniture1);
application.stage.addChild(room);
});
}

export function AnimationResetTest() {
return createShroom(({ application, shroom }) => {
const room = Room.create(shroom, {
tilemap: `
xxxxxxxxxxx
x0000000000
x0000000000
x0000000000
x0000000000
x0000000000
x0000000000
x0000000000
x0000000000
`,
});

const furniture1 = new FloorFurniture({
roomX: 1,
roomY: 1,
direction: 2,
look: "hr-3163-39.hd-180-2.lg-3202-1322-1329.ch-215-1331",
roomZ: 0,
animation: "0",
direction: 2,
id: 3675,
});

avatar.addAction(AvatarAction.Lay);

setTimeout(() => {
avatar.walk(1, 2, 0);
}, 2500);
furniture1.onClick = (event) => {
furniture1.animation = "1";
};

room.x = application.screen.width / 2 - room.roomWidth / 2;
room.y = application.screen.height / 2 - room.roomHeight / 2;
room.addRoomObject(furniture1);
room.addRoomObject(avatar);
application.stage.addChild(room);
});
}
49 changes: 49 additions & 0 deletions storybook/stories/Room.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Landscape,
WallFurniture,
RoomCamera,
Avatar,
} from "@jankuss/shroom";

import { createShroom } from "./common/createShroom";
Expand Down Expand Up @@ -472,6 +473,54 @@ export function HideTileCursor() {
});
}

export function TestTileClick() {
return createShroom(({ application, shroom }) => {
const room = Room.create(shroom, {
tilemap: `
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxx000000x
xxxxx000000x
xxxxx000000x
xxxxx000000x
xxxxx000000x
xxxxx000000x
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
`,
});

const avatar = new Avatar({
look:
"hd-180-1.hr-828-61.ha-1012-110.he-1604-62.ea-1404-62.fa-1204-62.ch-255-66.lg-280-110.sh-305-62",
direction: 3,
roomX: 1,
roomY: 1,
roomZ: 0,
headDirection: 3,
});

room.onTileClick = (event) => {
console.log("ROOM", event);
avatar.walk(event.roomX, event.roomY, event.roomZ);
};

room.addRoomObject(avatar);

setTimeout(() => {
room.destroy();
}, 5000);

application.stage.addChild(room);
});
}

export default {
title: "Room",
};

0 comments on commit 9f2dcbb

Please sign in to comment.