client/src/js/automaton.js

144 lines
3.4 KiB
JavaScript

function Automaton(async, dom, messaging, screen, session, ui) {
var menus = {
start: {
entries: [
{label: 'New Game', action: newGame, close: true},
{label: 'Settings', action: settings}
],
cancel: intro,
name: 'start'
},
settings: {
entries: [
{label: 'Buttons', action: ui.setLayout},
{label: 'Text speed', action: function() {
ui.setTextSpeed(choices.textSpeed);
}}
],
cancel: function() {},
name: 'settings'
}
};
var choices = {
name: {
entries: [
{label: 'Alex', value: 'Alex'},
{label: 'Lenore', value: 'Lenore'},
{label: 'Thomas', value: 'Thomas'},
{label: null, size: 15}
],
name: 'name'
},
skin: {
direction: 'horizontal',
entries: [
{picto: {src: 'image/characters/Alex/full.png'}, value: 0},
{picto: {src: 'image/characters/Lenore/full.png'}, value: 1},
{picto: {src: 'image/characters/Thomas/full.png'}, value: 2}
],
name: 'skin'
},
gender: {
entries: [
{label: 'un garçon', value: 'M'},
{label: 'une personne non-binaire', value: 'NB'},
{label: 'une fille', value: 'F'}
],
name: 'gender'
},
textSpeed: {
entries: [
{label: 'Slow', value: 'slow'},
{label: 'Medium', value: 'medium'},
{label: 'Fast', value: 'fast'}
],
cancel: function() {},
name: 'textSpeed'
}
};
var game = session.get('game');
if(game != undefined) {
menus.start.entries.unshift(
{label: 'Continue', action: function() { messaging.send({tag: 'Resume', game: game}); }}
);
}
intro();
return {};
function intro() {
var title = dom.make('p', {textContent: "P O K E M O N", class: 'title'});
var subtitle = dom.make('p', {textContent: "< press start >", class: 'subtitle'});
ui.frame('Intro');
async.run(
ui.cinematic([
{action: function() {}, delay: 500},
{action: function() { screen.show(title); }, delay: 1000},
{action: function() { screen.show(subtitle); }, delay: null}
], {
B: function() { intro(); },
Start: startMenu
})
);
}
function startMenu() {
ui.frame('Start');
ui.menu(menus.start);
}
function settings() {
ui.menu(menus.settings);
}
function newGame() {
var message = { tag: 'Initialize' };
var set = function(key) {
return function(value) {
message[key] = value;
return async.wrap(value);
};
};
ui.frame('GameInit');
messaging.send({tag: 'NewGame'});
async.run(
session.syncGame(),
async.bind(
askName(),
set('name'),
askSkin,
set('skin'),
askGender,
set('gender')
),
async.apply(messaging.send, message),
async.apply(screen.clear, 'text'),
);
}
function askName() {
return async.sequence(
async.sequence(
ui.text("Bonjour ! Bienvenue dans le monde merveilleux des pokémons !"),
ui.text("Pour certains, les pokemons sont des amis. Pour d'autres, ils sont une ressource. Pour ma part, hé bien l'étude des pokémons est mon métier mais aussi ma passion."),
ui.text("Mais, dis-moi, tu viens d'arriver dans la ville non ? Comment t'appelles-tu ?")
),
ui.ask(choices.name)
);
}
function askSkin(name) {
return async.sequence(
ui.text("Ah ? Tu t'appelles " + name + " ? C'est un joli nom, ma foi. Mais je ne te vois pas très bien avec le jour tombant, dis-moi, à quoi ressembles-tu ?"),
ui.ask(choices.skin)
);
}
function askGender() {
return async.sequence(
ui.text("Wow ! Quel super look pour"),
ui.ask(choices.gender)
);
}
}