Skip to content

Commit b401e88

Browse files
authored
Merge pull request #169 from easycoder/dev
Pass URL in to init iwsy
2 parents a5246bc + d175154 commit b401e88

File tree

3 files changed

+49
-31
lines changed

3 files changed

+49
-31
lines changed

dist/plugins/iwsy.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ const EasyCoder_IWSY = {
3030
}
3131
break;
3232
case `init`:
33+
const cdn = compiler.nextValue();
34+
compiler.addCommand({
35+
domain: `iwsy`,
36+
keyword: `iwsy`,
37+
lino,
38+
action,
39+
cdn
40+
});
41+
return true;
3342
case `stop`:
3443
compiler.next();
3544
compiler.addCommand({
@@ -164,15 +173,13 @@ const EasyCoder_IWSY = {
164173
let script;
165174
switch (action) {
166175
case `init`:
167-
program.require(`js`, `https://easycoder.github.io/iwsy/iwsy.js`,
176+
const cdn = program.getValue(command.cdn);
177+
program.require(`js`, `${cdn}/iwsy.js`,
168178
function () {
169179
program.run(command.pc + 1);
170180
});
171181
return 0;
172182
case `load`:
173-
// if (program.iwsyFunctions) {
174-
// throw Error(`IWSY has already been set up`);
175-
// }
176183
const playerRecord = program.getSymbolRecord(command.player);
177184
const player = playerRecord.element[playerRecord.index];
178185
player.innerHTML = ``;

iwsy/iwsy.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const IWSY = (playerElement, scriptObject) => {
55
let script = scriptObject;
66
let homeScript = script;
77
let afterRun;
8-
let path;
98
let plugins;
109
let timeouts = [];
1110
let intervals = [];
@@ -980,25 +979,35 @@ const IWSY = (playerElement, scriptObject) => {
980979
const onStepCB = script.onStepCB;
981980
if (step.action === `chain`) {
982981
const runMode = script.runMode;
983-
fetch(`${path}${step.script}?v=${Date.now()}`)
984-
.then(response => {
985-
if (response.status >= 400) {
986-
throw Error(`Unable to load ${step.script}: ${response.status}`);
987-
}
988-
response.json().then(data => {
989-
script = data;
990-
if (onStepCB) {
991-
onStepCB(-1);
982+
if (step.mode === `static`) {
983+
script = window.localStorage.getItem(step.script);
984+
if (onStepCB) {
985+
onStepCB(-1);
986+
}
987+
initScript();
988+
script.runMode = runMode;
989+
doStep(script.steps[1]);
990+
} else {
991+
fetch(`${script.path}${step.script}?v=${Date.now()}`)
992+
.then(response => {
993+
if (response.status >= 400) {
994+
throw Error(`Unable to load ${step.script}: ${response.status}`);
992995
}
993-
initScript();
994-
script.runMode = runMode;
995-
doStep(script.steps[1]);
996+
response.json().then(data => {
997+
script = data;
998+
if (onStepCB) {
999+
onStepCB(-1);
1000+
}
1001+
initScript();
1002+
script.runMode = runMode;
1003+
doStep(script.steps[1]);
1004+
});
1005+
})
1006+
.catch(err => {
1007+
throw Error(`Fetch Error :${err}`);
9961008
});
997-
})
998-
.catch(err => {
999-
throw Error(`Fetch Error :${err}`);
1000-
});
1001-
return;
1009+
return;
1010+
}
10021011
}
10031012

10041013
const actionName = step.action.split(` `).join(``);
@@ -1051,11 +1060,6 @@ const IWSY = (playerElement, scriptObject) => {
10511060
initScript();
10521061
};
10531062

1054-
// Set the path
1055-
const setPath = p => {
1056-
path = p;
1057-
};
1058-
10591063
// Go to a specified step number
10601064
const gotoStep = target => {
10611065
script.scanTarget = target;

js/plugins/iwsy.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ const EasyCoder_IWSY = {
3030
}
3131
break;
3232
case `init`:
33+
const cdn = compiler.nextValue();
34+
compiler.addCommand({
35+
domain: `iwsy`,
36+
keyword: `iwsy`,
37+
lino,
38+
action,
39+
cdn
40+
});
41+
return true;
3342
case `stop`:
3443
compiler.next();
3544
compiler.addCommand({
@@ -164,15 +173,13 @@ const EasyCoder_IWSY = {
164173
let script;
165174
switch (action) {
166175
case `init`:
167-
program.require(`js`, `https://easycoder.github.io/iwsy/iwsy.js`,
176+
const cdn = program.getValue(command.cdn);
177+
program.require(`js`, `${cdn}/iwsy.js`,
168178
function () {
169179
program.run(command.pc + 1);
170180
});
171181
return 0;
172182
case `load`:
173-
// if (program.iwsyFunctions) {
174-
// throw Error(`IWSY has already been set up`);
175-
// }
176183
const playerRecord = program.getSymbolRecord(command.player);
177184
const player = playerRecord.element[playerRecord.index];
178185
player.innerHTML = ``;

0 commit comments

Comments
 (0)