collision-mask-util.lua:
Code: Select all
collision_mask_util.masks_collide = function(mask_1, mask_2)
local map = util.list_to_map(mask_1)
if map["not-colliding-with-itself"] and collision_mask_util.masks_are_same(mask_1, mask_2) then
return false
end
clear_flags(map)
for k, layer in pairs (mask_2) do
if map[layer] then
return true
end
end
return false
end
collision_mask_util.masks_are_same = function(mask_1, mask_2)
local map = util.list_to_map(mask_1)
for k, v in pairs (mask_2) do
if not map[v] then return false end
map[v] = nil
end
return not next(map)
end
Code: Select all
log("Test 1: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"object-layer"})))
log("Test 2: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"not-colliding-with-itself", "object-layer"})))
log("Test 3: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"not-colliding-with-itself", "consider-tile-transitions", "object-layer"})))
log("Test 4: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "consider-tile-transitions", "object-layer"}, {"not-colliding-with-itself", "object-layer"})))
log("Test 5: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "consider-tile-transitions", "object-layer"}, {"not-colliding-with-itself", "consider-tile-transitions", "object-layer"})))
Code: Select all
2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:5: Test 1: true
2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:6: Test 2: false
2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:7: Test 3: true
2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:8: Test 4: true
2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:9: Test 5: false