Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions editor/src/I18nManager.js

Large diffs are not rendered by default.

81 changes: 69 additions & 12 deletions editor/src/utils/BgmSequenceEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* Entries play in order and repeat:
* { type: 'track', name, volume, pitch, pan, fadeIn } (any entry may set `once`)
* { type: 'silence', duration }
* { type: 'palette', duration, fadeIn, fadeOut, single, layers: [{ volume, pitch, pan, order, pool }] }
* where a pool holds tracks (`{ type: 'track', name, volume }`) and silences.
* { type: 'palette', duration, fadeIn, fadeOut, single, layers: [{ volume, pitch, pan, order, repeats?, pool }] }
* where a pool holds tracks (`{ type: 'track', name, volume, tail?, weight? }`)
* and silences (`{ type: 'silence', duration, weight? }`). The optional keys are
* written only when they differ from what their absence means: no `tail` uses
* the palette's fade-out, no `weight` is 1, no `repeats` keeps the no-repeat draw.
*
* The model functions are static so a save can normalize and validate what
* the form holds without the DOM; the instance renders one container and
Expand Down Expand Up @@ -94,19 +97,46 @@ class RRBgmSequenceEditor {
};
}

/** A pool item's share of a random draw, to two decimals; 1 when blank or unreadable. */
static weight(value) {
if (value === null || value === undefined || value === '') return 1;
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 0) return 1;
return Math.min(1000, Math.round(parsed * 100) / 100);
}

/** A pool track's own tail in seconds, or null for the palette's fade-out. 0 is a real value. */
static tail(value) {
if (value === null || value === undefined || value === '') return null;
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 0) return null;
return Math.min(600, Math.round(parsed * 10) / 10);
}

static poolEntry(raw) {
if (!raw || typeof raw !== 'object') return null;
if (raw.type === 'silence') return { type: 'silence', duration: RRBgmSequenceEditor.seconds(raw.duration) };
return { type: 'track', name: typeof raw.name === 'string' ? raw.name : '',
volume: RRBgmSequenceEditor.number(raw.volume, 100, 0, 100) };
let item;
if (raw.type === 'silence') {
item = { type: 'silence', duration: RRBgmSequenceEditor.seconds(raw.duration) };
} else {
item = { type: 'track', name: typeof raw.name === 'string' ? raw.name : '',
volume: RRBgmSequenceEditor.number(raw.volume, 100, 0, 100) };
const tail = RRBgmSequenceEditor.tail(raw.tail);
if (tail !== null) item.tail = tail;
}
const weight = RRBgmSequenceEditor.weight(raw.weight);
if (weight !== 1) item.weight = weight;
return item;
}

static layer(raw) {
const source = raw && typeof raw === 'object' ? raw : {};
return Object.assign(RRBgmSequenceEditor.levels(source), {
order: source.order === 'sequential' || source.order === 'shuffle' ? source.order : 'random',
pool: (Array.isArray(source.pool) ? source.pool : []).map(RRBgmSequenceEditor.poolEntry).filter(Boolean)
const layer = Object.assign(RRBgmSequenceEditor.levels(source), {
order: source.order === 'sequential' || source.order === 'shuffle' ? source.order : 'random'
});
if (source.repeats === true) layer.repeats = true;
layer.pool = (Array.isArray(source.pool) ? source.pool : []).map(RRBgmSequenceEditor.poolEntry).filter(Boolean);
return layer;
}

static entry(raw) {
Expand Down Expand Up @@ -429,12 +459,23 @@ class RRBgmSequenceEditor {
}
const layers = entry.layers.map((layer, l) => {
const lp = `${path}.layers.${l}`;
const weightField = (ip, item) => `<label title="${this.escape(this.tt('This entry’s share of a random draw against the rest of the pool. 2 is drawn twice as often as 1; 0 is never drawn. Random order only.'))}" style="flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Draw weight'))} ${this.numberInput(`${ip}.weight`, Number.isFinite(item.weight) ? item.weight : 1, 0, 1000, 0.1, 54)}</label>`;
const pool = layer.pool.map((item, i) => {
const ip = `${lp}.pool.${i}`;
const body = item.type === 'silence'
? `<span style="display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Silence'))} ${this.numberInput(`${ip}.duration`, item.duration, 0, 3600, 0.5, 60)} ${this.escape(this.tt('s'))}</span>`
: `${nameBox(ip, item.name, null)}<label style="flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Volume'))} ${this.numberInput(`${ip}.volume`, item.volume, 0, 100, 1, 54)}</label>`;
return `<div class="bgm-seq-depth-3" style="display: flex; gap: 6px; align-items: center;">${body}${this.smallButton('remove', ip, '×', this.tt('Remove'))}</div>`;
if (item.type === 'silence') {
return `<div class="bgm-seq-depth-3" style="display: flex; gap: 6px; align-items: center;">`
+ `<span style="flex: 1; display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Silence'))} ${this.numberInput(`${ip}.duration`, item.duration, 0, 3600, 0.5, 60)} ${this.escape(this.tt('s'))}</span>`
+ `${weightField(ip, item)}${this.smallButton('remove', ip, '×', this.tt('Remove'))}</div>`;
}
// The name needs the row's width, so the two draw settings take
// a line of their own under it, as a layer's controls do.
return `<div class="bgm-seq-depth-3">
<div style="display: flex; gap: 6px; align-items: center;">${nameBox(ip, item.name, null)}<label style="flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Volume'))} ${this.numberInput(`${ip}.volume`, item.volume, 0, 100, 1, 54)}</label>${this.smallButton('remove', ip, '×', this.tt('Remove'))}</div>
<div style="display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 3px 0 0 6px;">
<label title="${this.escape(this.tt('How many seconds before this track ends the next draw starts, this one fading away under it. Empty uses the palette’s fade-out; 0 plays it to its end.'))}" style="display: inline-flex; align-items: center; gap: 4px; font-size: 12px;">${this.escape(this.tt('Tail (s)'))} ${this.numberInput(`${ip}.tail`, Number.isFinite(item.tail) ? item.tail : '', 0, 600, 0.1, 60)}</label>
${weightField(ip, item)}
</div>
</div>`;
}).join('');
// Four controls plus the remove button do not fit the column, the
// same way the palette's timings did not: the title line keeps the
Expand All @@ -450,6 +491,7 @@ class RRBgmSequenceEditor {
<label style="display: inline-flex; align-items: center; gap: 4px;">${this.escape(this.tt('Pitch'))} ${this.numberInput(`${lp}.pitch`, layer.pitch, 50, 150, 1, 54)}</label>
<label style="display: inline-flex; align-items: center; gap: 4px;">${this.escape(this.tt('Pan'))} ${this.numberInput(`${lp}.pan`, layer.pan, -100, 100, 1, 54)}</label>
<label style="display: inline-flex; align-items: center; gap: 4px;">${this.escape(this.tt('Order'))} ${this.orderSelect(`${lp}.order`, layer.order)}</label>
<label title="${this.escape(this.tt('A random draw may pick the entry that just played. Random order only.'))}" style="display: inline-flex; align-items: center; gap: 4px;"><input type="checkbox" data-path="${lp}.repeats"${layer.repeats ? ' checked' : ''}> ${this.escape(this.tt('Allow repeats'))}</label>
</div>
${pool}
<div style="display: flex; gap: 4px; padding: 3px 0 0 14px;">
Expand Down Expand Up @@ -596,6 +638,21 @@ class RRBgmSequenceEditor {
else if (key === 'pan') node[key] = RRBgmSequenceEditor.number(input.value, 0, -100, 100);
else if (key === 'order') node[key] = input.value === 'sequential' || input.value === 'shuffle' ? input.value : 'random';
else if (key === 'once' || key === 'single') { node[key] = !!input.checked; this.edited(); return; }
else if (key === 'repeats') {
// Left off the layer when unticked, as normalize() writes it.
if (input.checked) node.repeats = true;
else delete node.repeats;
this.edited();
return;
} else if (key === 'tail') {
// Empty is its own value -- the palette's fade-out -- and 0 is another.
const tail = RRBgmSequenceEditor.tail(input.value);
if (tail === null) delete node.tail;
else node.tail = tail;
input.value = tail === null ? '' : tail;
this.edited();
return;
} else if (key === 'weight') node[key] = RRBgmSequenceEditor.weight(input.value);
input.value = node[key];
this.edited();
}
Expand Down
Loading
Loading