Skip to content

Commit eb41585

Browse files
committed
UI commands can now have variables, prefilling prompt command is possible. Also:
- updated version to 15.12.1 - updated changelog
1 parent add4460 commit eb41585

8 files changed

Lines changed: 146 additions & 37 deletions

File tree

bin/WebStoryEngine.js

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7263,7 +7263,7 @@ define("WSE", function (EventBus, assets, commands, dataSources, functions) {
72637263

72647264
"use strict";
72657265

7266-
var WSE = {}, version = "2015.11.1-final.1511061334";
7266+
var WSE = {}, version = "2015.12.1-final.1512231127";
72677267

72687268
EventBus.inject(WSE);
72697269

@@ -10261,7 +10261,10 @@ define("WSE.LoadingScreen", function (transform, CoreObject) {
1026110261

1026210262
/* global using */
1026310263

10264-
using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
10264+
using(
10265+
"WSE.tools::warn",
10266+
"WSE.tools::replaceVariables"
10267+
).define("WSE.tools.ui", function (warn, replaceVars) {
1026510268

1026610269
"use strict";
1026710270

@@ -10449,8 +10452,8 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1044910452
prompt: function (interpreter, args) {
1045010453

1045110454
var title, message, submitText, cancelText, callback, root, dialog, oldState;
10452-
var tEl, mEl, buttonEl, cancelEl, inputEl, container, defaultValue, pause, doNext;
10453-
var allowEmptyInput, hideCancelButton;
10455+
var tEl, mEl, buttonEl, cancelEl, inputEl, container, pause, doNext;
10456+
var allowEmptyInput, hideCancelButton, prefill;
1045410457

1045510458
interpreter.waitCounter += 1;
1045610459
// interpreter.keysDisabled += 1;
@@ -10460,14 +10463,14 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1046010463
message = args.message || "Please enter something:";
1046110464
submitText = args.submitText || "Submit";
1046210465
cancelText = args.cancelText || "Cancel";
10463-
defaultValue = args.defaultValue || "";
1046410466
callback = typeof args.callback === "function" ? args.callback : function () {};
1046510467
root = args.parent || interpreter.stage;
1046610468
pause = args.pause === true ? true : false;
1046710469
oldState = interpreter.state;
1046810470
doNext = args.doNext === true ? true : false;
1046910471
allowEmptyInput = args.allowEmptyInput;
1047010472
hideCancelButton = args.hideCancelButton;
10473+
prefill = args.prefill || "";
1047110474

1047210475
if (pause === true) {
1047310476
interpreter.state = "pause";
@@ -10488,8 +10491,8 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1048810491
mEl.setAttribute("class", "message");
1048910492

1049010493
inputEl = document.createElement("input");
10491-
inputEl.setAttribute("value", defaultValue);
10492-
inputEl.value = defaultValue;
10494+
inputEl.setAttribute("value", prefill);
10495+
inputEl.value = prefill;
1049310496
inputEl.setAttribute("class", "input text");
1049410497
inputEl.setAttribute("type", "text");
1049510498

@@ -10536,7 +10539,7 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1053610539
buttonEl.setAttribute("class", "submit button");
1053710540
buttonEl.setAttribute("type", "button");
1053810541

10539-
if (!allowEmptyInput && !defaultValue) {
10542+
if (!allowEmptyInput && !prefill) {
1054010543
buttonEl.disabled = true;
1054110544
}
1054210545

@@ -10616,16 +10619,38 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1061610619
return function (command, interpreter) {
1061710620

1061810621
var title, message, container, key, doNext, hideCancelButton, allowEmptyInput;
10619-
var submitText, cancelText;
10622+
var submitText, cancelText, prefill;
1062010623

1062110624
title = command.getAttribute("title") || "Input required...";
1062210625
message = command.getAttribute("message") || "Your input is required:";
1062310626
key = command.getAttribute("var") || null;
10624-
doNext = command.getAttribute("next") === "false" ? false : true;
10625-
hideCancelButton = command.getAttribute("hideCancelButton") === "yes" ? true : false;
10626-
allowEmptyInput = command.getAttribute("allowEmptyInput") === "no" ? false : true;
1062710627
submitText = command.getAttribute("submitText") || "";
1062810628
cancelText = command.getAttribute("cancelText") || "";
10629+
prefill = command.getAttribute("prefill") || "";
10630+
10631+
allowEmptyInput =
10632+
replaceVars(command.getAttribute("allowEmptyInput") || "", interpreter) === "no" ?
10633+
false :
10634+
true;
10635+
10636+
hideCancelButton =
10637+
replaceVars(command.getAttribute("hideCancelButton") || "", interpreter) === "yes" ?
10638+
true :
10639+
false;
10640+
10641+
doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
10642+
false :
10643+
true;
10644+
10645+
if (key !== null) {
10646+
key = replaceVars(key, interpreter);
10647+
}
10648+
10649+
title = replaceVars(title, interpreter);
10650+
message = replaceVars(message, interpreter);
10651+
cancelText = replaceVars(cancelText, interpreter);
10652+
submitText = replaceVars(submitText, interpreter);
10653+
prefill = replaceVars(prefill, interpreter);
1062910654

1063010655
interpreter.bus.trigger("wse.interpreter.commands." + type, command);
1063110656

@@ -10652,8 +10677,10 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
1065210677
allowEmptyInput: allowEmptyInput,
1065310678
hideCancelButton: hideCancelButton,
1065410679
submitText: submitText,
10655-
cancelText: cancelText
10656-
});
10680+
cancelText: cancelText,
10681+
prefill: prefill
10682+
}
10683+
);
1065710684

1065810685
return {
1065910686
doNext: true
@@ -12850,16 +12877,27 @@ define("WSE.assets.Background", function (applyUnits, DisplayObject, warn) {
1285012877

1285112878
/* global using */
1285212879

12853-
using("WSE.tools.ui", "WSE.tools").define("WSE.commands.alert", function (ui, tools) {
12880+
using(
12881+
"WSE.tools.ui",
12882+
"WSE.tools",
12883+
"WSE.tools::replaceVariables"
12884+
).define("WSE.commands.alert", function (ui, tools, replaceVars) {
1285412885

1285512886
function alert (command, interpreter) {
1285612887

1285712888
var title, message, doNext;
1285812889

1285912890
title = command.getAttribute("title") || "Alert!";
1286012891
message = command.getAttribute("message") || "Alert!";
12892+
12893+
doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
12894+
false :
12895+
true;
12896+
12897+
message = replaceVars(message, interpreter);
12898+
title = replaceVars(title, interpreter);
12899+
1286112900
message = tools.textToHtml(message);
12862-
doNext = command.getAttribute("next") === "false" ? false : true;
1286312901

1286412902
interpreter.bus.trigger("wse.interpreter.commands.alert", command);
1286512903

bin/WebStoryEngine.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

changelog.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
====== WebStory Engine Changelog ======
22

3-
===== Version 2015.10.x ======
3+
===== Version 2015.x ======
4+
5+
==== Version 2015.12.1 ====
6+
7+
* UI commands can now have attributes with variables.
8+
* Added a `prefill` attribute to the prompt comannd. It sets a default value.
9+
10+
==== Version 2015.11.1 ====
11+
12+
* WebStory code can now be embedded in the HTML so that the engine works without a server on local file systems. Take a look at the xml_embedded test for an example of this.
13+
* The loading screen can now be customized by adding a `loadingScreen` element to the `settings` section. It can contain an HTML template snippet with these variables: `{$all}`, `{$loaded}`, `{$remaining}` and `{$progress}`
14+
15+
==== Version 2015.10.2 ====
16+
17+
* Default extensions didn't work with new module system (mainly side-images)
18+
* Added a test game for the side-images extension
19+
* Added head images for Cecile and Jack for testing
420

521
==== Version 2015.10.1 ====
622

js/WSE.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define("WSE", function (EventBus, assets, commands, dataSources, functions) {
55

66
"use strict";
77

8-
var WSE = {}, version = "2015.11.1-final.1511061334";
8+
var WSE = {}, version = "2015.12.1-final.1512231127";
99

1010
EventBus.inject(WSE);
1111

js/commands/alert.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
/* global using */
22

3-
using("WSE.tools.ui", "WSE.tools").define("WSE.commands.alert", function (ui, tools) {
3+
using(
4+
"WSE.tools.ui",
5+
"WSE.tools",
6+
"WSE.tools::replaceVariables"
7+
).define("WSE.commands.alert", function (ui, tools, replaceVars) {
48

59
function alert (command, interpreter) {
610

711
var title, message, doNext;
812

913
title = command.getAttribute("title") || "Alert!";
1014
message = command.getAttribute("message") || "Alert!";
15+
16+
doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
17+
false :
18+
true;
19+
20+
message = replaceVars(message, interpreter);
21+
title = replaceVars(title, interpreter);
22+
1123
message = tools.textToHtml(message);
12-
doNext = command.getAttribute("next") === "false" ? false : true;
1324

1425
interpreter.bus.trigger("wse.interpreter.commands.alert", command);
1526

js/tools/ui.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* global using */
22

3-
using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
3+
using(
4+
"WSE.tools::warn",
5+
"WSE.tools::replaceVariables"
6+
).define("WSE.tools.ui", function (warn, replaceVars) {
47

58
"use strict";
69

@@ -188,8 +191,8 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
188191
prompt: function (interpreter, args) {
189192

190193
var title, message, submitText, cancelText, callback, root, dialog, oldState;
191-
var tEl, mEl, buttonEl, cancelEl, inputEl, container, defaultValue, pause, doNext;
192-
var allowEmptyInput, hideCancelButton;
194+
var tEl, mEl, buttonEl, cancelEl, inputEl, container, pause, doNext;
195+
var allowEmptyInput, hideCancelButton, prefill;
193196

194197
interpreter.waitCounter += 1;
195198
// interpreter.keysDisabled += 1;
@@ -199,14 +202,14 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
199202
message = args.message || "Please enter something:";
200203
submitText = args.submitText || "Submit";
201204
cancelText = args.cancelText || "Cancel";
202-
defaultValue = args.defaultValue || "";
203205
callback = typeof args.callback === "function" ? args.callback : function () {};
204206
root = args.parent || interpreter.stage;
205207
pause = args.pause === true ? true : false;
206208
oldState = interpreter.state;
207209
doNext = args.doNext === true ? true : false;
208210
allowEmptyInput = args.allowEmptyInput;
209211
hideCancelButton = args.hideCancelButton;
212+
prefill = args.prefill || "";
210213

211214
if (pause === true) {
212215
interpreter.state = "pause";
@@ -227,8 +230,8 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
227230
mEl.setAttribute("class", "message");
228231

229232
inputEl = document.createElement("input");
230-
inputEl.setAttribute("value", defaultValue);
231-
inputEl.value = defaultValue;
233+
inputEl.setAttribute("value", prefill);
234+
inputEl.value = prefill;
232235
inputEl.setAttribute("class", "input text");
233236
inputEl.setAttribute("type", "text");
234237

@@ -275,7 +278,7 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
275278
buttonEl.setAttribute("class", "submit button");
276279
buttonEl.setAttribute("type", "button");
277280

278-
if (!allowEmptyInput && !defaultValue) {
281+
if (!allowEmptyInput && !prefill) {
279282
buttonEl.disabled = true;
280283
}
281284

@@ -355,16 +358,38 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
355358
return function (command, interpreter) {
356359

357360
var title, message, container, key, doNext, hideCancelButton, allowEmptyInput;
358-
var submitText, cancelText;
361+
var submitText, cancelText, prefill;
359362

360363
title = command.getAttribute("title") || "Input required...";
361364
message = command.getAttribute("message") || "Your input is required:";
362365
key = command.getAttribute("var") || null;
363-
doNext = command.getAttribute("next") === "false" ? false : true;
364-
hideCancelButton = command.getAttribute("hideCancelButton") === "yes" ? true : false;
365-
allowEmptyInput = command.getAttribute("allowEmptyInput") === "no" ? false : true;
366366
submitText = command.getAttribute("submitText") || "";
367367
cancelText = command.getAttribute("cancelText") || "";
368+
prefill = command.getAttribute("prefill") || "";
369+
370+
allowEmptyInput =
371+
replaceVars(command.getAttribute("allowEmptyInput") || "", interpreter) === "no" ?
372+
false :
373+
true;
374+
375+
hideCancelButton =
376+
replaceVars(command.getAttribute("hideCancelButton") || "", interpreter) === "yes" ?
377+
true :
378+
false;
379+
380+
doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
381+
false :
382+
true;
383+
384+
if (key !== null) {
385+
key = replaceVars(key, interpreter);
386+
}
387+
388+
title = replaceVars(title, interpreter);
389+
message = replaceVars(message, interpreter);
390+
cancelText = replaceVars(cancelText, interpreter);
391+
submitText = replaceVars(submitText, interpreter);
392+
prefill = replaceVars(prefill, interpreter);
368393

369394
interpreter.bus.trigger("wse.interpreter.commands." + type, command);
370395

@@ -391,8 +416,10 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
391416
allowEmptyInput: allowEmptyInput,
392417
hideCancelButton: hideCancelButton,
393418
submitText: submitText,
394-
cancelText: cancelText
395-
});
419+
cancelText: cancelText,
420+
prefill: prefill
421+
}
422+
);
396423

397424
return {
398425
doNext: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
<scene id="start">
2121

22+
<var name="prefill" value="foo!" />
23+
2224
<show asset="bg" />
2325

2426
<prompt
@@ -46,6 +48,21 @@
4648
hideCancelButton="yes"
4749
allowEmptyInput="no" />
4850

51+
<prompt
52+
title="Prompt with ({$prefill}) variables."
53+
message="This prompt has a default ({$prefill}) value loaded from a variable."
54+
var="foo"
55+
prefill="{$prefill}" />
56+
57+
<alert
58+
title="An alert with {$prefill}"
59+
message="Its message has {$prefill}" />
60+
61+
<confirm
62+
var="foo"
63+
title="A confirm with {$prefill}"
64+
message="Its message has {$prefill}" />
65+
4966
<restart />
5067
</scene>
5168

0 commit comments

Comments
 (0)