From 8ba84e03aa170a267a67cfcdd2733564e11b48a9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 22 Mar 2021 18:58:53 +0100 Subject: [PATCH] feat: add way to get map name --- sonic-radiance.love/core/modules/world/baseworld.lua | 5 ++++- sonic-radiance.love/core/modules/world/maps/sti.lua | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/core/modules/world/baseworld.lua b/sonic-radiance.love/core/modules/world/baseworld.lua index f16e67e..9257a31 100644 --- a/sonic-radiance.love/core/modules/world/baseworld.lua +++ b/sonic-radiance.love/core/modules/world/baseworld.lua @@ -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 diff --git a/sonic-radiance.love/core/modules/world/maps/sti.lua b/sonic-radiance.love/core/modules/world/maps/sti.lua index 6554959..5ab0342 100644 --- a/sonic-radiance.love/core/modules/world/maps/sti.lua +++ b/sonic-radiance.love/core/modules/world/maps/sti.lua @@ -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)