update
updated dev branch to master changes added bugfix for basalt.update
This commit is contained in:
@@ -369,6 +369,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
getMaxScroll = function(self)
|
||||||
|
return maxScroll
|
||||||
|
end,
|
||||||
|
|
||||||
|
getMinScroll = function(self)
|
||||||
|
return minScroll
|
||||||
|
end,
|
||||||
|
|
||||||
show = function(self)
|
show = function(self)
|
||||||
base.show(self)
|
base.show(self)
|
||||||
if(self.parent==nil)then
|
if(self.parent==nil)then
|
||||||
|
|||||||
@@ -232,11 +232,11 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
getX = function(self)
|
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;
|
end;
|
||||||
|
|
||||||
getY = function(self)
|
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;
|
end;
|
||||||
|
|
||||||
getPosition = function(self)
|
getPosition = function(self)
|
||||||
@@ -275,11 +275,11 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
getHeight = function(self)
|
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;
|
end;
|
||||||
|
|
||||||
getWidth = function(self)
|
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;
|
end;
|
||||||
|
|
||||||
getSize = function(self)
|
getSize = function(self)
|
||||||
|
|||||||
@@ -50,18 +50,21 @@ end,
|
|||||||
|
|
||||||
splitString = splitString,
|
splitString = splitString,
|
||||||
|
|
||||||
createText = function(msg, maxWidth)
|
createText = function(str, width)
|
||||||
local words = splitString(msg, " ")
|
local uniqueLines = splitString(str, "\n")
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local line = ""
|
for k,v in pairs(uniqueLines)do
|
||||||
for k,v in pairs(words)do
|
local line = ""
|
||||||
if(#line+#v <= maxWidth)then
|
local words = splitString(v, " ")
|
||||||
line = line=="" and v or line.." "..v
|
for a,b in pairs(words)do
|
||||||
if(k==#words)then table.insert(lines, line) end
|
if(#line+#b <= width)then
|
||||||
else
|
line = line=="" and b or line.." "..b
|
||||||
table.insert(lines, line)
|
if(a==#words)then table.insert(lines, line) end
|
||||||
line = v:sub(1,maxWidth)
|
else
|
||||||
if(k==#words)then table.insert(lines, line) end
|
table.insert(lines, line)
|
||||||
|
line = b:sub(1,width)
|
||||||
|
if(a==#words)then table.insert(lines, line) end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return lines
|
return lines
|
||||||
|
|||||||
133
Basalt/main.lua
133
Basalt/main.lua
@@ -1,15 +1,17 @@
|
|||||||
local basaltEvent = require("basaltEvent")()
|
local basaltEvent = require("basaltEvent")()
|
||||||
local Frame = require("Frame")
|
local Frame = require("Frame")
|
||||||
local theme = require("theme")
|
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 baseTerm = term.current()
|
||||||
local version = 4
|
local version = 5
|
||||||
local debugger = true
|
local debugger = true
|
||||||
|
|
||||||
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
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
|
local mainFrame, activeFrame, focusedObject, updaterActive
|
||||||
|
|
||||||
if not term.isColor or not term.isColor() then
|
if not term.isColor or not term.isColor() then
|
||||||
@@ -85,15 +87,50 @@ local bInstance = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local function handleShedules(event, p1, p2, p3, p4)
|
local basaltError = function(errMsg)
|
||||||
if(#shedules>0)then
|
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 = {}
|
local finished = {}
|
||||||
for n=1,#shedules do
|
for n=1,#schedules do
|
||||||
if(shedules[n]~=nil)then
|
if(schedules[n]~=nil)then
|
||||||
if (coroutine.status(shedules[n]) == "suspended")then
|
if (coroutine.status(schedules[n]) == "suspended")then
|
||||||
local ok, result = coroutine.resume(shedules[n], event, p1, p2, p3, p4)
|
local ok, result = coroutine.resume(schedules[n], event, p1, p2, p3, p4)
|
||||||
if not(ok)then
|
if not(ok)then
|
||||||
table.insert(finished, n)
|
basaltError(result)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(finished, n)
|
table.insert(finished, n)
|
||||||
@@ -101,21 +138,19 @@ local function handleShedules(event, p1, p2, p3, p4)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for n=1,#finished do
|
for n=1,#finished do
|
||||||
table.remove(shedules, finished[n]-(n-1))
|
table.remove(schedules, finished[n]-(n-1))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawFrames()
|
local function drawFrames()
|
||||||
if(updaterActive)then
|
if(mainFrame~=nil)then
|
||||||
if(mainFrame~=nil)then
|
mainFrame:draw()
|
||||||
mainFrame:draw()
|
mainFrame:drawUpdate()
|
||||||
mainFrame:drawUpdate()
|
end
|
||||||
end
|
for _,v in pairs(monFrames)do
|
||||||
for _,v in pairs(monFrames)do
|
v:draw()
|
||||||
v:draw()
|
v:drawUpdate()
|
||||||
v:drawUpdate()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -160,49 +195,15 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
|||||||
for _, v in pairs(frames) do
|
for _, v in pairs(frames) do
|
||||||
v:eventHandler(event, p1, p2, p3, p4)
|
v:eventHandler(event, p1, p2, p3, p4)
|
||||||
end
|
end
|
||||||
handleShedules(event, p1, p2, p3, p4)
|
handleSchedules(event, p1, p2, p3, p4)
|
||||||
drawFrames()
|
drawFrames()
|
||||||
end
|
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 = {}
|
local basalt = {}
|
||||||
basalt = {
|
basalt = {
|
||||||
setTheme = setTheme,
|
setTheme = setTheme,
|
||||||
getTheme = getTheme,
|
getTheme = getTheme,
|
||||||
|
drawFrames = drawFrames,
|
||||||
getVersion = function()
|
getVersion = function()
|
||||||
return version
|
return version
|
||||||
end,
|
end,
|
||||||
@@ -231,7 +232,11 @@ basalt = {
|
|||||||
|
|
||||||
update = function(event, p1, p2, p3, p4)
|
update = function(event, p1, p2, p3, p4)
|
||||||
if (event ~= nil) then
|
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
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -270,13 +275,15 @@ basalt = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
shedule = function(f)
|
schedule = function(f)
|
||||||
assert(f~="function", "Shedule needs a function in order to work!")
|
assert(f~="function", "Schedule needs a function in order to work!")
|
||||||
return function(...)
|
return function(...)
|
||||||
local co = coroutine.create(f)
|
local co = coroutine.create(f)
|
||||||
local ok, result = coroutine.resume(co, ...)
|
local ok, result = coroutine.resume(co, ...)
|
||||||
if(ok)then
|
if(ok)then
|
||||||
table.insert(shedules, co)
|
table.insert(schedules, co)
|
||||||
|
else
|
||||||
|
basaltError(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -316,7 +323,9 @@ basalt = {
|
|||||||
str = str .. tostring(value) .. (#args ~= key and ", " or "")
|
str = str .. tostring(value) .. (#args ~= key and ", " or "")
|
||||||
end
|
end
|
||||||
basalt.debugLabel:setText("[Debug] " .. str)
|
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
|
if (basalt.debugList:getItemCount() > 50) then
|
||||||
basalt.debugList:removeItem(1)
|
basalt.debugList:removeItem(1)
|
||||||
end
|
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.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()
|
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
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
local xmlValue = require("utils").getValueFromXML
|
local xmlValue = require("utils").getValueFromXML
|
||||||
local basaltEvent = require("basaltEvent")
|
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)
|
local lerp = function(s, e, pct)
|
||||||
return s + (e - s) * pct
|
return s + (e - s) * pct
|
||||||
@@ -12,8 +12,8 @@ local linear = function (t)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local flip = function (x)
|
local flip = function (t)
|
||||||
return 1 - x
|
return 1 - t
|
||||||
end
|
end
|
||||||
|
|
||||||
local easeIn = function (t)
|
local easeIn = function (t)
|
||||||
@@ -28,6 +28,18 @@ local easeInOut = function(t)
|
|||||||
return lerp(easeIn(t), easeOut(t), t)
|
return lerp(easeIn(t), easeOut(t), t)
|
||||||
end
|
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 = {
|
local lerp = {
|
||||||
linear = linear,
|
linear = linear,
|
||||||
lerp = lerp,
|
lerp = lerp,
|
||||||
@@ -35,6 +47,9 @@ local lerp = {
|
|||||||
easeIn=easeIn,
|
easeIn=easeIn,
|
||||||
easeOut=easeOut,
|
easeOut=easeOut,
|
||||||
easeInOut=easeInOut,
|
easeInOut=easeInOut,
|
||||||
|
easeOutSine = easeOutSine,
|
||||||
|
easeInSine = easeInSine,
|
||||||
|
easeInOutSine = easeInOutSine,
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(name)
|
return function(name)
|
||||||
@@ -122,7 +137,7 @@ return function(name)
|
|||||||
addAnimationPart(t+0.05, function()
|
addAnimationPart(t+0.05, function()
|
||||||
x,y = get(_OBJ)
|
x,y = get(_OBJ)
|
||||||
end)
|
end)
|
||||||
for n=0.05,d,0.05 do
|
for n=0.05,d+0.01,0.05 do
|
||||||
addAnimationPart(t+n, function()
|
addAnimationPart(t+n, function()
|
||||||
local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5)
|
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)
|
local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local Object = require("Object")
|
local Object = require("Object")
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
local xmlValue = utils.getValueFromXML
|
local xmlValue = utils.getValueFromXML
|
||||||
|
local createText = utils.createText
|
||||||
local tHex = require("tHex")
|
local tHex = require("tHex")
|
||||||
local bigFont = require("bigfont")
|
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(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
|
||||||
if(fontsize==0)then
|
if(fontsize==0)then
|
||||||
if not(autoSize)then
|
if not(autoSize)then
|
||||||
local splittedText = utils.splitString(self:getValue(), " ")
|
local text = createText(self:getValue(), self:getWidth())
|
||||||
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
|
|
||||||
for k,v in pairs(text)do
|
for k,v in pairs(text)do
|
||||||
self.parent:setText(obx, oby+k-1, v)
|
self.parent:setText(obx, oby+k-1, v)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -104,12 +104,17 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setActiveSymbol = function(self, sym)
|
||||||
|
symbol = sym:sub(1,1)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setSelectedItem = function(self, bgCol, fgCol, boxBG, boxFG, active)
|
setSelectedItem = function(self, bgCol, fgCol, boxBG, boxFG, active)
|
||||||
itemSelectedBG = bgCol or itemSelectedBG
|
itemSelectedBG = bgCol or itemSelectedBG
|
||||||
itemSelectedFG = fgCol or itemSelectedFG
|
itemSelectedFG = fgCol or itemSelectedFG
|
||||||
boxSelectedBG = boxBG or boxSelectedBG
|
boxSelectedBG = boxBG or boxSelectedBG
|
||||||
boxSelectedFG = boxFG or boxSelectedFG
|
boxSelectedFG = boxFG or boxSelectedFG
|
||||||
selectionColorActive = active
|
selectionColorActive = active~=nil and active or true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -123,7 +128,7 @@ return function(name)
|
|||||||
if (self.parent ~= nil) then
|
if (self.parent ~= nil) then
|
||||||
self.parent:setFocusedObject(self)
|
self.parent:setFocusedObject(self)
|
||||||
end
|
end
|
||||||
--eventSystem:sendEvent(event, self, event, button, x, y)
|
self:getEventSystem():sendEvent(event, self, event, button, x, y)
|
||||||
self:setVisualChanged()
|
self:setVisualChanged()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user