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 !
; saves a game into the .dbn file format that I just made up.
; don't worry, it's sexpy.
; TODO write loader
(define (save-game! s filename)
(let ([g (GameState-grid s)]
[f (open-output-file filename)])
(pretty-write
(quasiquote
((player0
(unquote (player-name (first (GameState-players s)))))
(player1
(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))))
`((player0 ,(player-name (first (GameState-players s))))
(player1 ,(player-name (second (GameState-players s))))
(grid ,(grid-width g) ,(grid-height g))
(score ,(first (GameState-scores s)) ,(second (GameState-scores s)))
(lines
(unquote (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)
,((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)
(close-output-port f)))
; path -> GameState
; loads a game from a .dbn file into a GameState structure
; TODO lines, scores, etc
(define (load-game! p)
(let* ([f (open-input-file p)]
[data (read f)])