diff --git a/README.md b/README.md index 01005a3..378eff1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ ![alt text](https://i.imgur.com/ZQBQfsa.png "Helium") # Helium +![Helium main menu demo](https://j.gifs.com/nRrKmp.gif) + +*a main menu demo made with helium, in action, find [it here](https://github.com/qeffects/main-menu-example)* + ## Basic overview: Helium is practically more like a UI framework than a fully fledged UI library. The idea is to build custom and build simple. @@ -119,4 +123,6 @@ Or continue on to the State and Input guide: [Here](./docs/State-Input-Guide.md) If you are using gamestates, scene guide will be of interest: [Here](./docs/core/Scenes.md) For a more general overview of the whole library: [Module index](./docs/Modules-Index.md) +Also check out the helium configuration values: [Config](./docs/Configuration.md) + There's also a main menu example project available here: [Project](https://github.com/qeffects/main-menu-example) diff --git a/conf.lua b/conf.lua index c63997a..b45eba6 100644 --- a/conf.lua +++ b/conf.lua @@ -1,4 +1,15 @@ +---@class __HELIUM_CONFIG +---@field DEBUG boolean +---@field LOAD_HOOKS boolean +---@field LOAD_LAYOUT boolean +---@field LOAD_SHELL boolean +---@field MANUAL_CACHING boolean + +---@type __HELIUM_CONFIG return { - AUTO_RUN = true, --Replaces the default love.run - DEBUG = true, --Reserved for later + DEBUG = true, --Reserved for later + LOAD_HOOKS = false, --Loads the hooks module in to helium table + LOAD_LAYOUT = false, --Loads the layout module in to helium table + LOAD_SHELL = false, --Loads the shell mocule in to helium table + MANUAL_CACHING = false, --Whether or not to perform automatic caching } \ No newline at end of file diff --git a/core/atlas.lua b/core/atlas.lua index 55e56d7..67b0739 100644 --- a/core/atlas.lua +++ b/core/atlas.lua @@ -3,7 +3,8 @@ Copyright (c) 2021 Elmārs Āboliņš https://github.com/qeffects/helium ----------------------------------------------------]] - +local path = string.sub(..., 1, string.len(...) - string.len(".core.atlas")) +local helium = require(path..'.dummy') local atlas = {} atlas.__index = atlas ---@class atlases @@ -39,20 +40,22 @@ end function atlases:assign(element) local avg, sum, canvasID = 0, 0, element.context:getCanvasIndex(true) or 1 - for i, e in ipairs(element.renderBench) do - sum = sum + e - end + if not helium.conf.MANUAL_CACHING then + for i, e in ipairs(element.renderBench) do + sum = sum + e + end - avg = sum/#element.renderBench + avg = sum/#element.renderBench - local areaBelow = self:getFreeArea(canvasID) - local area = element.view.h*element.view.w + local areaBelow = self:getFreeArea(canvasID) + local area = element.view.h*element.view.w - local areaCoef = (2-(self:getRatio(canvasID)) )-(area/(areaBelow/(4+3*self:getRatio(canvasID)))) - local speedCoef = avg/selfRenderTime + local areaCoef = (2-(self:getRatio(canvasID)) )-(area/(areaBelow/(4+3*self:getRatio(canvasID)))) + local speedCoef = avg/selfRenderTime - if not ((areaCoef+speedCoef)>coefficient) then - return + if not ((areaCoef+speedCoef)>coefficient) then + return + end end local elW = element.view.w diff --git a/core/element.lua b/core/element.lua index a0f8727..62421fa 100644 --- a/core/element.lua +++ b/core/element.lua @@ -124,7 +124,6 @@ function element:posChange(i, v) if not self.deferRepos then self.deferRepos = true end - if self.callbacks.onPosChange then for i, cb in ipairs(self.callbacks.onPosChange) do @@ -258,13 +257,13 @@ local setColor, rectangle, setFont, printf = love.graphics.setColor, love.graphi local calcT function element:internalRender() - if self.settings.testRenderPasses > 0 and selfRenderTime then + if self.settings.testRenderPasses > 0 and selfRenderTime and not helium.conf.MANUAL_CACHING then calcT = love.timer.getTime() end self.renderer() - if self.settings.testRenderPasses > 0 and selfRenderTime then + if self.settings.testRenderPasses > 0 and selfRenderTime and not helium.conf.MANUAL_CACHING then self.settings.testRenderPasses = self.settings.testRenderPasses-1 local selfTime = love.timer.getTime()-calcT table.insert(self.renderBench, selfTime) @@ -334,10 +333,12 @@ end function element:externalUpdate() self.context:set() self.context:zIndex() - if not self.settings.failedCanvas + if ((not self.settings.failedCanvas and self.settings.testRenderPasses == 0 - and not self.settings.hasCanvas - and scene.activeScene.cached then + and scene.activeScene.cached + and not helium.conf.MANUAL_CACHING) + or self.settings.forcedCanvas) + and not self.settings.hasCanvas then self:createCanvas() diff --git a/core/init.lua b/core/init.lua new file mode 100644 index 0000000..ed9bd93 --- /dev/null +++ b/core/init.lua @@ -0,0 +1,17 @@ +local path = ... + +---@class __HELIUM_CORE +---@field atlas any +---@field element any +---@field events any +---@field input any +---@field scene any +---@field stack any +return { + atlas = require(path..'.atlas'), + element = require(path..'.element'), + events = require(path..'.events'), + input = require(path..'.input'), + scene = require(path..'.scene'), + stack = require(path..'.stack'), +} \ No newline at end of file diff --git a/core/input.lua b/core/input.lua index 086f8d7..fe50308 100644 --- a/core/input.lua +++ b/core/input.lua @@ -172,11 +172,11 @@ function subscription:emit(...) end function subscription:checkInside(x, y) - return x>self.stack.absX and xself.stack.absY and yself.x and xself.y and yself.stack.absX and xself.stack.absY and yself.x and xself.y and y