-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.go
42 lines (34 loc) · 790 Bytes
/
lib.go
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
package ldtkbridgego
// Return all json data of a LDtk Level with a given name
func (world *LdtkJSON) GetLevelByName(name string) *Level {
for _, l := range world.Levels {
if l.Identifier == name {
return &l
}
}
return nil
}
func (world *LdtkJSON) GetLevelIndex(name string) int {
for index, l := range world.Levels {
if l.Identifier == name {
return index
}
}
return -1
}
func (level *Level) GetLayerByName(name string) *LayerInstance {
for _, layer := range level.LayerInstances {
if layer.Identifier == name {
return &layer
}
}
return nil
}
func (layer *LayerInstance) GetInt(x, y int) int {
if x < 0 || x > layer.CWid-1 || y < 0 || y > layer.CHei-1 {
// Check if out of level
return -1
} else {
return layer.IntGridCsv[x+y*layer.CWid]
}
}