From 4aeab1534097494eb904df5cb20b526def03e2c7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 2 Jan 2020 21:56:42 +0100 Subject: [PATCH] feat: load map data from layout files --- .../maps/shoot}/chunks/basics.lua | 0 .../maps/shoot}/chunks/terrains.lua | 0 .../gamedata/maps/shoot/testlevel/test1.lua | 14 ++++++++++ .../sonic-boost/levels/testlevel/test1.lua | 26 ------------------- .../game/modules/world/maps/shoot.lua | 25 +++++++++++++++--- .../scenes/test_scene/init.lua | 4 +-- 6 files changed, 38 insertions(+), 31 deletions(-) rename sonic-bluestreak.love/datas/{subgame/sonic-boost => gamedata/maps/shoot}/chunks/basics.lua (100%) rename sonic-bluestreak.love/datas/{subgame/sonic-boost => gamedata/maps/shoot}/chunks/terrains.lua (100%) create mode 100644 sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua delete mode 100644 sonic-bluestreak.love/datas/subgame/sonic-boost/levels/testlevel/test1.lua diff --git a/sonic-bluestreak.love/datas/subgame/sonic-boost/chunks/basics.lua b/sonic-bluestreak.love/datas/gamedata/maps/shoot/chunks/basics.lua similarity index 100% rename from sonic-bluestreak.love/datas/subgame/sonic-boost/chunks/basics.lua rename to sonic-bluestreak.love/datas/gamedata/maps/shoot/chunks/basics.lua diff --git a/sonic-bluestreak.love/datas/subgame/sonic-boost/chunks/terrains.lua b/sonic-bluestreak.love/datas/gamedata/maps/shoot/chunks/terrains.lua similarity index 100% rename from sonic-bluestreak.love/datas/subgame/sonic-boost/chunks/terrains.lua rename to sonic-bluestreak.love/datas/gamedata/maps/shoot/chunks/terrains.lua diff --git a/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua b/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua new file mode 100644 index 0000000..0fa87f6 --- /dev/null +++ b/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua @@ -0,0 +1,14 @@ +return { + datas = { + zone = "forest", + bypass_zone = true, + bypass_data = { + tiles = 3, + background = nil + } + }, + layout = {{"self", {00}}, {"basics", {00, 00}},}, + parts = { + [0] = {{"basics", {01}}, {"basics", {00}}} + } +} diff --git a/sonic-bluestreak.love/datas/subgame/sonic-boost/levels/testlevel/test1.lua b/sonic-bluestreak.love/datas/subgame/sonic-boost/levels/testlevel/test1.lua deleted file mode 100644 index 551e60d..0000000 --- a/sonic-bluestreak.love/datas/subgame/sonic-boost/levels/testlevel/test1.lua +++ /dev/null @@ -1,26 +0,0 @@ -return { - datas = { - zone = "forest", - bypass_zone = false, - bypass_data = { - name = nil, - borders = 3, - tiles = 3, - background = nil, - music = nil - }, - missiondata = { - leveltype = "loop", - missiontype = "goal", - turns = 4 - } - }, - layout = {{"self", {00}}, {"basics", {00, 00}},}, - parts = { - [0] = {{"basics", {01}}, {"basics", {00}}} - }, - endless_parts = { - {"basics", 00}, - {"self", 00} - } -} diff --git a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua index 23eeb62..7fb89f4 100644 --- a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua +++ b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua @@ -10,9 +10,28 @@ function ShootMap:new(world, maptype, mapname) ShootMap.super.new(self, world) self:setPadding(0, 0, 0, 0) - self.textureId = zoneDatas[mapname].tiles - self.background = zoneDatas[mapname].background - self:generateTextures(self.textureId, self.background) + self:getLevelData(mapname) + self:generateTextures(self.datas.tiles, self.datas.background) +end + +function ShootMap:getLevelData(mapname) + local file = file or "testlevel.test1" + local level = require("datas.gamedata.maps.shoot." .. file) + + self.zone = level.datas.zone + + local currentZone_datas = zoneDatas[self.zone] + local bypass_data = level.datas.bypass_data + + self.datas = {} + + if (level.datas.bypass_zone) then + self.datas.tiles = bypass_data.tiles or currentZone_datas.tiles + self.datas.background = bypass_data.background or currentZone_datas.background + else + self.datas = currentZone_datas + end + end function ShootMap:loadCollisions() diff --git a/sonic-bluestreak.love/scenes/test_scene/init.lua b/sonic-bluestreak.love/scenes/test_scene/init.lua index 0c34a8b..957293b 100644 --- a/sonic-bluestreak.love/scenes/test_scene/init.lua +++ b/sonic-bluestreak.love/scenes/test_scene/init.lua @@ -33,9 +33,9 @@ function MovePlayer:new() end function MovePlayer:initWorld() - --ShootWorld(self, "coast") + ShootWorld(self, "testlevel.test1") --BattleWorld(self, "ebeach") - TestWorld(self) + --TestWorld(self) end return MovePlayer