Skip to content

Commit 8198da7

Browse files
committed
Player-editor linkages
1 parent 0046af5 commit 8198da7

File tree

3 files changed

+354
-253
lines changed

3 files changed

+354
-253
lines changed

dist/plugins/iwsy.js

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const EasyCoder_IWSY = {
3030
}
3131
break;
3232
case `init`:
33+
case `stop`:
3334
compiler.next();
3435
compiler.addCommand({
3536
domain: `iwsy`,
@@ -38,6 +39,16 @@ const EasyCoder_IWSY = {
3839
action
3940
});
4041
return true;
42+
case `script`:
43+
const script = compiler.getNextValue();
44+
compiler.addCommand({
45+
domain: `iwsy`,
46+
keyword: `iwsy`,
47+
lino,
48+
action,
49+
script
50+
});
51+
return true;
4152
case `goto`:
4253
const target = compiler.getNextValue();
4354
compiler.addCommand({
@@ -48,16 +59,47 @@ const EasyCoder_IWSY = {
4859
target
4960
});
5061
return true;
51-
case `script`:
52-
const script = compiler.getNextValue();
62+
case `run`:
63+
const pc = compiler.getPc();
64+
compiler.next();
5365
compiler.addCommand({
5466
domain: `iwsy`,
5567
keyword: `iwsy`,
5668
lino,
5769
action,
58-
script
70+
then: 0
5971
});
72+
// Get the 'then' code, if any
73+
if (compiler.tokenIs(`then`)) {
74+
const goto = compiler.getPc();
75+
// Add a 'goto' to skip the 'then'
76+
compiler.addCommand({
77+
domain: `core`,
78+
keyword: `goto`,
79+
goto: 0
80+
});
81+
// Fixup the link to the 'then' branch
82+
compiler.getCommandAt(pc).then = compiler.getPc();
83+
// Process the 'then' branch
84+
compiler.next();
85+
compiler.compileOne(true);
86+
compiler.addCommand({
87+
domain: `core`,
88+
keyword: `stop`
89+
});
90+
// Fixup the 'goto'
91+
compiler.getCommandAt(goto).goto = compiler.getPc();
92+
}
6093
return true;
94+
case `onstep`:
95+
compiler.next();
96+
compiler.addCommand({
97+
domain: `iwsy`,
98+
keyword: `iwsy`,
99+
lino,
100+
action
101+
});
102+
return compiler.completeHandler();
61103
default:
62104
break;
63105
}
@@ -67,6 +109,7 @@ const EasyCoder_IWSY = {
67109
run: (program) => {
68110
const command = program[program.pc];
69111
const action = command.action;
112+
let script;
70113
switch (action) {
71114
case `init`:
72115
program.require(`js`, `iwsy.js`,
@@ -80,16 +123,53 @@ const EasyCoder_IWSY = {
80123
player.innerHTML = ``;
81124
player.style.background = `none`;
82125
player.style.border = `none`;
83-
const script = program.getValue(command.script);
84-
EasyCoder.iwsyFunctions = IWSY(player, JSON.parse(script));
126+
script = program.getValue(command.script);
127+
try {
128+
script = JSON.parse(script);
129+
EasyCoder.iwsyFunctions = IWSY(player, script);
130+
} catch (err) {
131+
alert(`Badly formatted script`);
132+
}
133+
break;
134+
case `script`:
135+
script = program.getValue(command.script);
136+
try {
137+
script = JSON.parse(script);
138+
if (EasyCoder.iwsyFunctions) {
139+
EasyCoder.iwsyFunctions.setScript(script);
140+
}
141+
} catch (err) {
142+
alert(`Badly formatted script`);
143+
}
85144
break;
86145
case `goto`:
87-
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
146+
if (EasyCoder.iwsyFunctions) {
147+
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
148+
}
88149
break;
89-
case `script`:
90-
EasyCoder.iwsyFunctions.setScript(JSON.parse(program.getValue(command.script)));
150+
case `run`:
151+
if (EasyCoder.iwsyFunctions) {
152+
EasyCoder.iwsyFunctions.run(function() {
153+
program.run(command.then);
154+
});
155+
return 0;
156+
}
157+
break;
158+
case `stop`:
159+
if (EasyCoder.iwsyFunctions) {
160+
EasyCoder.iwsyFunctions.stop();
161+
}
162+
break;
163+
case `onstep`:
164+
const cb = command.pc + 2;
165+
if (EasyCoder.iwsyFunctions) {
166+
EasyCoder.iwsyFunctions.onStep(function(step) {
167+
program.iwsyStep = step;
168+
program.run(cb);
169+
});
170+
}
91171
break;
92-
}
172+
}
93173
return command.pc + 1;
94174
}
95175
},

0 commit comments

Comments
 (0)