======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==== |< 100% 130px - >| ^Name^Description^ |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).| |uniqueId|The unique ID of the unit| |assets|The object that holds assets.| |ready|The 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". |< 100% 130px - >| ^Name^Description^ |inventory|The asset to store the unit's public information.| |perk|The asset to store perks attached to the unit.| |setting|The asset to stores the unit's settings.| |skill|The asset to stores the unit's methods.| |spell|The 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. For more information on settings, please see below. * [[en:bitsmist-js-core:unit:settings|Unit Explained - Settings]] ====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"); });