Skip to content

Commit 77bc1b2

Browse files
committed
Fullscreen; documentation
1 parent ff57cf9 commit 77bc1b2

21 files changed

+326
-158
lines changed

dist/plugins/iwsy.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ const EasyCoder_IWSY = {
8383
return true;
8484
case `run`:
8585
const pc = compiler.getPc();
86-
compiler.next();
86+
let mode = {
87+
type: `constant`,
88+
numeric: false,
89+
content: `normal`
90+
};
91+
if (compiler.nextToken() !== `then`) {
92+
mode = compiler.getValue();
93+
}
8794
compiler.addCommand({
8895
domain: `iwsy`,
8996
keyword: `iwsy`,
9097
lino,
9198
action,
99+
mode,
92100
then: 0
93101
});
94102
// Get the 'then' code, if any
@@ -180,7 +188,7 @@ const EasyCoder_IWSY = {
180188
break;
181189
case `run`:
182190
if (EasyCoder.iwsyFunctions) {
183-
EasyCoder.iwsyFunctions.run(function() {
191+
EasyCoder.iwsyFunctions.run(program.getValue(command.mode), () => {
184192
program.run(command.then);
185193
});
186194
return 0;

iwsy/iwsy.js

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

3-
const IWSY = (player, text) => {
3+
const IWSY = (playerElement, text) => {
44

5+
let player = playerElement;
56
let script = text;
67
let clicked = false;
78

@@ -104,10 +105,9 @@ const IWSY = (player, text) => {
104105

105106
// Create a block
106107
const createBlock = block => {
107-
const r = player.getBoundingClientRect();
108108
let rect = {
109-
width: r.width,
110-
height: r.height,
109+
width: player.clientWidth,
110+
height: player.clientHeight,
111111
left: 0,
112112
top: 0
113113
}
@@ -634,39 +634,6 @@ const IWSY = (player, text) => {
634634
}
635635
};
636636

637-
// Go to a specified step number
638-
const gotoStep = (target) => {
639-
if (!script.stepping) {
640-
script.stepping = true;
641-
script.scanTarget = target;
642-
script.singleStep = true;
643-
script.runMode = `manual`;
644-
scan();
645-
}
646-
};
647-
648-
// Run the presentation
649-
const run = then => {
650-
if (!script.stepping) {
651-
initScript();
652-
script.runMode = `auto`;
653-
script.speed = `normal`;
654-
script.singleStep = false;
655-
script.then = then;
656-
doStep(script.steps[0]);
657-
}
658-
};
659-
660-
// Stop the run
661-
const stop = () => {
662-
script.stop = true;
663-
};
664-
665-
// Set a step callback
666-
const onStep = onStepCB => {
667-
script.onStepCB = onStepCB;
668-
};
669-
670637
// Chain to another presentation
671638
const chain = step => {
672639
step.next();
@@ -686,68 +653,6 @@ const IWSY = (player, text) => {
686653
}
687654
};
688655

689-
// Replace the script
690-
const setScript = newScript => {
691-
removeBlocks();
692-
script = newScript;
693-
initScript();
694-
};
695-
696-
// Show a block
697-
const block = blockIndex => {
698-
player.innerHTML = ``;
699-
const w = player.getBoundingClientRect().width / 1000;
700-
const h = player.getBoundingClientRect().height / 1000;
701-
script.blocks.forEach((block, index) => {
702-
const defaults = block.defaults;
703-
const element = document.createElement(`div`);
704-
player.appendChild(element);
705-
if (script.speed === `scan`) {
706-
element.style.display = `none`;
707-
}
708-
element.style.position = `absolute`;
709-
element.style.opacity = `0.5`;
710-
let val = defaults.left;
711-
if (!isNaN(val)) {
712-
val *= w;
713-
}
714-
element.style.left = val;
715-
val = defaults.top;
716-
if (!isNaN(val)) {
717-
val *= h;
718-
}
719-
element.style.top = val;
720-
val = defaults.width;
721-
if (!isNaN(val)) {
722-
val = `${val * w - 2}px`;
723-
} else {
724-
val = `calc(${val} - 2px)`
725-
}
726-
element.style.width = val;
727-
val = defaults.height;
728-
if (!isNaN(val)) {
729-
val = `${val * h - 2}px`;
730-
} else {
731-
val = `calc(${val} - 2px)`
732-
}
733-
element.style.height = val;
734-
element.style[`font-size`] = `${h * 40}px`
735-
element.innerHTML = defaults.name;
736-
if (index == blockIndex) {
737-
element.style.background = `#ddffdd`;
738-
element.style.border = `1px solid #00ff00`;
739-
element.style[`font-weight`] = `bold`
740-
element.style[`z-index`] = 10;
741-
element.style.color = `#006600`;
742-
} else {
743-
element.style.border = `1px solid #ff0000`;
744-
element.style[`text-align`] = `right`;
745-
element.style[`z-index`] = 0;
746-
element.style.color = `#ff0000`;
747-
}
748-
});
749-
};
750-
751656
// Set up Showdown
752657
const setupShowdown = () => {
753658
if (typeof showdown === `undefined`) {
@@ -858,14 +763,6 @@ const IWSY = (player, text) => {
858763
document.head.appendChild(style);
859764
};
860765

861-
// Remove all the CSS styles
862-
const removeStyles = () => {
863-
const styles = document.getElementsByClassName("iwsy-css");
864-
for (const style of styles) {
865-
style.parentNode.removeChild(style);
866-
}
867-
};
868-
869766
// Initialize the script
870767
const initScript = () => {
871768
document.onkeydown = null;
@@ -965,16 +862,140 @@ const IWSY = (player, text) => {
965862
}
966863
};
967864

865+
///////////////////////////////////////////////////////////////////////////////
866+
// These are all the exported functions
867+
868+
// Set the script
869+
const setScript = newScript => {
870+
removeBlocks();
871+
script = newScript;
872+
initScript();
873+
};
874+
875+
// Go to a specified step number
876+
const gotoStep = (target) => {
877+
if (!script.stepping) {
878+
script.stepping = true;
879+
script.scanTarget = target;
880+
script.singleStep = true;
881+
script.runMode = `manual`;
882+
scan();
883+
}
884+
};
885+
886+
// Show a block
887+
const block = blockIndex => {
888+
player.innerHTML = ``;
889+
const w = player.getBoundingClientRect().width / 1000;
890+
const h = player.getBoundingClientRect().height / 1000;
891+
script.blocks.forEach((block, index) => {
892+
const defaults = block.defaults;
893+
const element = document.createElement(`div`);
894+
player.appendChild(element);
895+
if (script.speed === `scan`) {
896+
element.style.display = `none`;
897+
}
898+
element.style.position = `absolute`;
899+
element.style.opacity = `0.5`;
900+
let val = defaults.left;
901+
if (!isNaN(val)) {
902+
val *= w;
903+
}
904+
element.style.left = val;
905+
val = defaults.top;
906+
if (!isNaN(val)) {
907+
val *= h;
908+
}
909+
element.style.top = val;
910+
val = defaults.width;
911+
if (!isNaN(val)) {
912+
val = `${val * w - 2}px`;
913+
} else {
914+
val = `calc(${val} - 2px)`
915+
}
916+
element.style.width = val;
917+
val = defaults.height;
918+
if (!isNaN(val)) {
919+
val = `${val * h - 2}px`;
920+
} else {
921+
val = `calc(${val} - 2px)`
922+
}
923+
element.style.height = val;
924+
element.style[`font-size`] = `${h * 40}px`
925+
element.innerHTML = defaults.name;
926+
if (index == blockIndex) {
927+
element.style.background = `#ddffdd`;
928+
element.style.border = `1px solid #00ff00`;
929+
element.style[`font-weight`] = `bold`
930+
element.style[`z-index`] = 10;
931+
element.style.color = `#006600`;
932+
} else {
933+
element.style.border = `1px solid #ff0000`;
934+
element.style[`text-align`] = `right`;
935+
element.style[`z-index`] = 0;
936+
element.style.color = `#ff0000`;
937+
}
938+
});
939+
};
940+
941+
// Run the presentation
942+
const run = (mode, then) => {
943+
if (mode === `fullscreen`) {
944+
if (document.fullscreenElement) {
945+
document.exitFullscreen();
946+
} else {
947+
player.requestFullscreen();
948+
document.onfullscreenchange = () => {
949+
if (document.fullscreenElement) {
950+
player = document.fullscreenElement;
951+
runPresentation(then);
952+
} else {
953+
player = playerElement;
954+
}
955+
};
956+
}
957+
} else {
958+
runPresentation(then);
959+
}
960+
}
961+
962+
const runPresentation = then => {
963+
if (!script.stepping) {
964+
initScript();
965+
script.runMode = `auto`;
966+
script.speed = `normal`;
967+
script.singleStep = false;
968+
script.then = then;
969+
doStep(script.steps[0]);
970+
}
971+
};
972+
973+
// Stop the run
974+
const stop = () => {
975+
script.stop = true;
976+
};
977+
978+
// Set a step callback
979+
const onStep = onStepCB => {
980+
script.onStepCB = onStepCB;
981+
};
982+
983+
// Remove all the CSS styles
984+
const removeStyles = () => {
985+
const styles = document.getElementsByClassName("iwsy-css");
986+
for (const style of styles) {
987+
style.parentNode.removeChild(style);
988+
}
989+
};
990+
991+
///////////////////////////////////////////////////////////////////////////
992+
968993
document.removeEventListener(`click`, init);
969994
if (script.runMode === `auto`) {
970995
document.addEventListener(`click`, onClick);
971996
}
972997
setupShowdown();
973998
initScript();
974-
IWSY.plugins = {};
975-
if (script.steps.length > 0) {
976-
doStep(script.steps[0]);
977-
}
978999
return {
9791000
setScript,
9801001
gotoStep,
@@ -984,4 +1005,4 @@ const IWSY = (player, text) => {
9841005
onStep,
9851006
removeStyles
9861007
};
987-
};
1008+
};

iwsy/resources/ecs/blocks.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Restart:
156156
if N is not SelectedBlock
157157
begin
158158
index EditButton to N
159-
set style `background` of EditButton to ``
159+
set style `background-color` of EditButton to `#eee`
160160
index Editor to N
161161
set style `display` of Editor to `none`
162162
clear Editor
@@ -168,7 +168,7 @@ Restart:
168168
index SaveButton to SelectedBlock
169169
if style `display` of Editor is `none`
170170
begin
171-
set style `background` of EditButton to `lightgray`
171+
set style `background-color` of EditButton to `lightgray`
172172
set style `display` of Editor to `block`
173173
put element SelectedBlock of Blocks into Block
174174
put property `defaults` of Block into Defaults

iwsy/resources/ecs/content.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Restart:
140140
if N is not SelectedItem
141141
begin
142142
index EditButton to N
143-
set style `background` of EditButton to ``
143+
set style `background` of EditButton to `#eee`
144144
index Editor to N
145145
set style `display` of Editor to `none`
146146
clear Editor
@@ -155,7 +155,7 @@ Restart:
155155
if style `display` of Editor is `none`
156156
begin
157157
put element SelectedItem of Items into Item
158-
set style `background` of EditButton to `lightgray`
158+
set style `background-color` of EditButton to `lightgray`
159159
create Row in Editor
160160
set the style of Row to `display:flex`
161161
create Cell in Row

iwsy/resources/ecs/help.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ GetPage:
5555
end
5656
put Page into storage as `.help`
5757
set the content of Container to showdown decode Content with DecoratorCallback
58+
scroll Container to 0
5859
set the elements of Link to LinkCount
5960
put 0 into N
6061
while N is less than LinkCount
@@ -119,6 +120,7 @@ ProcessImage:
119120
else if Item is `center` put Style cat `margin:0 auto;` into Style
120121
else if Item is `border` put Style cat `padding:2px;border:1px solid black;` into Style
121122
else if Item is `clear` put Style cat `clear:both;` into Style
123+
else if Item is `icon` put Style cat `height:0.9em;position:relative;top:0.05em` into Style
122124
else if right 1 of Item is `%` put Style cat `width:` cat Item cat `;` into Style
123125
else
124126
begin

0 commit comments

Comments
 (0)