furnace-module-interface
Version:
An interface for loading, processing and saving furnace modules in an object-oriented manner. Fully typed via TypeScript.
76 lines (75 loc) • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeChannelCount = exports.computeChannelObjects = exports.FurnaceChannel = exports.FurnaceChannelInfo = void 0;
const defaults_1 = require("./defaults");
class FurnaceChannelInfo {
constructor() {
this.longname = "";
this.shortname = "";
this.orders = [];
this.patterns = new Array(256).fill(null);
this.effects = defaults_1.defaults.effects;
this.hidden = false;
this.collapsed = false;
}
}
exports.FurnaceChannelInfo = FurnaceChannelInfo;
class FurnaceChannel {
constructor(channel, info, system, chip) {
this.channel = channel;
this.info = info;
this.system = system;
this.chip = chip;
}
get parentSystem() { return this.system; }
get parentChip() { return this.chip; }
get longname() { return this.info.longname; }
set longname(name) { this.info.longname = name; }
get shortname() { return this.info.shortname; }
set shortname(name) { this.info.shortname = name; }
get defaultLongname() { return this.channel.longname; }
get defaultShortname() { return this.channel.shortname; }
get activeLongname() { return this.info.longname.length > 0 ? this.info.longname : this.channel.longname; }
get activeShortname() { return this.info.shortname.length > 0 ? this.info.shortname : this.channel.shortname; }
get collapsed() { return this.info.collapsed; }
get hidden() { return this.info.hidden; }
get effectCount() { return this.info.effects; }
get orders() { return this.info.orders; }
get patterns() { return this.info.patterns; }
makePartialCopy() {
const info = new FurnaceChannelInfo();
info.longname = this.longname;
info.shortname = this.shortname;
info.orders = this.orders;
info.patterns = this.patterns;
info.effects = this.effectCount;
info.hidden = this.hidden;
info.collapsed = this.collapsed;
return new FurnaceChannel(this.channel, info, this.system, this.chip);
}
create(channel, info, system, chip) {
return new FurnaceChannel(channel, info, system, chip);
}
}
exports.FurnaceChannel = FurnaceChannel;
function computeChannelObjects(info, channels) {
const list = [];
info.systems.forEach((s) => {
s.chips.forEach((c) => {
c.channels.forEach((ch) => {
const index = list.length;
list.push(new FurnaceChannel(ch, channels[index], s, c));
});
});
});
return list;
}
exports.computeChannelObjects = computeChannelObjects;
function computeChannelCount(info) {
let count = 0;
info.systems.forEach((s) => {
count += s.chips.reduce((acc, c) => acc + c.channels.length, 0);
});
return count;
}
exports.computeChannelCount = computeChannelCount;