Skip to content

Embedding #136

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
Jun 22, 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
41 changes: 21 additions & 20 deletions dist/plugins/iwsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const EasyCoder_IWSY = {
});
return 0;
case `load`:
if (typeof EasyCoder.iwsyFunctions !== `undefined`) {
if (program.iwsyFunctions) {
throw Error(`IWSY has already been set up`);
}
const playerRecord = program.getSymbolRecord(command.player);
Expand All @@ -174,11 +174,11 @@ const EasyCoder_IWSY = {
} catch (err) {
alert(`iwsy load: Badly formatted script`);
}
EasyCoder.iwsyFunctions = IWSY(player, script);
program.iwsyFunctions = IWSY(player, script);
break;
case `path`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.setPath(program.getValue(command.path));
if (program.iwsyFunctions) {
program.iwsyFunctions.setPath(program.getValue(command.path));
}
break;
case `script`:
Expand All @@ -188,42 +188,43 @@ const EasyCoder_IWSY = {
} catch (err) {
alert(`iwsy script: Badly formatted script`);
}
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.setScript(script);
if (program.iwsyFunctions) {
program.iwsyFunctions.setScript(script);
}
break;
case `goto`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
if (program.iwsyFunctions) {
program.iwsyFunctions.gotoStep(program.getValue(command.target));
}
break;
case `block`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.block(program.getValue(command.block));
if (program.iwsyFunctions) {
program.iwsyFunctions.block(program.getValue(command.block));
}
break;
case `run`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.run(command.mode, command.startMode, () => {
if (program.iwsyFunctions) {
program.iwsyFunctions.run(command.mode, command.startMode, () => {
program.run(command.then);
});
return 0;
}
break;
case `stop`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.stop();
if (program.iwsyFunctions) {
program.iwsyFunctions.stop();
delete program.iwsyFunctions;
}
break;
case `removeStyles`:
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.removeStyles();
if (program.iwsyFunctions) {
program.iwsyFunctions.removeStyles();
}
break;
case `onstep`:
const cb = command.pc + 2;
if (EasyCoder.iwsyFunctions) {
EasyCoder.iwsyFunctions.onStep(function(step) {
if (program.iwsyFunctions) {
program.iwsyFunctions.onStep(function(step) {
program.iwsyStep = step;
program.run(cb);
});
Expand Down Expand Up @@ -274,8 +275,8 @@ const EasyCoder_IWSY = {
switch (value.type) {
case `script`:
let script = null;
if (EasyCoder.iwsyFunctions) {
script = EasyCoder.iwsyFunctions.getScript();
if (program.iwsyFunctions) {
script = program.iwsyFunctions.getScript();
return {
type: `constant`,
numeric: false,
Expand Down
197 changes: 103 additions & 94 deletions iwsy/iwsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ const IWSY = (playerElement, scriptObject) => {
doTransitionStep(block, target, ratio);
} catch (err) {
clearInterval(interval);
throw Error(err);
}
animStep++;
} else {
Expand Down Expand Up @@ -828,75 +827,80 @@ const IWSY = (playerElement, scriptObject) => {

// Process a single step
const doStep = step => {
if (!step) {
return;
}
if (step.title) {
console.log(`Step ${step.index}: ${step.title}`);
} else {
console.log(`Step ${step.index}: ${step.action}`);
}
if (script.speed === `scan` && step.index === script.scanTarget) {
script.speed = `normal`;
for (const block of script.blocks) {
if (block.element) {
block.element.style.display = `block`;
try {
if (!step) {
return;
}
if (step.title) {
console.log(`Step ${step.index}: ${step.title}`);
} else {
console.log(`Step ${step.index}: ${step.action}`);
}
if (script.speed === `scan` && step.index === script.scanTarget) {
script.speed = `normal`;
for (const block of script.blocks) {
if (block.element) {
block.element.style.display = `block`;
}
}
}
}

const onStepCB = script.onStepCB;
if (step.action === `chain`) {
const runMode = script.runMode;
fetch(`${path}${step.script}`)
.then(response => {
if (response.status >= 400) {
throw Error(`Unable to load ${step.script}: ${response.status}`)
}
response.json().then(data => {
script = data;
if (onStepCB) {
onStepCB(-1);
const onStepCB = script.onStepCB;
if (step.action === `chain`) {
const runMode = script.runMode;
fetch(`${path}${step.script}?v=${Date.now()}`)
.then(response => {
if (response.status >= 400) {
throw Error(`Unable to load ${step.script}: ${response.status}`)
}
initScript();
script.runMode = runMode;
doStep(script.steps[1]);
response.json().then(data => {
script = data;
if (onStepCB) {
onStepCB(-1);
}
initScript();
script.runMode = runMode;
doStep(script.steps[1]);
});
})
.catch(err => {
throw Error(`Fetch Error :${err}`);
});
})
.catch(err => {
throw Error(`Fetch Error :${err}`);
});
return;
}

const actionName = step.action.split(` `).join(``);
let handler = actions[actionName];
if (script.runMode === `auto`) {
if (typeof handler === `undefined`) {
handler = IWSY.plugins[actionName];
return;
}

const actionName = step.action.split(` `).join(``);
let handler = actions[actionName];
if (script.runMode === `auto`) {
if (typeof handler === `undefined`) {
throw Error(`Unknown action: '${step.action}'`);
handler = IWSY.plugins[actionName];
if (typeof handler === `undefined`) {
throw Error(`Unknown action: '${step.action}'`);
}
}
if (onStepCB) {
onStepCB(step.index);
}
try {
handler(step);
} catch (err) {
console.log(`Step ${step.index} (${step.action}): ${err}`);
alert(`Step ${step.index} (${step.action}): ${err}`);
}
} else {
try {
handler(step);
} catch (err) {
console.log(JSON.stringify(step,0,2) + `\n` + JSON.stringify(handler,0,2));
console.log(`Step ${step.index} (${step.action}): ${err}`);
alert(`Step ${step.index} (${step.action}): ${err}`);
}
}
if (onStepCB) {
onStepCB(step.index);
}
try {
handler(step);
} catch (err) {
console.log(`Step ${step.index} (${step.action}): ${err}`);
alert(`Step ${step.index} (${step.action}): ${err}`);
}
} else {
try {
handler(step);
} catch (err) {
console.log(JSON.stringify(step,0,2) + `\n` + JSON.stringify(handler,0,2));
console.log(`Step ${step.index} (${step.action}): ${err}`);
alert(`Step ${step.index} (${step.action}): ${err}`);
}
}

catch (err) {
console.log(`Step error: ${err}`);
throw Error(err);
}
};

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -983,41 +987,46 @@ const IWSY = (playerElement, scriptObject) => {

// Run the presentation
const run = (mode, startMode, then) => {
homeScript = JSON.parse(JSON.stringify(script));
afterRun = then;
initScript();
if (mode === `fullscreen`) {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
player.requestFullscreen();
document.onfullscreenchange = () => {
if (document.fullscreenElement) {
player = document.fullscreenElement;
script.nextStep = script.steps[0];
switch (startMode) {
case `auto`:
script.runMode = `auto`;
release();
break;
case `manual`:
script.runMode = `manual`;
release();
break;
case `wait`:
script.runMode = `manual`;
enterManualMode(null);
break;
try {
homeScript = JSON.parse(JSON.stringify(script));
afterRun = then;
initScript();
if (mode === `fullscreen`) {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
player.requestFullscreen();
document.onfullscreenchange = () => {
if (document.fullscreenElement) {
player = document.fullscreenElement;
script.nextStep = script.steps[0];
switch (startMode) {
case `auto`:
script.runMode = `auto`;
release();
break;
case `manual`:
script.runMode = `manual`;
release();
break;
case `wait`:
script.runMode = `manual`;
enterManualMode(null);
break;
}
} else {
player = playerElement;
script.stop = true;
}
} else {
player = playerElement;
script.stop = true;
}
};
};
}
} else {
script.runMode = `auto`;
doStep(script.steps[0]);
}
} else {
script.runMode = `auto`;
doStep(script.steps[0]);
} catch (err) {
console.log(`Run error: ${err}`);
throw Error(err);
}
}

Expand Down
Loading