]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/game/worlds/worlds.factor
factor: trim using lists
[factor.git] / extra / game / worlds / worlds.factor
index f8b3ae8587bbb00145f8e637090979ab81da5c86..5fdc110783be0342519daf92ea36a0b6b497220a 100644 (file)
@@ -1,7 +1,9 @@
-! (c)2009 Joe Groff bsd license
-USING: accessors combinators fry game.input game.loop generic kernel math
-parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
-words audio.engine destructors ;
+! Copyright (C) 2009 Joe Groff.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors audio.engine combinators concurrency.promises
+destructors game.input game.loop kernel math parser sequences
+threads ui ui.gadgets ui.gadgets.worlds vocabs.parser
+words.constant ;
 IN: game.worlds
 
 TUPLE: game-world < world
@@ -48,7 +50,7 @@ M: game-world begin-world
     [ >>game-loop begin-game-world ] keep start-loop ;
 
 M: game-world end-world
-    [ [ stop-loop ] when* f ] change-game-loop
+    dup game-loop>> [ stop-loop ] when*
     [ end-game-world ]
     [ audio-engine>> [ dispose ] when* ]
     [ use-game-input?>> [ close-game-input ] when ] tri ;
@@ -70,8 +72,18 @@ M: game-world apply-world-attributes
         [ call-next-method ]
     } cleave ;
 
+: start-game ( attributes -- game-world )
+    f swap open-window* ;
+
+: wait-game ( attributes -- game-world )
+    f swap open-window* dup promise>> ?promise drop ;
+
+: define-attributes-word ( word tuple -- )
+    [ name>> "-attributes" append create-word-in ] dip define-constant ;
+
 SYNTAX: GAME:
-    CREATE
-    game-attributes parse-main-window-attributes
+    scan-new-word
+    game-attributes parse-window-attributes
+    2dup define-attributes-word
     parse-definition
-    define-main-window ;
+    [ define-window ] [ 2drop current-vocab main<< ] 3bi ;