1
0
Fork 0
mirror of https://github.com/Oreolek/raconteur.git synced 2024-05-17 00:08:16 +03:00

Add main types of links and actions

This commit is contained in:
Bruno Dias 2015-04-08 22:00:06 -03:00
parent 56922f3e58
commit e4c5e6a295
2 changed files with 58 additions and 8 deletions

View file

@ -2,7 +2,8 @@ var situation = require('../lib/undularity.js'),
$ = require('jquery'),
undum = require('../lib/undum.js');
var a = situation.a;
var a = situation.a,
span = situation.span;
undum.game.id = "my_game_id";
undum.game.version = "1.0";
@ -57,12 +58,40 @@ situation('special-links', {
Also notable are ${a().id('replacer-link').content('replacer').replacer('replacer-link')}
links, which replace the content of a given id.
And finally, we have ${
a().once.content('inserter').inserter('inserter-link')
} links, which insert something into a specified element${
span().id('inserter-link').here
}.
`,
writers: {
writerlink: "Writer links can only be clicked once.",
'replacer-link': "switching"
'replacer-link': "switching",
'inserter-link': "-- like this"
},
tags: ['testing-option']
});
situation('custom-actions', {
content: `
# Special Actions
You can define actions with custom effects that access the underlying
Undum API. Try clicking
${a().content('this link').action('specialaction')} for example.
`,
actions: {
specialaction: function (character, system, from) {
system.write(`
<p>
Custom actions access Undum directly. They also have access
to the situation object itself, through <code>this</code>.
</p>`);
}
},
tags: ['testing-option'],
optionText: 'Special Actions'
})
$(function(){undum.begin()});

View file

@ -57,6 +57,7 @@ var UndularitySituation = function (spec) {
this.content = spec.content;
this.choices = (spec.choices === undefined) ? [] : spec.choices;
this.writers = (spec.writers === undefined) ? {} : spec.writers;
this.actions = (spec.actions === undefined) ? {} : spec.actions;
this.visited = false;
@ -77,6 +78,7 @@ UndularitySituation.prototype.enter = function (character, system, f) {
};
UndularitySituation.prototype.act = function (character, system, action) {
console.log("Act called with action ", action);
var actionClass,
self = this;
@ -84,20 +86,30 @@ UndularitySituation.prototype.act = function (character, system, action) {
writer: function (ref) {
system.write(
markdown.render(
self.writers[ref].fcall(this, character, system, action)
self.writers[ref].fcall(self, character, system, action)
).fade());
},
replacer: function (ref) {
console.log('Replacer called ', ref);
system.replaceWith(
markdown.renderInline(
self.writers[ref].fcall(this, character, system, action)
self.writers[ref].fcall(self, character, system, action)
).spanWrap().fade(), `#${ref}`);
},
inserter: function (ref) {
system.writeInto(
markdown.renderInline(
self.writers[ref].fcall(self, character, system, action)
).spanWrap().fade(), `#${ref}`);
}
};
if (actionClass = action.match(/^_(\w+)_(.+)$/)) {
responses[actionClass[1]](actionClass[2]);
} else if (self.actions.hasOwnProperty(action)) {
self.actions[action].call(self, character, system, action);
} else {
throw new Err(`Action "${action}" attempted with no corresponding` +
'action in current situation.');
}
};
@ -128,8 +140,16 @@ var a = function () {
id = "",
content = "";
var monad = {
writer: (ref) => `<a ${id} class="${once} writer" href="./_writer_${ref}">${markdown.renderInline(content)}</a>`,
replacer: (ref) => `<a ${id} class="${once} replacer" href="./_replacer_${ref}">${markdown.renderInline(content)}</a>`,
writer: (ref) =>
`<a ${id} class="${once} writer" href="./_writer_${ref}">${markdown.renderInline(content)}</a>`,
replacer: (ref) =>
`<a ${id} class="${once} replacer" href="./_replacer_${ref}">${markdown.renderInline(content)}</a>`,
inserter: (ref) =>
`<a ${id} class="${once} inserter" href="./_inserter_${ref}">${markdown.renderInline(content)}</a>`,
action: (ref) =>
`<a ${id} class="${once}" href="./${ref}">${markdown.renderInline(content)}</a>`,
external: (href) =>
`<a ${id} href="${ref}">${markdown.renderInline(content)}</a>`,
content: function (s) { content = s; return monad; },
id: function (s) {id = `id="${s}"`; return monad; },
get once () { once = "once"; return monad; }
@ -164,4 +184,5 @@ module.exports = function (name, spec) {
undum.game.situations[name] = new UndularitySituation(spec);
};
module.exports.a = a;
module.exports.a = a;
module.exports.span = span;