Skip to content

Commit 7b74d42

Browse files
authored
Merge pull request #116 from easycoder/dev
Dev
2 parents bac2b1c + 4bffb88 commit 7b74d42

File tree

9 files changed

+249
-18
lines changed

9 files changed

+249
-18
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: 18 additions & 6 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) {
@@ -568,6 +568,9 @@ const IWSY = (player, text) => {
568568
if (step.title) {
569569
document.title = step.title;
570570
}
571+
if (step.css) {
572+
setHeadStyle(step.css.split(`%0a`).join(`\n`));
573+
}
571574
const aspect = step[`aspect ratio`];
572575
if (aspect) {
573576
const colon = aspect.indexOf(`:`);
@@ -729,7 +732,7 @@ const IWSY = (player, text) => {
729732
if (typeof showdown === `undefined`) {
730733
require(`js`, `https://cdn.rawgit.com/showdownjs/showdown/1.9.1/dist/showdown.min.js`,
731734
() => {
732-
showdown.extension(`Extension`, {
735+
showdown.extension(`IWSY`, {
733736
type: `lang`,
734737
filter: function (text, converter) {
735738
return text.replace(/~([^~]+)~/g, function (match, group) {
@@ -829,10 +832,19 @@ const IWSY = (player, text) => {
829832
}
830833
}
831834
var style = document.createElement('style');
835+
style.className = `iwsy-css`;
832836
style.innerHTML = `${styleName} ${styleValue}`;
833837
document.head.appendChild(style);
834838
};
835839

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+
836848
// Initialize the script
837849
const initScript = () => {
838850
document.onkeydown = null;
@@ -843,6 +855,7 @@ const IWSY = (player, text) => {
843855
script.singleStep = true;
844856
script.labels = {};
845857
script.stop = false;
858+
removeStyles();
846859
for (const block of script.blocks) {
847860
const element = block.element;
848861
if (typeof element !== `undefined`) {
@@ -935,8 +948,6 @@ const IWSY = (player, text) => {
935948
if (script.runMode === `auto`) {
936949
document.addEventListener(`click`, onClick);
937950
}
938-
setHeadStyle(`p`, `{margin:0 0 0.5em 0}`)
939-
setHeadStyle(`h1, h2, h3, h4, h5, h6`, `{margin:0}`)
940951
setupShowdown();
941952
initScript();
942953
IWSY.plugins = {};
@@ -949,6 +960,7 @@ const IWSY = (player, text) => {
949960
block,
950961
run,
951962
stop,
952-
onStep
963+
onStep,
964+
removeStyles
953965
};
954966
};

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

0 commit comments

Comments
 (0)