Theme fix + main changes

This commit is contained in:
Robert Jelic
2025-04-06 19:27:10 +02:00
parent 86ab2b9a0c
commit 371dd8cec0
2 changed files with 24 additions and 2 deletions

View File

@@ -222,7 +222,7 @@ local keyEvents = {
}
local function updateEvent(event, ...)
if(event=="terminate")then basalt.stop() end
if(event=="terminate")then basalt.stop() return end
if lazyElementsEventHandler(event, ...) then return end
if(mouseEvents[event])then
@@ -272,6 +272,7 @@ end
--- @vararg any The event to run with
function basalt.update(...)
local f = function(...)
basalt.isRunning = true
updateEvent(...)
renderFrames()
end
@@ -280,6 +281,7 @@ function basalt.update(...)
errorManager.header = "Basalt Runtime Error"
errorManager.error(err)
end
basalt.isRunning = false
end
--- Stops the Basalt runtime

View File

@@ -1,3 +1,4 @@
local errorManager = require("errorManager")
local defaultTheme = {
default = {
background = colors.lightGray,
@@ -160,7 +161,21 @@ function BaseElement:applyTheme()
local styles = self:getTheme()
if(styles ~= nil) then
for prop, value in pairs(styles) do
self.set(prop, value)
local config = self._properties[prop]
if(config)then
if((config.type)=="color")then
if(type(value)=="string")then
if(colors[value])then
value = colors[value]
else
errorManager.error("Invalid color '" .. value .. "' for property '" .. prop .. "' in theme for " .. self._values.type)
end
end
end
self.set(prop, value)
else
errorManager.error("Invalid property '" .. prop .. "' in theme for " .. self._values.type)
end
end
end
return self
@@ -205,6 +220,11 @@ function ThemeAPI.loadTheme(path)
local content = file.readAll()
file.close()
themes.default = textutils.unserializeJSON(content)
if not themes.default then
errorManager.error("Failed to load theme from " .. path)
end
else
errorManager.error("Could not open theme file: " .. path)
end
end