Merge pull request #4 from ticklemynausea/master

moar crap
This commit is contained in:
Pedro de Oliveira 2016-10-24 09:48:51 +01:00 committed by GitHub
commit 6ecb551b26
7 changed files with 155 additions and 30 deletions

View File

@ -2,7 +2,10 @@
'use strict'; 'use strict';
const mapValues = require('lodash.mapvalues'); const _ = {
mapValues: require('lodash/mapvalues'),
sample: require('lodash/sample')
};
const Scene = require('./scene'); const Scene = require('./scene');
let Director = function(canvas) { let Director = function(canvas) {
@ -26,7 +29,7 @@
/* map object with scene definitions obtained above into object /* map object with scene definitions obtained above into object
* containing Scene objects with scene name as a key */ * containing Scene objects with scene name as a key */
this.scenes = mapValues(scenes, (value, key) => { this.scenes = _.mapValues(scenes, (value, key) => {
return new Scene(value, this.canvas); return new Scene(value, this.canvas);
}); });
@ -37,7 +40,8 @@
/* create user input area */ /* create user input area */
document.getElementById('ul-teclas').innerHTML = userChoices.reduce((accumulator, choice) => { document.getElementById('ul-teclas').innerHTML = userChoices.reduce((accumulator, choice) => {
accumulator += `<li class="user-action" id="li-${choice.name}" data-action="${choice.name}">${choice.key}<div>${choice.name}</div></li>`; accumulator +=
`<li class="user-action" id="li-${choice.name}" data-action="${choice.name}">${choice.key}<div>${choice.name}</div></li>`;
return accumulator; return accumulator;
}, ''); }, '');
@ -123,7 +127,11 @@
/* then play the chosen scene */ /* then play the chosen scene */
.then(() => this.scenes[scene].play()) .then(() => this.scenes[scene].play())
/* then play the reinaldo scene */ /* then play the reinaldo scene */
.then(() => this.scenes.reinaldo.play()) .then(() => {
/* set valor property for reinaldo scene */
this.scenes.reinaldo.properties.valor_acto = _.sample([1000, 2000, 3000]);
return this.scenes.reinaldo.play();
})
/* then start all over again */ /* then start all over again */
.then(main); .then(main);
}; };
@ -140,4 +148,4 @@
module.exports = Director; module.exports = Director;
})(); })();

View File

@ -1,8 +1,11 @@
(function() { (function() {
'use strict'; 'use strict';
const flattenDeep = require('lodash.flattendeep'); const _ = {
flattenDeep: require('lodash/flattendeep'),
cloneDeep: require('lodash/clonedeep')
};
let Scene = function(scene, canvas) { let Scene = function(scene, canvas) {
@ -12,6 +15,8 @@
/* the html5 canvas object */ /* the html5 canvas object */
this.canvas = canvas; this.canvas = canvas;
/* scene properties */
this.properties = {};
}; };
/* draw one of the specified frames in this scene */ /* draw one of the specified frames in this scene */
@ -23,33 +28,55 @@
}); });
}; };
/* */
Scene.prototype.testCondition = function(scene) {
if (!scene.if) {
return true;
}
/* check if all conditions specified in the 'if' property match
* the values stored in this scene's properties attribute */
return Object.keys(scene.if).reduce((accumulator, condition) => {
let value = scene.if[condition];
return accumulator && this.properties[condition] === scene.if[condition];
}, true);
};
/* play this scene on the given canvas */ /* play this scene on the given canvas */
Scene.prototype.play = function() { Scene.prototype.play = function() {
/* transform the scene roll definition given in the .json scene file /* transform the scene roll definition given in the .json scene file
* into a flat array of simple ({ name, duration }) objects. * into a flat array of simple ({ name, duration }) objects.
* this will deal with all the repeat: properties and multi level nesting */ * this will deal with all the repeat: properties and multi level nesting */
let expand = (roll) => { let expand = (scene) => {
/* recursively expand repeats */ /* test the if property for this scene. if it fails, filter it out
let expanded = roll.map((scene) => { * by returning an empty array as result of roll expansion */
if (!this.testCondition(scene)) {
return [];
}
if (scene.hasOwnProperty('repeat')) { /* expand this roll */
let roll = [];
for (let i = 0; i < (scene.repeat || 1); i++) {
roll = roll.concat(_.cloneDeep(scene.roll));
}
scene.roll = roll;
let roll = []; /* recursively expand child rolls */
let expanded = scene.roll.map((scene) => {
for (let i = 0; i < scene.repeat; i++) { if (scene.hasOwnProperty('roll')) {
roll = roll.concat(scene.roll); return expand(scene);
}
return expand(roll);
} }
return scene; return scene;
}); });
return flattenDeep(expanded); return _.flattenDeep(expanded);
}; };
@ -63,9 +90,7 @@
return () => new Promise((resolve, reject) => { return () => new Promise((resolve, reject) => {
this.drawFrame(frame.images); this.drawFrame(frame.images);
setTimeout(() => { setTimeout(() => resolve(), frame.duration);
return resolve();
}, frame.duration);
}); });
}); });
@ -76,7 +101,7 @@
/* expand the scene definition (get a flat array of simple { name, duration } /* expand the scene definition (get a flat array of simple { name, duration }
* objects */ * objects */
let expanded = expand(this.scene.roll); let expanded = expand(this.scene);
/* transform the array obtained into an array of functions */ /* transform the array obtained into an array of functions */
let functionalized = functionalize(expanded); let functionalized = functionalize(expanded);
@ -94,4 +119,4 @@
module.exports = Scene; module.exports = Scene;
})(); })();

View File

@ -9,8 +9,31 @@
"duration": 1500 "duration": 1500
}, },
{ {
"images": "reinaldo_balloon_sao_1000", "if": { "valor_acto": 1000 },
"duration": 1500 "roll": [
{
"images": "reinaldo_balloon_sao_1000",
"duration": 1500
}
]
},
{
"if": { "valor_acto": 2000 },
"roll": [
{
"images": "reinaldo_balloon_sao_2000",
"duration": 1500
}
]
},
{
"if": { "valor_acto": 3000 },
"roll": [
{
"images": "reinaldo_balloon_sao_3000",
"duration": 1500
}
]
}, },
{ {
"images": "reinaldo_balloon_nao_tenho", "images": "reinaldo_balloon_nao_tenho",
@ -141,4 +164,4 @@
"duration": 2000 "duration": 2000
} }
] ]
} }

13
assets/scenes/test.json Normal file
View File

@ -0,0 +1,13 @@
{
"repeat": 3,
"roll": [
{
"images": "choice_balloon_vaginal",
"duration": 500
},
{
"images": "choice_balloon_anal",
"duration": 500
}
]
}

44
assets/scenes/test2.json Normal file
View File

@ -0,0 +1,44 @@
{
"repeat": 10,
"roll": [
{
"images": "choice_balloon_vaginal",
"duration": 500
},
{
"images": "choice_balloon_anal",
"duration": 500
},
{
"repeat": 2,
"roll": [
{
"repeat": 3,
"roll": [
{
"images": "oral_frame1",
"duration": 250
},
{
"images": "oral_frame2",
"duration": 250
}
]
},
{
"repeat": 2,
"roll": [
{
"images": "reinaldo_violar_frame1",
"duration": 250
},
{
"images": "reinaldo_violar_frame2",
"duration": 250
}
]
}
]
}
]
}

View File

@ -20,8 +20,7 @@
"homepage": "https://github.com/falsovsky/paradise.js#readme", "homepage": "https://github.com/falsovsky/paradise.js#readme",
"dependencies": { "dependencies": {
"es6-promise": "^4.0.5", "es6-promise": "^4.0.5",
"lodash.flattendeep": "^4.4.0", "lodash": "^4.16.4"
"lodash.mapvalues": "^4.6.0"
}, },
"devDependencies": { "devDependencies": {
"babel-core": "^6.17.0", "babel-core": "^6.17.0",

View File

@ -1,3 +1,4 @@
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlWebpackOptions = { const htmlWebpackOptions = {
@ -8,7 +9,8 @@ module.exports = {
entry: "./app/index.js", entry: "./app/index.js",
output: { output: {
path: 'build', path: 'build',
filename: "bundle.js" filename: "bundle.js",
sourceMapFilename: 'bundle.js.map'
}, },
module: { module: {
loaders: [ loaders: [
@ -27,7 +29,18 @@ module.exports = {
{ test: /\.scss$/, loaders: ["style", "css", "sass"] } { test: /\.scss$/, loaders: ["style", "css", "sass"] }
] ]
}, },
devtool: 'sourcemap',
plugins: [ plugins: [
new HtmlWebpackPlugin(htmlWebpackOptions) new HtmlWebpackPlugin(htmlWebpackOptions),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false,
semicolons: true
},
sourceMap: true
})
] ]
}; };