Skip to content
Daniel Alejandro Cast edited this page May 25, 2017 · 1 revision

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.

Register a flow

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.

Flow object

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.

Input handler

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()

Switcher

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)

Example

'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'});
    }
  }
}

Modifier data

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.
  • Particles:
    • Code: particles
    • Modifiers:
      • size: can be max or min.
  • Screen shake:
    • Code: screenShake
    • Modifiers:
      • intensity: can be max or min.
  • Play audio:
    • Code: playAudio
    • Modifiers: none

Select flow

The user can select the flow with the command activate-power-mode:select-flow 1492404629142

User file 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.

Clone this wiki locally