mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-05-17 00:18:29 +03:00
Undum is included now, got rid of browserify dependencies.
This commit is contained in:
parent
16b82caf8d
commit
29fe51b179
|
@ -1,8 +1,8 @@
|
|||
# Salet
|
||||
A general client-side framework for cybertext interactive fiction games.
|
||||
|
||||
**Salet** is based upon the ideas of [Undum,](https://github.com/idmillington/undum) but is not a direct follower.
|
||||
It also uses some code from [Raconteur,](https://github.com/sequitur/raconteur) rewritten in CoffeeScript and altered to its own needs.
|
||||
**Salet** is based upon [Undum,](https://github.com/idmillington/undum) rewritten in CoffeeScript and altered to its own needs.
|
||||
It also uses some code from [Raconteur,](https://github.com/sequitur/raconteur) same deal.
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@ markdown = require('../../lib/markdown.coffee')
|
|||
room = require("../../lib/room.coffee")
|
||||
obj = require('../../lib/obj.coffee')
|
||||
dialogue = require('../../lib/dialogue.coffee')
|
||||
undum = require('undum-commonjs')
|
||||
oneOf = require('../../lib/oneOf.coffee')
|
||||
$ = require("jquery")
|
||||
require('../../lib/interface.coffee')
|
||||
languages = require('../../lib/localize.coffee')
|
||||
undum = require('../../lib/undum.js')
|
||||
undum.language = languages
|
||||
|
||||
undum.game.id = "your-game-id-here"
|
||||
undum.game.version = "1.0"
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<!-- CDN JS Libraries -->
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
||||
<script type="text/javascript" src="//code.jquery.com/jquery-2.2.0.min.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="game/bundle.js"></script>
|
||||
</body>
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
###
|
||||
Salet interface configuration.
|
||||
###
|
||||
$ = require("jquery")
|
||||
|
||||
undum = require('./undum.js')
|
||||
$(document).ready(() ->
|
||||
$("#ways").on("click", "a", (event) ->
|
||||
event.preventDefault()
|
||||
|
|
60
lib/localize.coffee
Normal file
60
lib/localize.coffee
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Internationalization support
|
||||
|
||||
languages = {}
|
||||
|
||||
# Default Messages
|
||||
|
||||
en = {
|
||||
terrible: "terrible",
|
||||
poor: "poor",
|
||||
mediocre: "mediocre",
|
||||
fair: "fair",
|
||||
good: "good",
|
||||
great: "great",
|
||||
superb: "superb",
|
||||
yes: "yes",
|
||||
no: "no",
|
||||
choice: "Choice {number}",
|
||||
no_group_definition: "Couldn't find a group definition for {id}.",
|
||||
link_not_valid: "The link '{link}' doesn't appear to be valid.",
|
||||
link_no_action: "A link with a situation of '.', must have an action.",
|
||||
unknown_situation: "You can't move to an unknown situation: {id}.",
|
||||
existing_situation: "You can't override situation {id} in HTML.",
|
||||
erase_message: "This will permanently delete this character and immediately return you to the start of the game. Are you sure?",
|
||||
no_current_situation: "I can't display, because we don't have a current situation.",
|
||||
no_local_storage: "No local storage available.",
|
||||
random_seed_error: "You must provide a valid random seed.",
|
||||
random_error: "Initialize the Random with a non-empty seed before use.",
|
||||
dice_string_error: "Couldn't interpret your dice string: '{string}'."
|
||||
}
|
||||
|
||||
# Set this data as both the default fallback language, and the english preferred language.
|
||||
languages[""] = en
|
||||
languages["en"] = en
|
||||
|
||||
languageCodes = Object.keys(languages)
|
||||
|
||||
localize = (languageCode, message) ->
|
||||
for thisCode in languageCodes
|
||||
localized = languages[languageCode]
|
||||
if localized
|
||||
return localized
|
||||
return message
|
||||
|
||||
# API
|
||||
String.prototype.l = (args) ->
|
||||
# Get lang attribute from html tag.
|
||||
lang = document.getElementsByTagName("html")[0].getAttribute("lang") || ""
|
||||
|
||||
# Find the localized form.
|
||||
localized = localize(lang, this)
|
||||
|
||||
# Merge in any replacement content.
|
||||
if args
|
||||
for name in args
|
||||
localized = localized.replace(
|
||||
new RegExp("\\{"+name+"\\}"), args[name]
|
||||
)
|
||||
return localized
|
||||
|
||||
module.exports = languages;
|
|
@ -1,6 +1,5 @@
|
|||
markdown = require('./markdown.coffee')
|
||||
undum = require('undum-commonjs')
|
||||
$ = require("jquery")
|
||||
undum = require('./undum.js')
|
||||
objlink = (content, ref) ->
|
||||
return "<a href='./_act_#{ref}'>#{content}</a>"
|
||||
|
||||
|
|
207
lib/random.js
Normal file
207
lib/random.js
Normal file
|
@ -0,0 +1,207 @@
|
|||
// Random Number generation based on seedrandom.js code by David Bau.
|
||||
// Copyright 2010 David Bau, all rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or
|
||||
// without modification, are permitted provided that the following
|
||||
// conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above
|
||||
// copyright notice, this list of conditions and the
|
||||
// following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the
|
||||
// following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of this module nor the names of its
|
||||
// contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
var width = 256;
|
||||
var chunks = 6;
|
||||
var significanceExponent = 52;
|
||||
var startdenom = Math.pow(width, chunks);
|
||||
var significance = Math.pow(2, significanceExponent);
|
||||
var overflow = significance * 2;
|
||||
|
||||
var Random = (function () {
|
||||
var Random = function(seed) {
|
||||
this.random = null;
|
||||
if (!seed) throw {
|
||||
name: "RandomSeedError",
|
||||
message: "random_seed_error".l()
|
||||
};
|
||||
var key = [];
|
||||
mixkey(seed, key);
|
||||
var arc4 = new ARC4(key);
|
||||
this.random = function() {
|
||||
var n = arc4.g(chunks);
|
||||
var d = startdenom;
|
||||
var x = 0;
|
||||
while (n < significance) {
|
||||
n = (n + x) * width;
|
||||
d *= width;
|
||||
x = arc4.g(1);
|
||||
}
|
||||
while (n >= overflow) {
|
||||
n /= 2;
|
||||
d /= 2;
|
||||
x >>>= 1;
|
||||
}
|
||||
return (n + x) / d;
|
||||
};
|
||||
};
|
||||
// Helper type.
|
||||
var ARC4 = function(key) {
|
||||
var t, u, me = this, keylen = key.length;
|
||||
var i = 0, j = me.i = me.j = me.m = 0;
|
||||
me.S = [];
|
||||
me.c = [];
|
||||
if (!keylen) { key = [keylen++]; }
|
||||
while (i < width) { me.S[i] = i++; }
|
||||
for (i = 0; i < width; i++) {
|
||||
t = me.S[i];
|
||||
j = lowbits(j + t + key[i % keylen]);
|
||||
u = me.S[j];
|
||||
me.S[i] = u;
|
||||
me.S[j] = t;
|
||||
}
|
||||
me.g = function getnext(count) {
|
||||
var s = me.S;
|
||||
var i = lowbits(me.i + 1); var t = s[i];
|
||||
var j = lowbits(me.j + t); var u = s[j];
|
||||
s[i] = u;
|
||||
s[j] = t;
|
||||
var r = s[lowbits(t + u)];
|
||||
while (--count) {
|
||||
i = lowbits(i + 1); t = s[i];
|
||||
j = lowbits(j + t); u = s[j];
|
||||
s[i] = u;
|
||||
s[j] = t;
|
||||
r = r * width + s[lowbits(t + u)];
|
||||
}
|
||||
me.i = i;
|
||||
me.j = j;
|
||||
return r;
|
||||
};
|
||||
me.g(width);
|
||||
};
|
||||
// Helper functions.
|
||||
var mixkey = function(seed, key) {
|
||||
seed += '';
|
||||
var smear = 0;
|
||||
for (var j = 0; j < seed.length; j++) {
|
||||
var lb = lowbits(j);
|
||||
smear ^= key[lb];
|
||||
key[lb] = lowbits(smear*19 + seed.charCodeAt(j));
|
||||
}
|
||||
seed = '';
|
||||
for (j in key) {
|
||||
seed += String.fromCharCode(key[j]);
|
||||
}
|
||||
return seed;
|
||||
};
|
||||
var lowbits = function(n) {
|
||||
return n & (width - 1);
|
||||
};
|
||||
|
||||
return Random;
|
||||
})();
|
||||
|
||||
/* Returns a random floating point number between zero and
|
||||
* one. NB: The prototype implementation below just throws an
|
||||
* error, it will be overridden in each Random object when the
|
||||
* seed has been correctly configured. */
|
||||
Random.prototype.random = function() {
|
||||
throw {
|
||||
name:"RandomError",
|
||||
message: "random_error".l()
|
||||
};
|
||||
};
|
||||
/* Returns an integer between the given min and max values,
|
||||
* inclusive. */
|
||||
Random.prototype.randomInt = function(min, max) {
|
||||
return min + Math.floor((max-min+1)*this.random());
|
||||
};
|
||||
/* Returns the result of rolling n dice with dx sides, and adding
|
||||
* plus. */
|
||||
Random.prototype.dice = function(n, dx, plus) {
|
||||
var result = 0;
|
||||
for (var i = 0; i < n; i++) {
|
||||
result += this.randomInt(1, dx);
|
||||
}
|
||||
if (plus) result += plus;
|
||||
return result;
|
||||
};
|
||||
/* Returns the result of rolling n averaging dice (i.e. 6 sided dice
|
||||
* with sides 2,3,3,4,4,5). And adding plus. */
|
||||
Random.prototype.aveDice = (function() {
|
||||
var mapping = [2,3,3,4,4,5];
|
||||
return function(n, plus) {
|
||||
var result = 0;
|
||||
for (var i = 0; i < n; i++) {
|
||||
result += mapping[this.randomInt(0, 5)];
|
||||
}
|
||||
if (plus) result += plus;
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
/* Returns a dice-roll result from the given string dice
|
||||
* specification. The specification should be of the form xdy+z,
|
||||
* where the x component and z component are optional. This rolls
|
||||
* x dice of with y sides, and adds z to the result, the z
|
||||
* component can also be negative: xdy-z. The y component can be
|
||||
* either a number of sides, or can be the special values 'F', for
|
||||
* a fudge die (with 3 sides, +,0,-), '%' for a 100 sided die, or
|
||||
* 'A' for an averaging die (with sides 2,3,3,4,4,5).
|
||||
*/
|
||||
|
||||
Random.prototype.diceString = (function () {
|
||||
var diceRe = /^([1-9][0-9]*)?d([%FA]|[1-9][0-9]*)([-+][1-9][0-9]*)?$/;
|
||||
return function(def) {
|
||||
var match = def.match(diceRe);
|
||||
if (!match) {
|
||||
throw new Error(
|
||||
"dice_string_error".l({string:def})
|
||||
);
|
||||
}
|
||||
|
||||
var num = match[1]?parseInt(match[1], 10):1;
|
||||
var sides;
|
||||
var bonus = match[3]?parseInt(match[3], 10):0;
|
||||
|
||||
switch (match[2]) {
|
||||
case 'A':
|
||||
return this.aveDice(num, bonus);
|
||||
case 'F':
|
||||
sides = 3;
|
||||
bonus -= num*2;
|
||||
break;
|
||||
case '%':
|
||||
sides = 100;
|
||||
break;
|
||||
default:
|
||||
sides = parseInt(match[2], 10);
|
||||
break;
|
||||
}
|
||||
return this.dice(num, sides, bonus);
|
||||
};
|
||||
})();
|
||||
|
||||
module.exports = Random;
|
|
@ -1,10 +1,9 @@
|
|||
# I confess that this world model heavily borrows from INSTEAD engine. - A.Y.
|
||||
|
||||
undum = require('undum-commonjs')
|
||||
undum = require('./undum.js')
|
||||
RaconteurSituation = require('./situation.coffee')
|
||||
obj = require('./obj.coffee')
|
||||
markdown = require('./markdown.coffee')
|
||||
$ = require("jquery")
|
||||
|
||||
way_to = (content, ref) ->
|
||||
return "<a href='#{ref}' class='way' id='waylink-#{ref}'>#{content}</a>"
|
||||
|
|
|
@ -14,7 +14,7 @@ The above copyright notice and this permission notice shall be included in
|
|||
all copies or substantial portions of the Software.
|
||||
###
|
||||
|
||||
undum = require('undum-commonjs')
|
||||
undum = require('./undum.js')
|
||||
markdown = require('./markdown.coffee')
|
||||
|
||||
###
|
||||
|
|
1833
lib/undum.js
Normal file
1833
lib/undum.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"undum-commonjs": "git://github.com/oreolek/undum-commonjs#commonjs",
|
||||
"jquery": "^2.1.3"
|
||||
},
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
|
|
Loading…
Reference in a new issue