rpg-bars v1.1.0
rpg-bars
status bars for terminal based adventures
Installation
npm install rpg-bars
Quick Start
There are currently five different bar types:
basic
, health
, mana
, stamina
, and xp
.
Every bar's constructor
takes a name
and a total
.
The name
property is exposed to increased flexibility. For example, if you wanted to display your character's name rather than the name of the bar, or if you wanted "mana" to be called "intellect" or something.
With the exception of xp
(where current = 1
), all other bars render their current
value equal to their total
upon initialization.
"use strict";
const Bar = require("rpg-bars");
//- * choose a bar * -//
var basic = new Bar.basic({
name: "Basic Bar",
total: 20
});
var h = new Bar.health({
name: "Health",
total: 20
});
var m = new Bar.mana({
name: "Mana",
total: 15
});
var s = new Bar.stamina({
name: "Stamina",
total: 10
});
var xp = new Bar.xp({
name: "XP",
total: 30
});
basic.display();
h.display();
m.display();
s.display();
xp.display();
Class Methods
Note: all class methods are chainable.
display():
Renders your bar in it's current state.
// # Continued from Quickstart
h.display();
log():
Console logs your bar. Typically useful for developing new bars + features.
// # Continued from Quickstart
h.log();
updateCurrent(num):
Negative num
values will subtract from current
count. Positive num
values will add them back.
Your current
cannot exceed your total
or go negative.
Use case: when your character takes damage, or is healed.
// # Continued from Quickstart
h.display()
.updateCurrent(-1)
.display()
.updateCurrent(-20)
.display();
updateTotal(num):
Changes the total
number of bars. Value cannot be negative. Updates the current
value to be equal to the total.
Use case: when your character levels up. It could be used to level your character down through negative values, but it was intended for use with positive values.
// # Continued from Quickstart
h.display()
.updateTotal(1)
.display()
.updateTotal(-2)
.display()
.updateTotal(-20)
.display();