### Dump Shroom Assets Source: https://github.com/jankuss/shroom/blob/master/docs/docs/install.md Globally installs the Shroom CLI and then uses it to dump game assets from a specified URL into a local directory. The `--url` and `--location` flags control the source and destination of the assets. ```bash npm install -g @jankuss/shroom shroom dump --url https://www.habbo.com/gamedata/external_variables/326b0a1abf9e2571d541ac05e6eb3173b83bddea --location ./public/resources ``` -------------------------------- ### Install Shroom Package with Yarn Source: https://github.com/jankuss/shroom/blob/master/docs/docs/install.md Installs the Shroom package and its peer dependency, Pixi.js, using yarn. This is an alternative package manager installation method. ```bash yarn add @jankuss/shroom pixi.js ``` -------------------------------- ### Implement Pathfinding with EasyStar for Avatar Movement in TypeScript Source: https://context7.com/jankuss/shroom/llms.txt Provides a complete example of setting up a Shroom room, an avatar, and integrating pathfinding using EasyStar.js for avatar movement. It covers loading room textures, handling tile clicks, and configuring EasyStar for path calculation. Requires PIXI.js, Shroom, and EasyStar.js. ```typescript import * as PIXI from "pixi.js"; import { Room, Avatar, FloorFurniture, Shroom, loadRoomTexture } from "@jankuss/shroom"; import EasyStar from "easystarjs"; const application = new PIXI.Application({ width: 1200, height: 900, backgroundColor: 0x000000, }); document.body.appendChild(application.view); const shroom = Shroom.create({ application, resourcePath: "./resources", }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const avatar = new Avatar({ look: "hd-605-2.hr-3012-45.ch-645-109.lg-720-63.sh-725-92", direction: 2, roomX: 1, roomY: 0, roomZ: 0, }); room.floorTexture = loadRoomTexture("./tile.png"); room.wallTexture = loadRoomTexture("./tile.png"); room.wallColor = "#dbbe6e"; room.floorColor = "#eeeeee"; // Implement pathfinding with EasyStar room.onTileClick = async (target) => { avatar.clearMovement(); const easystar = new EasyStar.js(); const grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]; easystar.setGrid(grid); easystar.setAcceptableTiles([0]); easystar.enableDiagonals(); easystar.findPath( avatar.roomX, avatar.roomY, target.roomX, target.roomY, (path) => { if (!path) return; path.forEach((position, index) => { if (index === 0) return; avatar.walk(position.x, position.y, 0, { direction: 2 }); }); } ); easystar.calculate(); }; room.addRoomObject(avatar); room.x = application.screen.width / 2 - room.roomWidth / 2; room.y = application.screen.height / 2 - room.roomHeight / 2; application.stage.addChild(room); ``` -------------------------------- ### Start Local Development Server with Yarn Source: https://github.com/jankuss/shroom/blob/master/docs/README.md Starts a local development server for the Docusaurus 2 website. Changes are typically reflected live without manual server restarts. ```console yarn start ``` -------------------------------- ### Install Shroom Package with npm Source: https://github.com/jankuss/shroom/blob/master/docs/docs/install.md Installs the Shroom package and its peer dependency, Pixi.js, using npm. This is the primary method for adding Shroom to your project. ```bash npm install @jankuss/shroom pixi.js ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/jankuss/shroom/blob/master/docs/README.md Installs project dependencies using the Yarn package manager. This is a standard step for setting up a Node.js project. ```console yarn install ``` -------------------------------- ### Initialize Shroom Instance in TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/install.md Imports and initializes the Shroom instance within a TypeScript project using Pixi.js. It requires a PIXI.Application instance and the path to the dumped resources. ```typescript import * as PIXI from "pixi.js"; import { Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); // Assuming the resources are available under http://localhost:8080/resources const shroom = Shroom.create({ application, resourcePath: "./resources" }); ``` -------------------------------- ### Implement Room Camera with Drag Navigation in TypeScript Source: https://context7.com/jankuss/shroom/llms.txt Shows how to implement drag-to-pan navigation for a room using `RoomCamera` in TypeScript. This setup allows users to move the camera view by dragging the room. It requires the Shroom library and a PIXI application instance. ```typescript import { Room, RoomCamera, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); room.x = 100; room.y = 200; // Wrap room in camera for drag-to-pan const camera = RoomCamera.forScreen(room); application.stage.addChild(camera); ``` -------------------------------- ### Dump Habbo Assets using Shroom CLI Source: https://context7.com/jankuss/shroom/llms.txt Dumps assets from a Habbo URL using the Shroom CLI. This command requires the CLI to be installed globally and specifies the URL to dump from and the local destination path. ```bash # Install CLI globally npm install -g @jankuss/shroom # Dump assets to your project shroom dump --url https://www.habbo.com/gamedata/external_variables/326b0a1abf9e2571d541ac05e6eb3173b83bddea --location ./public/resources ``` -------------------------------- ### Initialize BaseAvatar and BaseFurniture with Shroom Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/use-base-avatar-and-furniture.md This snippet shows how to create and configure `BaseAvatar` and `BaseFurniture` instances using a `Shroom` instance. It covers setting look, position, and z-index for avatars, and direction, type, and animation for furniture. The `onLoad` callback for avatars is also demonstrated. Dependencies include a `Shroom` instance and potentially an `application.stage`. ```typescript const avatar = BaseAvatar.fromShroom(shroom, { look: { actions: new Set(), direction: 2, look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", }, position: { x: 0, y: 100 }, zIndex: 0, onLoad: () => { // This is called when the avatar has been loaded completly. console.log("Loaded"); }, }); const furniture = BaseFurniture.fromShroom(shroom, application.stage, { direction: 2, type: { kind: "type", type: "club_sofa" }, animation: "0", }); furniture.x = 100; furniture.y = 50; application.stage.addChild(avatar); ``` -------------------------------- ### Create a Room with Tilemap - TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/create-room.md This snippet demonstrates the simplest way to create a room using the Shroom library. It initializes the PIXI application and the Shroom instance, then defines a room with a 4x3 tilemap. The room's position is set, and it's added to the PIXI stage. Dependencies include 'pixi.js' and '@jankuss/shroom'. ```typescript import * as PIXI from "pixi.js"; import { Room, FloorFurniture, Avatar, Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Initialize Shroom Engine with PixiJS Application Source: https://context7.com/jankuss/shroom/llms.txt Initializes the PixiJS application and then creates a Shroom engine instance. The Shroom instance requires the PixiJS application and a resource path to load assets. ```typescript import * as PIXI from "pixi.js"; import { Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); // Create Shroom instance with resource path to dumped assets const shroom = Shroom.create({ application, resourcePath: "./resources" }); ``` -------------------------------- ### Animate Avatar Movement Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/avatar-movement.md Demonstrates how to initialize a room and avatar, then animate the avatar's movement using `walk` and `move` methods. Requires Shroom, PIXI, and Room/Avatar objects. The code sets up a basic room and avatar, then triggers movement after a delay. ```typescript import * as PIXI from "pixi.js"; import { Room, Avatar, Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 2, roomX: 0, roomY: 1, roomZ: 0, }); room.x = 100; room.y = 200; room.onTileClick = (position) => { console.log("Send this probably to a server somewhere", position); }; setTimeout(() => { // Small delay here so we can witness the avatar moving. avatar.walk(0, 2, 0, { direction: 4 }); avatar.move(1, 2, 0); }, 3000); room.addRoomObject(avatar); application.stage.addChild(room); ``` -------------------------------- ### Add Wall Furniture (Windows) in TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/adding-windows.md Demonstrates creating and adding `WallFurniture` objects, specifically for windows, to a `Room` in the Shroom project. Requires PIXI.js for rendering and Shroom core modules. Initializes a PIXI application, Shroom instance, and a Room object with a tilemap. WallFurniture instances are then created with specified coordinates, direction, and type, and added to the room. ```typescript import * as PIXI from "pixi.js"; import { Room, FloorFurniture, Avatar, Shroom, WallFurniture } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const furni1 = new WallFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 4, type: "window_skyscraper", }); const furni2 = new WallFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 4, type: "window_skyscraper", }); room.addRoomObject(furni1); room.addRoomObject(furni2); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Avatar Movement and Animations Source: https://context7.com/jankuss/shroom/llms.txt Demonstrates avatar movement within the room, including walking with animations and instant movement without animations. It also shows how to clear any pending movement commands. ```typescript import { Room, Avatar, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 2, roomX: 0, roomY: 1, roomZ: 0, }); room.addRoomObject(avatar); room.x = 100; room.y = 200; // Walk with animation to new position avatar.walk(0, 2, 0, { direction: 4 }); // Move without walking animation (sliding) avatar.move(1, 2, 0); // Clear queued movement commands avatar.clearMovement(); application.stage.addChild(room); ``` -------------------------------- ### Implement Multi-State Furniture Behavior with TypeScript Source: https://context7.com/jankuss/shroom/llms.txt Demonstrates how to create a custom furniture behavior in TypeScript for Shroom. This behavior allows a piece of furniture to cycle through different states (animations) when clicked. It requires the Shroom library and extends `FloorFurniture`. ```typescript import { FloorFurniture, IFurnitureBehavior, Room, Shroom } from "@jankuss/shroom"; // Custom furniture behavior class MultiStateBehavior implements IFurnitureBehavior { private parent: FloorFurniture | undefined; private currentState: number; private count: number; constructor({ initialState, count }: { initialState: number; count: number }) { this.currentState = initialState; this.count = count; } setParent(furniture: FloorFurniture): void { this.parent = furniture; // Handle clicks to cycle states this.parent.onClick = (event) => { this.currentState = (this.currentState + 1) % this.count; this.parent!.animation = this.currentState.toString(); event.absorb(); }; } } const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: "xxx\nx00\nx00" }); const furniture = new FloorFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 0, type: "party_floor", animation: "0", behaviors: [new MultiStateBehavior({ initialState: 0, count: 10 })], }); room.addRoomObject(furniture); application.stage.addChild(room); ``` -------------------------------- ### Deploy Docusaurus Website to GitHub Pages with Yarn Source: https://github.com/jankuss/shroom/blob/master/docs/README.md Builds the static website and deploys it to the 'gh-pages' branch, specifically configured for hosting on GitHub Pages. Requires setting the GIT_USER environment variable and optionally using SSH. ```console GIT_USER= USE_SSH=true yarn deploy ``` -------------------------------- ### Add Wall Furniture to a Room Source: https://context7.com/jankuss/shroom/llms.txt Illustrates how to create and add wall furniture, such as windows, to a room. This involves setting up Shroom and the Room, then instantiating WallFurniture objects with their specific positions and types, and adding them to the room. Multiple pieces of wall furniture can be added. ```typescript import { Room, WallFurniture, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); // Create wall furniture (windows) const furni1 = new WallFurniture({ roomX: 0, roomY: 0, offsetX: 0, offsetY: 0, direction: 4, type: "window_skyscraper", }); const furni2 = new WallFurniture({ roomX: 1, roomY: 0, offsetX: 0, offsetY: 0, direction: 4, type: "window_skyscraper", }); room.addRoomObject(furni1); room.addRoomObject(furni2); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Build Static Website Content with Yarn Source: https://github.com/jankuss/shroom/blob/master/docs/README.md Generates the static content for the website, typically outputting to a 'build' directory. This content can then be hosted on any static hosting service. ```console yarn build ``` -------------------------------- ### Add Landscape Behind Windows Source: https://context7.com/jankuss/shroom/llms.txt Demonstrates adding a landscape to a room that will be visible through wall furniture like windows. This involves creating a WallFurniture (window), adding it to the room, then creating a Landscape object, loading its textures, setting its color, and adding it to the room. ```typescript import { Room, WallFurniture, Landscape, Shroom, loadRoomTexture } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const window1 = new WallFurniture({ roomX: 0, roomY: 0, offsetX: 0, offsetY: 0, direction: 4, type: "window_skyscraper", }); room.addRoomObject(window1); // Create landscape visible through windows const landscape = new Landscape(); landscape.leftTexture = loadRoomTexture("./images/left.png"); landscape.rightTexture = loadRoomTexture("./images/right.png"); landscape.color = "#ff0000"; room.addRoomObject(landscape); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Avatar Actions and Gestures Source: https://context7.com/jankuss/shroom/llms.txt Illustrates how to apply various actions and gestures to an avatar, such as smiling, respecting, sitting, or carrying an item. It also shows how to remove an action after a specified duration. ```typescript import { Room, Avatar, AvatarAction, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxx x000 x000 x000 `, }); const avatar = new Avatar({ roomX: 1, roomY: 1, roomZ: 0, direction: 2, look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", }); // Add multiple actions avatar.addAction(AvatarAction.GestureSmile); avatar.addAction(AvatarAction.Respect); avatar.addAction(AvatarAction.Sit); avatar.addAction(AvatarAction.CarryItem); avatar.item = 1; // Remove action after timeout setTimeout(() => { avatar.removeAction(AvatarAction.Sit); }, 5000); room.addRoomObject(avatar); application.stage.addChild(room); ``` -------------------------------- ### Create Shared Shroom Instance for Multiple PIXI Applications in TypeScript Source: https://context7.com/jankuss/shroom/llms.txt Illustrates how to create and use a shared Shroom instance across multiple PIXI applications in TypeScript. This is useful for applications that need to share resources like loaders and data. It utilizes the `createShared` and `for` methods of the Shroom class. ```typescript import * as PIXI from "pixi.js"; import { Shroom } from "@jankuss/shroom"; const app1 = new PIXI.Application({ width: 800, height: 600 }); const app2 = new PIXI.Application({ width: 800, height: 600 }); // Create shared dependencies const sharedShroom = Shroom.createShared({ resourcePath: "./resources", }); // Use shared instance with multiple applications const shroom1 = sharedShroom.for(app1); const shroom2 = sharedShroom.for(app2); // Both instances share the same loaders and data ``` -------------------------------- ### Apply Room Textures and Colors with TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/applying-room-textures.md This code snippet demonstrates how to apply custom wall and floor textures, as well as colors, to a room object in the Shroom project. It requires preloaded textures or promises that resolve after loading. The textures should be in a standard 2D format, as Shroom handles isometric projection automatically. Dependencies include PIXI.js and the Shroom library. ```typescript import * as PIXI from "pixi.js"; import { Room, FloorFurniture, Avatar, Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); room.x = 100; room.y = 200; // Note: If you are using PIXI Loader and the texture has been preloaded, // you can also specify the textures like the following. // room.wallTexture = PIXI.Texture.from("./wall.png") // The important thing here is that the texture is loaded before use. room.wallTexture = loadRoomTexture("./images/wall.png"); room.floorTexture = loadRoomTexture("./images/floor.png"); room.wallColor = "#dbbe6e"; room.floorColor = "#eeeeee"; application.stage.addChild(room); ``` -------------------------------- ### Handle Tile Click Events in a Room Source: https://context7.com/jankuss/shroom/llms.txt Explains how to set up an event handler for tile clicks within a room. When a tile is clicked, a callback function is executed, which can log the position and trigger an avatar to walk to that position. This involves creating a Room and an Avatar, then assigning a function to the `onTileClick` property of the Room. ```typescript import { Room, Avatar, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 2, roomX: 0, roomY: 1, roomZ: 0, }); // Handle tile clicks room.onTileClick = (position) => { console.log("Tile clicked at:", position); // Implement pathfinding and walk avatar to position avatar.walk(position.roomX, position.roomY, position.roomZ, { direction: 4 }); }; room.addRoomObject(avatar); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Add Floor Furniture to a Room Source: https://context7.com/jankuss/shroom/llms.txt Demonstrates how to create and add floor furniture to a room in the Shroom application. It involves initializing Shroom, creating a room with a tilemap, instantiating a FloorFurniture object with its properties, and adding it to the room. An Avatar is also created and set to an action. ```typescript import { Room, FloorFurniture, Avatar, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); // Create floor furniture with type identifier const furni = new FloorFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 4, type: "club_sofa", }); const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 4, roomX: 0, roomY: 0, roomZ: 0, }); avatar.action = "sit"; room.addRoomObject(furni); room.addRoomObject(avatar); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Create an Isometric Room with Tilemap Source: https://context7.com/jankuss/shroom/llms.txt Creates a new room instance within the Shroom engine using a string-based tilemap. The tilemap defines the room's structure, where 'x' denotes empty space and '0'/'1' denote floor tiles at different heights. The room is then added to the PixiJS application stage. ```typescript import * as PIXI from "pixi.js"; import { Room, Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); // Create room with string-based tilemap // 'x' = no tile, '0' = tile at height 0, '1' = tile at height 1 const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Apply Textures and Colors to a Room Source: https://context7.com/jankuss/shroom/llms.txt Explains how to load and apply custom textures and colors to the walls and floor of a room. This is an asynchronous operation for textures. It involves initializing Shroom and Room, then assigning loaded textures or color strings to the room's texture and color properties. ```typescript import { Room, Shroom, loadRoomTexture } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); room.x = 100; room.y = 200; // Load and apply textures (async) room.wallTexture = loadRoomTexture("./images/wall.png"); room.floorTexture = loadRoomTexture("./images/floor.png"); // Apply colors room.wallColor = "#dbbe6e"; room.floorColor = "#eeeeee"; application.stage.addChild(room); ``` -------------------------------- ### Add Landscape to Room in TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/adding-windows.md Illustrates how to create and configure a `Landscape` object to serve as a custom background for windows in a Shroom room. This snippet assumes a `Room` object and texture loading functions are already available. It involves creating a `Landscape` instance, assigning left and right textures, setting a color, and adding it to the room. ```typescript /* ...*/ const landscape = new Landscape(); landscape.leftTexture = loadRoomTexture("./images/left.png"); landscape.rightTexture = loadRoomTexture("./images/right.png"); landscape.color = "#ff0000"; room.addRoomObject(landscape); ``` -------------------------------- ### Move Floor Furniture in a Room Source: https://context7.com/jankuss/shroom/llms.txt Shows how to animate floor furniture to a new position within a room and then clear its movement queue. This is useful for creating dynamic environments. It requires initializing Shroom and a Room, creating a FloorFurniture object, adding it to the room, and then calling its move and clearMovement methods. ```typescript import { FloorFurniture, Room, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: "xxx\nx00\nx00" }); const furniture = new FloorFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 2, type: "club_sofa", animation: "0", }); room.addRoomObject(furniture); // Animate furniture to new position furniture.move(0, 1, 0); // Clear movement queue furniture.clearMovement(); ``` -------------------------------- ### Add FloorFurniture and Avatar to Shroom Room (TypeScript) Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/adding-objects.md This TypeScript snippet illustrates adding a sofa (FloorFurniture) and an avatar to a Shroom room. It initializes PIXI, Shroom, and Room, then creates instances of FloorFurniture and Avatar, configures their properties, and adds them to the room. The room is then positioned and added to the PIXI application stage. Dependencies include 'pixi.js' and '@jankuss/shroom'. ```typescript import * as PIXI from "pixi.js"; import { Room, FloorFurniture, Avatar, Shroom } from "@jankuss/shroom"; const view = document.querySelector("#root") as HTMLCanvasElement; const application = new PIXI.Application({ view }); const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); const furni = new FloorFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 4, type: "club_sofa", }); const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 4, roomX: 0, roomY: 0, roomZ: 0, }); avatar.action = "sit"; room.addRoomObject(furni); room.addRoomObject(avatar); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Animate Floor Furniture Movement Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/avatar-movement.md Illustrates how to animate the movement of a `FloorFurniture` object. This method is similar to avatar movement but only applies to floor furniture. Requires `FloorFurniture` object. ```typescript const furniture = new FloorFurniture({ roomX: 0, roomY: 0, roomZ: 0, direction: 2, type: "club_sofa", animation: "0", }); furniture.move(0, 1, 0); ``` -------------------------------- ### Add an Avatar to the Room Source: https://context7.com/jankuss/shroom/llms.txt Creates an avatar instance with a specific 'look' string and initial position, then adds it to the room. The avatar's appearance and position are defined by the provided parameters. ```typescript import { Room, Avatar, Shroom } from "@jankuss/shroom"; const shroom = Shroom.create({ application, resourcePath: "./resources" }); const room = Room.create(shroom, { tilemap: ` xxxxx x0000 x0000 x0000 `, }); // Create avatar with look string and initial position const avatar = new Avatar({ look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", direction: 4, roomX: 0, roomY: 0, roomZ: 0, }); room.addRoomObject(avatar); room.x = 100; room.y = 200; application.stage.addChild(room); ``` -------------------------------- ### Implement Dice Furniture Logic with TypeScript Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/implementing-furniture-logic.md This TypeScript snippet demonstrates how to implement the logic for a dice furniture ('edice') in Shroom. It handles click events on 'activate' and 'deactivate' areas to control rolling and disabling the dice. The implementation includes state management for rolling, value, and active status, along with animation updates. ```typescript /** * ... */ const room = Room.create(shroom, { tilemap: ` xxxx x000 x000 x000 `, }); const furniture = new FloorFurniture({ roomX: 1, roomY: 1, roomZ: 0, direction: 0, animation: "0", type: "edice", }); const handleDice = (furniture: IFurniture) => { interface State { rolling: boolean; value: number; active: boolean; } let state: State = { rolling: false, value: 1, active: false }; let timeout: any; const updateState = (newState: State) => { state = newState; if (state.rolling) { furniture.animation = "-1"; } else if (state.active) { furniture.animation = state.value.toString(); } else { furniture.animation = "0"; } }; const roll = () => { updateState({ ...state, rolling: true, active: true }); clearTimeout(timeout); // After 1 seconds, we set the dice value timeout = setTimeout(() => { updateState({ ...state, rolling: false, value: Math.floor(Math.random() * 6) + 1, }); }, 1000); }; const deactivate = () => { updateState({ ...state, rolling: false, active: !state.active }); }; furniture.onDoubleClick = (event) => { switch (event.tag) { case "activate": roll(); break; case "deactivate": deactivate(); break; } }; }; furniture.extradata.then(({ logic }) => { switch (logic) { // Here you should handle every possible logic a furniture can have. // We only handle the dice logic here. case "furniture_dice": handleDice(furniture); break; } }); room.addRoomObject(furniture); ``` -------------------------------- ### Parse Tilemap Strings to 2D Array in TypeScript Source: https://context7.com/jankuss/shroom/llms.txt Demonstrates how to parse a tilemap string into a 2D array representation using the `parseTileMapString` function from the Shroom library in TypeScript. The function interprets specific characters ('x', '0'-'9') to define tile types and heights. ```typescript import { parseTileMapString } from "@jankuss/shroom"; // Parse tilemap string into 2D array const tilemap = parseTileMapString(` 1111111111 1111111111 111111xx00 111111xx00 000000xx00 0000000000 `); // tilemap is TileType[][] where: // 'x' = no tile // '0'-'9' = tile at height 0-9 console.log(tilemap); ``` -------------------------------- ### Add and Remove Avatar Actions (TypeScript) Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/avatar-actions.md This snippet demonstrates how to add and remove actions for an avatar. It initializes a room, creates an avatar, adds several actions (Smile, Respect, Sit, CarryItem), and then removes the 'Sit' action after a 5-second delay. Dependencies include 'Room', 'Avatar', and 'AvatarAction' from the Shroom library. ```typescript /** * ... */ const room = Room.create(shroom, { tilemap: ` xxxx x000 x000 x000 `, }); const avatar = new Avatar({ roomX: 1, roomY: 1, roomZ: 0, direction: 2, look: "hd-180-1.hr-100-61.ch-210-66.lg-280-110.sh-305-62", }); avatar.addAction(AvatarAction.GestureSmile); avatar.addAction(AvatarAction.Respect); avatar.addAction(AvatarAction.Sit); avatar.addAction(AvatarAction.CarryItem); avatar.item = 1; setTimeout(() => { // Remove the sitting action after some time passed avatar.removeAction(AvatarAction.Sit); }, 5000); room.addRoomObject(avatar); application.stage.addChild(room); ``` -------------------------------- ### Clear Avatar Movement Queue Source: https://github.com/jankuss/shroom/blob/master/docs/docs/guides/avatar-movement.md Shows how to clear all queued movement animations for an avatar using the `clearMovement()` method. This stops all pending animations and allows the currently executing one to finish. ```typescript avatar.clearMovement(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.