======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 [[en:bitsmist-js-core:general:sample|"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. * [[en:bitsmist-js-core:reference:perk:basic-perk|BasicPerk]] * [[en:bitsmist-js-core:reference:perk:event-perk|EventPerk]] * [[en:bitsmist-js-core:reference:perk:setting-perk|SettingPerk]] * [[en:bitsmist-js-core:reference:perk:skin-perk|SkinPerk]] * [[en:bitsmist-js-core:reference:perk:status-perk|StatusPerk]] * [[en:bitsmist-js-core:reference:perk:style-perk|StylePerk]] * [[en:bitsmist-js-core:reference:perk:unit-perk|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 [[en:bitsmist-js-core:reference:perk:perk#apply|apply]] option of [[en:bitsmist-js-core:reference:perk:perk#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. ^Event^Perk^Description^ |doApplySettings|[[en:bitsmist-js-core:reference:perk:event-perk#doapplysettings|EventPerk]]|Install event handlers.| |:::|[[en:bitsmist-js-core:reference:perk:status-perk#doapplysettings|StatuePerk]]|Install event handlers to wait for other units.| |:::|[[en:bitsmist-js-core:reference:perk:unit-perk#doapplysettings|UnitPerk]]|Add child units.| |beforeTransform|[[en:bitsmist-js-core:reference:perk:skin-perk#beforetransform|SkinPerk]]|Load HTML file.| |:::|[[en:bitsmist-js-core:reference:perk:style-perk#dotransform|StylePerk]]|Load and Apply common CSS files.| |doTransform|[[en:bitsmist-js-core:reference:perk:skin-perk#dotransform|SkinPerk]]|Apply HTML file.| |:::|[[en:bitsmist-js-core:reference:perk:style-perk#dotransform|StylePerk]]|Load and Apply unit-specifi CSS files.| |afterTransform|[[en:bitsmist-js-core:reference:perk:event-perk#afterTransform|EventPerk]]|Install 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. ^Perk^Type^Name^ |BasicPerk|Method|[[en:bitsmist-js-core:reference:perk:basic-perk##cast_spellname_args|cast]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#use_skillname_args|use]]| |:::|Asset|[[en:bitsmist-js-core:reference:perk:basic-perk#inventory|inventory]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#perk|perk]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#skill|skill]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#spell|spell]]| |:::|Inventory|[[en:bitsmist-js-core:reference:perk:basic-perk#unitroot|basic.unitRoot]]| |:::|Skill|[[en:bitsmist-js-core:reference:perk:basic-perk#locate|basic.locate]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#locateall|basic.locateAll]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#scan|basic.scan]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#scanall|basic.scanAll]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:basic-perk#clear|basic.clear]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#fetch|basic.fetch]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#fill|basic.fill]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#refresh|basic.refresh]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#setup|basic.setup]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#start|basic.start]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#stop|basic.stop]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:basic-perk#transform|basic.transform]]| |EventPerk|Skill|[[en:bitsmist-js-core:reference:perk:event-perk#add|event.add]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:event-perk#init|event.init]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:event-perk#remove|event.remove]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:event-perk#reset|event.reset]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:event-perk#triggersync|event.triggerSync]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:event-perk#trigger|event.trigger]]| |Perk|Spell|[[en:bitsmist-js-core:reference:perk:perk-perk#attach|perk.attach]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:perk-perk#attachperks|perk.attachPerks]]| |SettingPerk|Asset|[[en:bitsmist-js-core:reference:perk:setting-perk#setting|setting]]| |:::|Skill|[[en:bitsmist-js-core:reference:perk:setting-perk#get|setting.get]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:setting-perk#merge|setting.merge]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:setting-perk#set|setting.set]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:setting-perk#apply|setting.apply]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:setting-perk#summon|setting.summon]]| |SkinPerk|Inventory|[[en:bitsmist-js-core:reference:perk:skin-perk#skins|skin.skins]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:skin-perk#active|skin.active]]| |:::|Skill|[[en:bitsmist-js-core:reference:perk:skin-perk#apply|skin.apply]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:skin-perk#summon|skin.summon]]| |StatusPerk|Inventory|[[en:bitsmist-js-core:reference:perk:status-perk#status|status.status]]| |:::|Skill|[[en:bitsmist-js-core:reference:perk:status-perk#change|status.change]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:status-perk#wait|status.wait]]| |StylePerk|Inventory|[[en:bitsmist-js-core:reference:perk:style-perk#styles|style.styles]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:style-perk#apply1|style.apply]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:style-perk#summon|style.summon]]| |UnitPerk|Inventory|[[en:bitsmist-js-core:reference:perk:unit-perk#units|unit.units]]| |:::|Spell|[[en:bitsmist-js-core:reference:perk:unit-perk#materialize|unit.materialize]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:unit-perk#materializeall|unit.materializeAll]]| |:::|:::|[[en:bitsmist-js-core:reference:perk:unit-perk#summon|unit.summon]]|