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';
|
'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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -124,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);
|
||||||
};
|
};
|
||||||
|
|
36
app/scene.js
36
app/scene.js
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const flattenDeep = require('lodash.flattendeep');
|
const _ = {
|
||||||
const cloneDeep = require('lodash.clonedeep');
|
flattenDeep: require('lodash/flattendeep'),
|
||||||
|
cloneDeep: require('lodash/clonedeep')
|
||||||
|
};
|
||||||
|
|
||||||
let Scene = function(scene, canvas) {
|
let Scene = function(scene, canvas) {
|
||||||
|
|
||||||
|
@ -13,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 */
|
||||||
|
@ -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 */
|
/* play this scene on the given canvas */
|
||||||
Scene.prototype.play = function() {
|
Scene.prototype.play = function() {
|
||||||
|
|
||||||
|
@ -32,10 +52,16 @@
|
||||||
* 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 = (scene) => {
|
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 */
|
/* expand this roll */
|
||||||
let roll = [];
|
let roll = [];
|
||||||
for (let i = 0; i < (scene.repeat || 1); i++) {
|
for (let i = 0; i < (scene.repeat || 1); i++) {
|
||||||
roll = roll.concat(cloneDeep(scene.roll));
|
roll = roll.concat(_.cloneDeep(scene.roll));
|
||||||
}
|
}
|
||||||
scene.roll = 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 }
|
/* expand the scene definition (get a flat array of simple { name, duration }
|
||||||
* objects */
|
* objects */
|
||||||
let expanded = expand(this.scene);
|
let expanded = expand(this.scene);
|
||||||
//console.log('expanded', JSON.stringify(expanded, null, 2));
|
|
||||||
/* 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);
|
||||||
|
|
||||||
|
|
|
@ -9,19 +9,31 @@
|
||||||
"duration": 1500
|
"duration": 1500
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"if": { "valor": 1000 },
|
"if": { "valor_acto": 1000 },
|
||||||
|
"roll": [
|
||||||
|
{
|
||||||
"images": "reinaldo_balloon_sao_1000",
|
"images": "reinaldo_balloon_sao_1000",
|
||||||
"duration": 1500
|
"duration": 1500
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"if": { "valor": 2000 },
|
"if": { "valor_acto": 2000 },
|
||||||
|
"roll": [
|
||||||
|
{
|
||||||
"images": "reinaldo_balloon_sao_2000",
|
"images": "reinaldo_balloon_sao_2000",
|
||||||
"duration": 1500
|
"duration": 1500
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"if": { "valor": 3000 },
|
"if": { "valor_acto": 3000 },
|
||||||
|
"roll": [
|
||||||
|
{
|
||||||
"images": "reinaldo_balloon_sao_3000",
|
"images": "reinaldo_balloon_sao_3000",
|
||||||
"duration": 1500
|
"duration": 1500
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"images": "reinaldo_balloon_nao_tenho",
|
"images": "reinaldo_balloon_nao_tenho",
|
||||||
|
|
|
@ -20,9 +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.flatten": "^4.4.0",
|
"lodash": "^4.16.4"
|
||||||
"lodash.flattendeep": "^4.4.0",
|
|
||||||
"lodash.mapvalues": "^4.6.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.17.0",
|
"babel-core": "^6.17.0",
|
||||||
|
|
Loading…
Reference in New Issue