Skip to content

Commit 4bffb88

Browse files
committed
Basic help functionality
1 parent f211f94 commit 4bffb88

File tree

8 files changed

+245
-20
lines changed

8 files changed

+245
-20
lines changed

dist/plugins/iwsy.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ const EasyCoder_IWSY = {
3939
action
4040
});
4141
return true;
42+
case `remove`:
43+
if (compiler.nextTokenIs(`styles`)) {
44+
compiler.next();
45+
compiler.addCommand({
46+
domain: `iwsy`,
47+
keyword: `iwsy`,
48+
lino,
49+
action: `removeStyles`
50+
});
51+
return true;
52+
}
53+
return false;
4254
case `script`:
4355
const script = compiler.getNextValue();
4456
compiler.addCommand({
@@ -176,6 +188,11 @@ const EasyCoder_IWSY = {
176188
EasyCoder.iwsyFunctions.stop();
177189
}
178190
break;
191+
case `removeStyles`:
192+
if (EasyCoder.iwsyFunctions) {
193+
EasyCoder.iwsyFunctions.removeStyles();
194+
}
195+
break;
179196
case `onstep`:
180197
const cb = command.pc + 2;
181198
if (EasyCoder.iwsyFunctions) {

iwsy/iwsy.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const IWSY = (player, text) => {
204204
for (const text of script.content) {
205205
if (text.name === item.content) {
206206
const converter = new showdown.Converter({
207-
extensions: [`Extension`]
207+
extensions: [`IWSY`]
208208
});
209209
block.textPanel.innerHTML =
210210
converter.makeHtml(text.content.split(`%0a`).join(`\n`));
@@ -307,7 +307,7 @@ const IWSY = (player, text) => {
307307
for (const content of script.content) {
308308
if (content.name === step.target) {
309309
const converter = new showdown.Converter({
310-
extensions: [`Extension`]
310+
extensions: [`IWSY`]
311311
});
312312
const newText = converter.makeHtml(content.content.split(`%0a`).join(`\n`));
313313
for (const block of script.blocks) {
@@ -732,7 +732,7 @@ const IWSY = (player, text) => {
732732
if (typeof showdown === `undefined`) {
733733
require(`js`, `https://cdn.rawgit.com/showdownjs/showdown/1.9.1/dist/showdown.min.js`,
734734
() => {
735-
showdown.extension(`Extension`, {
735+
showdown.extension(`IWSY`, {
736736
type: `lang`,
737737
filter: function (text, converter) {
738738
return text.replace(/~([^~]+)~/g, function (match, group) {
@@ -837,6 +837,14 @@ const IWSY = (player, text) => {
837837
document.head.appendChild(style);
838838
};
839839

840+
// Remove all the CSS styles
841+
const removeStyles = () => {
842+
const styles = document.getElementsByClassName("iwsy-css");
843+
for (const style of styles) {
844+
style.parentNode.removeChild(style);
845+
}
846+
};
847+
840848
// Initialize the script
841849
const initScript = () => {
842850
document.onkeydown = null;
@@ -847,10 +855,7 @@ const IWSY = (player, text) => {
847855
script.singleStep = true;
848856
script.labels = {};
849857
script.stop = false;
850-
const styles = document.getElementsByClassName("iwsy-css");
851-
for (const style of styles) {
852-
style.parentNode.removeChild(style);
853-
}
858+
removeStyles();
854859
for (const block of script.blocks) {
855860
const element = block.element;
856861
if (typeof element !== `undefined`) {
@@ -955,6 +960,7 @@ const IWSY = (player, text) => {
955960
block,
956961
run,
957962
stop,
958-
onStep
963+
onStep,
964+
removeStyles
959965
};
960966
};

iwsy/resources/ecs/content.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Restart:
164164
set the text of ItemNameInput to property `name` of Item
165165
set style `display` of Editor to `block`
166166
create TextArea in Editor
167-
set the style of TextArea to `width:100%;max-width:100%;height:8em`
167+
set the style of TextArea to `width:100%;max-width:100%;height:20em`
168168
put property `content` of Item into Content
169169
replace `%0a` with newline in Content
170170
set the content of TextArea to Content

iwsy/resources/ecs/help.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
! Help Manager
2+
3+
script HelpManager
4+
5+
import div Container
6+
7+
callback DecoratorCallback
8+
variable Mobile
9+
variable Page
10+
variable Content
11+
variable Payload
12+
variable ImageCount
13+
variable Function
14+
variable Data
15+
variable Source
16+
variable Style
17+
variable Item
18+
variable Len
19+
variable N
20+
21+
if portrait
22+
begin
23+
if mobile set Mobile else clear Mobile
24+
end
25+
26+
set style `padding` of Container to `0 1em`
27+
set style `overflow-y` of Container to `scroll`
28+
29+
load showdown
30+
on DecoratorCallback go to Decorate
31+
32+
on message go to Show
33+
set ready
34+
stop
35+
36+
Show:
37+
put 0 into ImageCount
38+
set style `display` of Container to `block`
39+
get Page from storage as `.help`
40+
GetPage:
41+
if Page is empty
42+
begin
43+
put `start` into Page
44+
put Page into storage as `.help`
45+
end
46+
iwsy remove styles
47+
rest get Content from `/resources/help/` cat Page cat `.md`
48+
or begin
49+
put empty into Page
50+
go to GetPage
51+
end
52+
set the content of Container to showdown decode Content with DecoratorCallback
53+
stop
54+
55+
!------------------------------------------------------------------------------
56+
! This is the Showndown extension.
57+
58+
! Decorate is called for every occurrence of ~...~ in the topic data
59+
Decorate:
60+
put the payload of DecoratorCallback into Payload
61+
put the position of `:` in Payload into N
62+
if N is -1
63+
begin
64+
if Payload is `clear` put `<div style="height:1px;clear:both"></div>` into Payload
65+
end
66+
else
67+
begin
68+
put left N of Payload into Function
69+
add 1 to N
70+
put from N of Payload into Data
71+
if Function is `img` gosub to ProcessImage
72+
end
73+
set the payload of DecoratorCallback to Payload
74+
stop
75+
76+
! Process an image, including positioning and class information
77+
ProcessImage:
78+
put the position of `:` in Data into N
79+
if N is -1 return
80+
put left N of Data into Source
81+
add 1 to N
82+
put from N of Data into Data
83+
json split Data on `,` into Data
84+
put empty into Style
85+
put 0 into N
86+
while N is less than the json count of Data
87+
begin
88+
put element N of Data into Item
89+
if Item is `left` put Style cat `float:left;` into Style
90+
else if Item is `right` put Style cat `float:right;` into Style
91+
else if Item is `center` put Style cat `margin:0 auto;` into Style
92+
else if Item is `border` put Style cat `padding:2px;border:1px solid black;` into Style
93+
else if Item is `clear` put Style cat `clear:both;` into Style
94+
else if right 1 of Item is `%` put Style cat `width:` cat Item cat `;` into Style
95+
else
96+
begin
97+
if left 1 of Item is not `{` go to NextItem
98+
if right 1 of Item is not `}` go to NextItem
99+
put from 1 of Item into Item
100+
put the length of Item into Len
101+
take 1 from Len
102+
put left Len of Item into Item
103+
put Style cat Item cat `;` into Style
104+
end
105+
NextItem:
106+
add 1 to N
107+
end
108+
put `<img id="ec-image-` cat ImageCount cat `" src="` cat Source
109+
cat `" style="` cat Style cat `" />` into Payload
110+
add 1 to ImageCount
111+
return
112+
113+
Exit:
114+
set style `display` of Container to `none`
115+
stop

iwsy/resources/ecs/iwsy.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
div Player
2020
div UserPanel
2121
div FileManPanel
22+
div HelpPanel
2223
div Panel
2324
div Div
2425
span Status
@@ -32,12 +33,14 @@
3233
img Delete
3334
img User
3435
img FileMan
36+
img Help
3537
a Link
3638
module StepsModule
3739
module BlocksModule
3840
module ContentModule
3941
module UserModule
4042
module FileManModule
43+
module HelpModule
4144
variable Mobile
4245
variable LastSavedState
4346
variable Content
@@ -111,7 +114,7 @@ L2:
111114

112115
create Masthead in Left
113116
set the style of Masthead to
114-
`border:0.2em solid purple;text-align:center;color: lemonchiffon;background:darkmagenta;position:relative`
117+
`border:0.2em solid purple;text-align:center;color:lemonchiffon;background:darkmagenta;position:relative`
115118
create Title in Masthead
116119
set the style of Title to `font-size:4em;font-weight:bold`
117120
set the content of Title to `I Wanna Show You`
@@ -173,6 +176,11 @@ L2:
173176
set attribute `src` of RunStop to `resources/icon/run.png`
174177
set attribute `title` of RunStop to `Run`
175178
create Link in Buttons
179+
create Help in Link
180+
set the style of Help to `width:40px;margin-right:1.5em`
181+
set attribute `src` of Help to `resources/icon/help.png`
182+
set attribute `title` of Help to `Help`
183+
create Link in Buttons
176184
create User in Link
177185
set the style of User to `width:40px;position:absolute;top:0.5em;right:0.5em`
178186
set attribute `src` of User to `resources/icon/user.png`
@@ -184,6 +192,9 @@ L2:
184192

185193
create FileManPanel in Left
186194
set the style of FileManPanel to `flex:1;display:none;margin-top:0.5em;border-top:1px solid black`
195+
196+
create HelpPanel in Left
197+
set the style of HelpPanel to `flex:1;display:none;margin-top:0.5em;border-top:1px solid black`
187198

188199
! The right-hand panel
189200
create Right in Body
@@ -353,10 +364,27 @@ L2:
353364
run Script with FileManPanel as FileManModule
354365
end
355366
set style `display` of Player to `none`
367+
set style `display` of HelpPanel to `none`
356368
set style `display` of FileManPanel to `block`
357369
send to FileManModule
358370
end
359371

372+
on click Help
373+
begin
374+
if Running stop
375+
if HelpModule is not running
376+
begin
377+
require js
378+
`https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/plugins/showdown.js?v=` cat now
379+
rest get Script from `/resources/ecs/help.txt?v=` cat now
380+
run Script with HelpPanel as HelpModule
381+
end
382+
set style `display` of Player to `none`
383+
set style `display` of FileManPanel to `none`
384+
set style `display` of HelpPanel to `block`
385+
send to HelpModule
386+
end
387+
360388
on click RunStop go to DoRunStop
361389

362390
on click User
@@ -690,6 +718,7 @@ DoRunStop:
690718
send Message to StepsModule
691719
end
692720

721+
set style `display` of HelpPanel to `none`
693722
iwsy run then
694723
begin
695724
gosub to ClearStepsButtons

iwsy/resources/ecs/steps.txt

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
input DurationInput
3535
input TargetInput
3636
input URLInput
37+
textarea InitCSS
3738
img AddStep
3839
img Up
3940
img UpContent
@@ -298,6 +299,7 @@ Restart:
298299
json add `aspect ratio` to InitProperties
299300
json add `background` to InitProperties
300301
json add `border` to InitProperties
302+
json add `css` to InitProperties
301303
set ContinueTypes to array
302304
json add `true` to ContinueTypes
303305
json add `false` to ContinueTypes
@@ -455,8 +457,12 @@ ReloadStepEditor:
455457
set the style of TD to `padding-bottom:0.2em`
456458
create InsertBefore in TD
457459
set the style of InsertBefore to `width:calc(100% / 3)`
458-
set the text of InsertBefore to `Add Step Before`
459-
on click InsertBefore go to AddStepBefore
460+
if SelectedStep is 0 set the text of InsertBefore to `---`
461+
else
462+
begin
463+
set the text of InsertBefore to `Add Step Before`
464+
on click InsertBefore go to AddStepBefore
465+
end
460466
create Save in TD
461467
set the style of Save to `width:calc(100% / 3)`
462468
set the text of Save to `Save`
@@ -487,12 +493,24 @@ EditInit:
487493
create Cell in BlockRow
488494
set the style of Cell to `width:6em;padding-left:0.2em`
489495
set the content of Cell to InitProperty
490-
index InitInput to B
491-
create InitInput in BlockRow
492-
set the style of InitInput to `flex:1`
493-
put property InitProperty of CurrentStep into Item
494-
replace `&quot;` with `"` in Item
495-
set the content of InitInput to Item
496+
if InitProperty is `css`
497+
begin
498+
create InitCSS in BlockRow
499+
set the style of InitCSS to `flex:1;height:20em`
500+
put property InitProperty of CurrentStep into Item
501+
replace `%0a` with newline in Item
502+
replace `&quot;` with `"` in Item
503+
set the content of InitCSS to Item
504+
end
505+
else
506+
begin
507+
index InitInput to B
508+
create InitInput in BlockRow
509+
set the style of InitInput to `flex:1`
510+
put property InitProperty of CurrentStep into Item
511+
replace `&quot;` with `"` in Item
512+
set the content of InitInput to Item
513+
end
496514
add 1 to B
497515
end
498516
return
@@ -893,7 +911,7 @@ SaveCurrentStep:
893911
index StepButton to SelectedStep
894912
set the text of StepButton to the content of TitleInput
895913
index LabelInput to SelectedStep
896-
set property `label` of CurrentStep to the content of LabelInput
914+
if SelectedStep is not 0 set property `label` of CurrentStep to the content of LabelInput
897915
put property `action` of CurrentStep into Action
898916
if Action is `init`
899917
begin
@@ -902,7 +920,12 @@ SaveCurrentStep:
902920
begin
903921
put element N of InitProperties into InitProperty
904922
index InitInput to N
905-
put InitInput into Item
923+
if InitProperty is `css`
924+
begin
925+
put the content of InitCSS into Item
926+
replace newline with `%0a` in Item
927+
end
928+
else put InitInput into Item
906929
replace `"` with `&quot;` in Item
907930
set property InitProperty of CurrentStep to Item
908931
add 1 to N

0 commit comments

Comments
 (0)