-
Notifications
You must be signed in to change notification settings - Fork 422
Flow
The flow you decides what effects are on or off given an input.
So you can define any custom flow when using this package, like activate particles only when numbers, reset the combo when delete or anything you could imagine, probably. By default the package provides two flows: the default one (the current one) and a user's file based one.
To register a flow use the service's function registerFlow
, you need to provide a code and the flow itself.
consumeActivatePowerModeServiceV1(service) {
flow = require('./my-flow');
service.registerFlow('myFlow', flow);
}
If you don't know how to consume the activate-power-mode's service, read the Consume the service page.
The flow can be any object implementing a handle function.
// Handles the input to decide what will be triggered or not.
handle(input, switcher, comboLvl) {}
You can see in the handle function you have access to the input, a switcher and the combo level.
Additionally your flow object can define title and description properties to be shown when the users select the flow.
The input parameter in your handler function is a helper object to ease the input handling. It provides functions to know what is the current input.
// Gets the original event object.
getEvent()
// Gets the input position.
getPosition()
// Gets whether or not the input is a new line.
isNewLine()
// Checks if the input has deleted a text.
hasDeleted()
// Check if the input has written a text.
hasWritten()
// Gets the input new text.
getText()
// Gets the deleted text.
getDeletedText()
It provides functions to turn on/off the plugins for the current input.
// Turns off all plugins.
offAll()
// Turns on all plugins.
onAll()
// Turns off a plugin by code.
off(code)
// Turns on a plugin by code, and you can pass some specific data for that plugin.
on(code, data)
'use babel'
module.exports = {
handle(input, switcher, comboLvl) {
// Reset combo on delete
if (input.hasDeleted()) {
switcher.on('comboMode', {'reset': true});
}
// Shakes the screen with max intensity on new lines
if (input.isNewLine()) {
switcher.on('screenShake', {'intensity': 'max'});
}
}
}
As you can see above, you can pass some special data to plugins to modify the default behavior. The core plugins has these options:
- Combo mode
- Code:
comboMode
- Modifiers:
-
reset
: to reset the combo to 0. -
qty
: to increase or decrease the combo by a number.
-
- Code:
- Particles:
- Code:
particles
- Modifiers:
-
size
: can bemax
ormin
.
-
- Code:
- Screen shake:
- Code:
screenShake
- Modifiers:
-
intensity
: can bemax
ormin
.
-
- Code:
- Play audio:
- Code:
playAudio
- Modifiers: none
- Code:
The user can select the flow with the command activate-power-mode:select-flow
You can define your own custom flow with no need to create a package.
You can use the User File
core flow, it reads an user-flow.js
or user-flow.coffee
file in your home directory.
Let's create that file, you can use the example above to start and when ready select the User File
flow with the activate-power-mode:select-flow
command.