-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
332 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ node_modules | |
|
||
# Jetbrains IDE | ||
.idea | ||
*.iml | ||
*.iml | ||
|
||
# IDE Plugins | ||
wallaby.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
## Developing | ||
|
||
Here's a brief intro about what a developer must do in order to start developing | ||
the project further: | ||
**Under Construction** | ||
|
||
```shell | ||
git clone https://github.com/mcherryleigh/make-believe.git | ||
cd make-believe/ | ||
npm install | ||
``` | ||
|
||
And state what happens step-by-step. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
/** | ||
* @class Entity | ||
* Class used to generate predictably random objects. | ||
*/ | ||
class Entity { | ||
/** | ||
* Create an Entity. Provide options in an EntityOptionsObject | ||
* @param {Object} [options={ | ||
* verbose: false, | ||
* plugins: [] | ||
* }] - An options | ||
* object | ||
*/ | ||
constructor(options) { | ||
const defaults = { | ||
verbose: false, | ||
}; | ||
this._options = Object.assign(defaults, options); | ||
this._schema = this._options.schema; | ||
this._variants = []; | ||
this._outputs = []; | ||
} | ||
|
||
/** | ||
* Get the seed that was used in the options object | ||
* @return {String} Return the seed that was used in the options object or the integer | ||
* which was generated if a seed was not given. | ||
*/ | ||
get schema() { | ||
return this._schema; | ||
} | ||
|
||
/** | ||
* Get a random integer within a range. | ||
* @method | ||
* @param {Object} schema - An object representing this entity's baseline schema. | ||
* @return {Entity} Return this entity. | ||
*/ | ||
setSchema(schema) { | ||
this._schema = schema; | ||
return this; | ||
} | ||
|
||
get options() { | ||
return this._options; | ||
} | ||
|
||
setOptions(options) { | ||
this._options = Object.assign(this._options, options); | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the seed that was used in the options object | ||
* @return {String} Return the seed that was used in the options object or the integer | ||
* which was generated if a seed was not given. | ||
*/ | ||
get variants() { | ||
return this._variants; | ||
} | ||
|
||
/** | ||
* Add a variant to the Entity's schema | ||
* @method | ||
* @param {Object} variantSchema - An object representing how this object is | ||
* different from the schema. | ||
* @return {Entity} Return this entity. | ||
*/ | ||
addVariant(variant) { | ||
this._variants = this._variants.concat(variant); | ||
return this; | ||
} | ||
|
||
/** | ||
* Get any outputs that have been loaded into the Entity. | ||
* @method | ||
* @param {Object} variantSchema - An object representing how this object is | ||
* different from the schema. | ||
* @return {Entity} Return this entity. | ||
*/ | ||
get outputs() { | ||
return this._outputs; | ||
} | ||
|
||
addOutputs(outputs) { | ||
this._outputs = this._outputs.concat(outputs); | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = Entity; | ||
|
||
/** | ||
* @typedef {Object} Entity~OptionsObject | ||
* @type Object | ||
* @param {Number} [rv=null] - A configured RandomValue. If none is provided one will | ||
* be created using default settings | ||
* @param {Number} [verbose=false] - Use verbose to get additional console logging information. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
/** | ||
* @class RandomValue | ||
* Class used to generate predictably random series of values. | ||
*/ | ||
class RandomValue { | ||
/** | ||
* @typedef {Object} PluginObject | ||
* @property {String} PluginObject.name - The name of your function. This will be used as the | ||
* method name unless an altName is also provided. | ||
* @property {String} PluginObject.altName - An override that will be used as the method name | ||
* for your object | ||
* @property {function} PluginObject.func - A function returning a value relative to your theme. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} OptionsObject | ||
* @property {number} OptionsObject.seed - The x coordinate. | ||
* @property {number} OptionsObject.verbose - The x coordinate. | ||
* @property {PluginObject[]} OptionsObject.plugins - The y coordinate. | ||
*/ | ||
|
||
/** | ||
* Create a RandomValue generator. Use the OptionsObject | ||
* to override default behavior. | ||
* @param {OptionsObject} [options] - An options object to set the seed and | ||
*/ | ||
constructor(options) { | ||
const defaults = { | ||
seed: Date.now(), | ||
verbose: false, | ||
plugins: [], | ||
}; | ||
this._options = Object.assign(defaults, options); | ||
// TODO handle strings in seed value | ||
this._state = Math.abs(this._options.seed % 2147483646) + 1; | ||
if (this._state <= 0) this._state += 2147483646; | ||
} | ||
|
||
/** | ||
* Get the seed that was used in the options object | ||
* @return {String} Return the seed that was used in the options object or the integer | ||
* which was generated if a seed was not given. | ||
*/ | ||
get seed() { | ||
return this._options.seed; | ||
} | ||
|
||
/** | ||
* Get the seed that was used in the options object | ||
* @return {RandomValue} Return the seed that was used in the options object or the integer | ||
* which was generated if a seed was not given. | ||
*/ | ||
setSeed(seed) { | ||
this._options.seed = seed; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the current state that will be used next random() call | ||
* @return {number} Return the current state of the random generator. | ||
*/ | ||
get state() { | ||
return this._state; | ||
} | ||
|
||
/** | ||
* Get the current state that will be used next random() call | ||
* @return {OptionsObject} Return the current state of the random generator. | ||
*/ | ||
get options() { | ||
return this._options; | ||
} | ||
|
||
next() { | ||
this._state = (this._state * 16807) % 2147483647; | ||
return this._state; | ||
} | ||
|
||
/** | ||
* Get the next random float in the series. | ||
* @return {number} Return the current state of the random generator. | ||
*/ | ||
random() { | ||
// TODO is this ok without using Math.abs approach from constructor? | ||
return (this.next() - 1) / 2147483646; | ||
} | ||
|
||
/** | ||
* Get a random integer within a range. | ||
* @param {number} min - The smallest integer you might generate. | ||
* @param {number} max - The largest integer you might generate. | ||
* @return {number} Return a random integer value. | ||
*/ | ||
randomInteger(options) { | ||
const one = this.random() * (options.max - options.min + 1); | ||
return Math.floor(one + options.min); | ||
} | ||
|
||
/** | ||
* Run a RandomValue method multiple times and return the result from each run in an array. | ||
* @param {function} func - An array of values to pick from. | ||
* @param {number} amount - How many values to pick from the array. | ||
* @return {any[]} Return an array of values returned from the method. | ||
*/ | ||
times() { | ||
return this; // TODO | ||
} | ||
|
||
/** | ||
* Pick one or more values from an array. Returned values may include duplicates. | ||
* @param {any[]} pickArray - An array of values to pick from. | ||
* @param {number} amount - How many values to pick from the array. | ||
* @return {any|any[]} Return a value or an array of values from the pickArray. | ||
*/ | ||
pick() { | ||
return this; | ||
} | ||
|
||
/** | ||
* Pick one or more values from an array. Returned values will be from uniquely picked indexes. | ||
* @param {any[]} pickArray - An array of values to pick from. | ||
* @param {number} amount - How many values to pick from the array. | ||
* @return {any|any[]} Return a value or an array of values from the pickArray. | ||
*/ | ||
pickUnique(pickArray, amount) { | ||
const outArray = this.shuffle(pickArray).slice(0, amount); | ||
return outArray; | ||
} | ||
|
||
/** | ||
* Run a RandomValue method multiple times and return a series of values from . | ||
* @param {function} method - An array of values to pick from. | ||
* @param {number} amount - How many values to pick from the array. | ||
* @return {any[]} Return an array of values returned from the method. | ||
*/ | ||
pickSeries() { | ||
return this; // TODO | ||
} | ||
|
||
/** | ||
* Pick one or more values from an array. Returned values will be picked weighted | ||
* relative to values given in the weightArray. | ||
* @param {any[]} pickArray - An array of values to pick from. | ||
* @param {number[]} weightArray - An array of values representing the weighting | ||
* values corresponding to the pickArray. | ||
* @param {number} amount - How many values to pick from the array. | ||
* @return {any|any[]} Return a value or an array of values from the pickArray. | ||
*/ | ||
pickWeighted() { | ||
return this; // TODO | ||
} | ||
|
||
/** | ||
* Shuffles array in place. | ||
* @param {Array} a items An array containing the items. | ||
*/ | ||
shuffle(arr) { | ||
let j; let x; let i; | ||
for (i = arr.length - 1; i > 0; i -= 1) { | ||
j = Math.floor(this.random() * (i + 1)); | ||
x = arr[i]; | ||
arr[i] = arr[j]; // eslint-disable-line no-param-reassign | ||
arr[j] = x; // eslint-disable-line no-param-reassign | ||
// TODO figure out how to do this without silencing eslint | ||
} | ||
return arr; | ||
} | ||
|
||
toJSON() { | ||
return { | ||
options: this._options, | ||
state: this._state, | ||
}; | ||
} | ||
} | ||
|
||
module.exports = RandomValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
/** | ||
* truly returns true | ||
* @return {boolean} | ||
*/ | ||
|
||
exports.truly = function truly() { | ||
return true; | ||
}; | ||
exports.RandomValue = require('./RandomValue'); | ||
exports.Entity = require('./Entity'); |
Oops, something went wrong.