1
0
Fork 0
mirror of https://github.com/Oreolek/undum.git synced 2024-06-01 07:48:10 +03:00

indentation fixes

This commit is contained in:
Alexander Yakovlev 2015-07-19 12:38:51 +07:00
parent 200c61d819
commit 64b0a0c282
4 changed files with 286 additions and 286 deletions

View file

@ -299,14 +299,14 @@ SimpleSituation.prototype.optionText = function(character, system, sitn) {
*/
var QualityDefinition = function(title, opts) {
var myOpts = extend(opts, {
priority: title,
group: null,
extraClasses: null
});
this.title = title;
this.priority = myOpts.priority;
this.group = myOpts.group;
this.extraClasses = myOpts.extraClasses;
priority: title,
group: null,
extraClasses: null
});
this.title = title;
this.priority = myOpts.priority;
this.group = myOpts.group;
this.extraClasses = myOpts.extraClasses;
};
/* Formats the value (which is always numeric) into the value to
* be displayed. The result should be HTML (but no tags are
@ -340,8 +340,8 @@ NonZeroIntegerQuality.prototype.format = function(character, value) {
return null;
} else {
return IntegerQuality.prototype.format.call(
this, character, value
);
this, character, value
);
}
};
@ -380,13 +380,13 @@ NumericQuality.inherits(QualityDefinition);
*/
var WordScaleQuality = function(title, values, opts) {
var myOpts = extend(opts, {
offset: null,
useBonuses: true
});
QualityDefinition.call(this, title, opts);
this.values = values;
this.offset = myOpts.offset;
this.useBonuses = myOpts.useBonuses;
offset: null,
useBonuses: true
});
QualityDefinition.call(this, title, opts);
this.values = values;
this.offset = myOpts.offset;
this.useBonuses = myOpts.useBonuses;
};
WordScaleQuality.inherits(QualityDefinition);
WordScaleQuality.prototype.format = function(character, value) {
@ -415,8 +415,13 @@ WordScaleQuality.prototype.format = function(character, value) {
*/
var FudgeAdjectivesQuality = function(title, opts) {
WordScaleQuality.call(this, title, [
"terrible".l(), "poor".l(), "mediocre".l(),
"fair".l(), "good".l(), "great".l(), "superb".l()
"terrible".l(),
"poor".l(),
"mediocre".l(),
"fair".l(),
"good".l(),
"great".l(),
"superb".l()
], opts);
if (!('offset' in opts)) this.offset = -3;
};
@ -430,10 +435,10 @@ FudgeAdjectivesQuality.inherits(WordScaleQuality);
* for QualityDefinition. */
var OnOffQuality = function(title, opts) {
var myOpts = extend(opts, {
onDisplay: ""
});
QualityDefinition.call(this, title, opts);
this.onDisplay = myOpts.onDisplay;
onDisplay: ""
});
QualityDefinition.call(this, title, opts);
this.onDisplay = myOpts.onDisplay;
};
OnOffQuality.inherits(QualityDefinition);
OnOffQuality.prototype.format = function(character, value) {
@ -451,12 +456,12 @@ OnOffQuality.prototype.format = function(character, value) {
*/
var YesNoQuality = function(title, opts) {
var myOpts = extend(opts,{
yesDisplay: "yes".l(),
noDisplay: "no".l()
});
QualityDefinition.call(this, title, opts);
this.yesDisplay = myOpts.yesDisplay;
this.noDisplay = myOpts.noDisplay;
yesDisplay: "yes".l(),
noDisplay: "no".l()
});
QualityDefinition.call(this, title, opts);
this.yesDisplay = myOpts.yesDisplay;
this.noDisplay = myOpts.noDisplay;
};
YesNoQuality.inherits(QualityDefinition);
YesNoQuality.prototype.format = function(character, value) {
@ -469,10 +474,10 @@ YesNoQuality.prototype.format = function(character, value) {
* `undum.game.qualityGroups` parameter. */
var QualityGroup = function(title, opts) {
var myOpts = extend(opts,{
priority: title,
extraClasses: null
});
this.title = title;
this.priority = myOpts.priority;
this.extraClasses = myOpts.extraClasses;
priority: title,
extraClasses: null
});
this.title = title;
this.priority = myOpts.priority;
this.extraClasses = myOpts.extraClasses;
};

View file

@ -701,97 +701,97 @@ var loadGame = function(characterData) {
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var Random = (function() {
// Within this closure function the code is basically
// David's. Undum's custom extensions are added to the
// prototype outside of this function.
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;
// Within this closure function the code is basically
// David's. Undum's custom extensions are added to the
// prototype outside of this function.
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(seed) {
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];
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;
r = r * width + s[lowbits(t + u)];
}
me.i = i;
me.j = j;
return r;
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);
};
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;
return Random;
})();
/* Returns a random floating point number between zero and
* one. NB: The prototype implementation below just throws an
@ -799,8 +799,8 @@ return Random;
* seed has been correctly configured. */
Random.prototype.random = function() {
throw {
name:"RandomError",
message: "random_error".l()
name:"RandomError",
message: "random_error".l()
};
};
/* Returns an integer between the given min and max values,
@ -821,16 +821,16 @@ Random.prototype.dice = function(n, dx, plus) {
/* 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 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)];
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
@ -841,13 +841,11 @@ Random.prototype.aveDice = (function() {
* '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 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})
);
throw new Error("dice_string_error".l({string:def}));
}
var num = match[1]?parseInt(match[1], 10):1;
@ -855,19 +853,19 @@ Random.prototype.diceString = (function() {
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;
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);
};
};
})();

View file

@ -68,11 +68,11 @@ function ready(fn) {
}
ready(function() {
// Compile additional situations from HTML
loadHTMLSituations();
// Compile additional situations from HTML
loadHTMLSituations();
// Handle storage.
if (hasLocalStorage()) {
// Handle storage.
if (hasLocalStorage()) {
var erase = document.getElementById("erase");
erase.addEventListener("click", doErase());
erase.addEventListener("keydown", doErase());
@ -82,50 +82,50 @@ ready(function() {
var storedCharacter = localStorage[getSaveId()];
if (storedCharacter) {
try {
loadGame(JSON.parse(storedCharacter));
save.setAttribute('disabled', true);
erase.setAttribute("disabled", false);
} catch(err) {
doErase(true);
}
try {
loadGame(JSON.parse(storedCharacter));
save.setAttribute('disabled', true);
erase.setAttribute("disabled", false);
} catch(err) {
doErase(true);
}
} else {
save.setAttribute('disabled', true);
erase.setAttribute("disabled", true);
startGame();
}
} else {
$(".buttons").html("<p>"+"no_local_storage".l()+"</p>");
startGame();
} else {
$(".buttons").html("<p>"+"no_local_storage".l()+"</p>");
startGame();
}
// Display the "click to begin" message. (We do this in code
// so that, if Javascript is off, it doesn't happen.)
document.getElementById("click_message").style.display = '';
// Show the game when we click on the title.
document.getElementById("title").addEventListener('click', function() {
showBlock("content")
showBlock("content_wrapper");
showBlock("legal");
showBlock("tools_wrapper");
document.getElementById("title").style.cursor = "default";
hideBlock("click_message");
});
/*
// Any point that an option list appears, its options are its
// first links.
var optionLinkEvent = function(event) {
// Make option clicks pass through to their first link.
var link = $("a", this);
if (link.length > 0) {
$(link.get(0)).click();
}
// Display the "click to begin" message. (We do this in code
// so that, if Javascript is off, it doesn't happen.)
document.getElementById("click_message").style.display = '';
// Show the game when we click on the title.
document.getElementById("title").addEventListener('click', function() {
showBlock("content")
showBlock("content_wrapper");
showBlock("legal");
showBlock("tools_wrapper");
document.getElementById("title").style.cursor = "default";
hideBlock("click_message");
});
/*
// Any point that an option list appears, its options are its
// first links.
var optionLinkEvent = function(event) {
// Make option clicks pass through to their first link.
var link = $("a", this);
if (link.length > 0) {
$(link.get(0)).click();
}
};
items = document.querySelectorAll("ul.options li, #menu li");
Array.prototype.forEach.call(items, function(element, index){
element.addEventListener('click', optionLinkEvent);
});
};
items = document.querySelectorAll("ul.options li, #menu li");
Array.prototype.forEach.call(items, function(element, index){
element.addEventListener('click', optionLinkEvent);
});
*/
});

View file

@ -109,8 +109,8 @@ System.prototype.doLink = function(code) {
System.prototype.clearLinks = function(code) {
var links = document.querySelectorAll("a[href='" + code + "']");
Array.prototype.forEach.call(links, function(element, index){
element.querySelectorAll("span").classList.add("ex_link");
});
element.querySelectorAll("span").classList.add("ex_link");
});
};
/* Given a list of situation ids, this outputs a standard option
@ -430,13 +430,13 @@ System.prototype.animateQuality = function(quality, newValue, opts) {
// Overload default options.
var myOpts = {
from: 0,
to: 1,
title: null,
showValue: true,
displayValue: null,
leftLabel: null,
rightLabel: null
from: 0,
to: 1,
title: null,
showValue: true,
displayValue: null,
leftLabel: null,
rightLabel: null
};
if (newValue < currentValue) {
myOpts.from = 1;
@ -449,9 +449,7 @@ from: 0,
if (qualityDefinition) {
// Work out how to display the value
if (myOpts.displayValue === null) {
myOpts.displayValue = qualityDefinition.format(
character, newValue
);
myOpts.displayValue = qualityDefinition.format(character, newValue);
}
// Use the title.
@ -496,24 +494,24 @@ from: 0,
// Start the animation
setTimeout(function() {
widthElement.animate(
{'width': myOpts.to*totalWidth}, 1000,
function() {
// After a moment to allow the bar to be read, we can
// remove it.
setTimeout(function() {
if (mobile) {
bar.fadeOut(1500, function() {$(this).remove();});
} else {
bar.animate({opacity: 0}, 1500).
slideUp(500, function() {
$(this).remove();
});
}
}, 2000);
widthElement.animate(
{'width': myOpts.to*totalWidth}, 1000,
function() {
// After a moment to allow the bar to be read, we can
// remove it.
setTimeout(function() {
if (mobile) {
bar.fadeOut(1500, function() {$(this).remove();});
} else {
bar.animate({opacity: 0}, 1500).
slideUp(500, function() {
$(this).remove();
});
}
);
}, 500);
}, 2000);
}
);
}, 500);
};
/* The character that is passed into each situation is of this
@ -556,85 +554,84 @@ var game = {
/* An object mapping from the unique id of each situation, to
* the situation object itself. This is the heart of the game
* specification. */
situations: {},
situations: {},
/* The unique id of the situation to enter at the start of a
* new game. */
start: "start",
/* The unique id of the situation to enter at the start of a
* new game. */
start: "start",
// Quality display definitions
// Quality display definitions
/* An object mapping the unique id of each quality to its
* QualityDefinition. You don't need definitions for every
* quality, but only qualities in this mapping will be
* displayed in the character box of the UI. */
qualities: {},
/* An object mapping the unique id of each quality to its
* QualityDefinition. You don't need definitions for every
* quality, but only qualities in this mapping will be
* displayed in the character box of the UI. */
qualities: {},
/* Qualities can have an optional group Id. This maps those
* Ids to the group definitions that says how to format its
* qualities.
*/
qualityGroups: {},
/* Qualities can have an optional group Id. This maps those
* Ids to the group definitions that says how to format its
* qualities.
*/
qualityGroups: {},
// Hooks
// Hooks
/* This function is called at the start of the game. It is
* normally overridden to provide initial character creation
* (setting initial quality values, setting the
* character-text. This is optional, however, as set-up
* processing could also be done by the first situation's
* enter function. If this function is given it should have
* the signature function(character, system).
*/
init: null,
/* This function is called at the start of the game. It is
* normally overridden to provide initial character creation
* (setting initial quality values, setting the
* character-text. This is optional, however, as set-up
* processing could also be done by the first situation's
* enter function. If this function is given it should have
* the signature function(character, system).
*/
init: null,
/* This function is called before entering any new
* situation. It is called before the corresponding situation
* has its `enter` method called. It can be used to implement
* timed triggers, but is totally optional. If this function
* is given it should have the signature:
*
* function(character, system, oldSituationId, newSituationId);
*/
enter: null,
/* This function is called before entering any new
* situation. It is called before the corresponding situation
* has its `enter` method called. It can be used to implement
* timed triggers, but is totally optional. If this function
* is given it should have the signature:
*
* function(character, system, oldSituationId, newSituationId);
*/
enter: null,
/* Hook for when the situation has already been carried out
* and printed. The signature is:
*
* function(character, system, oldSituationId, newSituationId);
*/
afterEnter: null,
/* Hook for when the situation has already been carried out
* and printed. The signature is:
*
* function(character, system, oldSituationId, newSituationId);
*/
afterEnter: null,
/* This function is called before carrying out any action in
* any situation. It is called before the corresponding
* situation has its `act` method called. If this optional
* function is given it should have the signature:
*
* function(character, system, situationId, actionId);
*
* If the function returns true, then it is indicating that it
* has consumed the action, and the action will not be passed
* on to the situation. Note that this is the only one of
* these global handlers that can consume the event.
*/
beforeAction: null,
/* This function is called before carrying out any action in
* any situation. It is called before the corresponding
* situation has its `act` method called. If this optional
* function is given it should have the signature:
*
* function(character, system, situationId, actionId);
*
* If the function returns true, then it is indicating that it
* has consumed the action, and the action will not be passed
* on to the situation. Note that this is the only one of
* these global handlers that can consume the event.
*/
beforeAction: null,
/* This function is called after carrying out any action in
* any situation. It is called after the corresponding
* situation has its `act` method called. If this optional
* function is given it should have the signature:
*
* function(character, system, situationId, actionId);
*/
afterAction: null,
/* This function is called after carrying out any action in
* any situation. It is called after the corresponding
* situation has its `act` method called. If this optional
* function is given it should have the signature:
*
* function(character, system, situationId, actionId);
*/
afterAction: null,
/* This function is called after leaving any situation. It is
* called after the corresponding situation has its `exit`
* method called. If this optional function is given it should
* have the signature:
*
* function(character, system, oldSituationId, newSituationId);
*/
exit: null
/* This function is called after leaving any situation. It is
* called after the corresponding situation has its `exit`
* method called. If this optional function is given it should
* have the signature:
*
* function(character, system, oldSituationId, newSituationId);
*/
exit: null
};