Skip to content

Commit 53b7ab7

Browse files
committed
Link from editor to player
1 parent 32f6553 commit 53b7ab7

File tree

6 files changed

+122
-58
lines changed

6 files changed

+122
-58
lines changed

dist/plugins/iwsy.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ const EasyCoder_IWSY = {
4848
target
4949
});
5050
return true;
51+
case `script`:
52+
const script = compiler.getNextValue();
53+
compiler.addCommand({
54+
domain: `iwsy`,
55+
keyword: `iwsy`,
56+
lino,
57+
action,
58+
script
59+
});
60+
return true;
5161
default:
5262
break;
5363
}
@@ -71,12 +81,15 @@ const EasyCoder_IWSY = {
7181
player.style.background = `none`;
7282
player.style.border = `none`;
7383
const script = program.getValue(command.script);
74-
EasyCoder.iwsyGotoStep = IWSY(player, JSON.parse(script));
84+
EasyCoder.iwsyFunctions = IWSY(player, JSON.parse(script));
7585
break;
7686
case `goto`:
77-
EasyCoder.iwsyGotoStep(program.getValue(command.target));
87+
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
7888
break;
79-
}
89+
case `script`:
90+
EasyCoder.iwsyFunctions.setScript(JSON.parse(program.getValue(command.script)));
91+
break;
92+
}
8093
return command.pc + 1;
8194
}
8295
},

iwsy/iwsy.js

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// IWSY
22

3-
const IWSY = (container, script) => {
3+
const IWSY = (container, text) => {
44

5+
let script = text;
56
let mode = `manual`;
67
let clicked = false;
78

@@ -94,7 +95,6 @@ const IWSY = (container, script) => {
9495

9596
// Create a block.
9697
const createBlock = (block) => {
97-
const container = block.container;
9898
if (block.element) {
9999
container.removeChild(block.element);
100100
}
@@ -104,6 +104,9 @@ const IWSY = (container, script) => {
104104
const element = document.createElement(`div`);
105105
container.appendChild(element);
106106
block.element = element;
107+
if (script.speed === `scan`) {
108+
element.style[`display`] = `none`;
109+
}
107110
element.style[`position`] = `absolute`;
108111
element.style[`opacity`] = `0.0`;
109112
let val = properties.left;
@@ -564,13 +567,6 @@ const IWSY = (container, script) => {
564567
}
565568
};
566569

567-
// Go to a specified step number
568-
const gotoStep = (target) => {
569-
script.scanTarget = target;
570-
script.singleStep = true;
571-
scan();
572-
};
573-
574570
// Load a plugin action
575571
const load = step => {
576572
if (script.speed === `scan`) {
@@ -616,14 +612,66 @@ const IWSY = (container, script) => {
616612

617613
// Chain to another presentation
618614
const chain = step => {
619-
step.next()
615+
step.next();
620616
};
621617

622618
// Embed another presentation
623619
const embed = step => {
624-
step.next()
620+
step.next();
625621
};
626622

623+
// Go to a specified step number
624+
const gotoStep = (target) => {
625+
script.scanTarget = target;
626+
script.singleStep = true;
627+
scan();
628+
};
629+
630+
// Replace the script
631+
const setScript = newScript => {
632+
script = newScript;
633+
initScript();
634+
initBlocks();
635+
};
636+
637+
// Initialize the script
638+
const initScript = () => {
639+
document.onkeydown = null;
640+
script.container = container;
641+
container.style.position = `relative`;
642+
container.style.overflow = `hidden`;
643+
container.style.cursor = 'none';
644+
container.style[`background-size`] = `cover`;
645+
script.speed = `normal`;
646+
script.singleStep = true;
647+
script.labels = {};
648+
for (const [index, step] of script.steps.entries()) {
649+
step.index = index;
650+
step.script = script;
651+
if (typeof step.label !== `undefined`) {
652+
script.labels[step.label] = index;
653+
}
654+
if (index < script.steps.length - 1) {
655+
step.next = () => {
656+
if (script.singleStep && script.speed != `scan`) {
657+
console.log(`Single-step`);
658+
} else {
659+
const next = step.index + 1;
660+
setTimeout(() => {
661+
doStep(script.steps[next]);
662+
}, 0);
663+
}
664+
}
665+
}
666+
else {
667+
step.next = () => {
668+
console.log(`Step ${index + 1}: Finished`);
669+
container.style.cursor = 'pointer';
670+
}
671+
};
672+
};
673+
}
674+
627675
const actions = {
628676
init,
629677
setcontent,
@@ -649,7 +697,7 @@ const IWSY = (container, script) => {
649697
for (const name in script.blocks) {
650698
const block = script.blocks[name];
651699
if (block.element) {
652-
block.element.style.opacity = block.opacity;
700+
block.element.style.display = `block`;
653701
}
654702
}
655703
}
@@ -676,43 +724,13 @@ const IWSY = (container, script) => {
676724
if (mode === `auto`) {
677725
document.addEventListener(`click`, onClick);
678726
}
679-
document.onkeydown = null;
680-
script.container = container;
681-
container.style.position = `relative`;
682-
container.style.overflow = `hidden`;
683-
container.style.cursor = 'none';
684-
container.style[`background-size`] = `cover`;
685-
script.speed = `normal`;
686-
script.singleStep = true;
687-
script.labels = {};
688-
for (const [index, step] of script.steps.entries()) {
689-
step.index = index;
690-
step.script = script;
691-
if (typeof step.label !== `undefined`) {
692-
script.labels[step.label] = index;
693-
}
694-
if (index < script.steps.length - 1) {
695-
step.next = () => {
696-
if (script.singleStep && script.speed != `scan`) {
697-
console.log(`Single-step`);
698-
} else {
699-
const next = step.index + 1;
700-
setTimeout(() => {
701-
doStep(script.steps[next]);
702-
}, 0);
703-
}
704-
}
705-
}
706-
else {
707-
step.next = () => {
708-
console.log(`Step ${index + 1}: Finished`);
709-
container.style.cursor = 'pointer';
710-
}
711-
};
712-
}
727+
initScript();
713728
IWSY.plugins = {};
714729
initBlocks();
715730
preloadImages();
716731
doStep(script.steps[0]);
717-
return gotoStep;
732+
return {
733+
setScript,
734+
gotoStep
735+
};
718736
};

iwsy/resources/ecs/iwsy.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
variable Section
4747
variable Item
4848
variable CurrentScriptName
49+
variable Action
4950
variable N
5051

5152
! The browser
@@ -308,14 +309,16 @@ L2:
308309
put Presentation into LastSavedState
309310
gosub to SetupSteps
310311
gosub to SetupBlocks
311-
gosub to SetupContent
312+
gosub to SetupContent
312313
put 0 into N
313314
gosub to SelectSection
314315

315316
on message
316317
begin
317-
put the message into N
318-
iwsy goto N
318+
put the message into Message
319+
put property `action` of Message into Action
320+
if Action is `goto` iwsy goto property `index` of Message
321+
else if Action is `script` iwsy script property `script` of Message
319322
end
320323
stop
321324

iwsy/resources/ecs/steps.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
variable ContinueTypes
6161
variable TrueFalse
6262
variable Response
63+
variable Message
6364
variable N
6465
variable B
6566

@@ -186,8 +187,20 @@ Restart:
186187
end
187188
on click ShowStep
188189
begin
190+
put 0 into N
191+
while N is less than the json count of Steps
192+
begin
193+
index StepButton to N
194+
set style `background` of StepButton to ``
195+
add 1 to N
196+
end
189197
put the index of ShowStep into N
190-
send N to parent
198+
index StepButton to N
199+
set style `background` of StepButton to `#ccf`
200+
set Message to object
201+
set property `action` of Message to `goto`
202+
set property `index` of Message to N
203+
send Message to parent
191204
end
192205

193206
! Set up the fixed lists
@@ -921,4 +934,8 @@ SaveCurrentStep:
921934
end
922935
set element SelectedStep of Steps to CurrentStep
923936
set property `steps` of Presentation to Steps
937+
set Message to object
938+
set property `action` of Message to `script`
939+
set property `script` of Message to Presentation
940+
send Message to parent
924941
return

iwsy/resources/json/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"blocks":{"title":{"background":"","border":"","borderRadius":"","fontColor":"","fontFamily":"","fontSize":100,"fontStyle":"","fontWeight":"","height":200,"left":0,"textAlign":"center","textMarginLeft":"","textMarginTop":"","top":400,"width":"100%"}},"content":{"main title":"This is my main title"},"steps":[{"title":"My first presentation","action":"init","label":"","aspect ratio":"16:9","background":"","border":"1px solid red"},{"title":"Setup main title","action":"set content","label":"","blocks":[{"block":"title","content":"main title"}]},{"title":"Fade up title","action":"fade up","label":"","blocks":["title"],"duration":1}]}
1+
{"blocks":{"center title":{"background":"","border":"","borderRadius":"","fontColor":"","fontFamily":"","fontSize":150,"fontStyle":"","fontWeight":"","height":200,"left":0,"textAlign":"center","textMarginLeft":"","textMarginTop":"","top":400,"width":"100%"}},"content":{"main title":"This is my main title"},"steps":[{"title":"My first presentation","action":"init","label":"","aspect ratio":"16:9","background":"","border":"1px solid green"},{"title":"Setup main title","action":"set content","label":"","blocks":[{"block":"center title","content":"main title"}]},{"title":"Fade up title","action":"fade up","label":"","blocks":["center title"],"duration":1}]}

js/plugins/iwsy.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ const EasyCoder_IWSY = {
4848
target
4949
});
5050
return true;
51+
case `script`:
52+
const script = compiler.getNextValue();
53+
compiler.addCommand({
54+
domain: `iwsy`,
55+
keyword: `iwsy`,
56+
lino,
57+
action,
58+
script
59+
});
60+
return true;
5161
default:
5262
break;
5363
}
@@ -71,12 +81,15 @@ const EasyCoder_IWSY = {
7181
player.style.background = `none`;
7282
player.style.border = `none`;
7383
const script = program.getValue(command.script);
74-
EasyCoder.iwsyGotoStep = IWSY(player, JSON.parse(script));
84+
EasyCoder.iwsyFunctions = IWSY(player, JSON.parse(script));
7585
break;
7686
case `goto`:
77-
EasyCoder.iwsyGotoStep(program.getValue(command.target));
87+
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
7888
break;
79-
}
89+
case `script`:
90+
EasyCoder.iwsyFunctions.setScript(JSON.parse(program.getValue(command.script)));
91+
break;
92+
}
8093
return command.pc + 1;
8194
}
8295
},

0 commit comments

Comments
 (0)