Commit 7c13755e authored by Leon Arnott's avatar Leon Arnott
Browse files

Fixed attachment of changers to (print:) and (display:) HookCommands.

I'm still waiting on a better name than "HookCommands" for this kind of data, but I need it to encompass both links, output elements like (print:) and input elements, and I can't use "element" because that should be reserved for raw HTML elements.
parent 6bd997b33a40
......@@ -12,6 +12,11 @@ define(['requestAnimationFrame', 'macros', 'utils', 'state', 'passages', 'engine
Macros that produce commands include (display:), (print:), (go-to:), (save-game:), (load-game:),
(link-goto:), and more.
*/
/*d:
HookCommand data
TBW
*/
const {Any, rest, optional} = Macros.TypeSignature;
const {assign} = Object;
......
......@@ -194,7 +194,7 @@ define(['jquery', 'macros', 'utils', 'utils/selectors', 'state', 'passages', 'en
*/
Macros.addHookCommand
/*d:
(link-goto: String, [String]) -> Command
(link-goto: String, [String]) -> HookCommand
Takes a string of link text, and an optional destination passage name, and makes a command to create
a link that takes the player to another passage. The link functions identically to a standard link.
......
......@@ -270,7 +270,7 @@ define(['jquery', 'utils/naturalsort', 'utils', 'utils/operationutils', 'datatyp
if (isHookCommand) {
cd = ChangeDescriptor.create();
}
return Object.assign({
const ret = Object.assign({
TwineScript_ObjectName: "a (" + firstName + ":) command",
TwineScript_TypeName: "a (" + firstName + ":) command",
TwineScript_Print: () => "`[A (" + firstName + ":) command]`",
......@@ -288,6 +288,7 @@ define(['jquery', 'utils/naturalsort', 'utils', 'utils/operationutils', 'datatyp
} : {
TwineScript_Run: () => runFn(...args),
});
return ret;
};
Macros = {
......
......@@ -246,6 +246,7 @@ define([
from raw JS just a few lines above) leaving it ready to be TwineScript_Run() far below.
*/
result = nextValue.TwineScript_Attach(result);
break;
}
/*
When the attachment can't happen, produce an error mentioning that only certain structures allow changers to attach.
......@@ -271,6 +272,9 @@ define([
If it's neither hook nor expression, then this evidently isn't connected to
a hook at all. Produce an error.
*/
if (!result.macroName) {
Utils.impossible('Section.runExpression', 'changer has no macroName');
}
const macroCall = (expr.attr('title') || ("(" + result.macroName + ": ...)"));
expr.replaceWith(TwineError.create("syntax",
"The (" + result.macroName + ":) changer should be stored in a variable or attached to a hook.",
......@@ -325,7 +329,7 @@ define([
return "earlyexit";
}
if (ChangeDescriptor.isPrototypeOf(result)) {
this.renderInto('', expr, result);
this.renderInto('', nextElem, result);
}
/*
This should be refactored out soon (May 2018)...
......@@ -333,7 +337,7 @@ define([
links, and all those should be HookCommands.
*/
if (typeof result === "string") {
this.renderInto(result, expr);
this.renderInto(result, nextElem);
}
}
/*
......
......@@ -57,6 +57,14 @@ describe("basic command macros", function() {
it("will error if an infinite regress is created", function() {
expect("(set: $x to '$x')(print: $x)").markupToError();
});
it("can be altered with attached style changers", function(done) {
var p = runPassage("(text-rotate: 20)(print: $x)");
var expr = p.find('tw-expression:last-child');
setTimeout(function() {
expect(expr.attr('style')).toMatch(/rotate\(20deg\)/);
done();
});
});
});
describe("the (display:) macro", function() {
it("requires exactly 1 string argument", function() {
......@@ -98,6 +106,15 @@ describe("basic command macros", function() {
createPassage("(display: 'grault')", "grault");
expect("(display: 'grault')").markupToError();
});
it("can be altered with attached style changers", function(done) {
createPassage("''Red''", "grault");
var p = runPassage("(text-rotate: 20)(display:'grault')");
var expr = p.find('tw-expression:last-child');
setTimeout(function() {
expect(expr.attr('style')).toMatch(/rotate\(20deg\)/);
done();
});
});
});
describe("the (go-to:) macro", function() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment