commit
29c860b90f
151
app/director.js
151
app/director.js
|
@ -21,6 +21,7 @@
|
||||||
return accumulator;
|
return accumulator;
|
||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
let scenes = requireScenes(require.context('../assets/scenes', true, /\.json$/));
|
let scenes = requireScenes(require.context('../assets/scenes', true, /\.json$/));
|
||||||
|
|
||||||
/* map object with scene definitions obtained above into object
|
/* map object with scene definitions obtained above into object
|
||||||
|
@ -31,56 +32,91 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* enable user input */
|
||||||
|
Director.prototype.enableUserInput = function(userChoices, afterChoice) {
|
||||||
|
|
||||||
|
/* create user input area */
|
||||||
|
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>`;
|
||||||
|
return accumulator;
|
||||||
|
}, '');
|
||||||
|
|
||||||
|
/* define and add event listeners */
|
||||||
|
/* * keyboard key listener * */
|
||||||
|
this.keyListener = function(event) {
|
||||||
|
|
||||||
|
let actions = userChoices.reduce((accumulator, choice) => {
|
||||||
|
accumulator[choice.keyCode] = choice.name;
|
||||||
|
return accumulator;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
let action = actions[event.keyCode];
|
||||||
|
|
||||||
|
if (action) {
|
||||||
|
afterChoice(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
/* * add event listener */
|
||||||
|
window.addEventListener('keydown', this.keyListener, false);
|
||||||
|
|
||||||
|
/* * mouse and touch listener */
|
||||||
|
this.mouseTouchListener = function(event) {
|
||||||
|
let action = this.getAttribute('data-action');
|
||||||
|
afterChoice(action);
|
||||||
|
};
|
||||||
|
/* LOL there is no forEach in DOM NodeList
|
||||||
|
* http://stackoverflow.com/questions/13433799/why-doesnt-nodelist-have-foreach */
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName('user-action'), (element) => {
|
||||||
|
|
||||||
|
/* add event listeners */
|
||||||
|
element.addEventListener('mouseup', this.mouseTouchListener, false);
|
||||||
|
element.addEventListener('touchup', this.mouseTouchListener, false);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* disable user input */
|
||||||
|
Director.prototype.disableUserInput = function() {
|
||||||
|
|
||||||
|
/* add event listeners */
|
||||||
|
window.removeEventListener('keydown', this.keyListener, false);
|
||||||
|
delete this.keyListener;
|
||||||
|
|
||||||
|
/* see in enableUserInput above */
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName('user-action'), (element) => {
|
||||||
|
|
||||||
|
/* remove event listeners */
|
||||||
|
element.removeEventListener('mouseup', this.mouseTouchListener, false);
|
||||||
|
element.removeEventListener('touchup', this.mouseTouchListener, false);
|
||||||
|
|
||||||
|
});
|
||||||
|
delete this.mouseTouchListener;
|
||||||
|
|
||||||
|
/* remove user input area */
|
||||||
|
document.getElementById('ul-teclas').innerHTML = '';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* begins the game (actually runs the whole game) */
|
/* begins the game (actually runs the whole game) */
|
||||||
/* @TODO lol everything is implemented here, if this needs to grow it will become ugly
|
/* @TODO lol everything is implemented here, if this needs to grow it will become ugly
|
||||||
* think about refactoring all the code in here later */
|
* think about refactoring all the code in here later */
|
||||||
Director.prototype.begin = function() {
|
Director.prototype.begin = function() {
|
||||||
|
|
||||||
/* enable user input */
|
/* defines which scenes can be chosen */
|
||||||
let enableUserInput = () => {
|
let userChoices = [
|
||||||
|
{ 'name': 'anal', keyCode: 67, key: 'c' },
|
||||||
|
{ 'name': 'vaginal', keyCode: 70, key: 'f' },
|
||||||
|
{ 'name': 'oral', keyCode: 66, key: 'b' }
|
||||||
|
];
|
||||||
|
|
||||||
/* add event listeners */
|
/* when user chooses action, function this is to be called */
|
||||||
window.addEventListener('keydown', keyListener, false);
|
let afterChoice = (scene) => {
|
||||||
|
|
||||||
/* LOL there is no forEach in DOM NodeList
|
this.disableUserInput();
|
||||||
* http://stackoverflow.com/questions/13433799/why-doesnt-nodelist-have-foreach */
|
|
||||||
Array.prototype.forEach.call(document.getElementsByClassName('user-action'), (element) => {
|
|
||||||
|
|
||||||
/* add event listeners */
|
|
||||||
element.addEventListener('mouseup', mouseListener, false);
|
|
||||||
element.addEventListener('touchup', touchListener, false);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/* hide user input area */
|
|
||||||
document.getElementById('ul-teclas').className = '';
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/* disable user input */
|
|
||||||
let disableUserInput = () => {
|
|
||||||
|
|
||||||
/* add event listeners */
|
|
||||||
window.removeEventListener('keydown', keyListener, false);
|
|
||||||
|
|
||||||
/* see above */
|
|
||||||
Array.prototype.forEach.call(document.getElementsByClassName('user-action'), (element) => {
|
|
||||||
|
|
||||||
/* remove event listeners */
|
|
||||||
element.removeEventListener('mouseup', mouseListener, false);
|
|
||||||
element.removeEventListener('touchup', touchListener, false);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/* hide user input area */
|
|
||||||
document.getElementById('ul-teclas').className = 'hidden';
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/* consequence of user action (key pressed) */
|
|
||||||
let choice = (scene) => {
|
|
||||||
|
|
||||||
disableUserInput();
|
|
||||||
|
|
||||||
/* play the selected choice screen */
|
/* play the selected choice screen */
|
||||||
this.scenes['choice_' + scene].play()
|
this.scenes['choice_' + scene].play()
|
||||||
|
@ -92,37 +128,10 @@
|
||||||
.then(main);
|
.then(main);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* keydown window event listener */
|
|
||||||
let keyListener = function(event) {
|
|
||||||
|
|
||||||
let actions = {
|
|
||||||
67: 'anal',
|
|
||||||
70: 'vaginal',
|
|
||||||
66: 'oral'
|
|
||||||
};
|
|
||||||
|
|
||||||
let action = actions[event.keyCode];
|
|
||||||
|
|
||||||
if (action) {
|
|
||||||
choice(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
let mouseListener = function(event) {
|
|
||||||
let action = this.getAttribute('data-action');
|
|
||||||
choice(action);
|
|
||||||
};
|
|
||||||
|
|
||||||
let touchListener = function(event) {
|
|
||||||
let action = this.getAttribute('data-action');
|
|
||||||
choice(action);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* the game starts by calling this */
|
/* the game starts by calling this */
|
||||||
let main = () => {
|
let main = () => {
|
||||||
return this.scenes.choice.play()
|
return this.scenes.choice.play()
|
||||||
.then(enableUserInput);
|
.then(() => this.enableUserInput(userChoices, afterChoice));
|
||||||
};
|
};
|
||||||
|
|
||||||
return main();
|
return main();
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/* polyfill es6 promise */
|
||||||
|
require('es6-promise').polyfill();
|
||||||
|
|
||||||
/* css stuff */
|
/* css stuff */
|
||||||
require('../assets/style.scss');
|
require('../assets/style.scss');
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul id="ul-teclas">
|
<ul id="ul-teclas">
|
||||||
<li class="user-action" id="li-anal" data-action="anal">c<div>anal</div></li>
|
|
||||||
<li class="user-action" id="li-vaginal" data-action="vaginal">f<div>vaginal</div></li>
|
|
||||||
<li class="user-action" id="li-oral" data-action="oral">b<div>oral</div></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -19,10 +19,14 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/falsovsky/paradise.js#readme",
|
"homepage": "https://github.com/falsovsky/paradise.js#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"es6-promise": "^4.0.5",
|
||||||
"lodash.flattendeep": "^4.4.0",
|
"lodash.flattendeep": "^4.4.0",
|
||||||
"lodash.mapvalues": "^4.6.0"
|
"lodash.mapvalues": "^4.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-core": "^6.17.0",
|
||||||
|
"babel-loader": "^6.2.5",
|
||||||
|
"babel-preset-es2015": "^6.16.0",
|
||||||
"css-loader": "^0.25.0",
|
"css-loader": "^0.25.0",
|
||||||
"file-loader": "^0.9.0",
|
"file-loader": "^0.9.0",
|
||||||
"handlebars": "^4.0.5",
|
"handlebars": "^4.0.5",
|
||||||
|
|
|
@ -12,6 +12,14 @@ module.exports = {
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: /(node_modules|bower_components)/,
|
||||||
|
loader: 'babel',
|
||||||
|
query: {
|
||||||
|
presets: ['es2015']
|
||||||
|
}
|
||||||
|
},
|
||||||
{ test: /\.css$/, loader: "style!css" },
|
{ test: /\.css$/, loader: "style!css" },
|
||||||
{ test: /\.json$/, loader: "json" },
|
{ test: /\.json$/, loader: "json" },
|
||||||
{ test: /\.hbs$/, loader: "handlebars-loader" },
|
{ test: /\.hbs$/, loader: "handlebars-loader" },
|
||||||
|
|
Loading…
Reference in New Issue