diff --git a/dist/plugins/iwsy.js b/dist/plugins/iwsy.js index f76dc9c..636c08a 100644 --- a/dist/plugins/iwsy.js +++ b/dist/plugins/iwsy.js @@ -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); @@ -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`: @@ -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); }); @@ -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, diff --git a/iwsy/iwsy.js b/iwsy/iwsy.js index 535e1a3..a779bd4 100644 --- a/iwsy/iwsy.js +++ b/iwsy/iwsy.js @@ -487,7 +487,6 @@ const IWSY = (playerElement, scriptObject) => { doTransitionStep(block, target, ratio); } catch (err) { clearInterval(interval); - throw Error(err); } animStep++; } else { @@ -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); + } }; /////////////////////////////////////////////////////////////////////////////// @@ -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); } } diff --git a/js/plugins/iwsy.js b/js/plugins/iwsy.js index f76dc9c..636c08a 100644 --- a/js/plugins/iwsy.js +++ b/js/plugins/iwsy.js @@ -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); @@ -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`: @@ -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); }); @@ -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,