Skip to content

Commit 32f6553

Browse files
committed
Development
1 parent c28e39b commit 32f6553

File tree

7 files changed

+1312
-122
lines changed

7 files changed

+1312
-122
lines changed

iwsy/iwsy.js

Lines changed: 17 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ const IWSY = (container, script) => {
9292
}
9393
};
9494

95-
// Create a text block.
96-
const createTextBlock = (block) => {
95+
// Create a block.
96+
const createBlock = (block) => {
9797
const container = block.container;
9898
if (block.element) {
9999
container.removeChild(block.element);
@@ -102,6 +102,7 @@ const IWSY = (container, script) => {
102102
const h = container.getBoundingClientRect().height / 1000;
103103
const properties = block.properties;
104104
const element = document.createElement(`div`);
105+
container.appendChild(element);
105106
block.element = element;
106107
element.style[`position`] = `absolute`;
107108
element.style[`opacity`] = `0.0`;
@@ -127,27 +128,23 @@ const IWSY = (container, script) => {
127128
element.style[`height`] = val;
128129
element.style[`background`] = properties.background;
129130
element.style[`border`] = properties.border;
130-
container.appendChild(element);
131131
val = properties.textMarginLeft;
132132
if (!isNaN(val)) {
133-
val = `${val * w}px`;
133+
val *= w;
134134
}
135-
element.style[`width`] = val;
136135
const marginLeft = val;
137136
val = properties.textMarginTop;
138137
if (!isNaN(val)) {
139-
val = `${val * h}px`;
138+
val *= h;
140139
}
141-
element.style[`height`] = val;
142140
const marginTop = val;
143-
const inner = document.createElement(`div`);
144-
inner.style[`position`] = `absolute`;
145-
inner.style[`left`] = marginLeft;
146-
inner.style[`top`] = marginTop;
147-
inner.style[`width`] = `calc(100% - ${marginLeft}px - ${marginLeft}px)`;
148-
element.appendChild(inner);
149-
element.inner = inner;
150141
const text = document.createElement(`div`);
142+
element.appendChild(text);
143+
text.style[`position`] = `absolute`;
144+
text.style[`left`] = marginLeft;
145+
text.style[`top`] = marginTop;
146+
text.style[`width`] = `calc(100% - ${marginLeft}px - ${marginLeft}px)`;
147+
text.style[`height`] = `calc(100% - ${marginTop}px - ${marginTop}px)`;
151148
text.style[`font-family`] = properties.fontFamily;
152149
val = properties.fontSize;
153150
if (!isNaN(val)) {
@@ -158,82 +155,20 @@ const IWSY = (container, script) => {
158155
text.style[`font-style`] = properties.fontStyle;
159156
text.style[`color`] = properties.fontColor;
160157
text.style[`text-align`] = properties.textAlign;
161-
inner.appendChild(text);
162-
inner.text = text;
163-
if (script.speed === `scan`) {
164-
element.style.opacity = 0;
165-
}
166-
};
167-
168-
// Create an image block.
169-
const createImageBlock = (block) => {
170-
const container = block.container;
171-
if (block.element) {
172-
container.removeChild(block.element);
173-
}
174-
const w = container.getBoundingClientRect().width / 1000;
175-
const h = container.getBoundingClientRect().height / 1000;
176-
const properties = block.properties;
177-
const element = document.createElement(`div`);
178-
block.element = element;
179-
element.style[`position`] = `absolute`;
180-
element.style[`opacity`] = `0.0`;
181-
let val = properties.left;
182-
if (!isNaN(val)) {
183-
val *= w;
184-
}
185-
element.style[`left`] = val;
186-
val = properties.top;
187-
if (!isNaN(val)) {
188-
val *= h;
189-
}
190-
element.style[`top`] = val;
191-
element.style[`top`] = val;
192-
val = properties.width;
193-
if (!isNaN(val)) {
194-
val = `${val * w}px`;
195-
}
196-
element.style[`width`] = val;
197-
val = properties.height;
198-
if (!isNaN(val)) {
199-
val = `${val * h}px`;
200-
}
201-
element.style[`height`] = val;
202-
element.style[`background`] = properties.background;
203-
element.style[`border`] = properties.border;
204-
element.style[`border-radius`] = properties.borderRadius;
205-
container.appendChild(element);
206-
if (script.speed === `scan`) {
207-
element.style.opacity = 0;
208-
}
158+
element.textPanel = text;
209159
};
210160

211161
// Set the content of a block
212162
const doSetContent = (spec) => {
213163
const block = script.blocks[spec.block];
214-
const contentSpec = script.content[spec.content];
164+
const content = script.content[spec.content];
215165
if (!block) {
216166
throw Error(`Block '${block}' cannot be found`);
217167
}
218-
switch (contentSpec.type) {
219-
case `text`:
220-
if (!block.element) {
221-
createTextBlock(block);
222-
}
223-
let content = contentSpec.content;
224-
if (Array.isArray(content)) {
225-
content = content.join(`<br><br>`);
226-
}
227-
block.element.inner.text.innerHTML = content.split(`\n`).join(`<br>`);
228-
break;
229-
case `image`:
230-
if (!block.element) {
231-
createImageBlock(block);
232-
}
233-
block.element.style[`background`] = `url("${contentSpec.url}")`;
234-
block.element.style[`background-size`] = `cover`;
235-
break;
168+
if (!block.element) {
169+
createBlock(block);
236170
}
171+
block.element.textPanel.innerHTML = content.split(`\n`).join(`<br>`);
237172
};
238173

239174
// Set the content of a block
@@ -280,14 +215,7 @@ const IWSY = (container, script) => {
280215
for (const b of stepBlocks) {
281216
const block = script.blocks[b];
282217
if (!block.element) {
283-
switch (block.type) {
284-
case `text`:
285-
createTextBlock(block);
286-
break;
287-
case `image`:
288-
createImageBlock(block);
289-
break;
290-
}
218+
createBlock(block);
291219
}
292220
}
293221
if (script.speed === `scan`) {

iwsy/resources/ecs/content.txt

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
tr TR
1313
td TD
1414
span ItemNameSpan
15-
span Span
1615
input ItemNameInput
17-
select TypeSelect
1816
textarea TextArea
1917
button EditButton
2018
img AddItem
@@ -24,28 +22,22 @@
2422
variable Item
2523
variable ItemNames
2624
variable ItemName
27-
variable TypeNames
28-
variable Content
2925
variable SelectedItem
3026
variable Action
3127
variable N
3228
variable B
3329

3430
put -1 into SelectedItem
3531

36-
set TypeNames to array
37-
json add `text` to TypeNames
38-
json add `image` to TypeNames
39-
4032
on message go to Start
4133
set ready
4234
stop
4335

4436
Start:
4537
if the message is `save`
4638
begin
47-
if SelectedItem is -1 stop
48-
go to SaveSelectedItem
39+
gosub to SaveSelectedItem
40+
stop
4941
end
5042

5143
Restart:
@@ -78,7 +70,6 @@ Restart:
7870
set the elements of EditButton to N
7971
set the elements of Editor to N
8072
set the elements of DeleteItem to N
81-
set the elements of TypeSelect to N
8273
set the elements of TextArea to N
8374
create Table in Panel
8475
set the style of Table to `width:100%`
@@ -116,6 +107,7 @@ Restart:
116107
end
117108
on click EditButton
118109
begin
110+
gosub to SaveSelectedItem
119111
put the index of EditButton into SelectedItem
120112
put the text of EditButton into Action
121113
put 0 into N
@@ -137,34 +129,23 @@ Restart:
137129
if Action is `Edit`
138130
begin
139131
set style `background` of EditButton to `lightgray`
140-
set the text of EditButton to `Content`
132+
set the text of EditButton to `Close`
141133
index ItemNameSpan to SelectedItem
142134
index ItemNameInput to SelectedItem
143-
index TypeSelect to SelectedItem
144135
index TextArea to SelectedItem
145136
set style `display` of ItemNameSpan to `none`
146137
set style `display` of ItemNameInput to `inline`
147138
index Editor to SelectedItem
148139
set style `display` of Editor to `block`
149140
clear Editor
150141
put property ItemName of Items into Item
151-
create Row in Editor
152-
set the style of Row to `width:100%;display:flex`
153-
create Span in Row
154-
set the style of Span to `flex:1`
155-
set the content of Span to `Type:`
156-
create TypeSelect in Row
157-
set the style of TypeSelect to `flex:1`
158-
set TypeSelect from TypeNames as property `type` of Item
159142
create TextArea in Editor
160143
set the style of TextArea to `width:100%;max-width:100%;height:8em`
161144
put element SelectedItem of ItemNames into ItemName
162-
put property `content` of Item into Content
163-
replace `%0a` with newline in Content
164-
set the content of TextArea to Content
165-
put property ItemName of Items into Item
145+
replace `%0a` with newline in Item
146+
set the content of TextArea to Item
166147
end
167-
else go to SaveSelectedItem
148+
else gosub to SaveSelectedItem
168149
end
169150
on click DeleteItem
170151
begin
@@ -179,10 +160,9 @@ Restart:
179160

180161
! Save the seleced content
181162
SaveSelectedItem:
182-
set property `type` of Item to TypeSelect
183-
put the content of TextArea into Content
184-
replace newline with `%0a` in Content
185-
set property `content` of Item to Content
163+
if SelectedItem is -1 return
164+
put the content of TextArea into Item
165+
replace newline with `%0a` in Item
186166
set property ItemName of Items to Item
187167
index ItemNameInput to SelectedItem
188168
if ItemNameInput is not ItemName
@@ -193,4 +173,4 @@ SaveSelectedItem:
193173
set property ItemName of Items to Item
194174
end
195175
set property `content` of Presentation to Items
196-
stop
176+
return

0 commit comments

Comments
 (0)