Page 1 of 1

[Klonan] collision_mask_util.masks_collide does improper check with "not-colliding-with-itself"

Posted: Wed Jun 15, 2022 4:36 am
by FuryoftheStars
According to all of the documentation, in the "not-colliding-with-itself" checks, all other flags should be ignored. However, that doesn't appear to be what is happening here.

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
I set up a few masks to run against each other:

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"})))
And this was what it returned:

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
Unless my understanding of things is wrong, tests 3 & 4 should've returned false as well.

Re: [Klonan] collision_mask_util.masks_collide does improper check with "not-colliding-with-itself"

Posted: Fri Sep 02, 2022 9:16 am
by Klonan
Thanks for the report

It is fixed for the next release