polf/systems/collision-resolution.lua

46 lines
1.7 KiB
Lua

filteredSystem("activated", { activated = T.Entity }, function(e, _, system)
local activated = e.activated
if activated.addOnActivate then
for _, toAdd in ipairs(activated.addOnActivate) do
system.world:addEntity(toAdd)
end
end
if activated.pickedUpOnClick and #HeldByCursor.entities == 0 then
activated.placedOnClick = T.marker
activated.moveWithCursor = T.marker
activated.canBeCollidedBy = 0
system.world:addEntity(activated)
elseif activated.gridPosition then
for _, held in pairs(HeldByCursor.entities) do
held.placedOnClick = nil
held.moveWithCursor = nil
held.highlighted = nil
held.canBeCollidedBy = CursorMask
Replace(activated, held)
end
end
system.world:removeEntity(e)
end)
Collisions = filteredSystem("collisionResolution", { collisionBetween = T.Collision }, function(e, _, system)
local collidedInto, collider = e.collisionBetween[1], e.collisionBetween[2]
if collider.highlightsCollided then
if collidedInto.unhighlightSiblings then
for sibling in pairs(collidedInto.unhighlightSiblings) do
sibling.highlighted = nil
sibling.canReceiveButtons = nil
system.world:addEntity(sibling)
end
end
if collidedInto.highlightOnMouseOver ~= nil then
collidedInto.highlighted = T.marker
collidedInto.canReceiveButtons = T.marker
system.world:addEntity(collidedInto)
end
if MouseJustPressed(1, true) and collider.isCursor then
system.world:addEntity({ activated = collidedInto })
end
end
system.world:removeEntity(e)
end)