Skip to content

Commit da26a61

Browse files
committed
Fix some problems with vfx animations
1 parent 065f29b commit da26a61

File tree

1 file changed

+45
-38
lines changed

1 file changed

+45
-38
lines changed

iwsy/iwsy.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const IWSY = (playerElement, scriptObject) => {
149149

150150
// Set the content of one or more blocks
151151
const setcontent = step => {
152+
const imagesToLoad = [];
153+
const imagesLoading = [];
152154
let continueFlag = true;
153155
for (const item of step.blocks)
154156
{
@@ -165,7 +167,6 @@ const IWSY = (playerElement, scriptObject) => {
165167
const converted = converter.makeHtml(text.content.split(`%0a`).join(`\n`));
166168
const tag = converted.match(/data-slide="([\w-_.]*)"/);
167169
if (tag) {
168-
const imagesLoading = [];
169170
for (const vfx of script.vfx) {
170171
if (vfx.name === tag[1]) {
171172
vfx.container = block.textPanel;
@@ -192,25 +193,12 @@ const IWSY = (playerElement, scriptObject) => {
192193
break;
193194
}
194195
} else {
196+
vfx.block = block;
195197
block.vfx.push(vfx);
196198
continueFlag = false;
197199
block.textPanel.innerHTML = converted;
198-
const image = new Image();
199-
vfx.image = image;
200-
image.id = vfx.name;
201-
image.src = vfx.url;
202-
image.addEventListener(`load`, () => {
203-
initImage(vfx);
204-
const index = imagesLoading.indexOf(image);
205-
if (index > -1) {
206-
imagesLoading.splice(index, 1);
207-
}
208-
if (imagesLoading.length === 0) {
209-
step.next();
210-
}
211-
});
212-
imagesLoading.push(image);
213-
block.textPanel.appendChild(image);
200+
imagesToLoad.push(vfx);
201+
imagesLoading.push(vfx);
214202
}
215203
break;
216204
}
@@ -228,6 +216,26 @@ const IWSY = (playerElement, scriptObject) => {
228216
}
229217
}
230218
}
219+
for (const vfx of imagesToLoad) {
220+
const image = new Image();
221+
vfx.image = image;
222+
image.vfx = vfx;
223+
image.id = vfx.name;
224+
image.src = vfx.url;
225+
image.addEventListener(`load`, (event) => {
226+
const image = event.target;
227+
const vfx = image.vfx;
228+
initImage(vfx);
229+
const index = imagesLoading.indexOf(vfx);
230+
if (index > -1) {
231+
imagesLoading.splice(index, 1);
232+
}
233+
if (imagesLoading.length === 0) {
234+
step.next();
235+
}
236+
});
237+
vfx.block.textPanel.appendChild(image);
238+
}
231239
if (continueFlag) {
232240
step.next();
233241
}
@@ -468,9 +476,13 @@ const IWSY = (playerElement, scriptObject) => {
468476
image.style.height = `${vfx.h2}px`;
469477
image.style.left = `${vfx.xoff2}px`;
470478
image.style.top = `${vfx.yoff2}px`;
471-
if (vfx.then) {
472-
vfx.then();
473-
}
479+
// if (!vfx.continueFlag) {
480+
// if (script.runMode === `manual`) {
481+
// enterManualMode(vfx.step);
482+
// } else {
483+
// vfx.step.next();
484+
// }
485+
// }
474486
}
475487
};
476488

@@ -485,15 +497,6 @@ const IWSY = (playerElement, scriptObject) => {
485497
step.vfx = [];
486498
}
487499
step.vfx.push(item);
488-
vfx.then = () => {
489-
const index = step.vfx.indexOf(item);
490-
if (index > -1) {
491-
step.vfx.splice(index, 1);
492-
}
493-
if (step.vfx.length === 0 && step.continue !== `yes`) {
494-
step.next();
495-
}
496-
};
497500
delete(vfx.start);
498501
if (script.speed === `scan`) {
499502
vfx.image.style.width = `${vfx.w2}px`;
@@ -502,6 +505,7 @@ const IWSY = (playerElement, scriptObject) => {
502505
vfx.image.style.top = `${vfx.yoff2}px`;
503506
step.next();
504507
} else {
508+
vfx.step = step;
505509
requestAnimationFrame(timestamp => {
506510
animatePanzoom(timestamp, vfx);
507511
});
@@ -516,21 +520,24 @@ const IWSY = (playerElement, scriptObject) => {
516520

517521
// Animate a block
518522
const animate = step => {
519-
let continueFlag = true;
523+
// let continueFlag = true;
520524
for (const block of script.blocks) {
521525
if (block.defaults.name === step.block) {
522526
for (const vfx of block.vfx) {
523-
continueFlag = step.continue === `yes`;
527+
// continueFlag = step.continue === `yes`;
524528
startVFX(step, vfx);
525529
}
526530
break;
527531
}
528532
}
529-
if (script.runMode === `manual`) {
530-
enterManualMode(step);
531-
} else if (continueFlag) {
532-
step.next();
533-
}
533+
// if (script.runMode === `manual`) {
534+
// enterManualMode(step);
535+
// } else if (continueFlag) {
536+
// step.next();
537+
// }
538+
539+
// An animation is not a transition, so move on immediately
540+
step.next();
534541
};
535542

536543
// Run a pan-zoom (for testing animations)
@@ -1139,8 +1146,8 @@ const IWSY = (playerElement, scriptObject) => {
11391146
script.labels[step.label] = index;
11401147
}
11411148
if (index < script.steps.length - 1) {
1142-
const nextStep = script.steps[step.index + 1];
11431149
step.next = () => {
1150+
const nextStep = script.steps[step.index + 1];
11441151
if (script.scanFinished) {
11451152
script.scanFinished = false;
11461153
} else {
@@ -1355,7 +1362,7 @@ const IWSY = (playerElement, scriptObject) => {
13551362
const run = (mode, startMode, then) => {
13561363
try {
13571364
player.innerHTML = ``;
1358-
homeScript = JSON.parse(JSON.stringify(script));
1365+
// homeScript = JSON.parse(JSON.stringify(script));
13591366
afterRun = then;
13601367
initScript();
13611368
if (mode === `fullscreen`) {

0 commit comments

Comments
 (0)