implementadas possibilidades diferentes para o valor do acto
changed usage of lodash individual functions to inclusion of individual functions from whole lodash package also lol commit messages in portuguese and english
This commit is contained in:
parent
c0e321d128
commit
c3891c18cf
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -124,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);
|
||||
};
|
||||
|
|
36
app/scene.js
36
app/scene.js
|
@ -2,8 +2,10 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const flattenDeep = require('lodash.flattendeep');
|
||||
const cloneDeep = require('lodash.clonedeep');
|
||||
const _ = {
|
||||
flattenDeep: require('lodash/flattendeep'),
|
||||
cloneDeep: require('lodash/clonedeep')
|
||||
};
|
||||
|
||||
let Scene = function(scene, canvas) {
|
||||
|
||||
|
@ -13,6 +15,8 @@
|
|||
/* the html5 canvas object */
|
||||
this.canvas = canvas;
|
||||
|
||||
/* scene properties */
|
||||
this.properties = {};
|
||||
};
|
||||
|
||||
/* draw one of the specified frames in this scene */
|
||||
|
@ -24,6 +28,22 @@
|
|||
});
|
||||
};
|
||||
|
||||
/* */
|
||||
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() {
|
||||
|
||||
|
@ -32,10 +52,16 @@
|
|||
* this will deal with all the repeat: properties and multi level nesting */
|
||||
let expand = (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 [];
|
||||
}
|
||||
|
||||
/* expand this roll */
|
||||
let roll = [];
|
||||
for (let i = 0; i < (scene.repeat || 1); i++) {
|
||||
roll = roll.concat(cloneDeep(scene.roll));
|
||||
roll = roll.concat(_.cloneDeep(scene.roll));
|
||||
}
|
||||
scene.roll = roll;
|
||||
|
||||
|
@ -50,7 +76,7 @@
|
|||
|
||||
});
|
||||
|
||||
return flattenDeep(expanded);
|
||||
return _.flattenDeep(expanded);
|
||||
|
||||
};
|
||||
|
||||
|
@ -76,7 +102,7 @@
|
|||
/* expand the scene definition (get a flat array of simple { name, duration }
|
||||
* objects */
|
||||
let expanded = expand(this.scene);
|
||||
//console.log('expanded', JSON.stringify(expanded, null, 2));
|
||||
|
||||
/* transform the array obtained into an array of functions */
|
||||
let functionalized = functionalize(expanded);
|
||||
|
||||
|
|
|
@ -9,19 +9,31 @@
|
|||
"duration": 1500
|
||||
},
|
||||
{
|
||||
"if": { "valor": 1000 },
|
||||
"images": "reinaldo_balloon_sao_1000",
|
||||
"duration": 1500
|
||||
"if": { "valor_acto": 1000 },
|
||||
"roll": [
|
||||
{
|
||||
"images": "reinaldo_balloon_sao_1000",
|
||||
"duration": 1500
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"if": { "valor": 2000 },
|
||||
"images": "reinaldo_balloon_sao_2000",
|
||||
"duration": 1500
|
||||
"if": { "valor_acto": 2000 },
|
||||
"roll": [
|
||||
{
|
||||
"images": "reinaldo_balloon_sao_2000",
|
||||
"duration": 1500
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"if": { "valor": 3000 },
|
||||
"images": "reinaldo_balloon_sao_3000",
|
||||
"duration": 1500
|
||||
"if": { "valor_acto": 3000 },
|
||||
"roll": [
|
||||
{
|
||||
"images": "reinaldo_balloon_sao_3000",
|
||||
"duration": 1500
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"images": "reinaldo_balloon_nao_tenho",
|
||||
|
|
|
@ -20,9 +20,7 @@
|
|||
"homepage": "https://github.com/falsovsky/paradise.js#readme",
|
||||
"dependencies": {
|
||||
"es6-promise": "^4.0.5",
|
||||
"lodash.flatten": "^4.4.0",
|
||||
"lodash.flattendeep": "^4.4.0",
|
||||
"lodash.mapvalues": "^4.6.0"
|
||||
"lodash": "^4.16.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.17.0",
|
||||
|
|
Loading…
Reference in New Issue