Commit 0b54e2f8 authored by Leon Arnott's avatar Leon Arnott
Browse files

Removed (cloak:), (uncloak:), (css:), (remove:), (nobr:)

(remove:) is one whose name I'm not keen on, and I've decided to remove it in place of the (replace:)[] idiom. (css:) is not a recommended use-case and can be accomplished with HTML, (nobr:) is fulfilled by the curly-brace syntax, and (cloak:) and (uncloak:) currently don't work too well with the rendering flow of sections. Maybe those will return in the future, but they're not too usable for 1.0.
parent 3728a666e3e9
......@@ -13,7 +13,7 @@ define([
'macrolib/enchantments',
'macrolib/links',
],
function($, TwineMarkup, Story, Macros, Utils, ChangerCommand, TwineWarning) {
function($, TwineMarkup, Story, Macros, Utils) {
"use strict";
/*
Twine macro standard library.
......@@ -36,92 +36,6 @@ function($, TwineMarkup, Story, Macros, Utils, ChangerCommand, TwineWarning) {
* verbs:
Should be saved for commands only.
*/
Macros.add
/*
(remove:) Removes the given hook or pseudo-hook from the section.
It accepts a standard selector, emits a side-effect, and returns "".
*/
("remove", function remove(section, selector) {
section.selectHook(selector).forEach(function(e) { e.remove(); });
return "";
});
/*
(cloak:) Hides the given hook or pseudo-hook.
(uncloak:) Shows the given hook or pseudo-hook.
They accept a standard selector, emits a side-effect, and returns "".
*/
["cloak", "uncloak"].forEach(function(name) {
Macros.add(name, function cloak(section, selector) {
var selection = section.selectHook(selector);
/*
To my regret, I must use a side-effect here for tracking
how many elements were affected by the macro.
*/
var count = 0;
selection.forEach(function(hook) {
/*
Let's just use the jQuery hide/show methods for now.
*/
hook[name === "cloak" ? "hide" : "show"]();
count += 1;
});
/*
If nothing was changed, provide a warning to the user, in case they
mistyped a hook name.
*/
if (!count) {
return new TwineWarning("The '" + selector.TwineScript_ObjectName + "' selector didn't select anything.");
}
return "";
});
});
/*
TODO: Maybe it would be better, or at least more functional, if
ChangerCommands returned a fresh ChangerDescriptor instead of permuting
the passed-in one.
*/
Macros.addChanger
/*
(nobr:)
Remove line breaks from the hook.
Manual line breaks can be inserted with <br>.
*/
("nobr",
function nobr() {
return ChangerCommand.create("nobr");
},
function(d) {
// To prevent keywords from being created by concatenating lines,
// replace the line breaks with a zero-width space.
d.code = d.code.replace(/\n/g, "&zwnj;");
return d;
}
)
/*
(CSS:)
Insert the enclosed raw CSS into a <style> tag that exists for the
duration of the current passage only.
contents: raw CSS.
*/
("CSS",
function CSS() {
return ChangerCommand.create("CSS");
},
function style(d) {
var selector = 'style#macro';
if (!$(selector).length) {
$(document.head).append($('<style id="macro">'));
}
$(selector).text(Utils.unescape(d.code));
d.code = "";
return d;
}
);
Utils.log("Loaded the built-in macros.");
});
......@@ -84,7 +84,7 @@ function($, Macros, Utils, Selectors, Story, State, Engine, ChangerCommand) {
TwineScript_ObjectName: "a (link-goto:) command",
TwineScript_Print: function() {
var visited = -1;
var visited = -1, passageID, passageName;
/*
The string representing the passage name is evaluated as TwineMarkup here -
the link syntax accepts TwineMarkup in both link and passage position
......@@ -97,8 +97,7 @@ function($, Macros, Utils, Selectors, Story, State, Engine, ChangerCommand) {
already discards the ordering of link text and passage name in the link
syntax ([[a->b]] vs [[b<-a]]) then this can't be helped, and probably doesn't matter.
*/
var passageName = section.evaluateTwineMarkup(Utils.unescape(passage || text));
var passageID = Story.getPassageID(passageName);
passageName = section.evaluateTwineMarkup(Utils.unescape(passage || text));
/*
If a <tw-error> was returned by evaluateTwineMarkup, replace the link with it.
......@@ -110,6 +109,7 @@ function($, Macros, Utils, Selectors, Story, State, Engine, ChangerCommand) {
*/
return passageName;
}
passageID = Story.getPassageID(passageName);
if (passageID) {
visited = (State.passageIDVisited(passageID));
......
......@@ -468,14 +468,9 @@ function($, Utils, Selectors, Renderer, Environ, Story, State, HookUtils, HookSe
}
/*
If no code is left in the descriptor, do nothing.
If there's code but no target, something
incorrect has transpired.
If there's no target, something incorrect has transpired.
*/
if (!desc.code && desc.append !== "remove") {
return;
}
else if (!desc.target) {
if (!desc.target) {
Utils.impossible("Section.renderInto",
"ChangeDescriptor has code but not a target!");
return;
......
......@@ -61,8 +61,12 @@ function(Utils, State, Story, Colour, AssignmentRequest, OperationUtils) {
// A cached error message fragment.
onlyIcan = "Only I can use data keys beginning with ",
// Hoisted variable.
match;
match,
error;
if((error = Utils.containsError(obj, prop))) {
return error;
}
if(prop.startsWith("__")) {
return new Error(onlyIcan + "'__'.");
}
......
......@@ -8,9 +8,9 @@
(print: "e" is in "egg" and is in "ego") (= true)
(print: "leg" contains "g") (= true)
(print: "eg" contains "g" and is in "ego") (= true)
(set: $a to [])
(set: $a to (a:))
(print: 1 is in $a) (= false)
(print: $a contains 1) (= false)
(set: $a.0 to 1)
(set: $a's 1st to 1)
(print: 1 is in $a) (= true)
(print: $a contains 1) (= true)
......@@ -4,10 +4,10 @@
<tw-story></tw-story><script data-main="../js/harlowe.js" src="../node_modules/requirejs/require.js"></script>
<tw-storydata options="debug" startnode="1">
<tw-passagedata pid="1" name="1" position="512,384" data-t8n="instant">
(set: $a to [])
(print: $a.1) (= error)
(print: $a.$e) (= error)
(print: $a.__proto__) (= error)
(set: $a.1 to 2)
(print: $a.1) (= 2)
(set: $a.__proto__ to 1) (= error)
(set: $a to (a:))
(print: $a's 2nd) (= error)
(print: $a's e) (= error)
(print: $a's __proto__) (= error)
(set: $a's 1st to 2)
(print: $a's 1st) (= 2)
(set: $a's __proto__ to 1) (= error)
......@@ -6,8 +6,8 @@
<tw-passagedata pid="1" name="1" position="512,384">
|Beans>[Beans] (= blank)
Fries Fries (= blank)
(remove: ?Beans)
(remove: "Fries")
(replace: ?Beans)[]
(replace: "Fries")[]
|Toast>[Toast] (= click -> blank)
(click: ?Toast)[(remove:?Toast)]
(click: ?Toast)[(replace:?Toast)[]]
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