Add even faster playback options; fix some demo decoding bugs

This commit is contained in:
Eevee (Evelyn Woods) 2020-12-12 00:22:51 -07:00
parent 769d424dde
commit cfdbe0705a
2 changed files with 13 additions and 5 deletions

View File

@ -205,6 +205,8 @@
</div> </div>
<p>Game speed: <p>Game speed:
<select name="speed"> <select name="speed">
<option value="100">100× faster</option>
<option value="50">50× faster</option>
<option value="20">20× faster</option> <option value="20">20× faster</option>
<option value="10">10× faster</option> <option value="10">10× faster</option>
<option value="5">5× faster</option> <option value="5">5× faster</option>

View File

@ -32,7 +32,10 @@ class CC2Demo {
l--; l--;
} }
for (let p = 3; p < l; p += 2) { for (let p = 3; p < l; p += 2) {
duration += this.bytes[p]; let delay = this.bytes[p];
if (delay === 0xff)
break;
duration += delay;
} }
duration = Math.floor(duration / 3); duration = Math.floor(duration / 3);
@ -66,15 +69,18 @@ class CC2Demo {
// TODO maybe turn this into, like, a type, or something // TODO maybe turn this into, like, a type, or something
return { return {
inputs: inputs, inputs: inputs,
final_input: input,
length: duration, length: duration,
get(t) { get(t) {
if (t >= this.inputs.length) { let input;
return new Set; if (t < this.inputs.length) {
input = this.inputs[t];
} }
else { else {
let input = this.inputs[t]; // Last input is implicitly repeated indefinitely
return new Set(Object.entries(CC2_DEMO_INPUT_MASK).filter(([action, bit]) => input & bit).map(([action, bit]) => action)); input = this.final_input;
} }
return new Set(Object.entries(CC2_DEMO_INPUT_MASK).filter(([action, bit]) => input & bit).map(([action, bit]) => action));
}, },
}; };
} }