-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiled-layer.rkt
47 lines (40 loc) · 1.45 KB
/
tiled-layer.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#lang typed/racket/base
(require math/array)
(provide
tiled-layer-order
tiled-layer-properties
tiled-layer-width
tiled-layer-height
build-tiled-layer
for-each-tile
pick-tile)
(struct tiled-layer ([id : Positive-Integer]
[order : Positive-Integer]
[name : String]
[width : Positive-Integer]
[height : Positive-Integer]
[properties : Any]
[data : (Array Nonnegative-Integer)]) #:transparent)
(: build-tiled-layer
(-> Positive-Integer Positive-Integer String Positive-Integer Positive-Integer Any
(-> Indexes Nonnegative-Integer) tiled-layer))
(define (build-tiled-layer id order name width height properties data-proc)
(tiled-layer
id order name width height properties
(build-array
(vector height width)
data-proc)))
(: for-each-tile
(-> tiled-layer
(-> Nonnegative-Integer Nonnegative-Integer Nonnegative-Integer Void)
Void))
(define (for-each-tile layer proc)
(for* ([row (tiled-layer-height layer)]
[col (tiled-layer-width layer)])
(define tile-index (array-ref (tiled-layer-data layer) (vector row col)))
(unless (zero? tile-index)
(proc row col tile-index))))
(: pick-tile
(-> tiled-layer Nonnegative-Integer Nonnegative-Integer Nonnegative-Integer))
(define (pick-tile layer row col)
(array-ref (tiled-layer-data layer) (vector row col)))