feat: add way to get map name

This commit is contained in:
Kazhnuz 2021-03-22 18:58:53 +01:00
parent ce5f56c556
commit 8ba84e03aa
2 changed files with 12 additions and 2 deletions

View file

@ -102,10 +102,13 @@ function BaseWorld:initActors( )
self.currentCreationID = 0
end
function BaseWorld:newActor(name, x, y, z, properties)
function BaseWorld:newActor(name, x, y, z, properties, mapname)
local debugstring = " at (" .. x .. ";" .. y .. ")."
core.debug:print("world2D", "adding actor " .. name .. debugstring)
local actor = self.obj.index[name](self, x, y)
if (mapname ~= nil) then
actor.mapname = mapname
end
if (properties ~= nil) then
actor:setProperties(properties)
end

View file

@ -9,6 +9,13 @@ function StiMap:new(world, mapfile)
self.sti = STI(mapfile)
StiMap.super.new(self, world)
self:setBackgroundColorFromTable(self.sti.backgroundcolor)
self.mapname = self:getMapName(mapfile)
end
function StiMap:getMapName(mapfile)
local filepath = utils.string.split(mapfile, "/")
local filenameMap = utils.string.split(filepath[#filepath], ".")
return filepath[#filepath - 1] .. "." .. filenameMap[1]
end
function StiMap:getDimensions()
@ -104,7 +111,7 @@ function StiMap:newActor(objectlayer, object)
y = y + z
end
self.world:newActor(objectlayer.name, object.x, y, z, object.properties)
self.world:newActor(objectlayer.name, object.x, y, z, object.properties, self.mapname)
end
function StiMap:newCollision(objectlayer, object)