Merge branch 'main' of tildegit.org:nihilazo/dotsandboxes

This commit is contained in:
Nico 2022-04-07 17:53:56 +01:00
commit c62d8a1653
1 changed files with 6 additions and 13 deletions

View File

@ -238,28 +238,21 @@
; GameState path ! ; GameState path !
; saves a game into the .dbn file format that I just made up. ; saves a game into the .dbn file format that I just made up.
; don't worry, it's sexpy. ; don't worry, it's sexpy.
; TODO write loader
(define (save-game! s filename) (define (save-game! s filename)
(let ([g (GameState-grid s)] (let ([g (GameState-grid s)]
[f (open-output-file filename)]) [f (open-output-file filename)])
(pretty-write (pretty-write
(quasiquote `((player0 ,(player-name (first (GameState-players s))))
((player0 (player1 ,(player-name (second (GameState-players s))))
(unquote (player-name (first (GameState-players s))))) (grid ,(grid-width g) ,(grid-height g))
(player1 (score ,(first (GameState-scores s)) ,(second (GameState-scores s)))
(unquote (player-name (second (GameState-players s)))))
(grid
(unquote (grid-width g)) (unquote (grid-height g)))
(score
(unquote (first (GameState-scores s))) (unquote (second (GameState-scores s))))
(lines (lines
(unquote (for/list ([l (grid-lines g)]) ,((for/list ([l (grid-lines g)])
(list (point-x (line-from l)) (point-y (line-from l)) (point-x (line-to l)) (point-y (line-to l)) (line-player l))))))) f) (list (point-x (line-from l)) (point-y (line-from l)) (point-x (line-to l)) (point-y (line-to l)) (line-player l)))))) f)
(close-output-port f))) (close-output-port f)))
; path -> GameState ; path -> GameState
; loads a game from a .dbn file into a GameState structure ; loads a game from a .dbn file into a GameState structure
; TODO lines, scores, etc
(define (load-game! p) (define (load-game! p)
(let* ([f (open-input-file p)] (let* ([f (open-input-file p)]
[data (read f)]) [data (read f)])