Initial
This commit is contained in:
parent
06b9fc4d51
commit
4f49861eb5
@ -1,2 +1,4 @@
|
|||||||
# plottoriffic
|
# Plottoriffic
|
||||||
Generate story plots based on Plotto
|
|
||||||
|
Generate plots based on [Plotto](http://garykac.github.io/plotto/plotto-mf.html).
|
||||||
|
|
||||||
|
52348
data/plotto.json
Normal file
52348
data/plotto.json
Normal file
File diff suppressed because it is too large
Load Diff
74
index.js
Normal file
74
index.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
'use strict'
|
||||||
|
const seedrandom = require('seedrandom');
|
||||||
|
const plotto = require("./data/plotto.json");
|
||||||
|
|
||||||
|
function pick(rng, arr) {
|
||||||
|
let min = 0;
|
||||||
|
let max = arr.length;
|
||||||
|
return arr[Math.floor(this.fn() * (max - min)) + min];
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveConflict(id) {
|
||||||
|
|
||||||
|
var ids = id.split(',');
|
||||||
|
var mainId = ids[0].match(/^\d+/);
|
||||||
|
|
||||||
|
for(let i of ids) {
|
||||||
|
|
||||||
|
let conflictid = i;
|
||||||
|
if(conflictid.indexOf(maniId) != 0)
|
||||||
|
conflictid = mainId + i;
|
||||||
|
|
||||||
|
let ch = /\s+ch (?:([a-zA-Z0-9-]+|“[^”]+”) to ([a-zA-Z0-9-]+|“[^”]+”))(?: & ([a-zA-Z0-9-]+|“[^”]+”) to ([a-zA-Z0-9-]+|“[^”]+”))*/;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlotGenerator {
|
||||||
|
|
||||||
|
constructor({ seed=null, flipGenders=undefined, names=plotto.characters } = {}) {
|
||||||
|
this._rng = seedrandom(seed);
|
||||||
|
this._names = names;
|
||||||
|
|
||||||
|
if(flipGenders === undefined) {
|
||||||
|
this._flipGenders = this._rng() < 0.5; //50% chance true/false
|
||||||
|
} else {
|
||||||
|
this._flipGenders = flipGenders;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get flipGenders() { return this._flipGenders; }
|
||||||
|
set flipGenders(flip) { this._flipGenders = flip; }
|
||||||
|
|
||||||
|
get names() { return this._names; }
|
||||||
|
set names(names) { this._names = Object.assign({}, plotto.characters, names); }
|
||||||
|
|
||||||
|
generate() {
|
||||||
|
|
||||||
|
let a = pick(this._rng, plotto.masterClauseA);
|
||||||
|
let b = pick(this._rng, plotto.masterClauseB);
|
||||||
|
let c = pick(this._rng, plotto.masterClauseA);
|
||||||
|
|
||||||
|
return [
|
||||||
|
a + ' ' + b.description,
|
||||||
|
this._expand(b),
|
||||||
|
c
|
||||||
|
].join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
_expand(b) {
|
||||||
|
|
||||||
|
let initial = plotto.conflicts[pick(this._rng, b.nodes)];
|
||||||
|
|
||||||
|
let leadIn = pick(this._rng, initial.leadIns);
|
||||||
|
let carryOn = pick(this._rng, initial.carryOns);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exports.PlotGenerator = PlotGenerator;
|
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "plottoriffic",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Generate plots based on Plotto",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/justinoverton/plottoriffic.git"
|
||||||
|
},
|
||||||
|
"author": "Justin Overton",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/justinoverton/plottoriffic/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/justinoverton/plottoriffic#readme",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"seedrandom": "^2.4.3"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user