Display & Layouts:Room Description Widgets
Room Description Widgets can show a description of the current
room, to give players a persistent room description. The widget can optionally
include the room's name, description, exits, and contents.
// RoomDescriptionWidget.js
/* global AdventureJS A RoomDescriptionWidget G */
var RoomDescriptionWidget = new AdventureJS.Game(
"RoomDescriptionWidget",
"RoomDescriptionWidgetContainer"
);
RoomDescriptionWidget.settings.set({
display: "inline",
title: "Room Widget",
author: "Ivan Cockrum",
description:
"Here is an example of a simple layout with a fixed room description widget that always shows the current room description to the player. ",
version: "0.0.1",
});
// Create the widget.
RoomDescriptionWidget.createWidget({
class: "RoomDescription",
id: "MyRoomDescriptionWidget",
cssclasses: ["custom", "room"],
region: "header",
print_name: false,
print_description: true,
print_exits: false,
print_contents: false,
});
RoomDescriptionWidget.createAsset({
class: "Player",
name: "Explorer",
place: { in: "Start Room" },
});
RoomDescriptionWidget.createAsset({
class: "Room",
name: "Start Room",
description: `
This is the Start Room. (If we had more to say about it, this
description would be longer.) You can go north, south, east, or west from here.
`,
exits: {
east: "East Room",
west: "West Room",
north: "North Room",
south: "South Room",
},
});
RoomDescriptionWidget.createAsset({
class: "Room",
name: "North Room",
description: `This is the North Room. (If we had more to say about it, this
description would be longer.) You can go south to the Start Room from here. `,
exits: {
south: "Start Room",
},
});
RoomDescriptionWidget.createAsset({
class: "Room",
name: "South Room",
description: `This is the South Room. (If we had more to say about it, this
description would be longer.) You can go north to the Start Room from here. `,
exits: {
north: "Start Room",
},
});
RoomDescriptionWidget.createAsset({
class: "Room",
name: "East Room",
description: `This is the East Room. (If we had more to say about it, this
description would be longer.) You can go west to the Start Room from here. `,
exits: {
west: "Start Room",
},
});
RoomDescriptionWidget.createAsset({
class: "Room",
name: "West Room",
description: `This is the West Room. (If we had more to say about it, this
description would be longer.) You can go east to the Start Room from here. `,
exits: {
east: "Start Room",
},
});
Demo Source files
Right-click and choose "Save as..." to download source files.
Notes:
- Demo games are set to a small size to fit doc pages. They can easily be enlarged via display settings.
- Demo games all use the same theme. Colors and fonts can be changed via custom CSS.
- Demo games don't include the core AdventureJS code. To run downloaded games locally, you'll need to also download copies of the core JS and CSS and set up this local folder structure.
AdventureJS └── js | └── adventure.min.js └── css | └── adventurejs.min.css └── games ├── demogame01 ├── demogame02 └── demogame03
Example Code
MyGame.createWidget({
class: "RoomDescription",
id: "MyRoomDescriptionWidget",
cssclasses: ["custom", "room"],
region: "header",
});
Room Description Widget Properties
- print_name {Boolean} If true, the room's name will be printed.
- print_description {Boolean} If true, the room's description will be printed.
- print_exits {Boolean} If true, a list of the room's exits will be printed.
- print_contents {Boolean} If true, a list of the room's contents will be printed.
- id {String} The ID to be given to the widget. If an HTML element with this ID already exists on the page, that element will be used. Otherwise an element with this ID will be created at game initialization.
- cssclasses {Array} Optional custom CSS classes to apply to the widget.
-
region
{String}
The region to place the widget in. Valid options are:
topleftrightbottom