-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtilemap.coffee
More file actions
56 lines (40 loc) · 1.48 KB
/
tilemap.coffee
File metadata and controls
56 lines (40 loc) · 1.48 KB
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
55
56
( ->
Map = (data, entityCallback) ->
tileHeight = data.tileHeight
tileWidth = data.tileWidth
spriteLookup = {}
for uuid, entity of App.entities
spriteLookup[uuid] = Sprite.fromURL(entity.tileSrc)
loadEntities = () ->
return unless entityCallback
data.layers.each (layer, layerIndex) ->
if instances = layer.instances
for instance in instances
{x, y, uuid} = instance
instanceData = Object.extend(
layer: layerIndex
sprite: spriteLookup[uuid]
x: x + tileWidth/2 # Centered Coordinates
y: y + tileHeight/2 # Centered Coordinates
, App.entities[uuid] # Global entity properties
#TODO: Maybe map specific properties?
, instance.properties) # Instance properties
entityCallback(instanceData)
loadEntities()
data
Tilemap = (name, callback, entityCallback) ->
fromPixieId(App.Tilemaps[name], callback, entityCallback)
loadByName = (name, callback, entityCallback) ->
url = ResourceLoader.urlFor("tilemaps", name)
proxy = {}
$.getJSON url, (data) ->
Object.extend(proxy, Map(data, entityCallback))
callback? proxy
return proxy
Tilemap.load = (options) ->
if options.pixieId
fromPixieId options.pixieId, options.complete, options.entity
else if options.name
loadByName options.name, options.complete, options.entity
(exports ? this)["Tilemap"] = Tilemap
)()