diff --git a/app/director.js b/app/director.js
index 646eb88..81b0c0a 100644
--- a/app/director.js
+++ b/app/director.js
@@ -2,7 +2,10 @@
'use strict';
- const mapValues = require('lodash.mapvalues');
+ const _ = {
+ mapValues: require('lodash/mapvalues'),
+ sample: require('lodash/sample')
+ };
const Scene = require('./scene');
let Director = function(canvas) {
@@ -26,7 +29,7 @@
/* map object with scene definitions obtained above into object
* 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);
});
@@ -37,7 +40,8 @@
/* create user input area */
document.getElementById('ul-teclas').innerHTML = userChoices.reduce((accumulator, choice) => {
- accumulator += `
${choice.key}${choice.name}
`;
+ accumulator +=
+ `${choice.key}${choice.name}
`;
return accumulator;
}, '');
@@ -123,7 +127,11 @@
/* then play the chosen scene */
.then(() => this.scenes[scene].play())
/* 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(main);
};
@@ -140,4 +148,4 @@
module.exports = Director;
-})();
\ No newline at end of file
+})();
diff --git a/app/scene.js b/app/scene.js
index eb1995c..f4e0ca4 100644
--- a/app/scene.js
+++ b/app/scene.js
@@ -1,8 +1,11 @@
-(function() {
+ (function() {
'use strict';
- const flattenDeep = require('lodash.flattendeep');
+ const _ = {
+ flattenDeep: require('lodash/flattendeep'),
+ cloneDeep: require('lodash/clonedeep')
+ };
let Scene = function(scene, canvas) {
@@ -12,6 +15,8 @@
/* the html5 canvas object */
this.canvas = canvas;
+ /* scene properties */
+ this.properties = {};
};
/* 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 */
Scene.prototype.play = function() {
/* transform the scene roll definition given in the .json scene file
* into a flat array of simple ({ name, duration }) objects.
* this will deal with all the repeat: properties and multi level nesting */
- let expand = (roll) => {
+ let expand = (scene) => {
- /* recursively expand repeats */
- let expanded = roll.map((scene) => {
+ /* test the if property for this scene. if it fails, filter it out
+ * 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++) {
- roll = roll.concat(scene.roll);
- }
-
- return expand(roll);
+ if (scene.hasOwnProperty('roll')) {
+ return expand(scene);
}
return scene;
});
- return flattenDeep(expanded);
+ return _.flattenDeep(expanded);
};
@@ -63,9 +90,7 @@
return () => new Promise((resolve, reject) => {
this.drawFrame(frame.images);
- setTimeout(() => {
- return resolve();
- }, frame.duration);
+ setTimeout(() => resolve(), frame.duration);
});
});
@@ -76,7 +101,7 @@
/* expand the scene definition (get a flat array of simple { name, duration }
* objects */
- let expanded = expand(this.scene.roll);
+ let expanded = expand(this.scene);
/* transform the array obtained into an array of functions */
let functionalized = functionalize(expanded);
@@ -94,4 +119,4 @@
module.exports = Scene;
-})();
\ No newline at end of file
+})();
diff --git a/assets/scenes/reinaldo.json b/assets/scenes/reinaldo.json
index 3a752cf..6b35e45 100644
--- a/assets/scenes/reinaldo.json
+++ b/assets/scenes/reinaldo.json
@@ -9,8 +9,31 @@
"duration": 1500
},
{
- "images": "reinaldo_balloon_sao_1000",
- "duration": 1500
+ "if": { "valor_acto": 1000 },
+ "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",
@@ -141,4 +164,4 @@
"duration": 2000
}
]
-}
\ No newline at end of file
+}
diff --git a/assets/scenes/test.json b/assets/scenes/test.json
new file mode 100644
index 0000000..eb77a7b
--- /dev/null
+++ b/assets/scenes/test.json
@@ -0,0 +1,13 @@
+{
+ "repeat": 3,
+ "roll": [
+ {
+ "images": "choice_balloon_vaginal",
+ "duration": 500
+ },
+ {
+ "images": "choice_balloon_anal",
+ "duration": 500
+ }
+ ]
+}
diff --git a/assets/scenes/test2.json b/assets/scenes/test2.json
new file mode 100644
index 0000000..f6113ee
--- /dev/null
+++ b/assets/scenes/test2.json
@@ -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
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/package.json b/package.json
index dbfb916..6e9caf5 100644
--- a/package.json
+++ b/package.json
@@ -20,8 +20,7 @@
"homepage": "https://github.com/falsovsky/paradise.js#readme",
"dependencies": {
"es6-promise": "^4.0.5",
- "lodash.flattendeep": "^4.4.0",
- "lodash.mapvalues": "^4.6.0"
+ "lodash": "^4.16.4"
},
"devDependencies": {
"babel-core": "^6.17.0",
diff --git a/webpack.config.js b/webpack.config.js
index 315f546..71e4f8c 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,3 +1,4 @@
+const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlWebpackOptions = {
@@ -8,7 +9,8 @@ module.exports = {
entry: "./app/index.js",
output: {
path: 'build',
- filename: "bundle.js"
+ filename: "bundle.js",
+ sourceMapFilename: 'bundle.js.map'
},
module: {
loaders: [
@@ -27,7 +29,18 @@ module.exports = {
{ test: /\.scss$/, loaders: ["style", "css", "sass"] }
]
},
+ devtool: 'sourcemap',
plugins: [
- new HtmlWebpackPlugin(htmlWebpackOptions)
+ new HtmlWebpackPlugin(htmlWebpackOptions),
+ new webpack.optimize.UglifyJsPlugin({
+ compress: {
+ warnings: false
+ },
+ output: {
+ comments: false,
+ semicolons: true
+ },
+ sourceMap: true
+ })
]
};