Skip to content

Commit df9e359

Browse files
author
Klayton Kowalski
committed
Added set_tile() function for manipulating a tilemap that is currently being managed by DTA. Very useful!
1 parent 2a36afd commit df9e359

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

dta/dta.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ function dta.animate(x, y, layer)
213213
end
214214
end
215215

216+
function dta.set_tile(layer, x, y, tile, h_flipped, v_flipped)
217+
if not dta.initialized then return end
218+
local group = dta.animation_groups[dta.tilemap_grid[layer][y][x]]
219+
if group ~= nil then
220+
for i = 1, #group.instances do
221+
if group.instances[i].x == x and group.instances[i].y == y and group.instances[i].layer then
222+
if group.trigger then
223+
if group.instances[i].handle ~= nil then
224+
timer.cancel(group.instances[i].handle)
225+
end
226+
end
227+
table.remove(group.instances, i)
228+
break
229+
end
230+
end
231+
end
232+
tilemap.set_tile(dta.tilemap_url, layer, x, y, tile, h_flipped, v_flipped)
233+
dta.tilemap_grid[layer][y][x] = tile
234+
if dta.animation_groups[tile] ~= nil then
235+
if dta.animation_groups[tile].trigger then
236+
table.insert(dta.animation_groups[tile].instances, { x = x, y = y, layer = layer, frame = 1, handle = nil })
237+
else
238+
table.insert(dta.animation_groups[tile].instances, { x = x, y = y, layer = layer })
239+
end
240+
end
241+
end
242+
216243
function dta.toggle_message_passing(flag, url)
217244
dta.msg_passing = flag
218245
dta.msg_passing_url = url

example/script.script

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local tile_size = 80
55
local h_str = {
66
acquire_input_focus = hash("acquire_input_focus"),
77
click = hash("click"),
8+
click_debug = hash("click_debug"),
89
terrain = hash("terrain")
910
}
1011

@@ -19,6 +20,9 @@ function on_input(self, action_id, action)
1920
local x = math.ceil(action.x / tile_size)
2021
local y = math.ceil(action.y / tile_size)
2122
dta.animate(x, y)
23+
elseif action_id == h_str.click_debug and action.pressed then
24+
-- ignore
25+
-- this space is used for development testing
2226
end
2327
end
2428

input/game.input_binding

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ mouse_trigger {
22
input: MOUSE_BUTTON_LEFT
33
action: "click"
44
}
5+
mouse_trigger {
6+
input: MOUSE_BUTTON_RIGHT
7+
action: "click_debug"
8+
}

0 commit comments

Comments
 (0)