From 3c498f2d164ce3ccd3e2d987c240d6215a4f786b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 29 Apr 2019 11:39:07 +0200 Subject: [PATCH] modules/world: add a basic view dimension system --- gamecore/modules/world/camera.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index 4427372..4f113c0 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -46,7 +46,8 @@ function CameraSystem:initViews() self.views = {} self.views.list = {} - self.views.width, self.views.height = core.screen:getDimensions() + self.views.basewidth, self.views.baseheight = core.screen:getDimensions() + self.views.width, self.views.height = self:getViewsDimensions() end -- INFO FUNCTIONS @@ -60,6 +61,23 @@ function CameraSystem:haveView() return (self:getViewNumber() == 0) end +function CameraSystem:getViewsDimensions() + local basewidth, baseheight = self.views.basewidth, self.views.baseheight + local viewnumber = self:getViewNumber() + + if (viewnumber <= 1) then + return basewidth, baseheight + elseif (viewnumber == 2) then + if (self.verticalSplit) then + return (basewidth/2), (baseheight) + else + return (basewidth), (baseheight/2) + end + else + return (basewidth/2), (baseheight/2) + end +end + -- WRAPPER and UTILS -- Access data from the views @@ -72,6 +90,7 @@ function CameraSystem:addView(x, y) -- to target a specific object table.insert(self.views.list, view) + self.views.width, self.views.height = self:getViewsDimensions() end end