From e30ab97e9681914a32a953808d94a09999a65d10 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Aug 2021 11:57:01 +0200 Subject: [PATCH] feat: add an index in the battlesystem world --- sonic-radiance.love/scenes/battlesystem/actors/parent.lua | 8 ++++++++ sonic-radiance.love/scenes/battlesystem/world.lua | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua index 44f997e..e74441f 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua @@ -35,6 +35,11 @@ function Parent:new(world, x, y, z) self:register() end +function Parent:setIndexName(indexName) + self.indexName = indexName + self.world.index[self.indexName] = self +end + function Parent:register() self.world:registerActor(self) end @@ -42,6 +47,9 @@ end function Parent:destroy() self.world:destroyActor(self) self.isDestroyed = true + if (self.indexName ~= nil) then + self.world.index[self.indexName] = nil + end end function Parent:update(dt) diff --git a/sonic-radiance.love/scenes/battlesystem/world.lua b/sonic-radiance.love/scenes/battlesystem/world.lua index 1f7f772..8c6e43e 100644 --- a/sonic-radiance.love/scenes/battlesystem/world.lua +++ b/sonic-radiance.love/scenes/battlesystem/world.lua @@ -29,6 +29,7 @@ function World:new(scene, battlefile) self.globalID = 0 self.map = Map(scene, HEIGHT, BORDER_BOTTOM, "city") + self.index = {} self.isBattleActive = false end @@ -68,6 +69,10 @@ function World:getActorInCase(x, y, notThisActor) return nil end +function World:getActorByName(name) + return self.index[name] +end + -- UPDATE FUNCTION -- Update all actors