Bitsmist
Docs» Extending with Perks

Extending with Perks

Overview

The core component of BitsmistJS “Unit” has few functions. Each unit can be extended in functionality by applying perks.

For example, in "Create a Sample Unit", an event handler is set in the configuration, which is handled by EventPerk. Loading and applying HTML files is done by SkinPerk.

Perk has the following functions.

  • Add event handlers to a unit to perform processing at specific event.
  • Add skills, spells, and inventories to a unit.

By default, the following perks are applied to a unit.

  • BasicPerk
  • EventPerk
  • SettingPerk
  • SkinPerk
  • StatusPerk
  • StylePerk
  • UnitPerk

Applying Perks

To apply a perk, it must be written in the settings of each unit. There are two ways to do so.

Write in the "perk" Section

Specify the name of the perks in apply option of Perk. Multiple perks can be specified.

_getSettings()
{
    return {
        "perk": {
            "options": {
                "apply": ["EventPerk"]
            }
        }
    };
}

Add Perk's Dedicated Section

Each perk has a dedicated section for the perk, and the presence of that section in the settings will automatically apply the perk.

For example, the following settings has an “event” section, so the EventPerk will be applied automatically.

_getSettings()
{
    return {
        "event": {
            "events": {
                "this": {
                    "handlers": {
                        "doSetup": this.onDoSetup
                    }
                },
            }
        }
    };
}

To see which perks are associated with which section, see the “section” tag under the title of each perk reference.

Event Handlers

Some perks register event handlers to the units and perform their own processing within those handlers. The event handlers registered by the perks have a higher priority and are designed to be processed before user event handlers.

Which events are handled and how they are handled varies from perk to perk. For example, SkinPerk loads the necessary HTML file in “beforeTransform” and applies it to the unit in “doTransform” event.

Below is a list of what the perk in the core library does at which events. For more information, please refer to each link.

EventPerkDescription
doApplySettingsEventPerkInstall event handlers.
StatuePerkInstall event handlers to wait for other units.
UnitPerkAdd child units.
beforeTransformSkinPerkLoad HTML file.
StylePerkLoad and Apply common CSS files.
doTransformSkinPerkApply HTML file.
StylePerkLoad and Apply unit-specifi CSS files.
afterTransformEventPerkInstall event handlers for child elements.

Extended Features

Each perk also has the ability to add assets, inventory, skills, and spells to the unit prototype and/or each instance.

Below is a list of the functions added by the perks in the core library. Please see the description of each perk for more details.

PerkTypeName
BasicPerkMethodcast
use
Assetinventory
perk
skill
spell
Inventorybasic.unitRoot
Skillbasic.locate
basic.locateAll
basic.scan
basic.scanAll
Spellbasic.clear
basic.fetch
basic.fill
basic.refresh
basic.setup
basic.start
basic.stop
basic.transform
EventPerkSkillevent.add
event.init
event.remove
event.reset
event.triggerSync
Spellevent.trigger
PerkSpellperk.attach
perk.attachPerks
SettingPerkAssetsetting
Skillsetting.get
setting.merge
setting.set
Spellsetting.apply
setting.summon
SkinPerkInventoryskin.skins
skin.active
Skillskin.apply
Spellskin.summon
StatusPerkInventorystatus.status
Skillstatus.change
Spellstatus.wait
StylePerkInventorystyle.styles
Spellstyle.apply
style.summon
UnitPerkInventoryunit.units
Spellunit.materialize
unit.materializeAll
unit.summon
Previous Next

© 2019-2023 Masaki Yasutake

Bitsmist

Table of Contents

Table of Contents

  • Extending with Perks
    • Overview
    • Applying Perks
      • Write in the "perk" Section
      • Add Perk's Dedicated Section
    • Event Handlers
    • Extended Features

Introduction

  • Overview
  • Installation
  • Create a Sample Unit

Unit Explained

  • Overview
  • Properties and Methods
  • Settings
  • Loading
  • Events
  • HTML
  • CSS
  • Extending with Perks

Reference - Unit

  • Unit

Reference - Perk

  • Perk (Base Class)
  • BasicPerk
  • EventPerk
  • SettingPerk
  • SkinPerk
  • StatusPerk
  • StylePerk
  • UnitPerk

Reference - Store

  • Store
  • ChainableStore

Reference - Utility

  • AjaxUtil
  • ClassUtil
  • URLUtil
  • Util