2018-11-20 15:56:28 +01:00
function Automaton ( async , dom , messaging , screen , session , ui ) {
2018-11-18 23:08:36 +01:00
var menus = {
start : {
entries : [
2018-12-14 23:37:07 +01:00
{ label : 'New Game' , action : newGame , close : true } ,
2018-11-30 14:51:42 +01:00
{ label : 'Settings' , action : settings }
2018-11-18 23:08:36 +01:00
] ,
2018-11-29 22:22:25 +01:00
cancel : intro ,
name : 'start'
2018-11-30 14:51:42 +01:00
} ,
settings : {
entries : [
{ label : 'Buttons' , action : ui . setLayout } ,
{ label : 'Text speed' , action : function ( ) {
ui . setTextSpeed ( choices . textSpeed ) ;
} }
] ,
2018-12-15 22:33:49 +01:00
cancel : function ( ) { } ,
2018-11-30 14:51:42 +01:00
name : 'settings'
2018-11-29 22:22:25 +01:00
}
} ;
var choices = {
2018-11-18 23:08:36 +01:00
name : {
2018-11-29 22:22:25 +01:00
entries : [
2018-12-10 23:06:18 +01:00
{ label : 'Alex' , value : 'Alex' } ,
2018-11-29 22:22:25 +01:00
{ label : 'Lenore' , value : 'Lenore' } ,
{ label : 'Thomas' , value : 'Thomas' } ,
{ label : null , size : 15 }
] ,
name : 'name'
2018-11-18 23:08:36 +01:00
} ,
skin : {
2018-12-17 12:31:03 +01:00
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'
2018-11-30 14:51:42 +01:00
} ,
textSpeed : {
entries : [
{ label : 'Slow' , value : 'slow' } ,
{ label : 'Medium' , value : 'medium' } ,
{ label : 'Fast' , value : 'fast' }
] ,
cancel : function ( ) { } ,
name : 'textSpeed'
2018-11-18 23:08:36 +01:00
}
} ;
var game = session . getGame ( ) ;
if ( game != undefined ) {
menus . start . entries . unshift (
{ label : 'Continue' , action : function ( ) { messaging . send ( { tag : 'Resume' , game : game } ) ; } }
) ;
2018-11-17 19:07:58 +01:00
}
2018-12-02 19:50:23 +01:00
intro ( ) ;
2018-11-17 19:07:58 +01:00
2018-12-02 19:50:23 +01:00
return { } ;
2018-11-18 23:08:36 +01:00
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' } ) ;
2018-11-20 15:56:28 +01:00
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 }
] , {
2018-11-29 22:22:25 +01:00
B : function ( ) { intro ( ) ; } ,
2018-11-30 14:51:42 +01:00
Start : startMenu
2018-11-20 15:56:28 +01:00
} )
) ;
2018-11-18 23:08:36 +01:00
}
2018-11-30 14:51:42 +01:00
function startMenu ( ) {
ui . frame ( 'Start' ) ;
ui . menu ( menus . start ) ;
}
function settings ( ) {
ui . menu ( menus . settings ) ;
}
2018-11-18 23:08:36 +01:00
function newGame ( ) {
2018-12-14 23:42:37 +01:00
var message = { tag : 'Initialize' } ;
var set = function ( key ) {
return function ( value ) {
message [ key ] = value ;
return async . wrap ( value ) ;
} ;
} ;
2018-11-20 15:56:28 +01:00
ui . frame ( 'GameInit' ) ;
2018-12-02 19:50:23 +01:00
messaging . send ( { tag : 'NewGame' } ) ;
2018-11-18 23:08:36 +01:00
async . run (
2018-12-14 23:42:37 +01:00
session . update ( ) ,
async . bind (
askName ( ) ,
set ( 'name' ) ,
askSkin ,
set ( 'skin' ) ,
askGender ,
set ( 'gender' )
) ,
2018-12-17 12:31:03 +01:00
async . apply ( messaging . send , message ) ,
async . apply ( screen . clear , 'text' ) ,
2018-12-02 19:50:23 +01:00
) ;
}
2018-12-14 23:42:37 +01:00
function askName ( ) {
2018-12-02 19:50:23 +01:00
return async . sequence (
2018-12-14 23:42:37 +01:00
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 ?" )
2018-12-02 19:50:23 +01:00
) ,
2018-12-14 23:42:37 +01:00
ui . ask ( choices . name )
2018-11-18 23:08:36 +01:00
) ;
}
2018-12-02 19:50:23 +01:00
2018-12-14 23:42:37 +01:00
function askSkin ( name ) {
2018-12-02 19:50:23 +01:00
return async . sequence (
2018-12-14 23:42:37 +01:00
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 ?" ) ,
2018-12-17 12:31:03 +01:00
ui . ask ( choices . skin )
2018-12-02 19:50:23 +01:00
) ;
}
2018-12-14 23:42:37 +01:00
function askGender ( ) {
return async . sequence (
2018-12-17 12:31:03 +01:00
ui . text ( "Wow ! Quel super look pour" ) ,
ui . ask ( choices . gender )
2018-12-14 23:42:37 +01:00
) ;
2018-12-02 19:50:23 +01:00
}
2018-11-17 19:07:58 +01:00
}