Skip to content

Reuse vfx blocks #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2020
Merged
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
145 changes: 67 additions & 78 deletions iwsy/iwsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,40 @@ const IWSY = (playerElement, scriptObject) => {
const converted = converter.makeHtml(text.content.split(`%0a`).join(`\n`));
const tag = converted.match(/data-slide="([\w-_.]*)"/);
if (tag) {
for (const vfx of script.vfx) {
if (vfx.name === tag[1]) {
vfx.container = block.textPanel;
if (vfx.url) {
if (vfx.url[0] === `=`) {
const lastVFX = vfx.url.slice(1);
for (const index in block.vfx) {
const vfx2 = block.vfx[index];
if (vfx2.name === lastVFX) {
vfx.image = vfx2.image;
initImage(vfx);
vfx.startsize = vfx2.endsize;
vfx.startxoff = vfx2.endxoff;
vfx.startyoff = vfx2.endyoff;
vfx.w = vfx2.w2;
vfx.h = vfx2.h2;
vfx.xoff = vfx2.xoff2;
vfx.yoff = vfx2.yoff2;
if (!vfx.image) {
throw new Error(`Unknown vfx ${lastVFX}`);
}
block.vfx[index] = vfx;
}
for (const sVFX of script.vfx) {
if (sVFX.name === tag[1]) {
const vfx = {
block,
container: block.textPanel,
name: sVFX.name,
type: sVFX.type,
aspect: sVFX.aspect,
url: sVFX.url,
duration: sVFX.duration,
startsize: 100,
startxoff: 0,
startyoff: 0,
endsize: sVFX.endsize,
endxoff: sVFX.endxoff,
endyoff: sVFX.endyoff
};
block.vfx.push(vfx);
continueFlag = false;
block.textPanel.innerHTML = converted;
imagesToLoad.push(vfx);
imagesLoading.push(vfx);

if (vfx.url[0] === `=`) {
const lastVFX = vfx.url.slice(1);
for (pVFX of script.vfx) {
if (pVFX.name === lastVFX) {
vfx.url = pVFX.url;
vfx.startsize = pVFX.endsize;
vfx.startxoff = pVFX.endxoff;
vfx.startyoff = pVFX.endyoff;
break;
}
} else {
vfx.block = block;
block.vfx.push(vfx);
continueFlag = false;
block.textPanel.innerHTML = converted;
imagesToLoad.push(vfx);
imagesLoading.push(vfx);
}
break;
}
break;
}
Expand Down Expand Up @@ -464,6 +464,7 @@ const IWSY = (playerElement, scriptObject) => {
const duration = vfx.duration * 1000;
if (elapsed < duration) {
const ratio = 0.5 - Math.cos(Math.PI * elapsed / duration) / 2;
// console.log(ratio);
image.style.width = `${vfx.w + (vfx.w2 - vfx.w) * ratio}px`;
image.style.height = `${vfx.h + (vfx.h2 - vfx.h) * ratio}px`;
image.style.left = `${vfx.xoff + (vfx.xoff2 - vfx.xoff) * ratio}px`;
Expand All @@ -476,66 +477,51 @@ const IWSY = (playerElement, scriptObject) => {
image.style.height = `${vfx.h2}px`;
image.style.left = `${vfx.xoff2}px`;
image.style.top = `${vfx.yoff2}px`;
// if (!vfx.continueFlag) {
// if (script.runMode === `manual`) {
// enterManualMode(vfx.step);
// } else {
// vfx.step.next();
// }
// }
}
};

// This is where the vfx animations are started
const startVFX = (step, vfx) => {
const vfxElement = vfx.container;
vfxElement.style.position = `relative`;
vfxElement.style.display = `inline-block`;
for (const item of script.vfx) {
if (item.name === vfx.name) {
if (!Array.isArray(step.vfx)) {
step.vfx = [];
}
step.vfx.push(item);
delete(vfx.start);
if (script.speed === `scan`) {
vfx.image.style.width = `${vfx.w2}px`;
vfx.image.style.height = `${vfx.h2}px`;
vfx.image.style.left = `${vfx.xoff2}px`;
vfx.image.style.top = `${vfx.yoff2}px`;
step.next();
} else {
vfx.step = step;
requestAnimationFrame(timestamp => {
animatePanzoom(timestamp, vfx);
});
}
break;
// Remove the vfx now we've done with it
const index = vfx.block.vfx.indexOf(vfx);
if (index > -1) {
vfx.block.vfx.splice(index, 1);
}
}
if (step.vfx.length === 0) {
step.next();
}
};

// Animate a block
const animate = step => {
// let continueFlag = true;
for (const block of script.blocks) {
if (block.defaults.name === step.block) {
for (const vfx of block.vfx) {
// continueFlag = step.continue === `yes`;
startVFX(step, vfx);
console.log(` VFX ${vfx.name}`);
const vfxElement = vfx.container;
vfxElement.style.position = `relative`;
vfxElement.style.display = `inline-block`;
for (const item of script.vfx) {
if (item.name === vfx.name) {
if (!Array.isArray(step.vfx)) {
step.vfx = [];
}
step.vfx.push(item);
delete(vfx.start);
if (script.speed === `scan`) {
vfx.image.style.width = `${vfx.w2}px`;
vfx.image.style.height = `${vfx.h2}px`;
vfx.image.style.left = `${vfx.xoff2}px`;
vfx.image.style.top = `${vfx.yoff2}px`;
} else {
vfx.step = step;
requestAnimationFrame(timestamp => {
animatePanzoom(timestamp, vfx);
});
}
break;
}
}
if (step.vfx.length === 0) {
step.next();
}
}
break;
}
}
// if (script.runMode === `manual`) {
// enterManualMode(step);
// } else if (continueFlag) {
// step.next();
// }

// An animation is not a transition, so move on immediately
step.next();
};
Expand All @@ -554,6 +540,9 @@ const IWSY = (playerElement, scriptObject) => {
for (const vfx2 of script.vfx) {
if (name === vfx2.name) {
url = vfx2.url;
vfx.startsize = vfx2.endsize;
vfx.startxoff = vfx2.endxoff;
vfx.startyoff = vfx2.endyoff;
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion iwsy/resources/ecs/steps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

script Steps

import div Panel and variable Presentation
import div Container and variable Presentation

div Panel
div StepsPanel
div BlockTable
div BlockRow
Expand Down Expand Up @@ -98,6 +99,9 @@
get IsHome from storage as `.ishome`
get CDN from storage as `.cdn`

clear Container
create Panel in Container
set the style of Panel to `width:100%;height:100%;display:flex;flex-direction:column`
create StepsPanel in Panel
set the style of StepsPanel to `flex:1;overflow-y:scroll`

Expand Down