Skip to content

Commit 868cbb0

Browse files
committed
Change block structure
1 parent 99ac06f commit 868cbb0

File tree

4 files changed

+89
-126
lines changed

4 files changed

+89
-126
lines changed

iwsy/iwsy.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,46 +142,32 @@ const IWSY = (container, text) => {
142142
block.textPanel = text;
143143
};
144144

145-
// Set the content of a block
146-
const doSetContent = (spec) => {
147-
const block = script.blocks[spec.block];
148-
const content = script.content[spec.content];
149-
if (!block) {
150-
throw Error(`Block '${block}' cannot be found`);
151-
}
152-
if (!block.element) {
153-
createBlock(block);
154-
}
155-
const converter = new showdown.Converter();
156-
block.textPanel.innerHTML = converter.makeHtml(content.split(`%0a`).join(`\n`));
157-
};
158-
159145
// Set the content of a block
160146
const setcontent = step => {
161-
if (step.blocks) {
162-
for (const spec of step.blocks)
163-
{
164-
doSetContent(spec);
147+
for (const item of step.blocks)
148+
{
149+
for (const block of script.blocks) {
150+
if (block.name === item.block) {
151+
if (!block.element) {
152+
createBlock(block);
153+
}
154+
const content = script.content[item.content];
155+
const converter = new showdown.Converter();
156+
block.textPanel.innerHTML = converter.makeHtml(content.split(`%0a`).join(`\n`));
157+
}
165158
}
166-
} else {
167-
doSetContent(step);
168159
}
169160
step.next();
170161
};
171162

172163
// Show or hide a block
173164
const doShowHide = (step, showHide) => {
174165
if (script.speed !== `scan`) {
175-
if (Array.isArray(step.blocks)) {
176-
for (const name of step.blocks)
177-
{
178-
script.blocks[name].opacity = showHide ? `1.0` : `0.0`;
179-
script.blocks[name].element.style[`opacity`] = script.blocks[name].opacity;
180-
}
181-
} else {
182-
script.blocks[step.blocks].opacity = showHide ? `1.0` : `0.0`;
183-
script.blocks[step.blocks].element.style[`opacity`] = script.blocks[step.blocks].opacity;
184-
}
166+
for (const name of step.blocks)
167+
{
168+
script.blocks[name].opacity = showHide ? `1.0` : `0.0`;
169+
script.blocks[name].element.style[`opacity`] = script.blocks[name].opacity;
170+
}
185171
}
186172
step.next();
187173
};
@@ -196,7 +182,15 @@ const IWSY = (container, text) => {
196182

197183
// Fade up or down
198184
const doFade = (step, upDown) => {
199-
const stepBlocks = step.blocks;
185+
const stepBlocks = [];
186+
for (const b of step.blocks) {
187+
script.blocks.forEach((block, index) => {
188+
if (block.name === b) {
189+
stepBlocks.push(index);
190+
}
191+
});
192+
}
193+
200194
for (const b of stepBlocks) {
201195
const block = script.blocks[b];
202196
if (!block.element) {
@@ -419,8 +413,16 @@ const IWSY = (container, text) => {
419413

420414
// Handle a transition
421415
const transition = step => {
422-
const block = script.blocks[step.block];
423-
const target = script.blocks[step.target];
416+
let block = null;
417+
let target = null;
418+
script.blocks.forEach((item, index) => {
419+
if (item.name === step.block) {
420+
block = item;
421+
}
422+
if (item.name === step.target) {
423+
target = item;
424+
}
425+
});
424426
if (script.speed === `scan`) {
425427
doTransitionStep(block, target, 1.0);
426428
step.next();

iwsy/resources/ecs/blocks.txt

Lines changed: 45 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
import div Panel and variable Presentation
66

77
div Editor
8+
div Title
9+
div Table
810
div Row
911
div Cell
10-
div Title
11-
table Table
12-
tr TR
13-
td TD
14-
span BlockNameSpan
15-
input BlockNameInput
1612
input PropertyValue
1713
button EditButton
1814
button SaveButton
@@ -21,21 +17,18 @@
2117
a Link
2218
variable Blocks
2319
variable Block
24-
variable BlockNames
25-
variable BlockName
20+
variable PropertyDefaults
2621
variable PropertyNames
2722
variable PropertyName
28-
variable Properties
2923
variable SelectedBlock
30-
variable Action
3124
variable Message
3225
variable N
33-
variable B
26+
variable NBlocks
3427

3528
put -1 into SelectedBlock
3629

37-
rest get Properties from `/resources/json/properties.json`
38-
put the json keys of Properties into PropertyNames
30+
rest get PropertyNames from `/resources/json/propertyNames.json`
31+
rest get PropertyDefaults from `/resources/json/propertyDefaults.json`
3932

4033
on message go to Start
4134
set ready
@@ -50,8 +43,6 @@ Start:
5043

5144
Restart:
5245
put property `blocks` of Presentation into Blocks
53-
put the json keys of Blocks into BlockNames
54-
5546
clear Panel
5647
create Row in Panel
5748
set the style of Row to `display:flex`
@@ -67,98 +58,72 @@ Restart:
6758
set attribute `src` of AddBlock to `resources/icon/plus.png`
6859
on click AddBlock
6960
begin
70-
put prompt `Name of new block:` with `new block` into BlockName
7161
set Block to object
7262
put 0 into N
7363
while N is less than the json count of PropertyNames
7464
begin
7565
put element N of PropertyNames into PropertyName
76-
set property PropertyName of Block to property PropertyName of Properties
66+
set property PropertyName of Block to property PropertyName of PropertyDefaults
7767
add 1 to N
7868
end
79-
set property BlockName of Blocks to Block
69+
json add Block to Blocks
8070
set property `blocks` of Presentation to Blocks
8171
go to Restart
8272
end
8373

84-
put the json count of BlockNames into N
85-
set the elements of BlockNameSpan to N
86-
set the elements of BlockNameInput to N
87-
set the elements of EditButton to N
88-
set the elements of SaveButton to N
89-
set the elements of Editor to N
90-
set the elements of DeleteBlock to N
74+
put the json count of Blocks into NBlocks
75+
set the elements of EditButton to NBlocks
76+
set the elements of SaveButton to NBlocks
77+
set the elements of Editor to NBlocks
78+
set the elements of DeleteBlock to NBlocks
9179
create Table in Panel
9280
set the style of Table to `width:100%`
93-
put 0 into B
94-
while B is less than the elements of EditButton
81+
put 0 into N
82+
while N is less than NBlocks
9583
begin
96-
put element B of BlockNames into BlockName
97-
create TR in Table
98-
create TD in TR
99-
set the style of TD to `width:8em;border:1px solid black;padding-left:0.5em`
100-
index BlockNameSpan to B
101-
create BlockNameSpan in TD
102-
set the content of BlockNameSpan to BlockName
103-
index BlockNameInput to B
104-
create BlockNameInput in TD
105-
set the style of BlockNameInput to `width:100%;display:none`
106-
set the content of BlockNameInput to BlockName
107-
create TD in TR
108-
set the style of TD to `border:1px solid black`
109-
index EditButton to B
110-
index DeleteBlock to B
111-
index Editor to B
112-
create Row in TD
113-
set the style of Row to `display:flex`
114-
create EditButton in Row
115-
set the style of EditButton to `flex:1`
116-
set the text of EditButton to `Edit`
84+
index EditButton to N
85+
index DeleteBlock to N
86+
index Editor to N
87+
create Row in Table
11788
create Cell in Row
118-
set the style of Cell to `width:1.4em;text-align:center`
89+
set the style of Cell to `width:100%;display:flex`
90+
create EditButton in Cell
91+
set the style of EditButton to `flex:1`
92+
put element N of Blocks into Block
93+
set the text of EditButton to property `name` of Block
11994
create Link in Cell
12095
create DeleteBlock in Link
121-
set the style of DeleteBlock to `width:1em;margin-top:0.1em`
96+
set the style of DeleteBlock to `width:1em;margin:0.1em 0 0 0.2em`
12297
set attribute `src` of DeleteBlock to `/resources/icon/stop.png`
123-
create Editor in TD
124-
set the style of Editor to `display:none`
125-
add 1 to B
98+
create Editor in Row
99+
set the style of Editor to `margin:0.5em;border:1px solid black;padding:0.2em;display:none`
100+
add 1 to N
126101
end
127102
on click EditButton
128103
begin
129104
gosub to SaveSelectedBlock
130105
put the index of EditButton into SelectedBlock
131106
put 0 into N
132-
while N is less than the json count of BlockNames
107+
while N is less than NBlocks
133108
begin
134-
index EditButton to N
135-
set style `background` of EditButton to ``
136-
if N is not SelectedBlock set the text of EditButton to `Edit`
137-
index BlockNameSpan to N
138-
index BlockNameInput to N
139-
set the content of BlockNameSpan to the text of BlockNameInput
140-
set style `display` of BlockNameSpan to `inline`
141-
set style `display` of BlockNameInput to `none`
142-
index Editor to N
143-
set style `display` of Editor to `none`
109+
if N is not SelectedBlock
110+
begin
111+
index EditButton to N
112+
set style `background` of EditButton to ``
113+
index Editor to N
114+
set style `display` of Editor to `none`
115+
clear Editor
116+
end
144117
add 1 to N
145118
end
146119
index EditButton to SelectedBlock
147-
put the text of EditButton into Action
148-
if Action is `Edit`
120+
index Editor to SelectedBlock
121+
if style `display` of Editor is `none`
149122
begin
150123
set style `background` of EditButton to `lightgray`
151-
set the text of EditButton to `Properties`
152-
index BlockNameSpan to SelectedBlock
153-
index BlockNameInput to SelectedBlock
154124
index SaveButton to SelectedBlock
155-
set style `display` of BlockNameSpan to `none`
156-
set style `display` of BlockNameInput to `inline`
157-
index Editor to SelectedBlock
158125
set style `display` of Editor to `block`
159-
clear Editor
160-
put element SelectedBlock of BlockNames into BlockName
161-
put property BlockName of Blocks into Block
126+
put element SelectedBlock of Blocks into Block
162127
put the json count of PropertyNames into N
163128
set the elements of PropertyValue to N
164129
put 0 into N
@@ -173,7 +138,7 @@ Restart:
173138
index PropertyValue to N
174139
create PropertyValue in Row
175140
set the style of PropertyValue to `flex:1`
176-
set the content of PropertyValue to property PropertyName of Block
141+
set the text of PropertyValue to property PropertyName of Block
177142
add 1 to N
178143
end
179144
create Row in Editor
@@ -185,17 +150,14 @@ Restart:
185150
else
186151
begin
187152
gosub to SaveSelectedBlock
188-
set the text of EditButton to `Edit`
189153
clear Editor
190154
set style `display` of Editor to `none`
191155
end
192156
end
193157
on click DeleteBlock
194158
begin
195159
put the index of DeleteBlock into N
196-
put element N of BlockNames into BlockName
197-
put property `blocks` of Presentation into Blocks
198-
json delete property BlockName of Blocks
160+
json delete element N of Blocks
199161
set property `blocks` of Presentation to Blocks
200162
go to Restart
201163
end
@@ -204,24 +166,16 @@ Restart:
204166
! Save the seleced block
205167
SaveSelectedBlock:
206168
if SelectedBlock is -1 return
169+
put element SelectedBlock of Blocks into Block
207170
put 0 into N
208171
while N is less than the json count of PropertyNames
209172
begin
210173
put element N of PropertyNames into PropertyName
211174
index PropertyValue to N
212-
set property PropertyName of Block to PropertyValue
175+
set property PropertyName of Block to the text of PropertyValue
213176
add 1 to N
214177
end
215-
index BlockNameInput to SelectedBlock
216-
put element SelectedBlock of BlockNames into BlockName
217-
if BlockNameInput is not BlockName
218-
begin
219-
print `deleting`
220-
json delete property BlockName of Blocks
221-
put BlockNameInput into BlockName
222-
set element SelectedBlock of BlockNames to BlockName
223-
end
224-
set property BlockName of Blocks to Block
178+
set element SelectedBlock of Blocks to Block
225179
set property `blocks` of Presentation to Blocks
226180

227181
! Tell the parent to refresh the script

iwsy/resources/ecs/iwsy.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ L2:
346346
CreateNewPresentation:
347347
set Presentation to object
348348
set Item to object
349-
set property `blocks` of Presentation to Item
350349
set property `content` of Presentation to Item
351350
set Item to array
352351
set property `steps` of Presentation to Item
352+
set property `blocks` of Presentation to Item
353353
return
354354

355355
SetupSteps:

iwsy/resources/ecs/steps.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,14 @@ CreateNewStep:
304304
EditStep:
305305
put property `blocks` of Presentation into Blocks
306306
put property `content` of Presentation into Contents
307-
put the json keys of Blocks into BlockNames
307+
set BlockNames to array
308+
put 0 into N
309+
while N is less than the json count of Blocks
310+
begin
311+
put element N of Blocks into Block
312+
json add property `name` of Block to BlockNames
313+
add 1 to N
314+
end
308315
put the json keys of Contents into ContentNames
309316
put element SelectedStep of Steps into CurrentStep
310317

0 commit comments

Comments
 (0)