Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
Tutorial explaining how to create custom object list widgets with images for AdventureJS. tutorial, custom, object list widgets ObjectListWidgetImages styles

Display & Layouts:Object List Widgets w/ Images

Object List Widgets can show images (with or without text labels).

 

// ObjectListWidgetImages.js
/* global AdventureJS A Game */

var ObjectListWidgetImages = new AdventureJS.Game(
  "ObjectListWidgetImages",
  "ObjectListWidgetImagesContainer"
);

ObjectListWidgetImages.settings.set({
  display: "inline",
  title: "Object List Widget w/ Images",
  author: "Ivan Cockrum",
  description:
    "Here is an example of a simple layout with a fixed object list widget that always shows a list of objects in the room. ",
  version: "0.0.1",
});

ObjectListWidgetImages.createImageLookup({
  images: [
    {
      id: "brasskey",
      src: "images/icon_brass-key.png",
    },
    {
      id: "hairpin",
      src: "images/icon_hairpin.png",
    },
    {
      id: "ann",
      src: "images/icon_raggedy-ann.png",
    },
    {
      id: "andy",
      src: "images/icon_raggedy-andy.png",
    },
    {
      id: "bluekey",
      src: "images/icon_blue-steel-key.png",
    },
    {
      id: "drawing",
      src: "images/icon_drawing-alt.png",
    },
    {
      id: "silverkey",
      src: "images/icon_silver-key.png",
    },
    {
      id: "lantern",
      src: "images/icon_brass-lantern.png",
    },
    {
      id: "knapsack",
      src: "images/icon_knapsack.png",
    },
  ],
});

// Create the widget.
ObjectListWidgetImages.createWidget({
  class: "ObjectList",
  id: "MyObjectListWidgetImages",
  title: "OBJECTS",
  cssclasses: ["custom", "object"],
  verb: "examine",
  region: "left",
  print_images: true,
});

ObjectListWidgetImages.createAsset({
  class: "Player",
  name: "Explorer",
  place: { in: "Start Room" },
});

ObjectListWidgetImages.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",
  },
});

ObjectListWidgetImages.createAsset({
  class: "Room",
  name: "North Room",
  description: `This is the North Room. `,
  exits: {
    south: "Start Room",
  },
});

ObjectListWidgetImages.createAsset({
  class: "Room",
  name: "South Room",
  description: `This is the South Room. `,
  exits: {
    north: "Start Room",
  },
});

ObjectListWidgetImages.createAsset({
  class: "Room",
  name: "East Room",
  description: `This is the East Room. `,
  exits: {
    west: "Start Room",
  },
});

ObjectListWidgetImages.createAsset({
  class: "Room",
  name: "West Room",
  description: `This is the West Room. `,
  exits: {
    east: "Start Room",
  },
});

ObjectListWidgetImages.createAsset({
  class: "Key",
  name: "brass key",
  image: "brasskey",
  synonyms: ["glass bead"],
  article: "a",
  adjectives: ["burnished", "chonky"],
  place: { in: "Start Room" },
  description: `It's a burnished brass key with chonky teeth 
  and a small glass bead mounted in the head. `,
}); // brass Key
ObjectListWidgetImages.createAsset({
  class: "Key",
  name: "blue steel key",
  image: "bluekey",
  synonyms: ["blue key", "steel key"],
  adjectives: ["victorian"],
  description: "It's an ornate Victorian key made of blue steel. ",
  // article: "a",
  place: { in: "North Room" },
});
ObjectListWidgetImages.createAsset({
  class: "Key",
  name: "tiny silver key",
  adjectives: ["tiny"],
  image: "silverkey",
  description: `It's tiny, and it's silver, and it's a key. It don't open nuthin' so don't even bother. `,
  article: "a",
  place: { in: "East Room" },
});
ObjectListWidgetImages.createAsset({
  class: "Doll",
  name: "Raggedy Ann doll",
  synonyms: ["dress", "trim", "hair"],
  image: "ann",
  place: { in: "Start Room" },
  description: `It's a well-loved Raggedy Ann doll in a white dress with blue and red trim. `,
});
ObjectListWidgetImages.createAsset({
  class: "Doll",
  name: "Raggedy Andy doll",
  synonyms: ["hat"],
  image: "andy",
  place: { in: "Start Room" },
  description: `It's a threadworn Raggedy Andy doll in a patched 
      sailor suit. His red hair is partially covered by a cap 
      that appears to be sewn on, though the old threads are wearing. `,
});
ObjectListWidgetImages.createAsset({
  class: "Lockpick",
  name: "copper hairpin",
  image: "hairpin",
  synonyms: ["pin", "beads", "tines", "head"],
  adjectives: ["hammered"],
  article: "the",
  description: `The hammered copper hairpin has two tines and  
    a butterfly shaped head with tiny beads affixed to it, in  
    a vaguely art nouveau style. It's actually quite nice. `,
  place: { in: "West 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: "ObjectList",
  id: "MyObjectListWidget",
  cssclasses: ["custom", "objects"],
  verb: "examine",
  region: "left",
  print_images: true,
});

Adding images to object list widgets requires adding images to each object. [More info...]

Object List Widget Properties

  • 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:
    • top
    • left
    • right
    • bottom