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 self.currentCreationID = 0
end end
function BaseWorld:newActor(name, x, y, z, properties) function BaseWorld:newActor(name, x, y, z, properties, mapname)
local debugstring = " at (" .. x .. ";" .. y .. ")." local debugstring = " at (" .. x .. ";" .. y .. ")."
core.debug:print("world2D", "adding actor " .. name .. debugstring) core.debug:print("world2D", "adding actor " .. name .. debugstring)
local actor = self.obj.index[name](self, x, y) local actor = self.obj.index[name](self, x, y)
if (mapname ~= nil) then
actor.mapname = mapname
end
if (properties ~= nil) then if (properties ~= nil) then
actor:setProperties(properties) actor:setProperties(properties)
end end

View file

@ -9,6 +9,13 @@ function StiMap:new(world, mapfile)
self.sti = STI(mapfile) self.sti = STI(mapfile)
StiMap.super.new(self, world) StiMap.super.new(self, world)
self:setBackgroundColorFromTable(self.sti.backgroundcolor) 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 end
function StiMap:getDimensions() function StiMap:getDimensions()
@ -104,7 +111,7 @@ function StiMap:newActor(objectlayer, object)
y = y + z y = y + z
end 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 end
function StiMap:newCollision(objectlayer, object) function StiMap:newCollision(objectlayer, object)