aboutsummaryrefslogtreecommitdiff
path: root/src/tilemap.scm
blob: a2833db8d5075024fcd2515ce652f50f53a3ea64 (plain)
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
48
49
50
51
52
53
54
(module tilemap
*
(import scheme
	(chicken io)
	expat
	defstruct)

(defstruct tileset
  tilewidth
  tileheight
  spacing
  tilecount
  columns
  image)

(defstruct layer
  name
  width
  height
  map)

(defstruct object
  name
  type
  x
  y
  width
  height
  properties)

(defstruct tilemap
  width
  height
  tilewidth
  tileheight
  tileset
  layers
  objects)

(define (parse-tilemap string-tilemap)
  (let ((parser (expat:make-parser))
	(current-tag "")
	(tilemap (tilemap)))
    (expat:set-start-handler! parser (lambda (tag attrs)
				       (set! current-tag tag)))
    (expat:set-end-handler! parser (lambda (tag) #f))
    (expat:set-character-data-handler! parser (lambda (text) #f))))

(define (load-tilemap file-name)
  (call-with-input-file file-name
    (lambda (port)
      (parse-tilemap (read-string port)))))

) ;; End tilemap module