Commit a90ccb4e by Phil Hagelberg

Track wrappers in tiled lib so we can actually work with objects in bump.

parent fa76dd8c
(local lume (require "lib.lume"))
(defn find [map which]
(lume.match map.layers.doors.objects (fn [d] (= which d.name))))
{:open (fn [map which]
(let [door (find map which)]
(when door
;; TODO: ugh we can't change collidable at runtime?!
;; I guess remove the closed door and replace with an open object?
(set door.properties.collidable false))))}
......@@ -61,6 +61,6 @@
sensor.x (- sensor.y sensor.height))))
:draw-doors (fn [layer]
(each [_ door (ipairs layer.objects)]
(love.graphics.draw (if door.properties.collidable
door-img door-open-img)
(love.graphics.draw (if door.properties.open
door-open-img door-img)
door.x (- door.y door.height))))}
......@@ -46,7 +46,7 @@
theta hit.item)]
(if theta2
(do (table.insert segments [x y new-x new-y])
(fire new-x new-y theta2 world segments
(fire new-x new-y theta2 world map segments
[hit.item] (- limit 1)))
(do (table.insert ignore hit.item)
(fire x y theta world map segments ignore limit))))
......@@ -58,7 +58,7 @@
(transparent? hit.item)
(do (table.insert ignore hit.item)
(fire x y theta world map segments ignore limit))
(fire x y theta world map segments ignore limit))
(do (table.insert segments [x y hit.x1 hit.y1])
segments))
......
......@@ -6,6 +6,9 @@
local lg = require((...):gsub('plugins.bump', 'graphics'))
local wrappers = {}
local bump_world = nil
return {
bump_LICENSE = "MIT/X11",
bump_URL = "https://github.com/karai17/Simple-Tiled-Implementation",
......@@ -17,6 +20,7 @@ return {
-- @return collidables table containing the handles to the objects in the Bump world.
bump_init = function(map, world)
local collidables = {}
bump_world = world
for _, tileset in ipairs(map.tilesets) do
for _, tile in ipairs(tileset.tiles) do
......@@ -38,6 +42,7 @@ return {
}
wrappers[object] = t
world:add(t, t.x, t.y, t.width, t.height)
table.insert(collidables, t)
end
......@@ -55,6 +60,7 @@ return {
properties = tile.properties
}
wrappers[tile] = t
world:add(t, t.x, t.y, t.width, t.height)
table.insert(collidables, t)
end
......@@ -82,6 +88,7 @@ return {
properties = object.properties
}
wrappers[object] = t
world:add(t, t.x, t.y, t.width, t.height)
table.insert(collidables, t)
end
......@@ -98,6 +105,7 @@ return {
properties = tile.properties
}
wrappers[tile] = t
world:add(t, t.x, t.y, t.width, t.height)
table.insert(collidables, t)
end
......@@ -123,10 +131,12 @@ return {
properties = obj.properties
}
-- PNH: what the hell?
if obj.gid then
t.y = t.y - obj.height
end
wrappers[obj] = t
world:add(t, t.x, t.y, t.width, t.height)
table.insert(collidables, t)
end -- TODO implement other object shapes?
......@@ -180,7 +190,15 @@ return {
end
lg.pop()
end
end,
-- PNH: we added this so we could work around STI shenanigans and actually
-- perform operations on the world directly. STI wraps each object in a
-- table before adding it to the bump world, so we look up the object in
-- the wrapper mapping before handing off to bump.
bump_wrap = function(method, object, ...)
return bump_world[method](bump_world, wrappers[object], ...)
end,
}
--- Custom Properties in Tiled are used to tell this plugin what to do.
......
;; sensors are represented in tiled as any item on the "sensor" layer.
;; they must have the collidable property set to work.
(local door (require "door"))
(local lume (require "lib.lume"))
(defn open [world map door]
(set door.properties.open true)
;; we can't use an object from the map directly with the bump world, because
;; the map wraps it in another table, so we have to go thru our hacked
;; addition to the map which looks up the wrapper and uses that instead.
(when (map.bump_wrap :hasItem door)
(print :removed)
(map.bump_wrap :remove door)))
(defn activate [world map item]
(set item.properties.on true)
(when item.properties.door
(door.open map item.properties.door)))
(let [d (lume.match map.layers.doors.objects
(fn [d] (= d.name item.properties.door)))]
(open world map d))))
{:is? (fn [item] (and item.properties item.properties.sensor))
:activate activate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment