chore(camera): put the view algorithm in a "utils" file

This commit is contained in:
Kazhnuz 2019-07-14 18:35:33 +02:00
parent e4b89ddd31
commit fb428b45c3
2 changed files with 49 additions and 37 deletions

View file

@ -27,6 +27,8 @@ local cwd = (...):gsub('%.init$', '') .. "."
local CameraSystem = Object:extend()
local View = require(cwd .. "libs.hump.camera")
local camutils = require(cwd .. "utils")
local SPLITSCREEN_ISVERTICAL = false
local SCREEN_LIMIT = 4
@ -57,43 +59,7 @@ function CameraSystem:initViews()
self.views.basewidth, self.views.baseheight = core.screen:getDimensions()
self.views.width, self.views.height = self:getViewsDimensions()
self.views.posList = {}
self.views.posList.dual = {}
self.views.posList.multi = {}
if (self.verticalSplit) then
self.views.posList.dual[1] = {}
self.views.posList.dual[1].x = 0
self.views.posList.dual[1].y = (self.views.baseheight/4)
self.views.posList.dual[2] = {}
self.views.posList.dual[2].x = 0
self.views.posList.dual[2].y = -(self.views.baseheight/4)
else
self.views.posList.dual[1] = {}
self.views.posList.dual[1].x = -(self.views.basewidth/4)
self.views.posList.dual[1].y = 0
self.views.posList.dual[2] = {}
self.views.posList.dual[2].x = (self.views.basewidth/4)
self.views.posList.dual[2].y = 0
end
self.views.posList.multi[1] = {}
self.views.posList.multi[1].x = -(self.views.basewidth /4)
self.views.posList.multi[1].y = -(self.views.baseheight/4)
self.views.posList.multi[2] = {}
self.views.posList.multi[2].x = (self.views.basewidth /4)
self.views.posList.multi[2].y = -(self.views.baseheight/4)
self.views.posList.multi[3] = {}
self.views.posList.multi[3].x = -(self.views.basewidth /4)
self.views.posList.multi[3].y = (self.views.baseheight/4)
self.views.posList.multi[4] = {}
self.views.posList.multi[4].x = (self.views.basewidth /4)
self.views.posList.multi[4].y = (self.views.baseheight/4)
self.views.posList = camutils.getViewsPositions(self.views.basewidth, self.views.baseheight, self.verticalSplit)
end
-- INFO FUNCTIONS

View file

@ -0,0 +1,46 @@
local camutils = {}
function camutils.getViewsPositions(basewidth, baseheight, verticalSplit)
local posList = {}
posList.dual = {}
posList.multi = {}
if (verticalSplit) then
posList.dual[1] = {}
posList.dual[1].x = 0
posList.dual[1].y = (baseheight/4)
posList.dual[2] = {}
posList.dual[2].x = 0
posList.dual[2].y = -(baseheight/4)
else
posList.dual[1] = {}
posList.dual[1].x = -(basewidth/4)
posList.dual[1].y = 0
posList.dual[2] = {}
posList.dual[2].x = (basewidth/4)
posList.dual[2].y = 0
end
posList.multi[1] = {}
posList.multi[1].x = -(basewidth /4)
posList.multi[1].y = -(baseheight/4)
posList.multi[2] = {}
posList.multi[2].x = (basewidth /4)
posList.multi[2].y = -(baseheight/4)
posList.multi[3] = {}
posList.multi[3].x = -(basewidth /4)
posList.multi[3].y = (baseheight/4)
posList.multi[4] = {}
posList.multi[4].x = (basewidth /4)
posList.multi[4].y = (baseheight/4)
return posList
end
return camutils