Table of Contents

Properties and Methods

Overview

In BitmistJS, functionality is added to units by attaching what is called a perk to the unit. Units can have additional properties and methods, but the addition of properties and methods is kept to a minimum to avoid name conflicts between the functions added by the various perks. Instead, we have a container called an asset, into which each perk will add functions. Items in assets are prefixed with a period-separated perk-specific word, such as “basic.scan”, to prevent name collisions.

There is no restriction on adding properties or methods on the library side. Prefixing is also a rule, and there is no mechanism to enforce it. It is solely up to the creator to decide whether or not to comply.

The asset provides vessels for storing various types of items. By default, there are assets called “inventory”, “setting”, “skill”, and “spell” assets.

Properties and Methods

The following is a small but present list of properties and methods that the BitsmistJS core library adds to units.

Public

NameDescription
set()Stores a value in an asset.
get()Get a value from an asset.
has()Checks if the specified item exists in the asset.
use()Use a synchronous function (called skill) in the asset.
cast()Use an asynchronous function (called spell) in the asset.
upgrade()Upgrade a unit (Add functionality to a unit).
uniqueIdThe unique ID of the unit
assetsThe object that holds assets.
readyThe promise that resolves when a unit is ready.
_getSettings()Returns the unit settings.

Assets

An asset is a container for various types of items. By default, there are “inventory”, “setting”, “skill”, and “spell”.

NameDescription
inventoryThe asset to store the unit's public information.
perkThe asset to store perks attached to the unit.
settingThe asset to stores the unit's settings.
skillThe asset to stores the unit's methods.
spellThe asset to store the asynchronous methods of the unit.

When items are added to an asset, The items in the assets are prefixed with a period-delimited, perk-specific prefix, such as “basic.scan”, to avoid name conflicts.

Inventory

There is an asset for storing information: inventory. The set() and get() methods are used to access the contents.

this.get("inventory", "skin.skins.default");
this.set("inventory", "style.applied", ["default"]);

Setting

The “setting” asset is used to store settings. The items in the settings, like in other assets, are separated by a prefix for each perk.

this.get("setting", "skin.options.skinRef");

At startup, it reads and stores settings from its own _getSettings() method or from an external settings file.

Skill and Spell

There are two assets for storing methods: “skill” and “spell”. The difference between skill and spell is that skill stores synchronous methods and spell stores asynchronous methods. Spells return a promise and should be handled appropriately.

The items in skill and spell, like in other assets, are also separated by the prefix of each perk.

// Skill
let ele = this.use("basic.scan", "btn-menu");
 
// Spell
this.cast("unit.materialize").then((addedUnit) => {
    addedUnit.cast("dialog.open");
});