From 00f3267901b109ce5ae5060105848f532c8ef16b Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Fri, 29 Jul 2022 00:56:32 +0200 Subject: [PATCH] update updated dev branch to master changes added bugfix for basalt.update --- Basalt/Frame.lua | 8 +++ Basalt/Object.lua | 8 +-- Basalt/libraries/utils.lua | 25 ++++--- Basalt/main.lua | 133 +++++++++++++++++++---------------- Basalt/objects/Animation.lua | 23 ++++-- Basalt/objects/Label.lua | 14 +--- Basalt/objects/Radio.lua | 9 ++- 7 files changed, 125 insertions(+), 95 deletions(-) diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 9af50b2..c61dcaa 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -369,6 +369,14 @@ return function(name, parent, pTerm, basalt) return self end, + getMaxScroll = function(self) + return maxScroll + end, + + getMinScroll = function(self) + return minScroll + end, + show = function(self) base.show(self) if(self.parent==nil)then diff --git a/Basalt/Object.lua b/Basalt/Object.lua index e0a68cd..f532d9e 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -232,11 +232,11 @@ return function(name) end; getX = function(self) - return type(self.x) == "number" and self.x or self.x[1] + return type(self.x) == "number" and self.x or math.floor(self.x[1]+0.5) end; getY = function(self) - return type(self.y) == "number" and self.y or self.y[1] + return type(self.y) == "number" and self.y or math.floor(self.y[1]+0.5) end; getPosition = function(self) @@ -275,11 +275,11 @@ return function(name) end; getHeight = function(self) - return type(self.height) == "number" and self.height or self.height[1] + return type(self.height) == "number" and self.height or math.floor(self.height[1]+0.5) end; getWidth = function(self) - return type(self.width) == "number" and self.width or self.width[1] + return type(self.width) == "number" and self.width or math.floor(self.width[1]+0.5) end; getSize = function(self) diff --git a/Basalt/libraries/utils.lua b/Basalt/libraries/utils.lua index 5e9c973..5791eaa 100644 --- a/Basalt/libraries/utils.lua +++ b/Basalt/libraries/utils.lua @@ -50,18 +50,21 @@ end, splitString = splitString, -createText = function(msg, maxWidth) - local words = splitString(msg, " ") +createText = function(str, width) + local uniqueLines = splitString(str, "\n") local lines = {} - local line = "" - for k,v in pairs(words)do - if(#line+#v <= maxWidth)then - line = line=="" and v or line.." "..v - if(k==#words)then table.insert(lines, line) end - else - table.insert(lines, line) - line = v:sub(1,maxWidth) - if(k==#words)then table.insert(lines, line) end + for k,v in pairs(uniqueLines)do + local line = "" + local words = splitString(v, " ") + for a,b in pairs(words)do + if(#line+#b <= width)then + line = line=="" and b or line.." "..b + if(a==#words)then table.insert(lines, line) end + else + table.insert(lines, line) + line = b:sub(1,width) + if(a==#words)then table.insert(lines, line) end + end end end return lines diff --git a/Basalt/main.lua b/Basalt/main.lua index e431308..bf30e9e 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -1,15 +1,17 @@ local basaltEvent = require("basaltEvent")() local Frame = require("Frame") local theme = require("theme") -local uuid = require("utils").uuid +local utils = require("utils") +local uuid = utils.uuid +local createText = utils.createText local baseTerm = term.current() -local version = 4 +local version = 5 local debugger = true local projectDirectory = fs.getDir(table.pack(...)[2] or "") -local activeKey, frames, monFrames, variables, shedules = {}, {}, {}, {}, {} +local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {} local mainFrame, activeFrame, focusedObject, updaterActive if not term.isColor or not term.isColor() then @@ -85,15 +87,50 @@ local bInstance = { end } -local function handleShedules(event, p1, p2, p3, p4) - if(#shedules>0)then +local basaltError = function(errMsg) + baseTerm.clear() + baseTerm.setBackgroundColor(colors.black) + baseTerm.setTextColor(colors.red) + local w,h = baseTerm.getSize() + + local splitString = function(str, sep) + if sep == nil then + sep = "%s" + end + local t={} + for v in string.gmatch(str, "([^"..sep.."]+)") do + table.insert(t, v) + end + return t + end + local words = splitString(errMsg, " ") + local line = "Basalt error: " + local yPos = 1 + for n=1,#words do + baseTerm.setCursorPos(1,yPos) + if(#line+#words[n]0)then local finished = {} - for n=1,#shedules do - if(shedules[n]~=nil)then - if (coroutine.status(shedules[n]) == "suspended")then - local ok, result = coroutine.resume(shedules[n], event, p1, p2, p3, p4) + for n=1,#schedules do + if(schedules[n]~=nil)then + if (coroutine.status(schedules[n]) == "suspended")then + local ok, result = coroutine.resume(schedules[n], event, p1, p2, p3, p4) if not(ok)then - table.insert(finished, n) + basaltError(result) end else table.insert(finished, n) @@ -101,21 +138,19 @@ local function handleShedules(event, p1, p2, p3, p4) end end for n=1,#finished do - table.remove(shedules, finished[n]-(n-1)) + table.remove(schedules, finished[n]-(n-1)) end end end local function drawFrames() - if(updaterActive)then - if(mainFrame~=nil)then - mainFrame:draw() - mainFrame:drawUpdate() - end - for _,v in pairs(monFrames)do - v:draw() - v:drawUpdate() - end + if(mainFrame~=nil)then + mainFrame:draw() + mainFrame:drawUpdate() + end + for _,v in pairs(monFrames)do + v:draw() + v:drawUpdate() end end @@ -160,49 +195,15 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4) for _, v in pairs(frames) do v:eventHandler(event, p1, p2, p3, p4) end - handleShedules(event, p1, p2, p3, p4) + handleSchedules(event, p1, p2, p3, p4) drawFrames() end -local basaltError = function(errMsg) - baseTerm.clear() - baseTerm.setBackgroundColor(colors.black) - baseTerm.setTextColor(colors.red) - local w,h = baseTerm.getSize() - - local splitString = function(str, sep) - if sep == nil then - sep = "%s" - end - local t={} - for v in string.gmatch(str, "([^"..sep.."]+)") do - table.insert(t, v) - end - return t - end - local words = splitString(errMsg, " ") - local line = "Basalt error: " - local yPos = 1 - for n=1,#words do - baseTerm.setCursorPos(1,yPos) - if(#line+#words[n] 50) then basalt.debugList:removeItem(1) end @@ -333,4 +342,4 @@ basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText( basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show() basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show() -return basalt \ No newline at end of file +return basalt diff --git a/Basalt/objects/Animation.lua b/Basalt/objects/Animation.lua index 87b56a4..87589cb 100644 --- a/Basalt/objects/Animation.lua +++ b/Basalt/objects/Animation.lua @@ -2,7 +2,7 @@ local xmlValue = require("utils").getValueFromXML local basaltEvent = require("basaltEvent") -local floor = math.floor +local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi local lerp = function(s, e, pct) return s + (e - s) * pct @@ -12,8 +12,8 @@ local linear = function (t) return t end -local flip = function (x) - return 1 - x +local flip = function (t) + return 1 - t end local easeIn = function (t) @@ -28,6 +28,18 @@ local easeInOut = function(t) return lerp(easeIn(t), easeOut(t), t) end +local easeOutSine = function(t) + return sin((t * pi) / 2); +end + +local easeInSine = function(t) + return flip(cos((t * pi) / 2)) +end + +local easeInOutSine = function(t) + return -(cos(pi * x) - 1) / 2 +end + local lerp = { linear = linear, lerp = lerp, @@ -35,6 +47,9 @@ local lerp = { easeIn=easeIn, easeOut=easeOut, easeInOut=easeInOut, + easeOutSine = easeOutSine, + easeInSine = easeInSine, + easeInOutSine = easeInOutSine, } return function(name) @@ -122,7 +137,7 @@ return function(name) addAnimationPart(t+0.05, function() x,y = get(_OBJ) end) - for n=0.05,d,0.05 do + for n=0.05,d+0.01,0.05 do addAnimationPart(t+n, function() local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5) local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5) diff --git a/Basalt/objects/Label.lua b/Basalt/objects/Label.lua index c730253..8ac9765 100644 --- a/Basalt/objects/Label.lua +++ b/Basalt/objects/Label.lua @@ -1,6 +1,7 @@ local Object = require("Object") local utils = require("utils") local xmlValue = utils.getValueFromXML +local createText = utils.createText local tHex = require("tHex") local bigFont = require("bigfont") @@ -95,18 +96,7 @@ return function(name) if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end if(fontsize==0)then if not(autoSize)then - local splittedText = utils.splitString(self:getValue(), " ") - local text = {} - local line = "" - for k,v in pairs(splittedText)do - if(line:len()+v:len()<=w)then - line = line=="" and v or line.." "..v - if(k==#splittedText)then table.insert(text, line) end - else - table.insert(text, line) - line = v:sub(1,w) - end - end + local text = createText(self:getValue(), self:getWidth()) for k,v in pairs(text)do self.parent:setText(obx, oby+k-1, v) end diff --git a/Basalt/objects/Radio.lua b/Basalt/objects/Radio.lua index d09412c..0b5f8e6 100644 --- a/Basalt/objects/Radio.lua +++ b/Basalt/objects/Radio.lua @@ -104,12 +104,17 @@ return function(name) return self end; + setActiveSymbol = function(self, sym) + symbol = sym:sub(1,1) + return self + end, + setSelectedItem = function(self, bgCol, fgCol, boxBG, boxFG, active) itemSelectedBG = bgCol or itemSelectedBG itemSelectedFG = fgCol or itemSelectedFG boxSelectedBG = boxBG or boxSelectedBG boxSelectedFG = boxFG or boxSelectedFG - selectionColorActive = active + selectionColorActive = active~=nil and active or true return self end; @@ -123,7 +128,7 @@ return function(name) if (self.parent ~= nil) then self.parent:setFocusedObject(self) end - --eventSystem:sendEvent(event, self, event, button, x, y) + self:getEventSystem():sendEvent(event, self, event, button, x, y) self:setVisualChanged() return true end