From 3fbaad2b2bbbc3391de2425c245887d3a30c87c5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Jul 2019 11:05:54 +0200 Subject: [PATCH] improvement(gameutils): improve map type validation --- sonic-radiance.love/game/modules/utils/init.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/game/modules/utils/init.lua b/sonic-radiance.love/game/modules/utils/init.lua index 93643fb..59f0b57 100644 --- a/sonic-radiance.love/game/modules/utils/init.lua +++ b/sonic-radiance.love/game/modules/utils/init.lua @@ -8,11 +8,24 @@ function gameutils.getMapPath(maptype, mapname) end function gameutils.getMapDirectory(maptype, mapname) - if (maptype ~= "battle") and (maptype ~= "sti") then + if not gameutils.validateMapType(maptype) then error("Map type " .. maptype .. " doesn't exist.") end return "datas/gamedata/maps/" .. maptype .. "/" .. mapname .. "/" end +function gameutils.validateMapType(maptype) + local types = {"battle", "sti"} + local validated = false + + for i, type in ipairs(types) do + if (type == maptype) then + validated = true + end + end + + return validated +end + return gameutils