Skip to content

SupportClass/lfg-hypetrain

Repository files navigation

lfg-hypetrain Build Status

This is a NodeCG bundle.

This bundle manages the so-called "hype train" for subscriptions and/or donations. It does not automatically listen for donations and subscriptions, but rather relies on some other bundle's extension to inform it of these events. This may change in the future.

Installation

  • Install to nodecg/bundles/lfg-hypetrain
  • (OPTIONAL) Create nodecg/cfg/lfg-hypetrain.json to configure lfg-hypetrain

Config Example

{
    "autoStartCooldown": false,
    "resetAfterThreshold": false,
    "disableThresholdEditing": false
}

Usage

lfg-hypetrain isn't very useful on its own. It is a helper bundle meant to be leveraged by other bundles.

Messages sent

lfg-hypetrain broadcasts the following events that you can listen to in your bundle:

nodecg.listenFor('cooldownStart', 'lfg-hypetrain', callback);
nodecg.listenFor('cooldownTick', 'lfg-hypetrain', callback); // ticks every second with the elapsedTime and remainingTime
nodecg.listenFor('cooldownEnd', 'lfg-hypetrain', callback);

... where callback is the name of a function with the signature function callbackName(data)

Messages received

lfg-hypetrain can receive the following messages:

nodecg.sendMessageToBundle('getPassengers', 'lfg-hypetrain', callback);
nodecg.sendMessageToBundle('getDayTotal', 'lfg-hypetrain', callback);
nodecg.sendMessageToBundle('startCooldown', 'lfg-hypetrain');
nodecg.sendMessageToBundle('endCooldown', 'lfg-hypetrain');
nodecg.sendMessageToBundle('resetCooldown', 'lfg-hypetrain');

... where callback is the name of a function with the signature function callbackName(data)

Replicants

lfg-hypetrain makes extensive use of Replicants, all of which your bundle can access, either to listen to or modify directly.

// The number of 'passengers' on the train
nodecg.Replicant('passengers', 'lfg-hypetrain');

// How many passengers there have been today
nodecg.Replicant('dayTotal', 'lfg-hypetrain');

// Number of passengers needed to engage 'hype' status
nodecg.Replicant('threshold', 'lfg-hypetrain');

// Duration of the cooldown
nodecg.Replicant('duration', 'lfg-hypetrain');

// How much time has elapsed in the cooldown
nodecg.Replicant('elapsedTime', 'lfg-hypetrain');

// How much time is left in the cooldown
nodecg.Replicant('remainingTime', 'lfg-hypetrain');

// Is the countdown currently active and ticking
nodecg.Replicant('isCooldownActive', 'lfg-hypetrain');

Use in other bundles' extensions

To control the train, add lfg-hypetrain to your bundle's bundleDependencies. Then, add code like the following to your bundle's extension:

module.exports = function (nodecg) {
    var train = nodecg.extensions['lfg-hypetrain'];
    var sublistener = nodecg.extensions['lfg-sublistener'];
    
    sublistener.on('subscription', function onSubscription(subscription) {
        // train.addPassenger increments the passenger count and returns the current state of the train
        subscription.train = train.addPassenger();
        nodecg.sendMessage('subscription', subscription);
    
        // You can also control the cooldown directly
        // train.startCooldown();
        // train.resetCooldown();
        // train.endCooldown();
    
        // All events/synced variables listed above can be used here
    });
}

License

lfg-hypetrain is provided under the MIT license, which is available to read in the [LICENSE][] file. [license]: LICENSE

About

Easy 'hype trains' for NodeCG

Resources

License

Stars

Watchers

Forks

Packages

No packages published