Преглед на файлове

Backbone upgrade for recursive desc

Added hasAtLeast function to increase
 rule flexibility on test functions. added an extra1 passthrough to describe function to increase rule flexibility on test functions

Added pickString, a function that returns a random array element for text variation.
tags/v1.0.1
jsb5468 преди 7 години
родител
ревизия
579da1843b
променени са 1 файла, в които са добавени 16 реда и са изтрити 4 реда
  1. +16
    -4
      recursive-desc.js

+ 16
- 4
recursive-desc.js Целия файл

@@ -71,6 +71,13 @@ function hasLessThan(container, thing, amount) {
return false; return false;
} }


function hasAtleast(container, thing, amount) { //this function does not trigger in situations where you have a single object(..., 1 [thing], ...) nested inside of a larger group. If you have a case where that can feasibly happen it is reccomended to put a parent ofject of the one you want as an and condition.
if (container.contents.hasOwnProperty(thing))
if (container.contents[thing].count >= amount)
return true;
return false;
}

function hasExactly(container, thing, amount) { function hasExactly(container, thing, amount) {
if (!container.contents.hasOwnProperty(thing) && amount == 0) if (!container.contents.hasOwnProperty(thing) && amount == 0)
return true; return true;
@@ -110,11 +117,11 @@ function nothingLarger(container, thing) {
return true; return true;
} }


function describe(action, container, macro, verbose=true, flat=false) {
function describe(action, container, macro, verbose=true, flat=false, extra1=0) {
var options = []; var options = [];


for (var i = 0; i < rules[action].length; i++) { for (var i = 0; i < rules[action].length; i++) {
if(rules[action][i].test(container,macro)) {
if(rules[action][i].test(container, macro, extra1)) {
options.push(rules[action][i].desc); options.push(rules[action][i].desc);
} }
} }
@@ -125,10 +132,10 @@ function describe(action, container, macro, verbose=true, flat=false) {


if (options.length > 0 && Math.random() > (1 / (2 + rules[action].length))) { if (options.length > 0 && Math.random() > (1 / (2 + rules[action].length))) {
let choice = Math.floor(Math.random() * options.length); let choice = Math.floor(Math.random() * options.length);
return options[choice](container, macro, verbose, flat);
return options[choice](container, macro, verbose, flat, extra1);
} }
else { else {
return getDefault(action)(container, macro, verbose, flat);
return getDefault(action)(container, macro, verbose, flat, extra1);
} }
} }


@@ -136,6 +143,11 @@ function describeVictim(action, macro) {
return getDefaultVictim(action)(macro); return getDefaultVictim(action)(macro);
} }


function pickString(...array){
var strings = array;
var pick = strings[~~(Math.random() * strings.length)];
return pick;
}
// DEFAULTS // DEFAULTS


function defaultEat(container, macro, verbose, flat) { function defaultEat(container, macro, verbose, flat) {


Loading…
Отказ
Запис