updated dev branch to master changes
added bugfix for basalt.update
This commit is contained in:
Robert Jelic
2022-07-29 00:56:32 +02:00
parent 4782360bb6
commit 00f3267901
7 changed files with 125 additions and 95 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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]<w)then
line = line.." "..words[n]
else
baseTerm.write(line)
line = words[n]
yPos = yPos + 1
end
if(n==#words)then
baseTerm.write(line)
end
end
baseTerm.setCursorPos(1,yPos+1)
end
local function handleSchedules(event, p1, p2, p3, p4)
if(#schedules>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]<w)then
line = line.." "..words[n]
else
baseTerm.write(line)
line = words[n]
yPos = yPos + 1
end
if(n==#words)then
baseTerm.write(line)
end
end
baseTerm.setCursorPos(1,yPos+1)
end
local basalt = {}
basalt = {
setTheme = setTheme,
getTheme = getTheme,
drawFrames = drawFrames,
getVersion = function()
return version
end,
@@ -231,7 +232,11 @@ basalt = {
update = function(event, p1, p2, p3, p4)
if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4)
local ok, err = pcall(basaltUpdateEvent, event, p1, p2, p3, p4)
if not(ok)then
basaltError(err)
return
end
end
end,
@@ -270,13 +275,15 @@ basalt = {
end
end,
shedule = function(f)
assert(f~="function", "Shedule needs a function in order to work!")
schedule = function(f)
assert(f~="function", "Schedule needs a function in order to work!")
return function(...)
local co = coroutine.create(f)
local ok, result = coroutine.resume(co, ...)
if(ok)then
table.insert(shedules, co)
table.insert(schedules, co)
else
basaltError(result)
end
end
end,
@@ -316,7 +323,9 @@ basalt = {
str = str .. tostring(value) .. (#args ~= key and ", " or "")
end
basalt.debugLabel:setText("[Debug] " .. str)
basalt.debugList:addItem(str)
for k,v in pairs(createText(str, basalt.debugList:getWidth()))do
basalt.debugList:addItem(v)
end
if (basalt.debugList:getItemCount() > 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
return basalt

View File

@@ -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)

View File

@@ -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

View File

@@ -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