From a1d0cd02255429d6969f27e7690e30d72d35a4f9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 22 Aug 2019 22:04:38 +0200 Subject: [PATCH] feat(cbs/utils): add a way to automatically get a map from a mask --- .../scenes/battlesystem/utils.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sonic-radiance.love/scenes/battlesystem/utils.lua b/sonic-radiance.love/scenes/battlesystem/utils.lua index 97d82cb..5f2455a 100644 --- a/sonic-radiance.love/scenes/battlesystem/utils.lua +++ b/sonic-radiance.love/scenes/battlesystem/utils.lua @@ -67,6 +67,23 @@ function maputils.isInMask(x, y, ox, oy, shape, size, direction) end end +function maputils.maskToMap(ox, oy, shape, size, direction) + local map = maputils.newEmptyMap() + + for i, line in ipairs(map) do + for j, case in ipairs(line) do + local isInMask = maputils.isInMask(j, i, ox, oy, shape, size, direction) + if (isInMask) then + map[i][j] = 1 + else + map[i][j] = 0 + end + end + end + + return map +end + function maputils.gridToPixel(x, y, center) local pixelx, pixely local center = center or false