-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapStringGenerator.lua
More file actions
157 lines (125 loc) · 3.64 KB
/
MapStringGenerator.lua
File metadata and controls
157 lines (125 loc) · 3.64 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local sti = require "assets/MapStringGenerator/sti"
layerInfo ={}
layerInfo.layerWidth = 0
layerInfo.layerHeight = 0
local map_loaded = false
local map = nil
function getMapString(map_path, layer_name, main_layer)
-- Load a map exported to Lua from Tiled
if not map_loaded then
map = sti.new(map_path, nil)
map_loaded = true
end
-- Create a Custom Layer
--map:addCustomLayer("Sprite Layer", 3)
-- Add data to Custom Layer
local tileLayer = map.layers[layer_name]
--local itemLayer = map.layers["BlocksAndPushables"]
local mapString = [[]]
if tileLayer == nil then
return mapString .. "!"
end
--for _,layers in ipairs(tileLayer) do
local tileData = tileLayer.data
for y = 1,tileLayer.height do
for x = 1,tileLayer.width do
if tileData[y][x] ~= nil then
mapString = mapString .. tileData[y][x].properties["tilechar"]
--mapString = mapString .. "b"
else
mapString = mapString .. "z"
end
end
mapString = mapString .. "\n"
end
--set up the layer info for the camera
if main_layer then
layerInfo.layerHeight = tileLayer.height*32
layerInfo.layerWidth = tileLayer.width*32
end
return mapString
end
function resetMap()
map_loaded = false
map = nil
end
function loadDoors(map_path)
if not map_loaded then
map = sti.new(map_path, nil)
map_loaded = true
end
local doorObjects = map.layers["Door Layer"].objects
local doors = {}
for _,obj in ipairs(doorObjects) do
local door = {}
door.x = obj.x
door.y = obj.y
door.width = obj.width
door.height = obj.height
door.destination = obj.properties["destination"]
door.position = obj.properties["position"]
--if door.position == "right" then door.x = door.x - door.width end
table.insert(doors,door)
print(door.x)
end
return doors
end
function getMapTileset(map_path, tileset_name)
-- Load a map exported to Lua from Tiled
if not map_loaded then
map = sti.new(map_path, nil)
map_loaded = true
end
-- Create a Custom Layer
--map:addCustomLayer("Sprite Layer", 3)
-- Add data to Custom Layer
local tileset = nil
for _,tiles in ipairs(map.tilesets) do
if tiles.name == tileset_name then
tileset = tiles
end
end
if tileset == nil then
return
end
local quadInfo = {}
local function getTiles(i, t, m, s)
i = i - m
local n = 0
while i >= t do
i = i - t
if n ~= 0 then i = i - s end
if i >= 0 then n = n + 1 end
end
return n
end
local quad = love.graphics.newQuad
local mw = 32
local iw = tileset.imagewidth
local ih = tileset.imageheight
local tw = tileset.tilewidth
local th = tileset.tileheight
local s = tileset.spacing
local m = tileset.margin
local w = getTiles(iw, tw, m, s)
local h = getTiles(ih, th, m, s)
local tileinfo = tileset.tiles
local charlist = {}
for _,tile in ipairs(tileinfo) do
if tile.properties["tilechar"] ~= nil then
table.insert(charlist,tile.properties["tilechar"])
else table.insert(charlist,"!")
print("ha")
end
end
for y = 1,h do
for x = 1,w do
local char = table.remove(charlist,1)
local info = {char,(x-1)*32,(y-1)*32}
table.insert(quadInfo,info)
end
end
return quadInfo
end
function getMapQuads()
end