implement sane page changing
This commit is contained in:
34
main.sex
34
main.sex
@@ -20,7 +20,10 @@
|
|||||||
(return)))))
|
(return)))))
|
||||||
|
|
||||||
(pub record app-state
|
(pub record app-state
|
||||||
((page page)))
|
((page page)
|
||||||
|
;; TODO: fix macro expansion in fields!!!
|
||||||
|
;; Should've been (tag-type page). Fuck!!!!
|
||||||
|
(target-page (enum pageǂ))))
|
||||||
|
|
||||||
(import menu)
|
(import menu)
|
||||||
(import game)
|
(import game)
|
||||||
@@ -29,25 +32,30 @@
|
|||||||
;; TODO: add force arg to override changing to self protection
|
;; TODO: add force arg to override changing to self protection
|
||||||
(pub fn change-page ((self (* app-state))
|
(pub fn change-page ((self (* app-state))
|
||||||
(target (tag-type page))) void
|
(target (tag-type page))) void
|
||||||
(if (= (. self page tag) target)
|
(= (. self target-page) target))
|
||||||
|
|
||||||
|
(fn change-page- ((self (* app-state))) void
|
||||||
|
(if (== (. self page tag) (. self target-page))
|
||||||
;; Don't change page to itself
|
;; Don't change page to itself
|
||||||
(return))
|
(return))
|
||||||
(match (. self page)
|
(match (. self page)
|
||||||
((menu (state)) (rm-menu state))
|
((menu (state)) (rm-menu state))
|
||||||
((game (state)) (rm-game state)))
|
((game (state)) (rm-game state)))
|
||||||
(if (== target (sum-type page menu))
|
(if (== (. self target-page) (sum-type page menu))
|
||||||
(= (. self page) (mk-menu self)))
|
(= (. self page) (mk-menu self)))
|
||||||
(if (== target (sum-type page game))
|
(if (== (. self target-page) (sum-type page game))
|
||||||
(= (. self page) (mk-game self)))))
|
(= (. self page) (mk-game self)))))
|
||||||
|
|
||||||
(fn main-loop ((state (* app-state))) void
|
(fn main-loop ((void-state (* void))) void
|
||||||
|
(var state _ (cast void-state (* app-state)))
|
||||||
|
(.change-page- state)
|
||||||
(match (. state page)
|
(match (. state page)
|
||||||
((menu (state))
|
((menu (state))
|
||||||
(render-menu state)
|
(process-input-menu state)
|
||||||
(process-input-menu state))
|
(render-menu state))
|
||||||
((game (state))
|
((game (state))
|
||||||
(render-game state)
|
(process-input-game state)
|
||||||
(process-input-game state))))
|
(render-game state))))
|
||||||
|
|
||||||
(fn init () void
|
(fn init () void
|
||||||
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
||||||
@@ -66,9 +74,9 @@
|
|||||||
(init)
|
(init)
|
||||||
(if (!= error 0)
|
(if (!= error 0)
|
||||||
(return error))
|
(return error))
|
||||||
(var state _ #(app-state : (mk-menu (& state))))
|
(var state _ #(app-state : (mk-menu (& state)) (sum-type page menu)))
|
||||||
(while (! (WindowShouldClose))
|
(while (! (WindowShouldClose))
|
||||||
(main-loop (& state)))
|
(main-loop (cast (& state) (* void))))
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|
||||||
#+emscripten
|
#+emscripten
|
||||||
@@ -77,6 +85,6 @@
|
|||||||
#+emscripten
|
#+emscripten
|
||||||
(pub fn main ((argc int) (argv [* const char])) int
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
(init)
|
(init)
|
||||||
(var state _ #(app-state : (mk-menu (& state))))
|
(var state _ #(app-state : (mk-menu (& state)) (sum-type page menu)))
|
||||||
(emscripten-set-main-loop-arg (cast (* void) (& state)) main-loop 0 true)
|
(emscripten-set-main-loop-arg main-loop (cast (& state) (* void)) 0 true)
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user