Simplified logger.js
This commit is contained in:
parent
c777efc79d
commit
1a0f8e6b16
@ -1,18 +1,16 @@
|
|||||||
export class Logger {
|
export class Logger {
|
||||||
historyLen = 17;
|
historyLen = 19;
|
||||||
history = [];
|
history = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a nicer log with a banner.
|
* Create a nicer log with a banner.
|
||||||
* @param ns {NS} - BitBurner API
|
* @param ns {NS} - BitBurner API
|
||||||
* @param titleFn {Function} - Function to generate title
|
* @param lineFns {Function[]} - Functions to generate a line (Seperated by a linebreak)
|
||||||
* @param extraFns {Function[]} - Extra info to put in the header
|
|
||||||
*/
|
*/
|
||||||
constructor(ns, titleFn, extraFns = []) {
|
constructor(ns, lineFns = []) {
|
||||||
this.ns = ns;
|
this.ns = ns;
|
||||||
this.title = titleFn;
|
this.fns = lineFns;
|
||||||
this.extra = extraFns;
|
this.historyLen -= fns.length * 2;
|
||||||
this.historyLen -= extraFns.length * 2;
|
|
||||||
this.history = Array(this.historyLen).fill('');
|
this.history = Array(this.historyLen).fill('');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,10 +26,8 @@ export class Logger {
|
|||||||
*/
|
*/
|
||||||
header() {
|
header() {
|
||||||
this.lineBreak();
|
this.lineBreak();
|
||||||
this.ns.print(this.title());
|
this.fns.forEach(fn => {
|
||||||
this.lineBreak();
|
this.ns.print(fn());
|
||||||
this.extra.forEach(extra => {
|
|
||||||
this.ns.print(extra());
|
|
||||||
this.lineBreak();
|
this.lineBreak();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user