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 : [
{ label : 'New Game' , action : newGame } ,
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 ) ;
} }
] ,
cancel : startMenu ,
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 : [
{ label : 'Max' , value : 'Max' } ,
{ label : 'Lenore' , value : 'Lenore' } ,
{ label : 'Thomas' , value : 'Thomas' } ,
{ label : null , size : 15 }
] ,
name : 'name'
2018-11-18 23:08:36 +01:00
} ,
skin : {
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 ( ) {
screen . clear ( ) ;
ui . menu ( menus . settings ) ;
}
2018-11-18 23:08:36 +01:00
function newGame ( ) {
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-02 19:50:23 +01:00
async . bind ( setName ( ) , setSkin )
) ;
}
function setName ( ) {
return async . sequence (
async . parallel (
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 ?" )
) ,
session . update ( )
) ,
2018-11-29 22:22:25 +01:00
async . bind ( ui . ask ( choices . name ) , function ( name ) {
screen . clear ( 'text' ) ;
2018-12-02 19:50:23 +01:00
messaging . send ( {
tag : 'Initialize' ,
step : 'Name' ,
value : name
} ) ;
return async . sequence (
session . update ( ) ,
async . wrap ( name )
) ;
2018-11-29 22:22:25 +01:00
} )
2018-11-18 23:08:36 +01:00
) ;
}
2018-12-02 19:50:23 +01:00
function setSkin ( 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 ?" )
) ;
}
function setGender ( ) {
}
2018-11-17 19:07:58 +01:00
}