mirror of
https://github.com/mehotkhan/BandersnatchInteractive.git
synced 2025-07-27 17:23:22 +00:00
assets/scripts.js: Fix non-choice transitions
The previous logic was completely wrong.
This commit is contained in:
parent
927aeac7b4
commit
0bccf68de1
1 changed files with 18 additions and 25 deletions
|
@ -159,16 +159,6 @@ function addItem(ul, text, url) {
|
||||||
var nextChoice = -1;
|
var nextChoice = -1;
|
||||||
var nextSegment = null;
|
var nextSegment = null;
|
||||||
|
|
||||||
function setNextSegment(segmentId, comment) {
|
|
||||||
console.log('setNextSegment', segmentId, comment);
|
|
||||||
nextSegment = segmentId;
|
|
||||||
nextChoice = -1;
|
|
||||||
var ul = newList("nextSegment");
|
|
||||||
var caption = 'nextSegment: ' + segmentId;
|
|
||||||
addItem(ul, comment ? caption + ' (' + comment + ')' : caption,
|
|
||||||
'javascript:playSegment("' + segmentId + '")');
|
|
||||||
}
|
|
||||||
|
|
||||||
function addZones(segmentId) {
|
function addZones(segmentId) {
|
||||||
var ul = newList("interactionZones");
|
var ul = newList("interactionZones");
|
||||||
let caption = 'currentSegment(' + segmentId + ')';
|
let caption = 'currentSegment(' + segmentId + ')';
|
||||||
|
@ -187,18 +177,14 @@ function addZones(segmentId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ul = newList("nextSegments");
|
ul = newList("nextSegments");
|
||||||
let defaultSegmentId = null;
|
|
||||||
if (segment) {
|
if (segment) {
|
||||||
for (const [k, v] of Object.entries(segment.next)) {
|
for (const [k, v] of Object.entries(segment.next)) {
|
||||||
let caption = k;
|
let caption = k;
|
||||||
if (segment.defaultNext == k) {
|
if (segment.defaultNext == k)
|
||||||
caption = '[' + caption + ']';
|
caption = '[' + caption + ']';
|
||||||
defaultSegmentId = k;
|
|
||||||
}
|
|
||||||
addItem(ul, caption, 'javascript:playSegment("' + k + '")');
|
addItem(ul, caption, 'javascript:playSegment("' + k + '")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNextSegment(defaultSegmentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentChoiceMoment = null;
|
var currentChoiceMoment = null;
|
||||||
|
@ -280,8 +266,8 @@ function ontimeupdate(evt) {
|
||||||
console.log('ontimeupdate', lastSegment, '->', currentSegment, ms, msToString(ms), seeked);
|
console.log('ontimeupdate', lastSegment, '->', currentSegment, ms, msToString(ms), seeked);
|
||||||
prevSegment = lastSegment;
|
prevSegment = lastSegment;
|
||||||
lastSegment = currentSegment;
|
lastSegment = currentSegment;
|
||||||
if (!seeked) {
|
if (!seeked && prevSegment) {
|
||||||
if (playNextSegment()) {
|
if (playNextSegment(prevSegment)) {
|
||||||
// playSegment decided to seek, which means that this
|
// playSegment decided to seek, which means that this
|
||||||
// currentSegment is invalid, and a recursive
|
// currentSegment is invalid, and a recursive
|
||||||
// ontimeupdate invocation should have taken care of
|
// ontimeupdate invocation should have taken care of
|
||||||
|
@ -357,7 +343,8 @@ function ontimeupdate(evt) {
|
||||||
timerId = setTimeout(ontimeupdate, timeLeft);
|
timerId = setTimeout(ontimeupdate, timeLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
function playNextSegment() {
|
function playNextSegment(prevSegment) {
|
||||||
|
let nextSegment = null;
|
||||||
if (nextChoice >= 0) {
|
if (nextChoice >= 0) {
|
||||||
let x = currentChoiceMoment.choices[nextChoice];
|
let x = currentChoiceMoment.choices[nextChoice];
|
||||||
if (x.segmentId)
|
if (x.segmentId)
|
||||||
|
@ -367,19 +354,25 @@ function playNextSegment() {
|
||||||
else
|
else
|
||||||
nextSegment = null;
|
nextSegment = null;
|
||||||
console.log('choice', nextChoice, 'nextSegment', nextSegment);
|
console.log('choice', nextChoice, 'nextSegment', nextSegment);
|
||||||
|
nextChoice = -1;
|
||||||
applyImpression(x.impressionData);
|
applyImpression(x.impressionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nextSegment && prevSegment && prevSegment in segmentGroups)
|
||||||
|
nextSegment = resolveSegmentGroup(prevSegment);
|
||||||
|
|
||||||
|
if (!nextSegment && prevSegment && segmentMap.segments[prevSegment].defaultNext)
|
||||||
|
nextSegment = segmentMap.segments[prevSegment].defaultNext;
|
||||||
|
|
||||||
|
if (!nextSegment)
|
||||||
|
return false;
|
||||||
|
|
||||||
let breadcrumb = 'breadcrumb_' + nextSegment;
|
let breadcrumb = 'breadcrumb_' + nextSegment;
|
||||||
if (!(breadcrumb in ls))
|
if (!(breadcrumb in ls))
|
||||||
ls[breadcrumb] = prevSegment;
|
ls[breadcrumb] = prevSegment;
|
||||||
|
|
||||||
segmentTransition = true;
|
segmentTransition = true;
|
||||||
let segmentId = nextSegment;
|
return playSegment(nextSegment, true);
|
||||||
nextSegment = null;
|
|
||||||
if (segmentId)
|
|
||||||
return playSegment(segmentId, true);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function jumpForward() {
|
function jumpForward() {
|
||||||
|
@ -397,7 +390,7 @@ function jumpForward() {
|
||||||
if (interactionMs) {
|
if (interactionMs) {
|
||||||
seek(interactionMs);
|
seek(interactionMs);
|
||||||
} else {
|
} else {
|
||||||
playNextSegment();
|
playNextSegment(segmentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +547,7 @@ function choice(choiceIndex) {
|
||||||
nextChoice = choiceIndex;
|
nextChoice = choiceIndex;
|
||||||
newList("choices");
|
newList("choices");
|
||||||
if (!currentChoiceMoment.config.disableImmediateSceneTransition)
|
if (!currentChoiceMoment.config.disableImmediateSceneTransition)
|
||||||
playNextSegment();
|
playNextSegment(prevSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyImpression(impressionData) {
|
function applyImpression(impressionData) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue