Display & Layouts:Inventory List Widgets
Inventory list widgets can display a list of the player's current
inventory.
// InventoryListWidget.js
/* global AdventureJS A InventoryListWidget G */
var InventoryListWidget = new AdventureJS.Game(
"InventoryListWidget",
"InventoryListWidgetContainer"
);
InventoryListWidget.settings.set({
display: "inline",
title: "Inventory List Widget",
author: "Ivan Cockrum",
description:
"Here is an example of a simple layout with a fixed inventory widget that always shows a list of the player's inventory. ",
version: "0.0.1",
});
// Create the widget.
InventoryListWidget.createWidget({
class: "InventoryList",
id: "MyInventoryListWidget",
title: "INVENTORY",
cssclasses: ["custom", "inventory"],
region: "right",
verb: "examine",
});
InventoryListWidget.createAsset({
class: "Player",
name: "Explorer",
place: { in: "Start Room" },
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "indigo pencil",
a: "an",
adjectives: "indigo, colored",
place: { in: "Explorer" },
description: "It's an indigo colored pencil. ",
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "violet pencil",
article: "a",
adjectives: "violet, colored",
place: { in: "Explorer" },
description: "It's a violet colored pencil. ",
});
InventoryListWidget.createAsset({
class: "Room",
name: "Start Room",
description: `
This is the Start Room.
`,
exits: {
east: "East Room",
west: "West Room",
north: "North Room",
south: "South Room",
},
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "yellow pencil",
article: "a",
adjectives: "yellow, colored",
place: { in: "Start Room" },
description: "It's a yellow colored pencil. ",
});
InventoryListWidget.createAsset({
class: "Room",
name: "North Room",
description: `This is the North Room. `,
exits: {
south: "Start Room",
},
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "blue pencil",
article: "a",
adjectives: "blue, colored",
place: { in: "North Room" },
description: "It's a colored pencil, zinc blue. ",
});
InventoryListWidget.createAsset({
class: "Room",
name: "South Room",
description: `This is the South Room. `,
exits: {
north: "Start Room",
},
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "red pencil",
article: "a",
adjectives: "red, colored",
place: { in: "South Room" },
description: "It's a red colored pencil. ",
});
InventoryListWidget.createAsset({
class: "Room",
name: "East Room",
description: `This is the East Room. `,
exits: {
west: "Start Room",
},
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "orange pencil",
// article: "a",
adjectives: "orange, colored",
place: { in: "East Room" },
description: "It's an orange colored pencil. ",
});
InventoryListWidget.createAsset({
class: "Room",
name: "West Room",
description: `This is the West Room. `,
exits: {
east: "Start Room",
},
});
InventoryListWidget.createAsset({
class: "Pencil",
name: "green pencil",
article: "a",
adjectives: "green, colored",
place: { in: "West Room" },
description: "It's a green colored pencil. ",
});
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: "InventoryList",
id: "MyInventoryListWidget",
cssclasses: ["custom", "inventory"],
region: "header",
});
Objects in an inventory list widget are clickable, with this logic:
-
If a player clicks an object in the list without having typed anything in
the input field, the click will perform a verb action on the object. The
default verb action is
examine, meaning that if a player clicks an item in the list, they will automatically examine it. Authors can specify the verb to be used. - If a player clicks an object in the list while there is text in the input field, the name of the inventory object will be appended to the input field, leaving it up to the player to input.
Inventory List Widget Properties
-
assetclasses
{Array}
Inventory list widgets can be limited to specific asset classes by passing
class names in assetclasses.
assetclasses: [ "Key", "WritingImplement" ], -
is
{Array}
Inventory list widgets can be limited to specific states, like is.worn, to
create an inventory list widget that only shows worn items.
is: [ "worn", ], -
is_in
{Array}
Inventory list widgets can be limited to items within other specified
items, like only showing the contents of a knapsack.
is_in: [ "knapsack" ], -
verb
{String}
Optionally provide a verb to apply to the clicked asset if the player
clicks an item while the input field is empty. If the player has already
entered input to the input field, the item's name will be appended to it
rather than calling a verb action. The default verb is
examine. - 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