Skip to content

Commit

Permalink
Fix map format for chunk children, falling platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jul 5, 2019
1 parent 13b4b78 commit c845845
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions versions/v0.lisp
Expand Up @@ -33,12 +33,15 @@
`(player :location ,(encode (location player))))

(define-decoder (chunk v0) (initargs packet)
(destructuring-bind (&key name location size tileset layers) initargs
(make-instance 'chunk :name name
:location (decode 'vec2 location)
:size (decode 'vec2 size)
:tileset (decode 'asset tileset)
:layers (loop for file in layers collect (load-packet-file packet file T)))))
(destructuring-bind (&key name location size tileset layers children) initargs
(let ((chunk (make-instance 'chunk :name name
:location (decode 'vec2 location)
:size (decode 'vec2 size)
:tileset (decode 'asset tileset)
:layers (loop for file in layers collect (load-packet-file packet file T)))))
(loop for (type . initargs) in children
do (enter (decode type initargs) chunk))
chunk)))

(define-encoder (chunk v0) (_b packet)
(let ((layers (loop for i from 0
Expand All @@ -47,12 +50,15 @@
for path = (format NIL "resources/~a-~d.raw" (name chunk) i)
for stream = (make-instance 'fast-io:fast-input-stream :vector layer)
do (zip:write-zipentry packet path stream :file-write-date (get-universal-time))
collect path)))
collect path))
(children (for:for ((entity over chunk)
(_ collect (encode entity))))))
`(chunk :name ,(name chunk)
:location ,(encode (location chunk))
:size ,(encode (size chunk))
:tileset ,(encode (tileset chunk))
:layers ,layers)))
:layers ,layers
:children ,children)))

(define-decoder (background v0) (initargs _)
(destructuring-bind (&key texture) initargs
Expand All @@ -61,6 +67,18 @@
(define-encoder (background v0) (_b _p)
`(background :texture ,(encode (texture background))))

(define-decoder (falling-platform v0) (initargs _)
(destructuring-bind (&key texture acceleration location) initargs
(make-instance 'falling-platform
:texture (decode 'asset texture)
:acceleration (decode 'vec2 acceleration)
:location (decode 'vec2 location))))

(define-encoder (falling-platform v0) (_b _p)
`(falling-platform :texture ,(encode (texture falling-platform))
:acceleration ,(encode (acceleration falling-platform))
:location ,(encode (location falling-platform))))

(define-decoder (vec2 v0) (data _p)
(destructuring-bind (x y) data
(vec2 x y)))
Expand Down

0 comments on commit c845845

Please sign in to comment.