Skip to content

Commit

Permalink
UI commands can now have variables, prefilling prompt command is poss…
Browse files Browse the repository at this point in the history
…ible. Also:

- updated version to 15.12.1
- updated changelog
  • Loading branch information
jsteinbeck committed Dec 23, 2015
1 parent add4460 commit eb41585
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 37 deletions.
70 changes: 54 additions & 16 deletions bin/WebStoryEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7263,7 +7263,7 @@ define("WSE", function (EventBus, assets, commands, dataSources, functions) {

"use strict";

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

EventBus.inject(WSE);

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

/* global using */

using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
using(
"WSE.tools::warn",
"WSE.tools::replaceVariables"
).define("WSE.tools.ui", function (warn, replaceVars) {

"use strict";

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

var title, message, submitText, cancelText, callback, root, dialog, oldState;
var tEl, mEl, buttonEl, cancelEl, inputEl, container, defaultValue, pause, doNext;
var allowEmptyInput, hideCancelButton;
var tEl, mEl, buttonEl, cancelEl, inputEl, container, pause, doNext;
var allowEmptyInput, hideCancelButton, prefill;

interpreter.waitCounter += 1;
// interpreter.keysDisabled += 1;
Expand All @@ -10460,14 +10463,14 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
message = args.message || "Please enter something:";
submitText = args.submitText || "Submit";
cancelText = args.cancelText || "Cancel";
defaultValue = args.defaultValue || "";
callback = typeof args.callback === "function" ? args.callback : function () {};
root = args.parent || interpreter.stage;
pause = args.pause === true ? true : false;
oldState = interpreter.state;
doNext = args.doNext === true ? true : false;
allowEmptyInput = args.allowEmptyInput;
hideCancelButton = args.hideCancelButton;
prefill = args.prefill || "";

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

inputEl = document.createElement("input");
inputEl.setAttribute("value", defaultValue);
inputEl.value = defaultValue;
inputEl.setAttribute("value", prefill);
inputEl.value = prefill;
inputEl.setAttribute("class", "input text");
inputEl.setAttribute("type", "text");

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

if (!allowEmptyInput && !defaultValue) {
if (!allowEmptyInput && !prefill) {
buttonEl.disabled = true;
}

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

var title, message, container, key, doNext, hideCancelButton, allowEmptyInput;
var submitText, cancelText;
var submitText, cancelText, prefill;

title = command.getAttribute("title") || "Input required...";
message = command.getAttribute("message") || "Your input is required:";
key = command.getAttribute("var") || null;
doNext = command.getAttribute("next") === "false" ? false : true;
hideCancelButton = command.getAttribute("hideCancelButton") === "yes" ? true : false;
allowEmptyInput = command.getAttribute("allowEmptyInput") === "no" ? false : true;
submitText = command.getAttribute("submitText") || "";
cancelText = command.getAttribute("cancelText") || "";
prefill = command.getAttribute("prefill") || "";

allowEmptyInput =
replaceVars(command.getAttribute("allowEmptyInput") || "", interpreter) === "no" ?
false :
true;

hideCancelButton =
replaceVars(command.getAttribute("hideCancelButton") || "", interpreter) === "yes" ?
true :
false;

doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
false :
true;

if (key !== null) {
key = replaceVars(key, interpreter);
}

title = replaceVars(title, interpreter);
message = replaceVars(message, interpreter);
cancelText = replaceVars(cancelText, interpreter);
submitText = replaceVars(submitText, interpreter);
prefill = replaceVars(prefill, interpreter);

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

Expand All @@ -10652,8 +10677,10 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
allowEmptyInput: allowEmptyInput,
hideCancelButton: hideCancelButton,
submitText: submitText,
cancelText: cancelText
});
cancelText: cancelText,
prefill: prefill
}
);

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

/* global using */

using("WSE.tools.ui", "WSE.tools").define("WSE.commands.alert", function (ui, tools) {
using(
"WSE.tools.ui",
"WSE.tools",
"WSE.tools::replaceVariables"
).define("WSE.commands.alert", function (ui, tools, replaceVars) {

function alert (command, interpreter) {

var title, message, doNext;

title = command.getAttribute("title") || "Alert!";
message = command.getAttribute("message") || "Alert!";

doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
false :
true;

message = replaceVars(message, interpreter);
title = replaceVars(title, interpreter);

message = tools.textToHtml(message);
doNext = command.getAttribute("next") === "false" ? false : true;

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

Expand Down
8 changes: 4 additions & 4 deletions bin/WebStoryEngine.min.js

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
====== WebStory Engine Changelog ======

===== Version 2015.10.x ======
===== Version 2015.x ======

==== Version 2015.12.1 ====

* UI commands can now have attributes with variables.
* Added a `prefill` attribute to the prompt comannd. It sets a default value.

==== Version 2015.11.1 ====

* 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.
* 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}`

==== Version 2015.10.2 ====

* Default extensions didn't work with new module system (mainly side-images)
* Added a test game for the side-images extension
* Added head images for Cecile and Jack for testing

==== Version 2015.10.1 ====

Expand Down
2 changes: 1 addition & 1 deletion js/WSE.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define("WSE", function (EventBus, assets, commands, dataSources, functions) {

"use strict";

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

EventBus.inject(WSE);

Expand Down
15 changes: 13 additions & 2 deletions js/commands/alert.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* global using */

using("WSE.tools.ui", "WSE.tools").define("WSE.commands.alert", function (ui, tools) {
using(
"WSE.tools.ui",
"WSE.tools",
"WSE.tools::replaceVariables"
).define("WSE.commands.alert", function (ui, tools, replaceVars) {

function alert (command, interpreter) {

var title, message, doNext;

title = command.getAttribute("title") || "Alert!";
message = command.getAttribute("message") || "Alert!";

doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
false :
true;

message = replaceVars(message, interpreter);
title = replaceVars(title, interpreter);

message = tools.textToHtml(message);
doNext = command.getAttribute("next") === "false" ? false : true;

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

Expand Down
53 changes: 40 additions & 13 deletions js/tools/ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* global using */

using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
using(
"WSE.tools::warn",
"WSE.tools::replaceVariables"
).define("WSE.tools.ui", function (warn, replaceVars) {

"use strict";

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

var title, message, submitText, cancelText, callback, root, dialog, oldState;
var tEl, mEl, buttonEl, cancelEl, inputEl, container, defaultValue, pause, doNext;
var allowEmptyInput, hideCancelButton;
var tEl, mEl, buttonEl, cancelEl, inputEl, container, pause, doNext;
var allowEmptyInput, hideCancelButton, prefill;

interpreter.waitCounter += 1;
// interpreter.keysDisabled += 1;
Expand All @@ -199,14 +202,14 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
message = args.message || "Please enter something:";
submitText = args.submitText || "Submit";
cancelText = args.cancelText || "Cancel";
defaultValue = args.defaultValue || "";
callback = typeof args.callback === "function" ? args.callback : function () {};
root = args.parent || interpreter.stage;
pause = args.pause === true ? true : false;
oldState = interpreter.state;
doNext = args.doNext === true ? true : false;
allowEmptyInput = args.allowEmptyInput;
hideCancelButton = args.hideCancelButton;
prefill = args.prefill || "";

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

inputEl = document.createElement("input");
inputEl.setAttribute("value", defaultValue);
inputEl.value = defaultValue;
inputEl.setAttribute("value", prefill);
inputEl.value = prefill;
inputEl.setAttribute("class", "input text");
inputEl.setAttribute("type", "text");

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

if (!allowEmptyInput && !defaultValue) {
if (!allowEmptyInput && !prefill) {
buttonEl.disabled = true;
}

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

var title, message, container, key, doNext, hideCancelButton, allowEmptyInput;
var submitText, cancelText;
var submitText, cancelText, prefill;

title = command.getAttribute("title") || "Input required...";
message = command.getAttribute("message") || "Your input is required:";
key = command.getAttribute("var") || null;
doNext = command.getAttribute("next") === "false" ? false : true;
hideCancelButton = command.getAttribute("hideCancelButton") === "yes" ? true : false;
allowEmptyInput = command.getAttribute("allowEmptyInput") === "no" ? false : true;
submitText = command.getAttribute("submitText") || "";
cancelText = command.getAttribute("cancelText") || "";
prefill = command.getAttribute("prefill") || "";

allowEmptyInput =
replaceVars(command.getAttribute("allowEmptyInput") || "", interpreter) === "no" ?
false :
true;

hideCancelButton =
replaceVars(command.getAttribute("hideCancelButton") || "", interpreter) === "yes" ?
true :
false;

doNext = replaceVars(command.getAttribute("next") || "", interpreter) === "false" ?
false :
true;

if (key !== null) {
key = replaceVars(key, interpreter);
}

title = replaceVars(title, interpreter);
message = replaceVars(message, interpreter);
cancelText = replaceVars(cancelText, interpreter);
submitText = replaceVars(submitText, interpreter);
prefill = replaceVars(prefill, interpreter);

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

Expand All @@ -391,8 +416,10 @@ using("WSE.tools::warn").define("WSE.tools.ui", function (warn) {
allowEmptyInput: allowEmptyInput,
hideCancelButton: hideCancelButton,
submitText: submitText,
cancelText: cancelText
});
cancelText: cancelText,
prefill: prefill
}
);

return {
doNext: true
Expand Down
17 changes: 17 additions & 0 deletions tests/prompt_command/game.xml → tests/ui_commands/game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

<scene id="start">

<var name="prefill" value="foo!" />

<show asset="bg" />

<prompt
Expand Down Expand Up @@ -46,6 +48,21 @@
hideCancelButton="yes"
allowEmptyInput="no" />

<prompt
title="Prompt with ({$prefill}) variables."
message="This prompt has a default ({$prefill}) value loaded from a variable."
var="foo"
prefill="{$prefill}" />

<alert
title="An alert with {$prefill}"
message="Its message has {$prefill}" />

<confirm
var="foo"
title="A confirm with {$prefill}"
message="Its message has {$prefill}" />

<restart />
</scene>

Expand Down
File renamed without changes.

0 comments on commit eb41585

Please sign in to comment.