Bitsmist Frameworks
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 the unit to perform processing at specific times.
  • Add skills, spells, and inventories to the unit instance or prototype.

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

  • BasicPerk
  • EventPerk
  • PerkPerk
  • 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 PerkPerk. Multiple perks can be specified.

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

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.
doTransformSkinPerkApply HTML file.
StylePerkLoad and Apply CSS files.
afterTransformEventPerkInstall event handlers for child elements.

Extended Features

Each perk also has the ability to add assets, inventory, states, 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
BasicPerkPropertyuniqueId
unitRoot
Methodget
has
set
use
Assetinventory
skill
spell
state
vault
Skillbasic.locate
basic.locateAll
basic.scanAll
basic.scan
Spellbasic.clear
basic.fetch
basic.fill
basic.refresh
basic.setup
basic.start
basic.stop
basic.transform
EventPerkSkillevent.add
event.init
event.remove
event.reset
trigger
triggerSync
PerkPerkSpellperk.attach
attachPerks
SettingPerkAssetsetting
Skillseting.get
setting.merge
setting.set
Spellsetting.apply
setting.summon
SkinPerkInventoryskin.skins
Stateskin.active.skinName
Skillskin.apply
skin.clone
Spellskin.summon
StatusPerkStatestatus.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 Frameworks

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
  • PerkPerk
  • SettingPerk
  • SkinPerk
  • StatusPerk
  • StylePerk
  • UnitPerk

Reference - Store

  • Store
  • ChainableStore

Reference - Utility

  • AjaxUtil
  • ClassUtil
  • URLUtil
  • Util