feat: add an index in the battlesystem world

This commit is contained in:
Kazhnuz 2021-08-07 11:57:01 +02:00
parent c9644b2e86
commit e30ab97e96
2 changed files with 13 additions and 0 deletions

View file

@ -35,6 +35,11 @@ function Parent:new(world, x, y, z)
self:register() self:register()
end end
function Parent:setIndexName(indexName)
self.indexName = indexName
self.world.index[self.indexName] = self
end
function Parent:register() function Parent:register()
self.world:registerActor(self) self.world:registerActor(self)
end end
@ -42,6 +47,9 @@ end
function Parent:destroy() function Parent:destroy()
self.world:destroyActor(self) self.world:destroyActor(self)
self.isDestroyed = true self.isDestroyed = true
if (self.indexName ~= nil) then
self.world.index[self.indexName] = nil
end
end end
function Parent:update(dt) function Parent:update(dt)

View file

@ -29,6 +29,7 @@ function World:new(scene, battlefile)
self.globalID = 0 self.globalID = 0
self.map = Map(scene, HEIGHT, BORDER_BOTTOM, "city") self.map = Map(scene, HEIGHT, BORDER_BOTTOM, "city")
self.index = {}
self.isBattleActive = false self.isBattleActive = false
end end
@ -68,6 +69,10 @@ function World:getActorInCase(x, y, notThisActor)
return nil return nil
end end
function World:getActorByName(name)
return self.index[name]
end
-- UPDATE FUNCTION -- UPDATE FUNCTION
-- Update all actors -- Update all actors