Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
681d54b406 | ||
|
|
eab8794d38 | ||
|
|
1d3e2018ef | ||
|
|
44402b1d26 | ||
|
|
56d89ad6f0 | ||
|
|
4af3df72ab | ||
|
|
f404e0ad8f | ||
|
|
45bb23476b | ||
|
|
bd61da9593 | ||
|
|
9acf7d5345 | ||
|
|
1efca45639 | ||
|
|
2dfe69fe43 | ||
|
|
40b24ccf46 | ||
|
|
1ebeda0375 | ||
|
|
9a514e6f7c | ||
|
|
4f1baee771 | ||
|
|
6ed31dd44c | ||
|
|
19bc07e350 | ||
|
|
27321380ae | ||
|
|
bf9f01aae7 | ||
|
|
651690d8ab | ||
|
|
7bcbafe30b | ||
|
|
72f2c527b9 | ||
|
|
77eeb1ce81 | ||
|
|
04d5919a82 | ||
|
|
6fa519be86 | ||
|
|
00fff1c2f0 | ||
|
|
140f1b0014 | ||
|
|
153f2b9146 | ||
|
|
21467fe4f4 | ||
|
|
6f372fa070 | ||
|
|
3ca6ac5af0 | ||
|
|
ab767e16dd | ||
|
|
93a0c738fa | ||
|
|
04d85b633c | ||
|
|
4d83697537 | ||
|
|
ff12c040df | ||
|
|
897b7018a1 |
@@ -1,9 +1,10 @@
|
||||
local module = require("module")
|
||||
local Object = require("Object")
|
||||
local _OBJECTS = require("loadObjects")
|
||||
local BasaltDraw = require("basaltDraw")
|
||||
local utils = require("utils")
|
||||
local layout = require("layout")
|
||||
local basaltMon = require("basaltMon")
|
||||
local layout = module("layout")
|
||||
local basaltMon = module("basaltMon")
|
||||
local uuid = utils.uuid
|
||||
local rpairs = utils.rpairs
|
||||
local xmlValue = utils.getValueFromXML
|
||||
@@ -352,19 +353,6 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function focusSystem(self)
|
||||
if(focusedObject~=focusedObjectCache)then
|
||||
if(focusedObject~=nil)then
|
||||
focusedObject:loseFocusHandler()
|
||||
end
|
||||
if(focusedObjectCache~=nil)then
|
||||
focusedObjectCache:getFocusHandler()
|
||||
end
|
||||
focusedObject = focusedObjectCache
|
||||
end
|
||||
end
|
||||
|
||||
object = {
|
||||
barActive = false,
|
||||
barBackground = colors.gray,
|
||||
@@ -386,8 +374,15 @@ return function(name, parent, pTerm, basalt)
|
||||
end;
|
||||
|
||||
setFocusedObject = function(self, obj)
|
||||
focusedObjectCache = obj
|
||||
focusSystem(self)
|
||||
if(focusedObject~=obj)then
|
||||
if(focusedObject~=nil)then
|
||||
focusedObject:loseFocusHandler()
|
||||
end
|
||||
if(obj~=nil)then
|
||||
obj:getFocusHandler()
|
||||
end
|
||||
focusedObject = obj
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -463,8 +458,10 @@ return function(name, parent, pTerm, basalt)
|
||||
end;
|
||||
|
||||
removeFocusedObject = function(self)
|
||||
focusedObjectCache = nil
|
||||
focusSystem(self)
|
||||
if(focusedObject~=nil)then
|
||||
focusedObject:loseFocusHandler()
|
||||
end
|
||||
focusedObject = nil
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -527,7 +524,7 @@ return function(name, parent, pTerm, basalt)
|
||||
|
||||
|
||||
getScrollAmount = function(self)
|
||||
return autoScroll and scrollAmount or calculateMaxScroll(self)
|
||||
return autoScroll and calculateMaxScroll(self) or scrollAmount
|
||||
end,
|
||||
|
||||
show = function(self)
|
||||
@@ -732,14 +729,14 @@ return function(name, parent, pTerm, basalt)
|
||||
if(focusedObject~=nil)then focusedObject:getFocusHandler() end
|
||||
end;
|
||||
|
||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||
base.eventHandler(self, event, p1, p2, p3, p4)
|
||||
eventHandler = function(self, event, ...)
|
||||
base.eventHandler(self, event, ...)
|
||||
if(events["other_event"]~=nil)then
|
||||
for _, index in ipairs(eventZIndex["other_event"]) do
|
||||
if (events["other_event"][index] ~= nil) then
|
||||
for _, value in rpairs(events["other_event"][index]) do
|
||||
if (value.eventHandler ~= nil) then
|
||||
if (value:eventHandler(event, p1, p2, p3, p4)) then
|
||||
if (value:eventHandler(event, ...)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -816,7 +813,7 @@ return function(name, parent, pTerm, basalt)
|
||||
for _, value in rpairs(events["mouse_click"][index]) do
|
||||
if (value.mouseHandler ~= nil) then
|
||||
if (value:mouseHandler(button, x, y)) then
|
||||
focusSystem(self)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -849,7 +846,6 @@ return function(name, parent, pTerm, basalt)
|
||||
for _, value in rpairs(events["mouse_up"][index]) do
|
||||
if (value.mouseUpHandler ~= nil) then
|
||||
if (value:mouseUpHandler(button, x, y)) then
|
||||
focusSystem(self)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -857,7 +853,6 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
end
|
||||
focusSystem(self)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -871,7 +866,6 @@ return function(name, parent, pTerm, basalt)
|
||||
for _, value in rpairs(events["mouse_scroll"][index]) do
|
||||
if (value.scrollHandler ~= nil) then
|
||||
if (value:scrollHandler(dir, x, y)) then
|
||||
focusSystem(self)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -894,6 +888,25 @@ return function(name, parent, pTerm, basalt)
|
||||
return false
|
||||
end,
|
||||
|
||||
hoverHandler = function(self, x, y, stopped)
|
||||
if(base.hoverHandler(self, x, y, stopped))then
|
||||
if(events["mouse_move"]~=nil)then
|
||||
for _, index in pairs(eventZIndex["mouse_move"]) do
|
||||
if (events["mouse_move"][index] ~= nil) then
|
||||
for _, value in rpairs(events["mouse_move"][index]) do
|
||||
if (value.hoverHandler ~= nil) then
|
||||
if (value:hoverHandler(x, y, stopped)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if (isDragging) then
|
||||
local xO, yO = self.parent:getOffsetInternal()
|
||||
@@ -915,7 +928,6 @@ return function(name, parent, pTerm, basalt)
|
||||
for _, value in rpairs(events["mouse_drag"][index]) do
|
||||
if (value.dragHandler ~= nil) then
|
||||
if (value:dragHandler(button, x, y)) then
|
||||
focusSystem(self)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -924,7 +936,7 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
end
|
||||
focusSystem(self)
|
||||
|
||||
base.dragHandler(self, button, x, y)
|
||||
return false
|
||||
end,
|
||||
@@ -1036,6 +1048,24 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end;
|
||||
|
||||
blit = function (self, x, y, t, f, b)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (y >= 1) and (y <= self:getHeight()) then
|
||||
local w = self:getWidth()
|
||||
if (self.parent ~= nil) then
|
||||
t = sub(t, max(1 - x + 1, 1), w - x + 1)
|
||||
f = sub(f, max(1 - x + 1, 1), w - x + 1)
|
||||
b = sub(b, max(1 - x + 1, 1), w - x + 1)
|
||||
self.parent:blit(max(x + (obx - 1), obx), oby + y - 1, t, f, b)
|
||||
else
|
||||
t = sub(t, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||
f = sub(f, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||
b = sub(b, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||
basaltDraw.blit(max(x + (obx - 1), obx), oby + y - 1, t, f, b)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
drawBackgroundBox = function(self, x, y, width, height, bgCol)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ return function(name)
|
||||
local ignOffset = false
|
||||
local isVisible = true
|
||||
local initialized = false
|
||||
local isHovered = false
|
||||
local isClicked = false
|
||||
|
||||
local shadow = false
|
||||
local borderColors = {
|
||||
@@ -118,6 +120,8 @@ return function(name)
|
||||
if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end
|
||||
if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end
|
||||
if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end
|
||||
if(xmlValue("onHover", data)~=nil)then self:generateXMLEventFunction(self.onHover, xmlValue("onHover", data)) end
|
||||
if(xmlValue("onLeave", data)~=nil)then self:generateXMLEventFunction(self.onLeave, xmlValue("onLeave", data)) end
|
||||
if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end
|
||||
if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end
|
||||
if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end
|
||||
@@ -270,10 +274,10 @@ return function(name)
|
||||
|
||||
setSize = function(self, width, height, rel)
|
||||
if(type(width)=="number")then
|
||||
self.width = rel and self.width+width or width
|
||||
self.width = rel and self:getWidth()+width or width
|
||||
end
|
||||
if(type(height)=="number")then
|
||||
self.height = rel and self.height+height or height
|
||||
self.height = rel and self:getHeight()+height or height
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
if(type(width)=="string")then
|
||||
@@ -417,46 +421,48 @@ return function(name)
|
||||
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
|
||||
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
|
||||
end
|
||||
|
||||
local bgCol = self.bgColor
|
||||
if(borderColors["left"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y, 1, h, "\149")
|
||||
self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor)
|
||||
self.parent:drawForegroundBox(x-1, y, 1, h, borderColors["left"])
|
||||
end
|
||||
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
|
||||
self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor)
|
||||
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColors["left"])
|
||||
self.parent:drawTextBox(x, y, 1, h, "\149")
|
||||
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, h, self.bgColor) end
|
||||
self.parent:drawForegroundBox(x, y, 1, h, borderColors["left"])
|
||||
end
|
||||
if(borderColors["top"]~=false)then
|
||||
|
||||
self.parent:drawTextBox(x, y-1, w, 1, "\131")
|
||||
self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor)
|
||||
self.parent:drawForegroundBox(x, y-1, w, 1, borderColors["top"])
|
||||
self.parent:drawTextBox(x, y, w, 1, "\131")
|
||||
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, w, 1, self.bgColor) end
|
||||
self.parent:drawForegroundBox(x, y, w, 1, borderColors["top"])
|
||||
end
|
||||
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y-1, 1, 1, "\148")
|
||||
self.parent:drawForegroundBox(x+w, y-1, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y-1, 1, 1, borderColors["right"])
|
||||
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
|
||||
self.parent:drawTextBox(x, y, 1, 1, "\151")
|
||||
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, 1, self.bgColor) end
|
||||
self.parent:drawForegroundBox(x, y, 1, 1, borderColors["left"])
|
||||
end
|
||||
if(borderColors["right"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y, 1, h, "\149")
|
||||
self.parent:drawForegroundBox(x+w, y, 1, h, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y, 1, h, borderColors["right"])
|
||||
end
|
||||
if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y+h, 1, 1, "\133")
|
||||
self.parent:drawForegroundBox(x+w, y+h, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y+h, 1, 1, borderColors["right"])
|
||||
self.parent:drawTextBox(x+w-1, y, 1, h, "\149")
|
||||
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, h, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x+w-1, y, 1, h, borderColors["right"])
|
||||
end
|
||||
if(borderColors["bottom"]~=false)then
|
||||
self.parent:drawTextBox(x, y+h, w, 1, "\143")
|
||||
self.parent:drawForegroundBox(x, y+h, w, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x, y+h, w, 1, borderColors["bottom"])
|
||||
self.parent:drawTextBox(x, y+h-1, w, 1, "\143")
|
||||
if(bgCol~=false)then self.parent:drawForegroundBox(x, y+h-1, w, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x, y+h-1, w, 1, borderColors["bottom"])
|
||||
end
|
||||
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
|
||||
self.parent:drawTextBox(x+w-1, y, 1, 1, "\148")
|
||||
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x+w-1, y, 1, 1, borderColors["right"])
|
||||
end
|
||||
if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
|
||||
self.parent:drawTextBox(x+w-1, y+h-1, 1, 1, "\133")
|
||||
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y+h-1, 1, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x+w-1, y+h-1, 1, 1, borderColors["right"])
|
||||
end
|
||||
if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y+h, 1, 1, "\138")
|
||||
self.parent:drawForegroundBox(x-1, y+h, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x-1, y+h, 1, 1, borderColors["left"])
|
||||
self.parent:drawTextBox(x, y+h-1, 1, 1, "\138")
|
||||
if(bgCol~=false)then self.parent:drawForegroundBox(x-1, y+h-1, 1, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x, y+h-1, 1, 1, borderColors["left"])
|
||||
end
|
||||
end
|
||||
draw = false
|
||||
@@ -560,6 +566,8 @@ return function(name)
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
activeEvents["mouse_up"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
@@ -571,26 +579,68 @@ return function(name)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
activeEvents["mouse_up"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
onScroll = function(self, ...)
|
||||
onRelease = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_scroll", v)
|
||||
self:registerEvent("mouse_release", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
activeEvents["mouse_scroll"] = true
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
activeEvents["mouse_up"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onScroll = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_scroll", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
activeEvents["mouse_scroll"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onHover = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_hover", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_move", self)
|
||||
activeEvents["mouse_move"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onLeave = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_leave", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_move", self)
|
||||
activeEvents["mouse_move"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onDrag = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
@@ -626,13 +676,25 @@ return function(name)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key", v)
|
||||
self:registerEvent("char", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("char", self)
|
||||
activeEvents["key"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onChar = function(self, ...)
|
||||
if(isEnabled)then
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("char", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("char", self)
|
||||
activeEvents["char"] = true
|
||||
end
|
||||
end
|
||||
@@ -717,7 +779,8 @@ return function(name)
|
||||
|
||||
isCoordsInObject = function(self, x, y)
|
||||
if(isVisible)and(isEnabled)then
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if(x==nil)or(y==nil)then return false end
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local w, h = self:getSize()
|
||||
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
|
||||
return true
|
||||
@@ -728,11 +791,13 @@ return function(name)
|
||||
|
||||
mouseHandler = function(self, button, x, y, isMon)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y, isMon)
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x - (objX-1), y - (objY-1), isMon)
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
isClicked = true
|
||||
isDragging = true
|
||||
dragStartX, dragStartY = x, y
|
||||
return true
|
||||
@@ -742,8 +807,14 @@ return function(name)
|
||||
|
||||
mouseUpHandler = function(self, button, x, y)
|
||||
isDragging = false
|
||||
if(isClicked)then
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local val = eventSystem:sendEvent("mouse_release", self, "mouse_release", button, x - (objX-1), y - (objY-1))
|
||||
isClicked = false
|
||||
end
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y)
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x - (objX-1), y - (objY-1))
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
@@ -752,16 +823,8 @@ return function(name)
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if(isDragging)then
|
||||
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
||||
if (self.parent ~= nil) then
|
||||
xO, yO = self.parent:getOffsetInternal()
|
||||
xO = xO < 0 and math.abs(xO) or -xO
|
||||
yO = yO < 0 and math.abs(yO) or -yO
|
||||
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
||||
end
|
||||
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
|
||||
local val = eventSystem:sendEvent("mouse_drag", self, button, dX, dY, dragStartX-x, dragStartY-y, x, y)
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local val = eventSystem:sendEvent("mouse_drag", self, "mouse_drag", button, x - (objX-1), y - (objY-1), dragStartX-x, dragStartY-y, x, y)
|
||||
dragStartX, dragStartY = x, y
|
||||
if(val~=nil)then return val end
|
||||
if(self.parent~=nil)then
|
||||
@@ -780,7 +843,8 @@ return function(name)
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
|
||||
local objX, objY = self:getAbsolutePosition()
|
||||
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x - (objX-1), y - (objY-1))
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
@@ -790,6 +854,21 @@ return function(name)
|
||||
return false
|
||||
end,
|
||||
|
||||
hoverHandler = function(self, x, y, stopped)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_hover", self, "mouse_hover", x, y, stopped)
|
||||
if(val==false)then return false end
|
||||
isHovered = true
|
||||
return true
|
||||
end
|
||||
if(isHovered)then
|
||||
local val = eventSystem:sendEvent("mouse_leave", self, "mouse_leave", x, y, stopped)
|
||||
if(val==false)then return false end
|
||||
isHovered = false
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
keyHandler = function(self, key, isHolding)
|
||||
if(isEnabled)and(isVisible)then
|
||||
if (self:isFocused()) then
|
||||
@@ -815,7 +894,7 @@ return function(name)
|
||||
charHandler = function(self, char)
|
||||
if(isEnabled)and(isVisible)then
|
||||
if (self:isFocused()) then
|
||||
local val = eventSystem:sendEvent("char", self, "char", char)
|
||||
local val = eventSystem:sendEvent("char", self, "char", char)
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
@@ -858,6 +937,7 @@ return function(name)
|
||||
initialized = true
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
local function line(x1,y1,x2,y2)
|
||||
local points = {}
|
||||
if x1 == x2 and y1 == y2 then return {x=x1,y=x2} end
|
||||
local minX = math.min(x1, x2)
|
||||
local maxX, minY, maxY
|
||||
if minX == x1 then minY,maxX,maxY = y1,x2,y2
|
||||
else minY,maxX,maxY = y2,x1,y1 end
|
||||
local xDiff,yDiff = maxX - minX,maxY - minY
|
||||
if xDiff > math.abs(yDiff) then
|
||||
local y = minY
|
||||
local dy = yDiff / xDiff
|
||||
for x = minX, maxX do
|
||||
table.insert(points,{x=x,y=math.floor(y + 0.5)})
|
||||
y = y + dy
|
||||
end
|
||||
else
|
||||
local x,dx = minX,xDiff / yDiff
|
||||
if maxY >= minY then
|
||||
for y = minY, maxY do
|
||||
table.insert(points,{x=math.floor(x + 0.5),y=y})
|
||||
x = x + dx
|
||||
end
|
||||
else
|
||||
for y = minY, maxY, -1 do
|
||||
table.insert(points,{x=math.floor(x + 0.5),y=y})
|
||||
x = x - dx
|
||||
end
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
local function filledCircle(xC, yC, r)
|
||||
local points = {}
|
||||
for x=-r, r+1 do
|
||||
local dy = math.floor(math.sqrt(r*r - x*x))
|
||||
for y=-dy, dy+1 do
|
||||
table.insert(points, {x=xC+x, y=yC+y})
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
local function ellipse(xC, yC, r1, r2, filled)
|
||||
local rx,ry = math.ceil(math.floor(r1-0.5)/2),math.ceil(math.floor(r2-0.5)/2)
|
||||
local x,y=0,ry
|
||||
local d1 = ((ry * ry) - (rx * rx * ry) + (0.25 * rx * rx))
|
||||
local dx = 2*ry^2*x
|
||||
local dy = 2*rx^2*y
|
||||
local points = {}
|
||||
while dx < dy do
|
||||
table.insert(points,{x=x+xC,y=y+yC})
|
||||
table.insert(points,{x=-x+xC,y=y+yC})
|
||||
table.insert(points,{x=x+xC,y=-y+yC})
|
||||
table.insert(points,{x=-x+xC,y=-y+yC})
|
||||
if filled then
|
||||
for y=-y+yC+1,y+yC-1 do
|
||||
table.insert(points,{x=x+xC,y=y})
|
||||
table.insert(points,{x=-x+xC,y=y})
|
||||
end
|
||||
end
|
||||
if d1 < 0 then
|
||||
x = x + 1
|
||||
dx = dx + 2*ry^2
|
||||
d1 = d1 + dx + ry^2
|
||||
else
|
||||
x,y = x+1,y-1
|
||||
dx = dx + 2*ry^2
|
||||
dy = dy - 2*rx^2
|
||||
d1 = d1 + dx - dy + ry^2
|
||||
end
|
||||
end
|
||||
local d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry))
|
||||
while y >= 0 do
|
||||
table.insert(points,{x=x+xC,y=y+yC})
|
||||
table.insert(points,{x=-x+xC,y=y+yC})
|
||||
table.insert(points,{x=x+xC,y=-y+yC})
|
||||
table.insert(points,{x=-x+xC,y=-y+yC})
|
||||
if filled then
|
||||
for y=-y+yC,y+yC do
|
||||
table.insert(points,{x=x+xC,y=y})
|
||||
table.insert(points,{x=-x+xC,y=y})
|
||||
end
|
||||
end
|
||||
if d2 > 0 then
|
||||
y = y - 1
|
||||
dy = dy - 2*rx^2
|
||||
d2 = d2 + rx^2 - dy
|
||||
else
|
||||
y = y - 1
|
||||
x = x + 1
|
||||
dy = dy - 2*rx^2
|
||||
dx = dx + 2*ry^2
|
||||
d2 = d2 + dx - dy + rx^2
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
local function circle(xC, yC, r, filled)
|
||||
return ellipse(xC, yC, r, r, filled)
|
||||
end
|
||||
|
||||
return {
|
||||
circle = function(x, y, radius, filled)
|
||||
return circle(x, y, radius, filled)
|
||||
end,
|
||||
|
||||
rectangle = function(x1, y1, x2, y2, filled)
|
||||
local points = {}
|
||||
if(filled)then
|
||||
for y=y1,y2 do
|
||||
for x=x1,x2 do
|
||||
table.insert(points, {x=x,y=y})
|
||||
end
|
||||
end
|
||||
else
|
||||
for y=y1,y2 do
|
||||
for x=x1,x2 do
|
||||
if(x==x1)or(x==x2)or(y==y1)or(y==y2)then
|
||||
table.insert(points, {x=x,y=y})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return points
|
||||
end,
|
||||
|
||||
triangle = function(x1, y1, x2, y2, x3, y3, filled)
|
||||
local function drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3)
|
||||
local m1 = (x3 - x1) / (y3 - y1)
|
||||
local m2 = (x3 - x2) / (y3 - y2)
|
||||
local yStart = math.ceil(y1 - 0.5)
|
||||
local yEnd = math.ceil(y3 - 0.5)-1
|
||||
for y = yStart, yEnd do
|
||||
local px1 = m1 * (y + 0.5 - y1) + x1
|
||||
local px2 = m2 * (y + 0.5 - y2) + x2
|
||||
local xStart = math.ceil(px1 - 0.5)
|
||||
local xEnd = math.ceil(px2 - 0.5)
|
||||
for x=xStart,xEnd do
|
||||
table.insert(points,{x=x,y=y})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3)
|
||||
local m1 = (x2 - x1) / (y2 - y1)
|
||||
local m2 = (x3 - x1) / (y3 - y1)
|
||||
local yStart = math.ceil(y1-0.5)
|
||||
local yEnd = math.ceil(y3-0.5)-1
|
||||
for y = yStart, yEnd do
|
||||
local px1 = m1 * (y + 0.5 - y1) + x1
|
||||
local px2 = m2 * (y + 0.5 - y1) + x1
|
||||
local xStart = math.ceil(px1 - 0.5)
|
||||
local xEnd = math.ceil(px2 - 0.5)
|
||||
for x=xStart,xEnd do
|
||||
table.insert(points,{x=x,y=y})
|
||||
end
|
||||
end
|
||||
end
|
||||
local points = {}
|
||||
if(filled)then
|
||||
if y2 < y1 then x1,y1,x2,y2 = x2,y2,x1,y1 end
|
||||
if y3 < y2 then x2,y2,x3,y3 = x3,y3,x2,y2 end
|
||||
if y2 < y2 then x1,y1,x2,y2 = x2,y2,x1,y1 end
|
||||
if y1 == y2 then
|
||||
if x2 < x1 then x1,y1,x2,y2 = x2,y2,x1,y1 end
|
||||
drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3)
|
||||
elseif y2 == y3 then
|
||||
if x3 < x2 then x3,y3,x2,y2 = x2,y2,x3,y3 end
|
||||
drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3)
|
||||
else
|
||||
local alphaSplit = (y2-y1)/(y3-y1)
|
||||
local x = x1 + ((x3 - x1) * alphaSplit)
|
||||
local y = y1 + ((y3 - y1) * alphaSplit)
|
||||
if x2 < x then
|
||||
drawFlatBottomTriangle(points,x1,y1,x2,y2,x, y)
|
||||
drawFlatTopTriangle(points,x2,y2,x,y,x3,y3)
|
||||
else
|
||||
drawFlatBottomTriangle(points,x1,y1,x,y,x1,y1)
|
||||
drawFlatTopTriangle(points,x,y,x2,y2,x3,y3)
|
||||
end
|
||||
end
|
||||
else
|
||||
points = line(x1,y1,x2,y2)
|
||||
for k,v in pairs(line(x2,y2,x3,y3))do table.insert(points, v) end
|
||||
for k,v in pairs(line(x3,y3,x1,y1))do table.insert(points, v) end
|
||||
end
|
||||
return points
|
||||
end,
|
||||
|
||||
line = line,
|
||||
|
||||
ellipse = function(xCenter, yCenter, radius1, radius2, filled)
|
||||
return ellipse(xCenter, yCenter, radius1, radius2, filled)
|
||||
end
|
||||
}
|
||||
4
Basalt/libraries/module.lua
Normal file
4
Basalt/libraries/module.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return function(path)
|
||||
local exists, content = pcall(require, path)
|
||||
return exists and content or nil
|
||||
end
|
||||
146
Basalt/main.lua
146
Basalt/main.lua
@@ -6,11 +6,11 @@ local log = require("basaltLogs")
|
||||
local uuid = utils.uuid
|
||||
local createText = utils.createText
|
||||
local count = utils.tableCount
|
||||
|
||||
local moveThrottle = 300
|
||||
local dragThrottle = 50
|
||||
|
||||
local baseTerm = term.current()
|
||||
local version = "1.6.2"
|
||||
local debugger = true
|
||||
|
||||
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
||||
|
||||
@@ -29,6 +29,39 @@ local function stop()
|
||||
baseTerm.setCursorPos(1, 1)
|
||||
end
|
||||
|
||||
local basaltError = function(errMsg)
|
||||
baseTerm.clear()
|
||||
baseTerm.setBackgroundColor(colors.black)
|
||||
baseTerm.setTextColor(colors.red)
|
||||
local w,h = baseTerm.getSize()
|
||||
if(basalt.logging)then
|
||||
log(errMsg, "Error")
|
||||
end
|
||||
|
||||
local text = createText("Basalt error: "..errMsg, w)
|
||||
local yPos = 1
|
||||
for k,v in pairs(text)do
|
||||
baseTerm.setCursorPos(1,yPos)
|
||||
baseTerm.write(v)
|
||||
yPos = yPos + 1
|
||||
end
|
||||
baseTerm.setCursorPos(1,yPos+1)
|
||||
updaterActive = false
|
||||
end
|
||||
|
||||
local function schedule(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(schedules, co)
|
||||
else
|
||||
basaltError(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local setVariable = function(name, var)
|
||||
variables[name] = var
|
||||
end
|
||||
@@ -94,6 +127,8 @@ local bInstance = {
|
||||
return baseTerm
|
||||
end,
|
||||
|
||||
schedule = schedule,
|
||||
|
||||
stop = stop,
|
||||
newFrame = Frame,
|
||||
|
||||
@@ -102,26 +137,6 @@ local bInstance = {
|
||||
end
|
||||
}
|
||||
|
||||
local basaltError = function(errMsg)
|
||||
baseTerm.clear()
|
||||
baseTerm.setBackgroundColor(colors.black)
|
||||
baseTerm.setTextColor(colors.red)
|
||||
local w,h = baseTerm.getSize()
|
||||
if(basalt.logging)then
|
||||
log(errMsg, "Error")
|
||||
end
|
||||
|
||||
local text = createText("Basalt error: "..errMsg, w)
|
||||
local yPos = 1
|
||||
for k,v in pairs(text)do
|
||||
baseTerm.setCursorPos(1,yPos)
|
||||
baseTerm.write(v)
|
||||
yPos = yPos + 1
|
||||
end
|
||||
baseTerm.setCursorPos(1,yPos+1)
|
||||
updaterActive = false
|
||||
end
|
||||
|
||||
local function handleSchedules(event, p1, p2, p3, p4)
|
||||
if(#schedules>0)then
|
||||
local finished = {}
|
||||
@@ -159,6 +174,40 @@ local function drawFrames()
|
||||
end
|
||||
end
|
||||
|
||||
local stopped, moveX, moveY = nil, nil, nil
|
||||
local moveTimer = nil
|
||||
local function mouseMoveEvent(stp, x, y)
|
||||
stopped, moveX, moveY = stopped, x, y
|
||||
if(moveTimer==nil)then
|
||||
moveTimer = os.startTimer(moveThrottle/1000)
|
||||
end
|
||||
end
|
||||
|
||||
local function moveHandlerTimer()
|
||||
moveTimer = nil
|
||||
mainFrame:hoverHandler(moveX, moveY, stopped)
|
||||
activeFrame = mainFrame
|
||||
end
|
||||
|
||||
local btn, dragX, dragY = nil, nil, nil
|
||||
local dragTimer = nil
|
||||
local function dragHandlerTimer()
|
||||
dragTimer = nil
|
||||
mainFrame:dragHandler(btn, dragX, dragY)
|
||||
activeFrame = mainFrame
|
||||
end
|
||||
|
||||
local function mouseDragEvent(b, x, y)
|
||||
btn, dragX, dragY = b, x, y
|
||||
if(dragThrottle<50)then
|
||||
dragHandlerTimer()
|
||||
else
|
||||
if(dragTimer==nil)then
|
||||
dragTimer = os.startTimer(dragThrottle/1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
|
||||
if(mainFrame~=nil)then
|
||||
@@ -166,16 +215,18 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
mainFrame:mouseHandler(p1, p2, p3, false)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_drag") then
|
||||
mainFrame:dragHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
mouseDragEvent(p1, p2, p3)
|
||||
elseif (event == "mouse_up") then
|
||||
mainFrame:mouseUpHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_scroll") then
|
||||
mainFrame:scrollHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_move") then
|
||||
mouseMoveEvent(p1, p2, p3)
|
||||
end
|
||||
end
|
||||
|
||||
if(event == "monitor_touch") then
|
||||
if(monFrames[p1]~=nil)then
|
||||
monFrames[p1]:mouseHandler(1, p2, p3, true)
|
||||
@@ -213,9 +264,15 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
if(updaterActive==false)then return end
|
||||
end
|
||||
end
|
||||
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
|
||||
for k, v in pairs(frames) do
|
||||
v:eventHandler(event, p1, p2, p3, p4)
|
||||
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="mouse_move")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
|
||||
if(event=="timer")and(p1==moveTimer)then
|
||||
moveHandlerTimer()
|
||||
elseif(event=="timer")and(p1==dragTimer)then
|
||||
dragHandlerTimer()
|
||||
else
|
||||
for k, v in pairs(frames) do
|
||||
v:eventHandler(event, p1, p2, p3, p4)
|
||||
end
|
||||
end
|
||||
end
|
||||
handleSchedules(event, p1, p2, p3, p4)
|
||||
@@ -242,6 +299,28 @@ basalt = {
|
||||
log(...)
|
||||
end,
|
||||
|
||||
setMouseMoveThrottle = function(amount)
|
||||
if(_HOST:find("CraftOS%-PC"))then
|
||||
if(config.get("mouse_move_throttle")~=10)then config.set("mouse_move_throttle", 10) end
|
||||
if(amount<100)then
|
||||
moveThrottle = 100
|
||||
else
|
||||
moveThrottle = amount
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
setMouseDragThrottle = function(amount)
|
||||
if(amount<=0)then
|
||||
dragThrottle = 0
|
||||
else
|
||||
dragTimer = nil
|
||||
dragThrottle = amount
|
||||
end
|
||||
end,
|
||||
|
||||
autoUpdate = function(isActive)
|
||||
updaterActive = isActive
|
||||
if(isActive==nil)then updaterActive = true end
|
||||
@@ -304,18 +383,7 @@ basalt = {
|
||||
end
|
||||
end,
|
||||
|
||||
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(schedules, co)
|
||||
else
|
||||
basaltError(result)
|
||||
end
|
||||
end
|
||||
end,
|
||||
schedule = schedule,
|
||||
|
||||
createFrame = function(name)
|
||||
name = name or uuid()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
local basaltEvent = require("basaltEvent")
|
||||
|
||||
local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi
|
||||
local floor,sin,cos,pi,sqrt,pow = math.floor,math.sin,math.cos,math.pi,math.sqrt,math.pow
|
||||
|
||||
-- You can find the easing curves here https://easings.net
|
||||
|
||||
local lerp = function(s, e, pct)
|
||||
return s + (e - s) * pct
|
||||
@@ -39,16 +41,183 @@ local easeInOutSine = function(t)
|
||||
return -(cos(pi * x) - 1) / 2
|
||||
end
|
||||
|
||||
local easeInBack = function(t)
|
||||
local c1 = 1.70158;
|
||||
local c3 = c1 + 1
|
||||
return c3*t^3-c1*t^2
|
||||
end
|
||||
|
||||
local easeInCubic = function(t)
|
||||
return t^3
|
||||
end
|
||||
|
||||
local easeInElastic = function(t)
|
||||
local c4 = (2*pi)/3;
|
||||
return t == 0 and 0 or (t == 1 and 1 or (
|
||||
-2^(10*t-10)*sin((t*10-10.75)*c4)
|
||||
))
|
||||
end
|
||||
|
||||
local function easeInExpo(t)
|
||||
return t == 0 and 0 or 2^(10*t-10)
|
||||
end
|
||||
|
||||
local function easeInExpo(t)
|
||||
return t == 0 and 0 or 2^(10*t-10)
|
||||
end
|
||||
|
||||
local function easeInOutBack(t)
|
||||
local c1 = 1.70158;
|
||||
local c2 = c1 * 1.525;
|
||||
return t < 0.5 and ((2*t)^2*((c2+1)*2*t-c2))/2 or ((2*t-2)^2*((c2+1)*(t*2-2)+c2)+2)/2
|
||||
end
|
||||
|
||||
local function easeInOutCubic(t)
|
||||
return t < 0.5 and 4 * t^3 or 1-(-2*t+2)^3 / 2
|
||||
end
|
||||
|
||||
local function easeInOutElastic(t)
|
||||
local c5 = (2*pi) / 4.5
|
||||
return t==0 and 0 or (t == 1 and 1 or (t < 0.5 and -(2^(20*t-10) * sin((20*t - 11.125) * c5))/2 or (2^(-20*t+10) * sin((20*t - 11.125) * c5))/2 + 1))
|
||||
end
|
||||
|
||||
local function easeInOutExpo(t)
|
||||
return t == 0 and 0 or (t == 1 and 1 or (t < 0.5 and 2^(20*t-10)/2 or (2-2^(-20*t+10)) /2))
|
||||
end
|
||||
|
||||
local function easeInOutQuad(t)
|
||||
return t < 0.5 and 2*t^2 or 1-(-2*t+2)^2/2
|
||||
end
|
||||
|
||||
local function easeInOutQuart(t)
|
||||
return t < 0.5 and 8*t^4 or 1 - (-2*t+2)^4 / 2
|
||||
end
|
||||
|
||||
local function easeInOutQuint(t)
|
||||
return t < 0.5 and 16*t^5 or 1-(-2*t+2)^5 / 2
|
||||
end
|
||||
|
||||
local function easeInQuad(t)
|
||||
return t^2
|
||||
end
|
||||
|
||||
local function easeInQuart(t)
|
||||
return t^4
|
||||
end
|
||||
|
||||
local function easeInQuint(t)
|
||||
return t^5
|
||||
end
|
||||
|
||||
local function easeOutBack(t)
|
||||
local c1 = 1.70158;
|
||||
local c3 = c1 + 1
|
||||
return 1+c3*(t-1)^3+c1*(t-1)^2
|
||||
end
|
||||
|
||||
local function easeOutCubic(t)
|
||||
return 1 - (1-t)^3
|
||||
end
|
||||
|
||||
local function easeOutElastic(t)
|
||||
local c4 = (2*pi)/3;
|
||||
|
||||
return t == 0 and 0 or (t == 1 and 1 or (2^(-10*t)*sin((t*10-0.75)*c4)+1))
|
||||
end
|
||||
|
||||
local function easeOutExpo(t)
|
||||
return t == 1 and 1 or 1-2^(-10*t)
|
||||
end
|
||||
|
||||
local function easeOutQuad(t)
|
||||
return 1 - (1 - t) * (1 - t)
|
||||
end
|
||||
|
||||
local function easeOutQuart(t)
|
||||
return 1 - (1-t)^4
|
||||
end
|
||||
|
||||
local function easeOutQuint(t)
|
||||
return 1 - (1 - t)^5
|
||||
end
|
||||
|
||||
local function easeInCirc(t)
|
||||
return 1 - sqrt(1 - pow(t, 2))
|
||||
end
|
||||
|
||||
local function easeOutCirc(t)
|
||||
return sqrt(1 - pow(t - 1, 2))
|
||||
end
|
||||
|
||||
local function easeInOutCirc(t)
|
||||
return t < 0.5 and (1 - sqrt(1 - pow(2 * t, 2))) / 2 or (sqrt(1 - pow(-2 * t + 2, 2)) + 1) / 2;
|
||||
end
|
||||
|
||||
local function easeOutBounce(t)
|
||||
local n1 = 7.5625;
|
||||
local d1 = 2.75;
|
||||
|
||||
if (t < 1 / d1)then
|
||||
return n1 * t * t
|
||||
elseif (t < 2 / d1)then
|
||||
local a = t - 1.5 / d1
|
||||
return n1 * a * a + 0.75;
|
||||
elseif (t < 2.5 / d1)then
|
||||
local a = t - 2.25 / d1
|
||||
return n1 * a * a + 0.9375;
|
||||
else
|
||||
local a = t - 2.625 / d1
|
||||
return n1 * a * a + 0.984375;
|
||||
end
|
||||
end
|
||||
|
||||
local function easeInBounce(t)
|
||||
return 1 - easeOutBounce(1 - t)
|
||||
end
|
||||
|
||||
local function easeInOutBounce(t)
|
||||
return x < 0.5 and (1 - easeOutBounce(1 - 2 * t)) / 2 or (1 + easeOutBounce(2 * t - 1)) / 2;
|
||||
end
|
||||
|
||||
|
||||
|
||||
local lerp = {
|
||||
linear = linear,
|
||||
lerp = lerp,
|
||||
flip=flip,
|
||||
easeIn=easeIn,
|
||||
easeOut=easeOut,
|
||||
easeInOut=easeInOut,
|
||||
easeOutSine = easeOutSine,
|
||||
easeInSine = easeInSine,
|
||||
easeInBack=easeInBack,
|
||||
easeInCubic=easeInCubic,
|
||||
easeInElastic=easeInElastic,
|
||||
easeInExpo=easeInExpo,
|
||||
easeInQuad=easeInQuad,
|
||||
easeInQuart=easeInQuart,
|
||||
easeInQuint=easeInQuint,
|
||||
easeInCirc=easeInCirc,
|
||||
easeInBounce=easeInBounce,
|
||||
easeOut=easeOut,
|
||||
easeOutSine = easeOutSine,
|
||||
easeOutBack=easeOutBack,
|
||||
easeOutCubic=easeOutCubic,
|
||||
easeOutElastic=easeOutElastic,
|
||||
easeOutExpo=easeOutExpo,
|
||||
easeOutQuad=easeOutQuad,
|
||||
easeOutQuart=easeOutQuart,
|
||||
easeOutQuint=easeOutQuint,
|
||||
easeOutCirc=easeOutCirc,
|
||||
easeOutBounce=easeOutBounce,
|
||||
easeInOut=easeInOut,
|
||||
easeInOutSine = easeInOutSine,
|
||||
easeInOutBack=easeInOutBack,
|
||||
easeInOutCubic=easeInOutCubic,
|
||||
easeInOutElastic=easeInOutElastic,
|
||||
easeInOutExpo=easeInOutExpo,
|
||||
easeInOutQuad=easeInOutQuad,
|
||||
easeInOutQuart=easeInOutQuart,
|
||||
easeInOutQuint=easeInOutQuint,
|
||||
easeInOutCirc=easeInOutCirc,
|
||||
easeInOutBounce=easeInOutBounce,
|
||||
}
|
||||
|
||||
local activeAnimations = {}
|
||||
@@ -185,6 +354,11 @@ return function(name)
|
||||
return self
|
||||
end,
|
||||
|
||||
addMode = function(self, modeId, modeF)
|
||||
lerp[modeId] = modeF
|
||||
return self
|
||||
end,
|
||||
|
||||
generateXMLEventFunction = function(self, func, val)
|
||||
local createF = function(str)
|
||||
if(str:sub(1,1)=="#")then
|
||||
@@ -362,9 +536,9 @@ return function(name)
|
||||
return self
|
||||
end,
|
||||
|
||||
add = function(self, func, wait)
|
||||
add = function(self, func, timer)
|
||||
lastFunc = func
|
||||
addAnimationPart((wait or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func)
|
||||
addAnimationPart((timer or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func)
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
@@ -17,8 +17,10 @@ return function(name)
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ButtonBG")
|
||||
self.fgColor = self.parent:getTheme("ButtonText")
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("ButtonBG")
|
||||
self.fgColor = self.parent:getTheme("ButtonText")
|
||||
end
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
|
||||
@@ -72,10 +72,12 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
base.init(self)
|
||||
self.bgColor = self.parent:getTheme("CheckboxBG")
|
||||
self.fgColor = self.parent:getTheme("CheckboxText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("CheckboxBG")
|
||||
self.fgColor = self.parent:getTheme("CheckboxText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -225,14 +225,14 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("DropdownBG")
|
||||
self.fgColor = self.parent:getTheme("DropdownText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("DropdownBG")
|
||||
self.fgColor = self.parent:getTheme("DropdownText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -1,471 +0,0 @@
|
||||
local Object = require("Object")
|
||||
local geometric = require("geometricPoints")
|
||||
local tHex = require("tHex")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
|
||||
local sub,len,max,min = string.sub,string.len,math.max,math.min
|
||||
|
||||
return function(name)
|
||||
-- Graphic
|
||||
local base = Object(name)
|
||||
local objectType = "Graphic"
|
||||
base:setZIndex(2)
|
||||
|
||||
local graphicObjects = {}
|
||||
local graphic = {}
|
||||
local shrinkedGraphic = {}
|
||||
local isGraphicShrinked = false
|
||||
local xOffset, yOffset = 0, 0
|
||||
local dragable = false
|
||||
local xMouse,yMouse
|
||||
local w, h = 40, 15
|
||||
local canvasSizeChanged = false
|
||||
|
||||
local tColourLookup = {}
|
||||
for n=1,16 do
|
||||
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
|
||||
end
|
||||
|
||||
local function stringToTable(str)
|
||||
local t = {}
|
||||
for i = 1, #str do
|
||||
t[i] = str:sub(i, i)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local function setBG(x, y, width, height, colorStr)
|
||||
if (y >= 1) and (y <= height) then
|
||||
if (x + len(colorStr) > 0) and (x <= width) then
|
||||
local oldCache = graphic[y]
|
||||
local newCache
|
||||
local nEnd = x + #colorStr - 1
|
||||
|
||||
if (x < 1) then
|
||||
colorStr = sub(colorStr, 1 - x + 1, width - x + 1)
|
||||
elseif (nEnd > width) then
|
||||
colorStr = sub(colorStr, 1, width - x + 1)
|
||||
end
|
||||
|
||||
if (x > 1) then
|
||||
newCache = sub(oldCache, 1, x - 1) .. colorStr
|
||||
else
|
||||
newCache = colorStr
|
||||
end
|
||||
if nEnd < width then
|
||||
newCache = newCache .. sub(oldCache, nEnd + 1, width)
|
||||
end
|
||||
graphic[y] = newCache
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function redrawCanvasSize()
|
||||
local w,h = w,h
|
||||
if(isGraphicShrinked)then w = w*2 h = h*3 end
|
||||
for y=1,h do
|
||||
if(graphic[y]~=nil)then
|
||||
if(w>graphic[y]:len())then
|
||||
graphic[y] = graphic[y]..(tHex[base.bgColor]):rep(w-graphic[y]:len())
|
||||
else
|
||||
graphic[y] = graphic[y]:sub(1,w)
|
||||
end
|
||||
else
|
||||
graphic[y] = (tHex[base.bgColor]):rep(w)
|
||||
end
|
||||
end
|
||||
end
|
||||
redrawCanvasSize()
|
||||
|
||||
|
||||
local function shrink()
|
||||
local function parseLine( tImageArg, sLine )
|
||||
local tLine = {}
|
||||
for x=1,sLine:len() do
|
||||
tLine[x] = tColourLookup[ string.byte(sLine,x,x) ] or 0
|
||||
end
|
||||
table.insert( tImageArg, tLine )
|
||||
end
|
||||
function parseImage( sRawData )
|
||||
if type( sRawData ) ~= "string" then
|
||||
error( "bad argument #1 (expected string, got " .. type( sRawData ) .. ")" )
|
||||
end
|
||||
local tImage = {}
|
||||
for sLine in ( sRawData .. "\n" ):gmatch( "(.-)\n" ) do
|
||||
parseLine( tImage, sLine )
|
||||
end
|
||||
return tImage
|
||||
end
|
||||
|
||||
local rawImg = ""
|
||||
for y=1,#graphic do
|
||||
if(y==#graphic)then
|
||||
rawImg = rawImg..graphic[y]
|
||||
else
|
||||
rawImg = rawImg..graphic[y].."\n"
|
||||
end
|
||||
end
|
||||
local img = parseImage(rawImg)
|
||||
-- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
|
||||
local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 },
|
||||
{ 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } }
|
||||
|
||||
local colourNum, exponents, colourChar = {}, {}, {}
|
||||
for i = 0, 15 do
|
||||
exponents[2 ^ i] = i
|
||||
end
|
||||
do
|
||||
local hex = "0123456789abcdef"
|
||||
for i = 1, 16 do
|
||||
colourNum[hex:sub(i, i)] = i - 1
|
||||
colourNum[i - 1] = hex:sub(i, i)
|
||||
colourChar[hex:sub(i, i)] = 2 ^ (i - 1)
|
||||
colourChar[2 ^ (i - 1)] = hex:sub(i, i)
|
||||
|
||||
local thisRel = relations[i - 1]
|
||||
for i = 1, #thisRel do
|
||||
thisRel[i] = 2 ^ thisRel[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getBestColourMatch(usage)
|
||||
local lastCol = relations[exponents[usage[#usage][1]]]
|
||||
|
||||
for j = 1, #lastCol do
|
||||
local thisRelation = lastCol[j]
|
||||
for i = 1, #usage - 1 do
|
||||
if usage[i][1] == thisRelation then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
local function colsToChar(pattern, totals)
|
||||
if not totals then
|
||||
local newPattern = {}
|
||||
totals = {}
|
||||
for i = 1, 6 do
|
||||
local thisVal = pattern[i]
|
||||
local thisTot = totals[thisVal]
|
||||
totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal
|
||||
end
|
||||
pattern = newPattern
|
||||
end
|
||||
|
||||
local usage = {}
|
||||
for key, value in pairs(totals) do
|
||||
usage[#usage + 1] = { key, value }
|
||||
end
|
||||
|
||||
if #usage > 1 then
|
||||
-- Reduce the chunk to two colours:
|
||||
while #usage > 2 do
|
||||
table.sort(usage, function(a, b)
|
||||
return a[2] > b[2]
|
||||
end)
|
||||
local matchToInd, usageLen = getBestColourMatch(usage), #usage
|
||||
local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1]
|
||||
for i = 1, 6 do
|
||||
if pattern[i] == matchFrom then
|
||||
pattern[i] = matchTo
|
||||
usage[matchToInd][2] = usage[matchToInd][2] + 1
|
||||
end
|
||||
end
|
||||
usage[usageLen] = nil
|
||||
end
|
||||
|
||||
-- Convert to character. Adapted from oli414's function:
|
||||
-- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/
|
||||
local data = 128
|
||||
for i = 1, #pattern - 1 do
|
||||
if pattern[i] ~= pattern[6] then
|
||||
data = data + 2 ^ (i - 1)
|
||||
end
|
||||
end
|
||||
return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]]
|
||||
else
|
||||
-- Solid colour character:
|
||||
return "\128", colourChar[pattern[1]], colourChar[pattern[1]]
|
||||
end
|
||||
end
|
||||
|
||||
local results, width, height, bgCol = { {}, {}, {} }, 0, #img + #img % 3, base.bgColor or colors.black
|
||||
for i = 1, #img do
|
||||
if #img[i] > width then
|
||||
width = #img[i]
|
||||
end
|
||||
end
|
||||
|
||||
for y = 0, height - 1, 3 do
|
||||
local cRow, tRow, bRow, counter = {}, {}, {}, 1
|
||||
|
||||
for x = 0, width - 1, 2 do
|
||||
-- Grab a 2x3 chunk:
|
||||
local pattern, totals = {}, {}
|
||||
|
||||
for yy = 1, 3 do
|
||||
for xx = 1, 2 do
|
||||
pattern[#pattern + 1] = (img[y + yy] and img[y + yy][x + xx]) and (img[y + yy][x + xx] == 0 and bgCol or img[y + yy][x + xx]) or bgCol
|
||||
totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1
|
||||
end
|
||||
end
|
||||
|
||||
cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals)
|
||||
counter = counter + 1
|
||||
end
|
||||
|
||||
results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow)
|
||||
end
|
||||
|
||||
results.width, results.height = #results[1][1], #results[1]
|
||||
|
||||
shrinkedGraphic = results
|
||||
end
|
||||
|
||||
local function redraw()
|
||||
local w,h = w,h
|
||||
if(isGraphicShrinked)then w = w*2 h = h*3 end
|
||||
for k,v in pairs(graphicObjects)do
|
||||
for a,b in pairs(v[1])do
|
||||
setBG(b.x, b.y, w, h, v[2])
|
||||
end
|
||||
end
|
||||
if(isGraphicShrinked)then
|
||||
shrink()
|
||||
end
|
||||
end
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("GraphicBG")
|
||||
end,
|
||||
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
setSize = function(self, width, height, rel)
|
||||
base.setSize(self, width, height, rel)
|
||||
if not(canvasSizeChanged)then
|
||||
w = width
|
||||
h = height
|
||||
redrawCanvasSize()
|
||||
end
|
||||
redraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setOffset = function(self, x, y)
|
||||
xOffset = x or xOffset
|
||||
yOffset = y or yOffset
|
||||
return self
|
||||
end,
|
||||
|
||||
setCanvasSize = function(self, width, height)
|
||||
w,h = width,height
|
||||
canvasSizeChanged = true
|
||||
redrawCanvasSize()
|
||||
return self
|
||||
end,
|
||||
|
||||
clearCanvas = function(self)
|
||||
graphicObjects = {}
|
||||
graphic = {}
|
||||
redrawCanvasSize()
|
||||
end,
|
||||
|
||||
getOffset = function(self)
|
||||
return xOffset,yOffset
|
||||
end,
|
||||
|
||||
setValuesByXMLData = function(self, data)
|
||||
base.setValuesByXMLData(self, data)
|
||||
if(xmlValue("text", data)~=nil)then self:setText(xmlValue("text", data)) end
|
||||
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
|
||||
if(xmlValue("yOffset", data)~=nil)then self:setOffset(xOffset, xmlValue("yOffset", data)) end
|
||||
if(xmlValue("wCanvas", data)~=nil)then w = xmlValue("wCanvas", data) end
|
||||
if(xmlValue("hCanvas", data)~=nil)then h = xmlValue("hCanvas", data) end
|
||||
if(xmlValue("shrink", data)~=nil)then if(xmlValue("shrink", data))then self:shrink() end end
|
||||
if(xmlValue("dragable", data)~=nil)then if(xmlValue("dragable", data))then dragable = true end end
|
||||
if(data["ellipse"]~=nil)then
|
||||
local tab = data["ellipse"]
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
for k,v in pairs(tab)do
|
||||
local col = colors[xmlValue("color", v)]
|
||||
local rad1 = xmlValue("radius", v)
|
||||
local rad2 = xmlValue("radius2", v)
|
||||
local x = xmlValue("x", v)
|
||||
local y = xmlValue("y", v)
|
||||
local filled = xmlValue("filled", v)
|
||||
self:addEllipse(col, rad1, rad2, x, y, filled)
|
||||
end
|
||||
end
|
||||
if(data["circle"]~=nil)then
|
||||
local tab = data["circle"]
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
for k,v in pairs(tab)do
|
||||
local col = colors[xmlValue("color", v)]
|
||||
local rad = tonumber(xmlValue("radius", v))
|
||||
local x = tonumber(xmlValue("x", v))
|
||||
local y = tonumber(xmlValue("y", v))
|
||||
local filled = xmlValue("filled", v)
|
||||
self:addCircle(col, rad, x, y, filled)
|
||||
end
|
||||
end
|
||||
if(data["line"]~=nil)then
|
||||
local tab = data["line"]
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
for k,v in pairs(tab)do
|
||||
local col = colors[xmlValue("color", v)]
|
||||
local x = tonumber(xmlValue("x", v))
|
||||
local x2 = tonumber(xmlValue("x2", v))
|
||||
local y = tonumber(xmlValue("y", v))
|
||||
local y2 = tonumber(xmlValue("y2", v))
|
||||
self:addLine(col, x, y, x2, y2)
|
||||
end
|
||||
end
|
||||
|
||||
if(data["rectangle"]~=nil)then
|
||||
local tab = data["rectangle"]
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
for k,v in pairs(tab)do
|
||||
local col = colors[xmlValue("color", v)]
|
||||
local x = tonumber(xmlValue("x", v))
|
||||
local x2 = tonumber(xmlValue("x2", v))
|
||||
local y = tonumber(xmlValue("y", v))
|
||||
local y2 = tonumber(xmlValue("y2", v))
|
||||
local filled = xmlValue("filled", v)=="true" and true or false
|
||||
self:addRectangle(col, x, y, x2, y2, filled)
|
||||
end
|
||||
end
|
||||
if(data["triangle"]~=nil)then
|
||||
local tab = data["triangle"]
|
||||
if(tab.properties~=nil)then tab = {tab} end
|
||||
for k,v in pairs(tab)do
|
||||
local col = colors[xmlValue("color", v)]
|
||||
local x = tonumber(xmlValue("x", v))
|
||||
local x2 = tonumber(xmlValue("x2", v))
|
||||
local x3 = tonumber(xmlValue("x2", v))
|
||||
local y = tonumber(xmlValue("y", v))
|
||||
local y2 = tonumber(xmlValue("y2", v))
|
||||
local y3 = tonumber(xmlValue("y3", v))
|
||||
local filled = xmlValue("filled", v)
|
||||
self:addTriangle(col, x, y, x2, y2, x3, y3, filled)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end,
|
||||
|
||||
addCircle = function(self, color, rad, x, y, filled)
|
||||
local col = tHex[color]
|
||||
table.insert(graphicObjects, {geometric.circle(x or 1, y or 1, rad, filled), tHex[color]})
|
||||
redraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
addEllipse = function(self, color, rad, rad2, x, y, filled)
|
||||
table.insert(graphicObjects, {geometric.ellipse(x or 1, y or 1, rad, rad2, filled), tHex[color]})
|
||||
redraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
addLine = function(self, color, x1, y1, x2, y2)
|
||||
table.insert(graphicObjects, {geometric.line(x1 or 1, y1 or 1, x2 or 1, y2 or 1), tHex[color]})
|
||||
redraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
addTriangle = function(self, color, x1, y1, x2, y2, x3, y3, filled)
|
||||
table.insert(graphicObjects, {geometric.triangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, x3 or 1, y3 or 1, filled), tHex[color]})
|
||||
redraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
addRectangle = function(self, color, x1, y1, x2, y2, filled)
|
||||
table.insert(graphicObjects, {geometric.rectangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, filled), tHex[color]})
|
||||
redraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
shrink = function(self)
|
||||
isGraphicShrinked = true
|
||||
redrawCanvasSize()
|
||||
shrink()
|
||||
return self
|
||||
end,
|
||||
|
||||
setDragable = function(self, drag)
|
||||
dragable = drag == true and true or false
|
||||
return self
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if(base.mouseHandler(self, event, button, x, y))then
|
||||
if(dragable)then
|
||||
if(event=="mouse_click")then
|
||||
xMouse,yMouse = x,y
|
||||
end
|
||||
|
||||
if(event=="mouse_drag")then
|
||||
if(xMouse~=nil)and(yMouse~=nil)then
|
||||
xOffset = max(min(xOffset+xMouse-x, w-self:getWidth()),0)
|
||||
xMouse = x
|
||||
yOffset = max(min(yOffset+yMouse-y, h-self:getHeight()),0)
|
||||
yMouse = y
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
end
|
||||
if (isGraphicShrinked) then
|
||||
-- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
|
||||
local t, tC, bC = shrinkedGraphic[1], shrinkedGraphic[2], shrinkedGraphic[3]
|
||||
for i = 1, shrinkedGraphic.height do
|
||||
local x, y = obx+xOffset, oby + i - 1 + yOffset
|
||||
if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then
|
||||
local tI = t[i]
|
||||
local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w)
|
||||
if type(tI) == "string" then
|
||||
self.parent:setText(xpos, y, sub(tI, substart, subend))
|
||||
self.parent:setFG(xpos, y, sub(tC[i], substart, subend))
|
||||
self.parent:setBG(xpos, y, sub(bC[i], substart, subend))
|
||||
elseif type(tI) == "table" then
|
||||
self.parent:setText(xpos, y, sub(tI[2], substart, subend))
|
||||
self.parent:setFG(xpos, y, sub(tC[i], substart, subend))
|
||||
self.parent:setBG(xpos, y, sub(bC[i], substart, subend))
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for i = 1, #graphic do
|
||||
local x, y = obx+xOffset, oby + i - 1 + yOffset
|
||||
if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then
|
||||
local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w)
|
||||
self.parent:setBG(xpos, y, sub(graphic[i],substart,subend))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
end
|
||||
@@ -202,12 +202,12 @@ return function(name)
|
||||
if (text:len() < inputLimit or inputLimit <= 0) then
|
||||
if (inputType == "number") then
|
||||
local cache = text
|
||||
if (char == ".") or (tonumber(char) ~= nil) then
|
||||
if (#text==0 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then
|
||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||
textX = textX + 1
|
||||
end
|
||||
if (tonumber(base.getValue()) == nil) then
|
||||
self:setValue(cache)
|
||||
--self:setValue(cache)
|
||||
end
|
||||
else
|
||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||
@@ -353,8 +353,6 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("InputBG")
|
||||
self.fgColor = self.parent:getTheme("InputText")
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("key", self)
|
||||
@@ -362,6 +360,10 @@ return function(name)
|
||||
self.parent:addEvent("other_event", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
end
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("InputBG")
|
||||
self.fgColor = self.parent:getTheme("InputText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ return function(name)
|
||||
text = tostring(text)
|
||||
base:setValue(text)
|
||||
if (autoSize) then
|
||||
self.width = text:len()
|
||||
if(text:len()+self:getX()>self.parent:getWidth())then
|
||||
local newW = self.parent:getWidth() - self:getX()
|
||||
base.setSize(self, newW, #createText(text, newW))
|
||||
else
|
||||
base.setSize(self, text:len(), 1)
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
@@ -86,6 +91,22 @@ return function(name)
|
||||
return self
|
||||
end;
|
||||
|
||||
eventHandler = function(self, event)
|
||||
if(event=="basalt_resize")then
|
||||
if (autoSize) then
|
||||
local text = self:getValue()
|
||||
if(text:len()+self:getX()>self.parent:getWidth())then
|
||||
local newW = self.parent:getWidth() - self:getX()
|
||||
base.setSize(self, newW, #createText(text, newW))
|
||||
else
|
||||
base.setSize(self, text:len(), 1)
|
||||
end
|
||||
else
|
||||
--self.parent:removeEvent("other_event", self)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
@@ -96,10 +117,21 @@ return function(name)
|
||||
if not(autoSize)then
|
||||
local text = createText(self:getValue(), self:getWidth())
|
||||
for k,v in pairs(text)do
|
||||
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
|
||||
if(k<=h)then
|
||||
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor)
|
||||
if(#self:getValue()+obx>self.parent:getWidth())then
|
||||
local text = createText(self:getValue(), self:getWidth())
|
||||
for k,v in pairs(text)do
|
||||
if(k<=h)then
|
||||
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor)
|
||||
end
|
||||
end
|
||||
else
|
||||
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray)
|
||||
@@ -112,15 +144,16 @@ return function(name)
|
||||
oby = oby or math.floor((oY - cY) / 2) + 1
|
||||
|
||||
for i = 1, cY do
|
||||
self.parent:setFG(obx, oby + i - 2, tData[2][i])
|
||||
self.parent:setBG(obx, oby + i - 2, tData[3][i])
|
||||
self.parent:setText(obx, oby + i - 2, tData[1][i])
|
||||
self.parent:setFG(obx, oby + i - 1, tData[2][i])
|
||||
self.parent:setBG(obx, oby + i - 1, tData[3][i])
|
||||
self.parent:setText(obx, oby + i - 1, tData[1][i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
init = function(self)
|
||||
self.parent:addEvent("other_event", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("LabelBG")
|
||||
self.fgColor = self.parent:getTheme("LabelText")
|
||||
|
||||
@@ -199,13 +199,15 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ListBG")
|
||||
self.fgColor = self.parent:getTheme("ListText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("ListBG")
|
||||
self.fgColor = self.parent:getTheme("ListText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -226,14 +226,14 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ local Object = require("Object")
|
||||
local tHex = require("tHex")
|
||||
local process = require("process")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
local log = require("basaltLogs")
|
||||
|
||||
local sub = string.sub
|
||||
|
||||
@@ -12,6 +11,7 @@ return function(name, parent)
|
||||
base:setZIndex(5)
|
||||
local object
|
||||
local cachedPath
|
||||
local enviroment = {}
|
||||
|
||||
local function createBasaltWindow(x, y, width, height, self)
|
||||
local xCursor, yCursor = 1, 1
|
||||
@@ -428,7 +428,21 @@ return function(name, parent)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
end
|
||||
|
||||
local function resumeProcess(self, event, ...)
|
||||
local ok, result = curProcess:resume(event, ...)
|
||||
if (ok==false)and(result~=nil)and(result~="Terminated")then
|
||||
local val = self:sendEvent("program_error", result)
|
||||
if(val~=false)then
|
||||
error("Basalt Program - "..result)
|
||||
end
|
||||
end
|
||||
|
||||
if(curProcess:getStatus()=="dead")then
|
||||
self:sendEvent("program_done")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -439,7 +453,7 @@ return function(name, parent)
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
|
||||
curProcess:resume(event, p1, x-absX+1, y-absY+1)
|
||||
resumeProcess(self, event, p1, x-absX+1, y-absY+1)
|
||||
updateCursor(self)
|
||||
end
|
||||
end
|
||||
@@ -452,7 +466,7 @@ return function(name, parent)
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if (self.draw) then
|
||||
curProcess:resume(event, key, isHolding)
|
||||
resumeProcess(self, event, key, isHolding)
|
||||
updateCursor(self)
|
||||
end
|
||||
end
|
||||
@@ -511,9 +525,14 @@ return function(name, parent)
|
||||
return "inactive"
|
||||
end;
|
||||
|
||||
setEnviroment = function(self, env)
|
||||
enviroment = env or {}
|
||||
return self
|
||||
end,
|
||||
|
||||
execute = function(self, path, ...)
|
||||
cachedPath = path or cachedPath
|
||||
curProcess = process:new(cachedPath, pWindow, ...)
|
||||
curProcess = process:new(cachedPath, pWindow, enviroment, ...)
|
||||
pWindow.setBackgroundColor(colors.black)
|
||||
pWindow.setTextColor(colors.white)
|
||||
pWindow.clear()
|
||||
@@ -521,7 +540,8 @@ return function(name, parent)
|
||||
pWindow.setBackgroundColor(self.bgColor)
|
||||
pWindow.setTextColor(self.fgColor)
|
||||
pWindow.basalt_setVisible(true)
|
||||
curProcess:resume()
|
||||
|
||||
resumeProcess(self)
|
||||
paused = false
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
@@ -539,7 +559,7 @@ return function(name, parent)
|
||||
stop = function(self)
|
||||
if (curProcess ~= nil) then
|
||||
if not (curProcess:isDead()) then
|
||||
curProcess:resume("terminate")
|
||||
resumeProcess(self, "terminate")
|
||||
if (curProcess:isDead()) then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(false)
|
||||
@@ -572,7 +592,7 @@ return function(name, parent)
|
||||
if (curProcess ~= nil) then
|
||||
if not (curProcess:isDead()) then
|
||||
if (paused == false) or (ign) then
|
||||
curProcess:resume(event, p1, p2, p3, p4)
|
||||
resumeProcess(self, event, p1, p2, p3, p4)
|
||||
else
|
||||
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
|
||||
end
|
||||
@@ -594,7 +614,7 @@ return function(name, parent)
|
||||
if (curProcess ~= nil) then
|
||||
if not (curProcess:isDead()) then
|
||||
for _, value in pairs(events) do
|
||||
curProcess:resume(value.event, table.unpack(value.args))
|
||||
resumeProcess(self, value.event, table.unpack(value.args))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -665,11 +685,9 @@ return function(name, parent)
|
||||
if (self.parent ~= nil) then
|
||||
local xCur, yCur = pWindow.getCursorPos()
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
if (self.parent ~= nil) then
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -699,7 +717,7 @@ return function(name, parent)
|
||||
if(w~=pW)or(h~=pH)then
|
||||
pWindow.basalt_resize(pW, pH)
|
||||
if not (curProcess:isDead()) then
|
||||
curProcess:resume("term_resize")
|
||||
resumeProcess(self, "term_resize")
|
||||
end
|
||||
end
|
||||
pWindow.basalt_reposition(self:getAnchorPosition())
|
||||
@@ -708,7 +726,7 @@ return function(name, parent)
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if(event ~= "terminate") then
|
||||
curProcess:resume(event, p1, p2, p3, p4)
|
||||
resumeProcess(self, event, p1, p2, p3, p4)
|
||||
end
|
||||
if (self:isFocused()) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
@@ -721,8 +739,7 @@ return function(name, parent)
|
||||
end
|
||||
|
||||
if (event == "terminate") then
|
||||
log(self:isFocused())
|
||||
curProcess:resume(event)
|
||||
resumeProcess(self, event)
|
||||
self.parent:setCursor(false)
|
||||
return true
|
||||
end
|
||||
@@ -739,15 +756,45 @@ return function(name, parent)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local xCur, yCur = pWindow.getCursorPos()
|
||||
local w,h = self:getSize()
|
||||
pWindow.basalt_reposition(obx, oby)
|
||||
pWindow.basalt_update()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
onError = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("program_error", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("other_event", self)
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
onDone = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("program_done", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("other_event", self)
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ProgramBG")
|
||||
if(base.init(self))then
|
||||
elf.bgColor = self.parent:getTheme("ProgramBG")
|
||||
end
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,11 @@ return function(name)
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ProgressbarBG")
|
||||
self.fgColor = self.parent:getTheme("ProgressbarText")
|
||||
activeBarColor = self.parent:getTheme("ProgressbarActiveBG")
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("ProgressbarBG")
|
||||
self.fgColor = self.parent:getTheme("ProgressbarText")
|
||||
activeBarColor = self.parent:getTheme("ProgressbarActiveBG")
|
||||
end
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
|
||||
@@ -153,13 +153,15 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarFG")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
boxSelectedBG = self.parent:getTheme("MenubarBG")
|
||||
boxSelectedFG = self.parent:getTheme("MenubarText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarFG")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
boxSelectedBG = self.parent:getTheme("MenubarBG")
|
||||
boxSelectedFG = self.parent:getTheme("MenubarText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -173,12 +173,14 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ScrollbarBG")
|
||||
self.fgColor = self.parent:getTheme("ScrollbarText")
|
||||
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("ScrollbarBG")
|
||||
self.fgColor = self.parent:getTheme("ScrollbarText")
|
||||
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -173,12 +173,14 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SliderBG")
|
||||
self.fgColor = self.parent:getTheme("SliderText")
|
||||
symbolColor = self.parent:getTheme("SliderSymbolColor")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("SliderBG")
|
||||
self.fgColor = self.parent:getTheme("SliderText")
|
||||
symbolColor = self.parent:getTheme("SliderSymbolColor")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -74,12 +74,14 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SwitchBG")
|
||||
self.fgColor = self.parent:getTheme("SwitchText")
|
||||
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
|
||||
inactiveBG = self.parent:getTheme("SwitchInactive")
|
||||
activeBG = self.parent:getTheme("SwitchActive")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("SwitchBG")
|
||||
self.fgColor = self.parent:getTheme("SwitchText")
|
||||
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
|
||||
inactiveBG = self.parent:getTheme("SwitchInactive")
|
||||
activeBG = self.parent:getTheme("SwitchActive")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +144,7 @@ return function(name)
|
||||
|
||||
editLine = function(self, index, text)
|
||||
lines[index] = text or lines[index]
|
||||
updateColors(self, index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
@@ -163,18 +164,20 @@ return function(name)
|
||||
lines[1] = text
|
||||
bgLines[1] = tHex[self.bgColor]:rep(text:len())
|
||||
fgLines[1] = tHex[self.fgColor]:rep(text:len())
|
||||
updateColors(self, 1)
|
||||
return self
|
||||
end
|
||||
if (index ~= nil) then
|
||||
table.insert(lines, index, text)
|
||||
table.insert(bgLines, index, tHex[self.bgColor]:rep(text:len()))
|
||||
table.insert(fgLines, tHex[self.fgColor]:rep(text:len()))
|
||||
table.insert(fgLines, index, tHex[self.fgColor]:rep(text:len()))
|
||||
else
|
||||
table.insert(lines, text)
|
||||
table.insert(bgLines, tHex[self.bgColor]:rep(text:len()))
|
||||
table.insert(fgLines, tHex[self.fgColor]:rep(text:len()))
|
||||
end
|
||||
end
|
||||
updateColors(self, index or #lines)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
@@ -605,14 +608,16 @@ return function(name)
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("TextfieldBG")
|
||||
self.fgColor = self.parent:getTheme("TextfieldText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("char", self)
|
||||
self.parent:addEvent("other_event", self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("TextfieldBG")
|
||||
self.fgColor = self.parent:getTheme("TextfieldText")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
17
docs/Home.md
17
docs/Home.md
@@ -1,24 +1,19 @@
|
||||
# Welcome to The Basalt Wiki!
|
||||
|
||||
*Note: The Basalt Wiki is a work in progress. Please treat Wiki errors the same as bugs and report them accordingly.*
|
||||
*Note: The Basalt Wiki is a work in progress. Please treat wiki errors the same as bugs and report them accordingly.*
|
||||
|
||||
Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display.
|
||||
|
||||
## About Basalt
|
||||
|
||||
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).
|
||||
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://modrinth.com/mod/cc-tweaked).
|
||||
|
||||
## Quick Demo
|
||||
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="600">
|
||||
|
||||

|
||||
|
||||
## Questions & Bugs
|
||||
|
||||
Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/Pyroxenium/Basalt/issues">issue</a>.
|
||||
Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new [Github Issue](https://github.com/Pyroxenium/Basalt/issues)
|
||||
|
||||
Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/Pyroxenium/Basalt/discussions">Basalt's Discussion Board</a>, or ask in our [discord](https://discord.gg/yNNnmBVBpE).
|
||||
|
||||
---
|
||||
|
||||
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
|
||||
|
||||
<br><br>
|
||||
Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on [Basalt's Discussion Board (Github)](https://github.com/Pyroxenium/Basalt/discussions), or ask in our [discord](https://discord.gg/yNNnmBVBpE).
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yM7kndJdJJ)
|
||||
---
|
||||
|
||||
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yNNnmBVBpE)
|
||||
@@ -1,4 +1,4 @@
|
||||
- Getting Started
|
||||
- [Home](Home.md)
|
||||
- [Quick Start](home/Quick-Start.md)
|
||||
- [Home](Home)
|
||||
- [Quick Start](home/Quick-Start)
|
||||
- [Installer](home/installer)
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
- About
|
||||
- [Home](Home.md)
|
||||
- [Home](Home.md)
|
||||
- [Quick Start](home/Quick-Start.md)
|
||||
- [Installer](home/installer)
|
||||
- Objects
|
||||
- [Basalt](objects/Basalt.md)
|
||||
- [Object](objects/Object.md)
|
||||
- [Button](objects/Button.md)
|
||||
- [Checkbox](objects/Checkbox.md)
|
||||
- [Dropdown](objects/Dropdown.md)
|
||||
- [Frame](objects/Frame.md)
|
||||
- [Image](objects/Image.md)
|
||||
- [Input](objects/Input.md)
|
||||
- [Label](objects/Label.md)
|
||||
- [List](objects/List.md)
|
||||
- [Menubar](objects/Menubar.md)
|
||||
- [Pane](objects/Pane.md)
|
||||
- [Program](objects/Program.md)
|
||||
- [Progressbar](objects/Progressbar.md)
|
||||
- [Radio](objects/Radio.md)
|
||||
- [Scrollbar](objects/Scrollbar.md)
|
||||
- [Slider](objects/Slider.md)
|
||||
- [Textfield](objects/Textfield.md)
|
||||
- [Animation](objects/Animation.md)
|
||||
- [Thread](objects/Thread.md)
|
||||
- [Timer](objects/Timer.md)
|
||||
- [Basalt](objects/Basalt.md)
|
||||
- [Object](objects/Object.md)
|
||||
- [Button](objects/Button.md)
|
||||
- [Checkbox](objects/Checkbox.md)
|
||||
- [Dropdown](objects/Dropdown.md)
|
||||
- [Frame](objects/Frame.md)
|
||||
- [Image](objects/Image.md)
|
||||
- [Input](objects/Input.md)
|
||||
- [Label](objects/Label.md)
|
||||
- [List](objects/List.md)
|
||||
- [Menubar](objects/Menubar.md)
|
||||
- [Pane](objects/Pane.md)
|
||||
- [Program](objects/Program.md)
|
||||
- [Progressbar](objects/Progressbar.md)
|
||||
- [Radio](objects/Radio.md)
|
||||
- [Scrollbar](objects/Scrollbar.md)
|
||||
- [Slider](objects/Slider.md)
|
||||
- [Textfield](objects/Textfield.md)
|
||||
- [Animation](objects/Animation.md)
|
||||
- [Thread](objects/Thread.md)
|
||||
- [Timer](objects/Timer.md)
|
||||
- Tips & Tricks
|
||||
- [Your Logic](tips/logic.md)
|
||||
- [Button coloring](tips/buttonColoring.md)
|
||||
- [Designing/Animating](tips/design.md)
|
||||
- [Dynamic Values](tips/dynamicvalues.md)
|
||||
- [XML](tips/xml.md)
|
||||
- [Your Logic](tips/logic.md)
|
||||
- [Button coloring](tips/buttonColoring.md)
|
||||
- [Designing/Animating](tips/design.md)
|
||||
- [Dynamic Values](tips/dynamicvalues.md)
|
||||
- [XML](tips/xml.md)
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
## HowTo Use
|
||||
# Quick Start
|
||||
|
||||
To load the framework into your project, make use of the following code on top of your code.
|
||||
## How to use
|
||||
|
||||
To load Basalt into your project, make use of the following code on top of your code.
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
```
|
||||
|
||||
It does not matter if you have installed the single file version or the full folder project. <br>
|
||||
It does not matter if you have installed the single file version or the full folder project.
|
||||
Both versions can be loaded by using `require("Basalt")`, you dont need to add `.lua`.
|
||||
|
||||
## Download
|
||||
|
||||
### Download the folder version
|
||||
This version is for people who'd like to work with Basalt, change something in Basalt or checkout the project.<br>
|
||||
But you are also able to just use it to create your own UI.<br>
|
||||
This version is for people who'd like to work with Basalt, change something in Basalt, or checkout the project.
|
||||
But you are also able to just use it to create your own UI.
|
||||
|
||||
|
||||
To install the full project to your CC:Tweaked Computer, use the following command on your CC:Tweaked shell:
|
||||
|
||||
@@ -30,7 +33,7 @@ This will download the project as a single file called "basalt.lua". You are imm
|
||||
|
||||
### Basalt Package Manager
|
||||
|
||||
The Basalt Package Manager is still in alpha!<br><br>
|
||||
**The Basalt Package Manager is still in alpha!**
|
||||
The Basalt Package Manager is a visual installer, you are able to change some settings, also to choose which objects are necessary for your projects and which are not.
|
||||
|
||||
To install the BPM (Basalt Package Manager) use the following command on your CC:Tweaked shell:
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# Installer
|
||||
|
||||
This is just a script which helps you to setup your program to automatically install the Basalt UI Framework, if it doesn't exists. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not, if not it installs it, or if you are using the advanced installer, it asks the user if the program is allowed to install basalt for you.
|
||||
This is just a script which helps you to setup your program to automatically install the Basalt UI Framework if it doesn't exist. Which means you create your program (which requires basalt), and add this on the top of your program. Now everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not. If it dosent exist it installs it, or if you are using the advanced installer it asks the user if the program is allowed to install basalt for you.
|
||||
|
||||
## Basic Installer
|
||||
Here is a very basic one which just installs basalt.lua if don't exist:
|
||||
Here is a very basic installer which just installs basalt.lua if it dosen't exist:
|
||||
```lua
|
||||
--Basalt configurated installer
|
||||
local filePath = "basalt.lua" --here you can change the file path default: basalt
|
||||
local filePath = "basalt.lua" --here you can change the file path that it installs to. default: /basalt.lua
|
||||
if not(fs.exists(filePath))then
|
||||
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
|
||||
end
|
||||
@@ -18,8 +18,8 @@ This is a visual version, it asks the user if he wants to install basalt.lua (if
|
||||

|
||||
```lua
|
||||
--Basalt configurated installer
|
||||
local filePath = "basalt.lua" --here you can change the file path default: basalt
|
||||
if not(fs.exists(filePath))then
|
||||
local filePath = "basalt.lua" --here you can change the file path it installs to. Default: /basalt.lua
|
||||
if not fs.exists(filePath) then
|
||||
local w,h = term.getSize()
|
||||
term.clear()
|
||||
local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6)
|
||||
@@ -68,7 +68,4 @@ if not(fs.exists(filePath))then
|
||||
term.setCursorPos(1,1)
|
||||
term.clear()
|
||||
end
|
||||
|
||||
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
|
||||
------------------------------
|
||||
```
|
||||
|
||||
@@ -38,8 +38,9 @@
|
||||
logo: '/_media/logo.png',
|
||||
loadNavbar: true,
|
||||
loadSidebar: true,
|
||||
loadFooter: '_footer.md',
|
||||
autoHeader: true,
|
||||
subMaxLevel: 2,
|
||||
subMaxLevel: 3,
|
||||
homepage: 'Home.md',
|
||||
name: 'Basalt',
|
||||
repo: 'https://github.com/Pyroxenium/Basalt',
|
||||
@@ -50,5 +51,7 @@
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/@alertbox/docsify-footer/dist/docsify-footer.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
295
docs/install.lua
Normal file
295
docs/install.lua
Normal file
@@ -0,0 +1,295 @@
|
||||
-- this file can download the project or other tools from github
|
||||
|
||||
local args = table.pack(...)
|
||||
local installer = {printStatus=true}
|
||||
installer.githubPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt/"
|
||||
|
||||
-- Creates a filetree based on my github project, ofc you can use this in your projects if you'd like to
|
||||
function installer.createTableTree(page, branch, dirName)
|
||||
dirName = dirName or ""
|
||||
if(installer.printStatus)then print("Receiving file tree for "..dirName) end
|
||||
local tree = {}
|
||||
local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
|
||||
if not(page)then return end
|
||||
if(request==nil)then error("API rate limit exceeded. It will be available again in a couple of hours.") end
|
||||
for _,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
|
||||
if(v.type=="blob")then
|
||||
table.insert(tree, {name = v.path, path=fs.combine(dirName, v.path), url=installer.githubPath..branch.."/Basalt/"..fs.combine(dirName, v.path), size=v.size})
|
||||
elseif(v.type=="tree")then
|
||||
tree[v.path] = installer.createTree(v.url, branch, fs.combine(dirName, v.path))
|
||||
end
|
||||
end
|
||||
return tree
|
||||
end
|
||||
|
||||
|
||||
function installer.createTree(page, branch, dirName)
|
||||
dirName = dirName or ""
|
||||
if(installer.printStatus)then print("Receiving file tree for "..dirName) end
|
||||
local tree = {}
|
||||
local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
|
||||
if not(page)then return end
|
||||
if(request==nil)then error("API rate limit exceeded. It will be available again in a couple of hours.") end
|
||||
for _,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
|
||||
if(v.type=="blob")then
|
||||
table.insert(tree, {name = v.path, path=fs.combine(dirName, v.path), url=installer.githubPath..branch.."/Basalt/"..fs.combine(dirName, v.path), size=v.size})
|
||||
elseif(v.type=="tree")then
|
||||
for k,v in pairs(installer.createTree(v.url, branch, fs.combine(dirName, v.path)))do
|
||||
table.insert(tree, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
return tree
|
||||
end
|
||||
|
||||
local function splitString(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
|
||||
|
||||
function installer.get(url)
|
||||
local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
|
||||
if(installer.printStatus)then print("Downloading "..url) end
|
||||
if(httpReq~=nil)then
|
||||
local content = httpReq.readAll()
|
||||
if not content then
|
||||
error("Could not connect to website")
|
||||
end
|
||||
return content
|
||||
end
|
||||
end
|
||||
|
||||
function installer.createIgnoreList(str)
|
||||
local files = splitString(str, ":")
|
||||
local ignList = {}
|
||||
for k,v in pairs(files)do
|
||||
local a = splitString(v, "/")
|
||||
if(#a>1)then
|
||||
if(ignList[a[1]]==nil)then ignList[a[1]] = {} end
|
||||
table.insert(ignList[a[1]], a[2])
|
||||
else
|
||||
table.insert(ignList, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function installer.download(url, file)
|
||||
local content = installer.get(url)
|
||||
if(content~=nil)then
|
||||
local f = fs.open(file, "w")
|
||||
f.write(content)
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
|
||||
function installer.getPackedProject(branch, ignoreList)
|
||||
installer.printStatus = false
|
||||
if (ignoreList==nil)then
|
||||
ignoreList = {"init.lua"}
|
||||
else
|
||||
table.insert(ignoreList, "init.lua")
|
||||
end
|
||||
local projTree = installer.createTableTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/"..branch..":Basalt", branch, "")
|
||||
local filteredList = {}
|
||||
local project = {}
|
||||
|
||||
local function isInIgnoreList(file, ign)
|
||||
if(ign~=nil)then
|
||||
for k,v in pairs(ign)do
|
||||
if(v==file.name)then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
for k,v in pairs(projTree)do
|
||||
if(type(k)=="string")then
|
||||
for a,b in pairs(v)do
|
||||
if not(isInIgnoreList(b, ignoreList~=nil and ignoreList[k] or nil))then
|
||||
if(filteredList[k]==nil)then filteredList[k] = {} end
|
||||
table.insert(filteredList[k], b)
|
||||
end
|
||||
end
|
||||
else
|
||||
if not(isInIgnoreList(v, ignoreList))then
|
||||
table.insert(filteredList, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local fList = {}
|
||||
local delay = 0
|
||||
for k,v in pairs(filteredList)do
|
||||
if(type(k)=="string")then
|
||||
for a,b in pairs(v)do
|
||||
table.insert(fList, function() sleep(delay)
|
||||
if(project[k]==nil)then project[k] = {} end
|
||||
table.insert(project[k], {content=installer.get(b.url), name=b.name, path=b.path, size = b.size, url = b.url})
|
||||
delay = delay + 0.05
|
||||
end)
|
||||
end
|
||||
else
|
||||
table.insert(fList, function() sleep(delay) table.insert(project, {content=installer.get(v.url), name=v.name, path=v.path, size = v.size, url = v.url}) delay = delay + 0.05 end)
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAll(table.unpack(fList))
|
||||
|
||||
local projectContent =
|
||||
[[
|
||||
local project = {}
|
||||
local packaged = true
|
||||
local baseRequire = require
|
||||
local require = function(path)
|
||||
for k,v in pairs(project)do
|
||||
if(type(v)=="table")then
|
||||
for name,b in pairs(v)do
|
||||
if(name==path)then
|
||||
return b()
|
||||
end
|
||||
end
|
||||
else
|
||||
if(k==path)then
|
||||
return v()
|
||||
end
|
||||
end
|
||||
end
|
||||
return baseRequire(path);
|
||||
end
|
||||
local getProject = function(subDir)
|
||||
if(subDir~=nil)then
|
||||
return project[subDir]
|
||||
end
|
||||
return project
|
||||
end
|
||||
]]
|
||||
|
||||
for k,v in pairs(project)do
|
||||
if(type(k)=="string")then
|
||||
local newSubDir = 'project["'..k..'"] = {}\n'
|
||||
projectContent = projectContent.."\n"..newSubDir
|
||||
for a,b in pairs(v)do
|
||||
local newFile = 'project["'..k..'"]["'..b.name:gsub(".lua", "")..'"] = function(...)\n'..b.content..'\nend'
|
||||
projectContent = projectContent.."\n"..newFile
|
||||
end
|
||||
else
|
||||
local newFile = 'project["'..v.name:gsub(".lua", "")..'"] = function(...)\n'..v.content..'\nend'
|
||||
projectContent = projectContent.."\n"..newFile
|
||||
end
|
||||
end
|
||||
projectContent = projectContent..'\n return project["main"]()'
|
||||
|
||||
return projectContent
|
||||
end
|
||||
|
||||
function installer.getProjectFiles(branch, ignoreList)
|
||||
local projTree = installer.createTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/"..branch..":Basalt", branch, "")
|
||||
local filteredList = {}
|
||||
local project = {}
|
||||
|
||||
local function isInIgnoreList(file)
|
||||
if(ignoreList~=nil)then
|
||||
for k,v in pairs(ignoreList)do
|
||||
if(v==file)then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
for k,v in pairs(projTree)do
|
||||
if not(isInIgnoreList(v))then
|
||||
table.insert(filteredList, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function downloadFile(url, path)
|
||||
project[path] = installer.get(url)
|
||||
end
|
||||
|
||||
local fList = {}
|
||||
local delay = 0
|
||||
for k,v in pairs(filteredList)do
|
||||
table.insert(fList, function() sleep(delay) downloadFile(v.url, v.path) delay = delay + 0.05 end)
|
||||
end
|
||||
parallel.waitForAll(table.unpack(fList))
|
||||
|
||||
return project
|
||||
end
|
||||
|
||||
function installer.downloadPacked(filename, branch, ignoreList, minify)
|
||||
local projectContent = installer.getPackedProject(branch, ignoreList)
|
||||
if(minify)then
|
||||
local min
|
||||
if(fs.exists("packager.lua"))then
|
||||
min = require("packager")
|
||||
else
|
||||
min = load(installer.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/packager.lua"))()
|
||||
end
|
||||
if(min~=nil)then
|
||||
success, data = min(projectContent)
|
||||
if(success)then
|
||||
projectContent = data
|
||||
else
|
||||
error(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
local f = fs.open(filename, "w")
|
||||
f.write(projectContent)
|
||||
f.close()
|
||||
end
|
||||
|
||||
function installer.downloadProject(projectDir, branch, ignoreList)
|
||||
local projectFiles = installer.getProjectFiles(branch, ignoreList)
|
||||
projectDir = projectDir or "basalt"
|
||||
branch = branch or "master"
|
||||
|
||||
local function downloadFile(url, path)
|
||||
print("Downloading "..path)
|
||||
local files = splitString(path)
|
||||
if(#files>1)then
|
||||
local folderPath = ""
|
||||
for a,b in pairs(files)do
|
||||
if(a<#files)then
|
||||
folderPath = fs.combine(folderPath, b)
|
||||
else
|
||||
if not (fs.exists(folderPath))then fs.makeDir(folderPath) end
|
||||
installer.download(url, fs.combine(projectDir, path))
|
||||
end
|
||||
end
|
||||
else
|
||||
installer.download(url, fs.combine(projectDir, path))
|
||||
end
|
||||
end
|
||||
|
||||
local fList = {}
|
||||
local delay = 0
|
||||
for k,v in pairs(projectFiles)do
|
||||
table.insert(fList, function() sleep(delay) downloadFile(v.url, v.path) delay = delay + 0.05 end)
|
||||
end
|
||||
parallel.waitForAll(table.unpack(fList))
|
||||
end
|
||||
|
||||
if(#args>0)then
|
||||
if(string.lower(args[1])=="bpm")or(string.lower(args[1])=="basaltpackagemanager")or(string.lower(args[1])=="gui")then
|
||||
installer.download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackageManager.lua", "basaltPackageManager.lua")
|
||||
if(args[2]=="true")then shell.run("basaltPackageManager.lua") fs.delete("basaltPackageManager.lua") end
|
||||
|
||||
elseif(string.lower(args[1])=="packed")then
|
||||
installer.downloadPacked(args[2] or "basalt.lua", args[3] or "master", args[4]~=nil and installer.createIgnoreList(args[4]) or nil, args[5] == "false" and false or true)
|
||||
elseif(string.lower(args[1])=="source")then
|
||||
installer.downloadProject(args[2] or "basalt", args[3] or "master", args[4]~=nil and installer.createIgnoreList(args[4]) or nil)
|
||||
end
|
||||
end
|
||||
|
||||
return installer
|
||||
@@ -1,487 +0,0 @@
|
||||
--Basalt configurated installer
|
||||
local filePath = "basalt.lua" --here you can change the file path default: basalt
|
||||
if not(fs.exists(filePath))then
|
||||
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
|
||||
end
|
||||
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
|
||||
|
||||
local maxCoWorker = 3
|
||||
|
||||
local recipeList = {}
|
||||
local craftingQueue = {}
|
||||
local bridge = peripheral.find("rsBridge")
|
||||
local w, h = term.getSize()
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local home = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-2)
|
||||
local recipes = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):hide()
|
||||
local log = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):hide()
|
||||
|
||||
local menuBar = main:addMenubar():addItem("Home"):addItem("Recipes"):addItem("Log"):setBackground(colors.gray):setSize(w, 1):setSpace(6):setScrollable():show()
|
||||
menuBar:onChange(function(self)
|
||||
home:hide()
|
||||
recipes:hide()
|
||||
log:hide()
|
||||
if(self:getValue().text=="Home")then
|
||||
home:show()
|
||||
elseif(self:getValue().text=="Recipes")then
|
||||
recipes:show()
|
||||
elseif(self:getValue().text=="Log")then
|
||||
log:show()
|
||||
end
|
||||
end)
|
||||
|
||||
local function buttonVisuals(btn)
|
||||
btn:onClick(basalt.schedule(function() btn:setBackground(colors.black) btn:setForeground(colors.lightGray) os.sleep(0.1) btn:setBackground(colors.gray) btn:setForeground(colors.black) end))
|
||||
end
|
||||
|
||||
local coworkerCount = home:addLabel():setText(maxCoWorker):setPosition(45,2):show()
|
||||
home:addLabel():setText("Co-Worker:"):setPosition(32,2):show()
|
||||
buttonVisuals(home:addButton():setText(">"):setSize(1,1):setPosition(47,2):onClick(function() if(maxCoWorker<100)then maxCoWorker = maxCoWorker+1 end coworkerCount:setText(maxCoWorker) end):show())
|
||||
buttonVisuals(home:addButton():setText("<"):setSize(1,1):setPosition(43,2):onClick(function() if(maxCoWorker>1)then maxCoWorker = maxCoWorker-1 end coworkerCount:setText(maxCoWorker) end):show())
|
||||
|
||||
local logList = log:addList():setPosition(2,2):setSize(w-2,h-3):setScrollable(false):show()
|
||||
local jobList = home:addList():setPosition(20,4):setSize(30,10):show()
|
||||
local rList = recipes:addList():setPosition(13,2):setSize(38,16):show()
|
||||
|
||||
local function logging(text)
|
||||
logList:addItem(text)
|
||||
if(logList:getItemCount()>h-3)then
|
||||
logList:removeItem(1)
|
||||
end
|
||||
end
|
||||
|
||||
logging("Loading autocrafter...")
|
||||
|
||||
function SaveToFile()
|
||||
local file = io.open("recipes", "wb")
|
||||
local sel = rList:getItemIndex()
|
||||
rList:clear()
|
||||
for _,v in pairs(recipeList)do
|
||||
if(v.useDmg)then
|
||||
file:write(v.name.."|"..v.damage.."|"..v.minAmount.."|"..v.maxCraftAmount.."|true|", "\n")
|
||||
else
|
||||
file:write(v.name.."|"..v.damage.."|"..v.minAmount.."|"..v.maxCraftAmount.."|false|", "\n")
|
||||
end
|
||||
rList:addItem(v.minAmount.."x "..v.name..":"..v.damage, nil, nil, v)
|
||||
end
|
||||
rList:selectItem(sel)
|
||||
file:close()
|
||||
end
|
||||
|
||||
buttonVisuals(recipes:addButton():setPosition(2,2):setText("Remove"):setSize(8,1):onClick(function()
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
table.remove(recipeList, k)
|
||||
logging("Removed recipe: "..v.name..":"..v.damage)
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
local changeAmn = recipes:addInput():setPosition(4,4):setSize(5,1):setInputType("number"):setForeground(colors.black):setDefaultText("32", colors.black):onChange(function(self)
|
||||
local val = tonumber(self:getValue()) or 32
|
||||
if(val<0)then
|
||||
self:setValue(0)
|
||||
end
|
||||
end)
|
||||
buttonVisuals(recipes:addButton():setPosition(2,4):setSize(1,1):setText("-"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = v.minAmount - val
|
||||
if(v.minAmount < 0)then v.minAmount = 0 end
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
buttonVisuals(recipes:addButton():setPosition(10,4):setSize(1,1):setText("+"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = v.minAmount + val
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
|
||||
buttonVisuals(recipes:addButton():setPosition(2,6):setSize(8,1):setText("Set"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = val
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
|
||||
local rItemFrame = home:addFrame():setPosition(7,3):setBackground(colors.gray):setSize(27,6):setMoveable(true):setBar("Remove Item", colors.black, colors.lightGray):showBar():hide()
|
||||
rItemFrame:addButton():setPosition(1,1):setAnchor("topRight"):setSize(1,1):setBackground(colors.black):setForeground(colors.lightGray):setText("x"):onClick(function() rItemFrame:hide() end):show()
|
||||
rItemFrame:addLabel():setText("Item ID:"):setPosition(2,3):show()
|
||||
local ritemId = rItemFrame:addInput("itemid"):setPosition(12,3):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setDefaultText("minecraft:stick", colors.gray):show()
|
||||
rItemFrame:addButton():setPosition(-7,0):setAnchor("bottomRight"):setSize(8,1):setBackground(colors.black):setForeground(colors.lightGray):setText("Remove"):onClick(function()
|
||||
local id = ritemId:getValue()
|
||||
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==id)then
|
||||
table.remove(recipeList, k)
|
||||
logging("Removed recipe: "..v.name..":"..v.damage)
|
||||
end
|
||||
end
|
||||
SaveToFile()
|
||||
end)
|
||||
|
||||
|
||||
local aItemFrame = home:addFrame():setPosition(7,3):setBackground(colors.gray):setSize(27,12):setMoveable(true):setBar("Add Item", colors.black, colors.lightGray):showBar():hide()
|
||||
aItemFrame:addLabel():setText("Item ID:"):setPosition(2,3)
|
||||
aItemFrame:addLabel():setText("Damage:"):setPosition(2,5)
|
||||
aItemFrame:addLabel():setText("Count:"):setPosition(2,7)
|
||||
aItemFrame:addLabel():setText("Max:"):setPosition(2,9)
|
||||
aItemFrame:addLabel():setText("Use Damage:"):setAnchor("bottomLeft"):setPosition(4,0)
|
||||
local itemId = aItemFrame:addInput():setPosition(12,3):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setDefaultText("minecraft:stick", colors.gray)
|
||||
local itemDamage = aItemFrame:addInput():setPosition(12,5):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("0", colors.gray)
|
||||
local itemCount = aItemFrame:addInput():setPosition(12,7):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("64", colors.gray)
|
||||
local itemMaxCount = aItemFrame:addInput():setPosition(12,9):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("0", colors.gray)
|
||||
local useDamage = aItemFrame:addCheckbox():setAnchor("bottomLeft"):setPosition(2,0):setBackground(colors.black):setForeground(colors.lightGray):setValue(true)
|
||||
aItemFrame:addButton():setAnchor("topRight"):setPosition(1,1):setSize(1,1):setBackground(colors.black):setForeground(colors.lightGray):setText("x"):onClick(function() aItemFrame:hide() end)
|
||||
aItemFrame:addButton():setAnchor("bottomRight"):setPosition(-4,0):setSize(5,1):setBackground(colors.black):setForeground(colors.lightGray):setText("Add"):onClick(function()
|
||||
local id = itemId:getValue()
|
||||
local dmg = itemDamage:getValue() == "" and 0 or itemDamage:getValue()
|
||||
local count = itemCount:getValue() == "" and 64 or itemCount:getValue()
|
||||
local maxCount = itemMaxCount:getValue() == "" and 0 or itemMaxCount:getValue()
|
||||
local usedamage = useDamage:getValue() or true
|
||||
if(id~="")then
|
||||
local itemExist = false
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==id)then
|
||||
if(usedamage)then
|
||||
if(v.damage==dmg)then
|
||||
itemExist = true
|
||||
v.minAmount = count or 64
|
||||
v.maxCraftAmount = maxCount or 0
|
||||
logging("Edited recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
else
|
||||
itemExist = true
|
||||
v.minAmount = count or 64
|
||||
v.maxCraftAmount = maxCount or 0
|
||||
logging("Edited recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(itemExist == false)then
|
||||
table.insert(recipeList, {name = id, damage = dmg or 0, minAmount = count, maxCraftAmount = maxCount or 0, useDmg = usedamage, fails = 0, timer = 0})
|
||||
logging("Added recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
SaveToFile()
|
||||
else
|
||||
logging("Please set a ID.")
|
||||
end
|
||||
end)
|
||||
|
||||
buttonVisuals(home:addButton():setText("Add Item"):setSize(12,3):setPosition(2,6):onClick(function() aItemFrame:show() aItemFrame:setFocus() end):show())
|
||||
buttonVisuals(home:addButton():setText("Remove Item"):setSize(12,3):setPosition(2,10):onClick(function() rItemFrame:show() rItemFrame:setFocus() end):show())
|
||||
|
||||
local function StringSeperate(str, seperator)
|
||||
local words = {}
|
||||
local word = ""
|
||||
|
||||
if(string.sub(str, str:len(), str:len())~=seperator)then
|
||||
str = str..""..seperator
|
||||
end
|
||||
for x=1,str:len() do
|
||||
local s = string.sub(str,x,x)
|
||||
if(s==seperator)then
|
||||
table.insert(words, word)
|
||||
word = ""
|
||||
else
|
||||
word = word..s
|
||||
end
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
if not(fs.exists("recipes"))then
|
||||
fs.open("recipes","w").close()
|
||||
end
|
||||
|
||||
local f = fs.open("recipes", "r")
|
||||
for line in f.readLine do
|
||||
local tab = StringSeperate(line, "|")
|
||||
if(tab[1]~=nil)and(tab[2]~=nil)and(tab[3]~=nil)and(tab[4]~=nil)and(tab[5]~=nil)then
|
||||
logging("Registered recipe: "..tab[3].."x "..tab[1]..":"..tab[2])
|
||||
local recipe = {name=tab[1],damage=tonumber(tab[2]),minAmount=tonumber(tab[3]),maxCraftAmount=tonumber(tab[4]),fails=0,timer=0}
|
||||
if(tab[5]=="true")then
|
||||
recipe.useDmg=true
|
||||
else
|
||||
recipe.useDmg=false
|
||||
end
|
||||
rList:addItem(recipe.minAmount.."x "..recipe.name..":"..recipe.damage, nil, nil, recipe)
|
||||
table.insert(recipeList, recipe)
|
||||
end
|
||||
end
|
||||
f.close()
|
||||
|
||||
local function findKeyWithItemName(table, itemname, damage)
|
||||
for k,v in pairs(table)do
|
||||
if(v.name==itemname)and(v.damage == damage)then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local scanChestBtn = home:addButton("scanChest"):setText("Scan Chest"):setSize(12,3):setPosition(2,2):show()
|
||||
local function checkChestForNewEntrys()
|
||||
scanChestBtn:setText("Scanning..")
|
||||
local inventory = peripheral.find("minecraft:chest")
|
||||
local items = {}
|
||||
local itemAmounts = {}
|
||||
local somethingChanged = false
|
||||
|
||||
if(inventory~=nil)then
|
||||
for x=1,inventory.size(), 1 do
|
||||
local item = inventory.getItemDetail(x)
|
||||
if(item~=nil)then
|
||||
if(item.damage==nil)then item.damage = 0 end
|
||||
table.insert(items, item)
|
||||
end
|
||||
os.sleep(0.1)
|
||||
end
|
||||
else
|
||||
logging("No chest available!")
|
||||
end
|
||||
|
||||
if(#items > 0)then
|
||||
for _,v in pairs(items)do
|
||||
local key = findKeyWithItemName(itemAmounts, v.name, v.damage)
|
||||
if(key~=nil)then
|
||||
itemAmounts[key].count = itemAmounts[key].count + v.count
|
||||
else
|
||||
table.insert( itemAmounts, {name=v.name, damage=v.damage, count = v.count})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(#itemAmounts > 0)then
|
||||
for _,v in pairs(itemAmounts)do
|
||||
local key = findKeyWithItemName(recipeList, v.name, v.damage)
|
||||
if(key~=nil)then
|
||||
if(recipeList[key].minAmount ~= v.count)then
|
||||
logging("Edited recipe: "..v.name.. ":"..v.damage.." new count: "..v.count)
|
||||
end
|
||||
somethingChanged = true
|
||||
recipeList[key].minAmount = v.count
|
||||
else
|
||||
table.insert( recipeList, {name=v.name, damage=v.damage, minAmount = v.count, maxCraftAmount = 0, useDmg = true, fails = 0, timer = 0})
|
||||
somethingChanged = true
|
||||
logging("Registered recipe: "..v.count.."x "..v.name.. ":"..v.damage)
|
||||
end
|
||||
end
|
||||
if(somethingChanged)then
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
scanChestBtn:setText("Scan Chest")
|
||||
logging("Scanning chest done.")
|
||||
end
|
||||
|
||||
local chestScanThread = main:addThread("chestScanThread")
|
||||
buttonVisuals(scanChestBtn:onClick(function() chestScanThread:start(checkChestForNewEntrys) end))
|
||||
|
||||
|
||||
local function GetAmount(itemAmount, recipe)
|
||||
local amount = 0
|
||||
if(itemAmount < recipe.minAmount)then
|
||||
if(recipe.maxCraftAmount > 0)then
|
||||
if(recipe.minAmount-itemAmount > recipe.maxCraftAmount)then
|
||||
amount = recipe.maxCraftAmount
|
||||
else
|
||||
amount = recipe.minAmount-itemAmount
|
||||
end
|
||||
else
|
||||
amount = recipe.minAmount-itemAmount
|
||||
end
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
function GetRecipeKey(pattern)
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name == pattern.name)then
|
||||
if(pattern.damage==nil)then return k end
|
||||
if(v.useDmg)then
|
||||
if(v.damage == pattern.damage)then
|
||||
return k
|
||||
end
|
||||
else
|
||||
return k
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function CheckCraftingRecipe(recipe)
|
||||
local pattern = bridge.getItem({name=recipe.name})
|
||||
local item = {pattern=pattern, amount=0}
|
||||
if(pattern~=nil)then
|
||||
local storedAmount = pattern.amount
|
||||
local neededItemAmount = GetAmount(storedAmount, recipe)
|
||||
if(neededItemAmount > 0)then
|
||||
item.amount = neededItemAmount
|
||||
table.insert(craftingQueue, item)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function RemoveRecipe(item)
|
||||
local key = -1
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name == item.name)and(v.damage== item.damage)then
|
||||
key = k
|
||||
end
|
||||
end
|
||||
if(key>=0)then
|
||||
table.remove(recipeList, key)
|
||||
end
|
||||
SaveToFile()
|
||||
end
|
||||
|
||||
local function FindKeyInTable(table, item)
|
||||
for k,v in pairs(table)do
|
||||
if(v==item)then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function CheckAllRecipes()
|
||||
for _,v in pairs(recipeList)do
|
||||
if(type(v)=="table")then
|
||||
CheckCraftingRecipe(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function jobCrafting(coworker, item)
|
||||
if(jobList:getItem(coworker)~=nil)then
|
||||
jobList:editItem(coworker, "Co-Worker "..coworker..": "..item.amountToCraft.."x "..item.item.displayName:gsub(" ", ""))
|
||||
else
|
||||
jobList:addItem("Co-Worker "..coworker..": "..item.amountToCraft.."x "..item.item.displayName:gsub(" ", ""))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function jobDone(coworker)
|
||||
if(jobList:getItem(coworker)~=nil)then
|
||||
jobList:editItem(coworker, "Co-Worker "..coworker..": waiting...")
|
||||
else
|
||||
jobList:addItem("Co-Worker "..coworker..": waiting...")
|
||||
end
|
||||
end
|
||||
|
||||
local coWorkerId = 1
|
||||
local function UpdateCraftingQueue()
|
||||
while(#craftingQueue > 0)do
|
||||
local activeCoWorkers = {}
|
||||
local craftingQueuesToRemove = {}
|
||||
for _,v in pairs(craftingQueue)do
|
||||
if(#activeCoWorkers+1 <= maxCoWorker)then
|
||||
local stack = v.pattern
|
||||
local recipeKey = GetRecipeKey(stack)
|
||||
|
||||
local waittimer = 0
|
||||
local multiplier = 1
|
||||
|
||||
if(recipeList[recipeKey].fails > 0)and(recipeList[recipeKey].fails <=10)then
|
||||
multiplier = recipeList[recipeKey].fails
|
||||
elseif(recipeList[recipeKey].fails > 10)then
|
||||
multiplier = 20
|
||||
end
|
||||
waittimer = multiplier * 30
|
||||
if(os.clock()>=recipeList[recipeKey].timer+waittimer)then
|
||||
if not(bridge.isItemCrafting(stack.name))then
|
||||
local currentItemState = {item=stack, curAmount = stack.count, amountToCraft = v.amount}
|
||||
if(bridge.isItemCraftable({name=stack.name}))then
|
||||
local task, errormsg = bridge.craftItem({name=stack.name, count = v.amount})
|
||||
if(task)then
|
||||
logging("Sheduled Task: "..v.amount.." ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
jobCrafting(coWorkerId, currentItemState)
|
||||
currentItemState.coWorker = coWorkerId
|
||||
coWorkerId = coWorkerId + 1
|
||||
if(coWorkerId > maxCoWorker)then coWorkerId = 1 end
|
||||
table.insert(activeCoWorkers, currentItemState)
|
||||
recipeList[recipeKey].fails = 0
|
||||
else
|
||||
logging("Error sheduling task: "..v.amount.."x ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
logging("Not enough materials!")
|
||||
recipeList[recipeKey].fails = recipeList[recipeKey].fails + 1
|
||||
recipeList[recipeKey].timer = os.clock()
|
||||
end
|
||||
else
|
||||
logging("Error sheduling task: "..v.amount.."x ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
logging("No pattern available!")
|
||||
recipeList[recipeKey].fails = recipeList[recipeKey].fails + 1
|
||||
recipeList[recipeKey].timer = os.clock()
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(craftingQueuesToRemove, v)
|
||||
end
|
||||
end
|
||||
|
||||
if(#craftingQueuesToRemove > 0)then
|
||||
for _,v in pairs(craftingQueuesToRemove)do
|
||||
local id = FindKeyInTable(craftingQueue, v)
|
||||
table.remove(craftingQueue, id)
|
||||
end
|
||||
end
|
||||
|
||||
while(#activeCoWorkers > 0)do
|
||||
local finishedCoworker = {}
|
||||
for _,v in pairs(activeCoWorkers)do
|
||||
if not(bridge.isItemCrafting(v.item.name))then
|
||||
logging("Task done: "..v.amountToCraft.."x ("..v.item.name..") "..v.item.displayName:gsub(" ", ""))
|
||||
table.insert(finishedCoworker, v)
|
||||
end
|
||||
end
|
||||
if(#finishedCoworker>0)then
|
||||
for _,v in pairs(finishedCoworker)do
|
||||
local id = FindKeyInTable(activeCoWorkers, v)
|
||||
table.remove(activeCoWorkers, id)
|
||||
jobDone(v.coWorker)
|
||||
end
|
||||
end
|
||||
os.sleep(0.75)
|
||||
end
|
||||
os.sleep(0.75)
|
||||
end
|
||||
end
|
||||
|
||||
main:addThread("craftingThread"):start(function() while true do CheckAllRecipes() os.sleep(1) UpdateCraftingQueue() os.sleep(1) end end)
|
||||
|
||||
logging("Autocrafter successfully loaded!")
|
||||
|
||||
basalt.autoUpdate()
|
||||
@@ -2,9 +2,9 @@
|
||||
Changes the background color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
1. `number` duration in seconds
|
||||
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
3. `...` multiple color numbers - example: colors.red, colors.yellow, colors.green
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
@@ -3,8 +3,10 @@ Changes the text while animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple text strings - example: {"i", "am", "groot"}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
1. `number` duration in seconds
|
||||
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
3. `...` multiple text strings - example: "i", "am", "groot"
|
||||
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
Changes the text color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
1. `number` duration in seconds
|
||||
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
1. `...` multiple color numbers - example: colors.red, colors.yellow, colors.green
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
@@ -1,37 +1,46 @@
|
||||
# Basalt
|
||||
|
||||
This is the UI Manager and the first thing you want to access.
|
||||
Before you can access Basalt, you need to add the following code on top of your file:
|
||||
|
||||
`local basalt = require("basalt")`
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
```
|
||||
|
||||
require loads the UI Framework into your project.
|
||||
|
||||
Now you are able to access the following list of methods:
|
||||
What this code does is it loads basalt into the basalt variable.
|
||||
You are now able to access the following list of methods:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[autoUpdate](objects/Basalt/autoUpdate.md)|Starts the event and draw listener
|
||||
|[createFrame](objects/Basalt/createFrame.md)|Creates a new base frame
|
||||
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|
||||
|[debug](objects/Basalt/debug.md)|Writes something into the debug console
|
||||
|[getFrame](objects/Basalt/getFrame.md)|Returns a frame object by it's id
|
||||
|[getActiveFrame](objects/Basalt/getActiveFrame.md)|Returns the currently active base frame
|
||||
|[autoUpdate](objects/Basalt/autoUpdate.md)|Starts the event and draw listener
|
||||
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
|
||||
|[stopUpdate](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|
||||
|[getTheme](objects/Basalt/getTheme.md)|Returns the currently active theme
|
||||
|[getVariable](objects/Basalt/getVariable.md)|Returns a variable defined with setVariable
|
||||
|[getVersion](objects/Basalt/getVersion.md)|Returns the Basalt version
|
||||
|[isKeyDown](objects/Basalt/isKeyDown.md)|Returns if the key is held down
|
||||
|[debug](objects/Basalt/debug.md)|Writes something into the debug console
|
||||
|[log](objects/Basalt/log.md)|Writes something into the log file
|
||||
|[onEvent](objects/Basalt/onEvent.md)|Event listener
|
||||
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|
||||
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
|
||||
|[setActiveFrame](objects/Basalt/setActiveFrame.md)|Sets the active frame
|
||||
|[setTheme](objects/Basalt/setTheme.md)|Changes the base theme of basalt
|
||||
|[setVariable](objects/Basalt/setVariable.md)|Sets a variable which you can access via XML
|
||||
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
|
||||
|[stopUpdate / stop](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|
||||
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
|
||||
|
||||
# Examples
|
||||
## Examples
|
||||
|
||||
Here is a lua example on how to create a empty base frame and start basalt's listener.
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt") -- we load the UI Framework into our project
|
||||
local basalt = require("basalt") -- Loads Basalt into our project
|
||||
|
||||
local main = basalt.createFrame() -- we create a base frame - on that frame we are able to add object's
|
||||
local main = basalt.createFrame() -- Creates a base frame. On that frame we are able to add object's
|
||||
|
||||
-- here we would add additional object's
|
||||
-- Here we would add additional object's
|
||||
|
||||
basalt.autoUpdate() -- we start listening to incoming events and draw stuff on the screen
|
||||
```
|
||||
basalt.autoUpdate() -- Starts listening to incoming events and draw stuff on the screen. This should nearly always be the last line.
|
||||
```
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
## basalt.autoUpdate
|
||||
# Basalt
|
||||
|
||||
## autoUpdate
|
||||
|
||||
This starts the event and draw handler for you. The listeners will run until you stop them.
|
||||
|
||||
#### Parameters:
|
||||
1. `boolean` optional - if you use false as the first parameter it would stop the listeners.
|
||||
### Parameters
|
||||
|
||||
1. `boolean` optional - if you use false as the first parameter it would stop the listeners. Using false is a synonym for [`basalt.stopUpdate()`](objects/Basalt/stopUpdate.md).
|
||||
|
||||
### Usage
|
||||
|
||||
* Enables the basalt listeners, otherwise the screen will not continue to update
|
||||
|
||||
#### Usage:
|
||||
* Enable the basalt listeners, otherwise the screen will not continue to update
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
## basalt.createFrame
|
||||
# Basalt
|
||||
|
||||
## createFrame
|
||||
|
||||
Creates a new base-frame, you can have as many base-frames as you want, but only 1 can be active (visible) at the same time.
|
||||
You can always switch between your base frames.
|
||||
|
||||
Only the currently active base-frame listens to incoming events (except for some events like time-events and peripheral-events)
|
||||
|
||||
#### Parameters:
|
||||
### Parameters
|
||||
|
||||
1. `string` id - optional (if you dont set a id it will automatically create a uuid for you)
|
||||
|
||||
#### Returns:
|
||||
### Returns
|
||||
|
||||
1. `frame` object
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* How to use multiple base frames:
|
||||
|
||||
```lua
|
||||
local main1 = basalt.createFrame() -- Visible base frame on program start
|
||||
local main2 = basalt.createFrame()
|
||||
@@ -24,4 +31,5 @@ main1:addButton()
|
||||
end)
|
||||
main2:addLabel()
|
||||
:setText("We are currently on main2")
|
||||
```
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
## basalt.debug
|
||||
# Basalt
|
||||
|
||||
## debug
|
||||
|
||||
Creates a label with some information on the main frame on the bottom left. When you click on that label it will open a log view for you. See it as the new print for debugging
|
||||
|
||||
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
|
||||
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable `basalt.debugLabel`
|
||||
which returns the debug Label.
|
||||
|
||||
Also basalt.debugFrame and basalt.debugList are available.
|
||||
`basalt.debugFrame` and `basalt.debugList` are also available.
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Parameters:
|
||||
1. `...` (multiple parameters are possible, like print does)
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Prints "Hello! ^-^" to the debug console
|
||||
|
||||
```lua
|
||||
basalt.debug("Hello! ", "^-^")
|
||||
```
|
||||
|
||||
* Changes the debug label's anchor
|
||||
|
||||
```lua
|
||||
basalt.debugLabel:setAnchor("topLeft") -- default anchor is bottomLeft
|
||||
basalt.debug("Hello!")
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
## basalt.getActiveFrame
|
||||
Returns the currently active/visible base frame
|
||||
# Basalt
|
||||
|
||||
## getActiveFrame
|
||||
|
||||
Returns the currently active/visible base frame.
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The current frame
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Displays the active frame name in the debug console
|
||||
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
basalt.debug(basalt.getActiveFrame():getName()) -- returns the id
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
## basalt.getFrame
|
||||
Returns a base frame by the given id
|
||||
# Basalt
|
||||
|
||||
## getFrame
|
||||
|
||||
Returns a base frame by the given id.
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Parameters:
|
||||
1. `string` id
|
||||
|
||||
#### Returns:
|
||||
1. `frame` object
|
||||
### Returns
|
||||
|
||||
1. `frame` The frame with the supplied id.
|
||||
|
||||
### Usage
|
||||
|
||||
#### Usage:
|
||||
* Creates, fetches and shows the "myFirstFrame" object
|
||||
|
||||
```lua
|
||||
local main = basalt.createFrame("firstBaseFrame")
|
||||
local main2 = basalt.createFrame("secondBaseFrame")
|
||||
@@ -16,8 +23,9 @@ main:addButton()
|
||||
:setText("Show")
|
||||
:onClick(function()
|
||||
local frame2 = basalt.getFrame("secondBaseFrame")
|
||||
if(frame2~=nil)then
|
||||
if(frame2 ~= nil)then
|
||||
frame2:show()
|
||||
end
|
||||
end)
|
||||
```
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
18
docs/objects/Basalt/getTheme.md
Normal file
18
docs/objects/Basalt/getTheme.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Basalt
|
||||
|
||||
## basalt.getTheme
|
||||
|
||||
Returns the current base-theme. This base-theme can be set using setTheme.md.
|
||||
A list of base-theme keys can be found [here](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua).
|
||||
|
||||
### Returns
|
||||
|
||||
1. `number` The color of the requested base-theme key.
|
||||
|
||||
### Usage
|
||||
|
||||
* Displays the color of the main background in the debug console
|
||||
|
||||
```lua
|
||||
basalt.debug(basalt.getTheme("BasaltBG"))
|
||||
```
|
||||
26
docs/objects/Basalt/getVariable.md
Normal file
26
docs/objects/Basalt/getVariable.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Basalt
|
||||
|
||||
## getVariable
|
||||
|
||||
Returns a variable defined with [setVariable](objects/Basalt/setVariable)
|
||||
|
||||
### Returns
|
||||
|
||||
1. `variable` The variable stored
|
||||
|
||||
### Usage
|
||||
|
||||
* Displays the stored variable in the debug console
|
||||
|
||||
```lua
|
||||
basalt.setVariable("abc", function()
|
||||
basalt.debug("I got clicked")
|
||||
return 1
|
||||
end)
|
||||
|
||||
basalt.debug(basalt.getVariable("abc")()) -- Should debug log "I got clicked" and debug log 1 (which was returned from the function)
|
||||
```
|
||||
|
||||
```xml
|
||||
<button onClick="abc" text="Click me" />
|
||||
```
|
||||
17
docs/objects/Basalt/getVersion.md
Normal file
17
docs/objects/Basalt/getVersion.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Basalt
|
||||
|
||||
## getVersion
|
||||
|
||||
Returns the currently active/visible base frame.
|
||||
|
||||
### Returns
|
||||
|
||||
1. `string` The current version of Basalt
|
||||
|
||||
### Usage
|
||||
|
||||
* Displays the version of Basalt in the debug console
|
||||
|
||||
```lua
|
||||
basalt.debug(basalt.getVersion()) -- Example: 1.6.2
|
||||
```
|
||||
@@ -1,14 +1,21 @@
|
||||
## basalt.isKeyDown
|
||||
# Basalt
|
||||
|
||||
## isKeyDown
|
||||
|
||||
Checks if the user is currently holding a key
|
||||
|
||||
#### Parameters:
|
||||
1. `number` key code (use the keys table for that)
|
||||
### Parameters
|
||||
|
||||
1. `number` key code (use the [keys table](https://tweaked.cc/module/keys.html) for that)
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` true or false
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
|
||||
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton()
|
||||
@@ -18,4 +25,4 @@ local aButton = mainFrame:addButton()
|
||||
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
## basalt.log
|
||||
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and
|
||||
you don't know why, you could use basalt.log
|
||||
# Basalt
|
||||
|
||||
The log files will automatically removed after you start your program again
|
||||
## log
|
||||
|
||||
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and you don't know why, you could use basalt.log The log files will automatically removed after you start your program again.
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The text to write into the log file
|
||||
2. `string` - optional (default: "Debug") - the type to write
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Writes "Hello!" into the log file
|
||||
|
||||
```lua
|
||||
basalt.log("Hello!")
|
||||
```
|
||||
|
||||
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][Debug]: Hello!`.
|
||||
|
||||
* Writes "Config file missing" into the log file, with warning as prefix.
|
||||
|
||||
```lua
|
||||
basalt.log("Config file is missing", "WARNING")
|
||||
```
|
||||
|
||||
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][WARNING]: Config file is missing`.
|
||||
|
||||
21
docs/objects/Basalt/onEvent.md
Normal file
21
docs/objects/Basalt/onEvent.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Basalt
|
||||
|
||||
## onEvent
|
||||
|
||||
This is the top-level method to intercept an event before sending it to the object event handlers. If you use return false, the event is not passed to the event handlers.
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `function` The function which should be called
|
||||
|
||||
### Usage
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
basalt.onEvent(function(event)
|
||||
if(event=="terminate")then
|
||||
return false
|
||||
end
|
||||
end)
|
||||
```
|
||||
@@ -1,17 +1,37 @@
|
||||
## basalt.removeFrame
|
||||
Removes the base frame by it's id. This only works for base-frames.
|
||||
# Basalt
|
||||
|
||||
#### Parameters:
|
||||
1. `string` id
|
||||
## removeFrame
|
||||
|
||||
Removes the base frame by it's id. **This only works for base-frames.**
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `string` id - ID of the base-frame.
|
||||
|
||||
### Usage
|
||||
|
||||
* Removes the previously created frame with id "secondBaseFrame"
|
||||
The frame id is gotten from a frame variable's `:getName()`
|
||||
|
||||
#### Usage:
|
||||
* Removes the previously created frame with id "myFirstFrame"
|
||||
```lua
|
||||
local main = basalt.createFrame("firstBaseFrame")
|
||||
local main2 = basalt.createFrame("secondBaseFrame")
|
||||
main:addButton()
|
||||
:setText("Remove")
|
||||
:onClick(function()
|
||||
basalt.removeFrame(main2:getName()) -- you can use main2:getName() to find out the id or just use "secondBaseFrame"
|
||||
basalt.removeFrame(main2:getName())
|
||||
end)
|
||||
```
|
||||
```
|
||||
|
||||
* Removes the previously created frame with id "secondBaseFrame", without frame stored in variable
|
||||
The frame id is the frame's name
|
||||
|
||||
```lua
|
||||
local main = basalt.createFrame("firstBaseFrame")
|
||||
local main2 = basalt.createFrame("secondBaseFrame")
|
||||
main:addButton()
|
||||
:setText("Remove")
|
||||
:onClick(function()
|
||||
basalt.removeFrame("secondBaseFrame")
|
||||
end)
|
||||
```
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
## basalt.schedule
|
||||
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
|
||||
# Basalt
|
||||
|
||||
## schedule
|
||||
|
||||
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
|
||||
**A guide can be found [here](/tips/logic).**
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Parameters:
|
||||
1. `function` a function which should get executed
|
||||
|
||||
#### Returns:
|
||||
### Returns
|
||||
|
||||
1. `function` it returns the function which you have to execute in order to start the coroutine
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Creates a schedule which switches the color between red and gray
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setText("Click me")
|
||||
@@ -25,4 +33,4 @@ aButton:onClick(basalt.schedule(function(self)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
end))
|
||||
```
|
||||
```
|
||||
|
||||
13
docs/objects/Basalt/setActiveFrame.md
Normal file
13
docs/objects/Basalt/setActiveFrame.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Basalt
|
||||
|
||||
## setActiveFrame
|
||||
|
||||
Sets what should be the active baseframe.
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `frame` frame - The frame that should be the active base-frame.
|
||||
|
||||
### Usage
|
||||
|
||||
TODO
|
||||
@@ -1,15 +1,21 @@
|
||||
## basalt.setTheme
|
||||
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
|
||||
# Basalt
|
||||
|
||||
## setTheme
|
||||
|
||||
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua). The theme can also be gotten with [`basalt.getTheme()`](objects/Basalt/getTheme)
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Parameters:
|
||||
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Sets the default theme of basalt.
|
||||
|
||||
```lua
|
||||
basalt.setTheme({
|
||||
ButtonBG = colors.yellow,
|
||||
ButtonText = colors.red,
|
||||
...,
|
||||
})
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
## basalt.setVariable
|
||||
# Basalt
|
||||
|
||||
## setVariable
|
||||
|
||||
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` a key name
|
||||
1. `any` any variable
|
||||
### Parameters
|
||||
|
||||
1. `string` a key name
|
||||
2. `any` any variable
|
||||
|
||||
### Usage
|
||||
|
||||
#### Usage:
|
||||
* Adds a function to basalt.
|
||||
|
||||
```lua
|
||||
basalt.setVariable("clickMe", function()
|
||||
basalt.debug("I got clicked")
|
||||
end)
|
||||
|
||||
```
|
||||
|
||||
```xml
|
||||
<button onClick="clickMe" text="Click me" />
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
## basalt.stopUpdate or basalt.stop
|
||||
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
|
||||
# Basalt
|
||||
|
||||
## stopUpdate / stop
|
||||
|
||||
Stops the automatic draw and event handler which got started by `basalt.autoUpdate()`.
|
||||
`basalt.autoUpdate(false)` also does the same.
|
||||
|
||||
### Usage
|
||||
|
||||
#### Usage:
|
||||
* When the quit button is clicked, the button stops basalt's event listeners and draw handlers
|
||||
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local aButton = main:addButton()
|
||||
main:addButton()
|
||||
:setPosition(2,2)
|
||||
:setText("Stop Basalt!")
|
||||
:onClick(function()
|
||||
basalt.stopUpdate()
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
## basalt.update
|
||||
# Basalt
|
||||
|
||||
## update
|
||||
|
||||
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
|
||||
Which means you have to pass the events into basalt.update.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The event to be received
|
||||
### Parameters
|
||||
|
||||
1. `string` The event to be received
|
||||
2. `...` Additional event variables to capture
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* Creates and starts a custom update cycle
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setPosition(2,2)
|
||||
mainFrame:addButton():setPosition(2,2)
|
||||
while true do
|
||||
local ev = table.pack(os.pullEventRaw())
|
||||
basalt.update(table.unpack(ev))
|
||||
end
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
This is the base class for all visual objects. It covers positioning, sizing, showing/hiding and much more.
|
||||
|
||||
By default a freshly created object is visible and automatically listens to all incoming events.
|
||||
By default a freshly created object is visible and doesn't listens to any incoming events.
|
||||
Its default position is always 1, 1 (based on it's parent frame). The default anchor is also topLeft.
|
||||
|
||||
| | |
|
||||
@@ -31,16 +31,40 @@ Its default position is always 1, 1 (based on it's parent frame). The default an
|
||||
|
||||
# Events
|
||||
|
||||
This is a list of all available events for all objects:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[onClick](objects/Object/onClick.md)|Fires as soon as the object gets clicked
|
||||
|[onClickUp](objects/Object/onClickUp.md)|Fires as soon as the mouse button gets released on the object
|
||||
|[onScroll](objects/Object/onScroll.md)|Fires as soon as you scroll with the mousewheel
|
||||
|[onRelease](objects/Object/onRelease.md)|Fires as soon as the mouse button gets released
|
||||
|[onScroll](objects/Object/onScroll.md)|Fires as soon as you scroll with the mousewheel
|
||||
|[onDrag](objects/Object/onDrag.md)|Fires as soon as the object is beeing dragged
|
||||
|[onKey](objects/Object/onKey.md)|Fires when the object is focused and a keyboard key has been clicked
|
||||
|[onChar](objects/Object/onChar.md)|Fires when the object is focused and a character has been clicked
|
||||
|[onKeyUp](objects/Object/onKeyUp.md)|Fires when the object is focused and a keyboard key has been released
|
||||
|[onChange](objects/Object/onChange.md)|Fires when the object value has been changed
|
||||
|[onResize](objects/Object/onResize.md)|Fires when the object got resized
|
||||
|[onReposition](objects/Object/onReposition.md)|Fires when the object has been repositioned
|
||||
|[onGetFocus](objects/Object/onGetFocus.md)|Fires when the object is focused
|
||||
|[onLoseFocus](objects/Object/onLoseFocus.md)|Fires when the object lost it's focus
|
||||
|[onLoseFocus](objects/Object/onLoseFocus.md)|Fires when the object lost it's focus
|
||||
|[onEvent](objects/Object/onEvent.md)|Fires on any other event
|
||||
|
||||
Sidenote: When you use return false this will skip the object's event handler. Here is a example for that.
|
||||
|
||||
This code would make it impossible to write a into the input:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local input = main:addInput()
|
||||
:setPosition(3,3)
|
||||
|
||||
function checkInput(self, event, char)
|
||||
if(char=="a")then
|
||||
return false
|
||||
end
|
||||
end
|
||||
main:onChar(checkInput)
|
||||
```
|
||||
|
||||
25
docs/objects/Object/onChar.md
Normal file
25
docs/objects/Object/onChar.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# onChar
|
||||
|
||||
`onChar(self, event, char)`<br>
|
||||
The computercraft event which triggers this method is `char`.
|
||||
|
||||
The char event always happens after the key event (just like in cc:tweaked)
|
||||
|
||||
Here is a example on how to add a onChar event to your frame:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local subFrame = main:addFrame()
|
||||
:setPosition(3,3)
|
||||
:setSize(18,6)
|
||||
:hide()
|
||||
|
||||
function openSubFrame(self, event, char)
|
||||
if(char=="a")then
|
||||
subFrame:show()
|
||||
end
|
||||
end
|
||||
main:onChar(openSubFrame)
|
||||
```
|
||||
20
docs/objects/Object/onEvent.md
Normal file
20
docs/objects/Object/onEvent.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# onEvent
|
||||
|
||||
`onEvent(self, event, ...)`
|
||||
|
||||
This event gets called on any other event. Some examples: http_success, disk, modem_message, paste, peripheral, redstone,...
|
||||
|
||||
You can find a full list here: [CC:Tweaked](https://tweaked.cc/) (on the left sidebar)
|
||||
|
||||
Here is a example on how to add a onEvent event to your frame:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
main:onEvent(function(event, side, channel, replyChannel, message, distance)
|
||||
if(event=="modem_message")then
|
||||
basalt.debug("Mesage received: "..tostring(message))
|
||||
end
|
||||
end)
|
||||
```
|
||||
@@ -11,6 +11,7 @@ local main = basalt.createFrame()
|
||||
local subFrame = main:addFrame()
|
||||
:setPosition(3,3)
|
||||
:setSize(18,6)
|
||||
:hide()
|
||||
|
||||
function openSubFrame(self, event, key)
|
||||
if(key==keys.c)then
|
||||
|
||||
27
docs/objects/Object/onRelease.md
Normal file
27
docs/objects/Object/onRelease.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# onRelease
|
||||
`onRelease(self, event, button, x, y)`<br>
|
||||
The computercraft event which triggers this method is `mouse_up`.
|
||||
|
||||
The difference between onRelease and :onClickUp is that :onRelease is called even when the mouse is no longer over the object, while :onClickUp is only called when the mouse is over the object.
|
||||
|
||||
Here is a example on how to add a onRelease event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local button = main:addButton()
|
||||
:setPosition(3,3)
|
||||
:setSize(12,3)
|
||||
:setText("Click")
|
||||
|
||||
function buttonOnClick(self, button, x, y)
|
||||
basalt.debug("Button got clicked!")
|
||||
end
|
||||
button:onClick(buttonOnClick)
|
||||
|
||||
function buttonOnRelease(self, button, x, y)
|
||||
basalt.debug("Button got released!")
|
||||
end
|
||||
button:onRelease(buttonOnRelease)
|
||||
```
|
||||
@@ -1,4 +1,5 @@
|
||||
# onResize
|
||||
|
||||
`onResize(self)`<br>
|
||||
This is a custom event which gets triggered as soon as the parent frame gets resized.
|
||||
|
||||
@@ -16,4 +17,4 @@ local function onButtonResize(self)
|
||||
end
|
||||
|
||||
aButton:onResize(onButtonResize)
|
||||
```
|
||||
```
|
||||
|
||||
@@ -12,3 +12,12 @@ Program objects are here for opening other executable programs in your main prog
|
||||
|[injectEvent](objects/Program/injectEvent.md)|Injects a event into the program
|
||||
|[injectEvents](objects/Program/injectEvents.md)|Injects a table of events
|
||||
|[getQueuedEvents](objects/Program/getQueuedEvents.md)|Returns currently queued events
|
||||
|
||||
# Events
|
||||
|
||||
This is a list of all available events for programs:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[onError](objects/Program/onError.md)|Fires when a program errors
|
||||
|[onDone](objects/Program/onDone.md)|Fires when a program has finished
|
||||
|
||||
19
docs/objects/Program/onDone.md
Normal file
19
docs/objects/Program/onDone.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# onDone
|
||||
|
||||
`onDone(self, err)`<br>
|
||||
This is a custom event which gets triggered as soon as the program has finished.
|
||||
|
||||
Here is a example on how to add a onDone event to your program:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function onProgramDone()
|
||||
basalt.debug("Program has finished")
|
||||
end
|
||||
|
||||
aProgram:onDone(onProgramDone)
|
||||
```
|
||||
34
docs/objects/Program/onError.md
Normal file
34
docs/objects/Program/onError.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# onError
|
||||
|
||||
`onError(self, err)`<br>
|
||||
This is a custom event which gets triggered as soon as the program catched a error.
|
||||
|
||||
Here is a example on how to add a onError event to your program:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function onProgramError(self, err)
|
||||
local errFrame = main:addFrame()
|
||||
:setSize(30, 10)
|
||||
:setPosition("parent.w / 2 - self.w / 2", "parent.h / 2 - self.h / 2")
|
||||
|
||||
errFrame:addLabel()
|
||||
:setPosition(2, 3)
|
||||
:setSize("parent.w - 2", "parent.h - 3")
|
||||
:setText(err)
|
||||
|
||||
errFrame:addButton()
|
||||
:setPosition("parent.w", 1)
|
||||
:setSize(1, 1)
|
||||
:setText("X")
|
||||
:onClick(function()
|
||||
errFrame:remove()
|
||||
end)
|
||||
end
|
||||
|
||||
aProgram:onError(onProgramError)
|
||||
```
|
||||
@@ -11,3 +11,10 @@ want to add some energy progress you have to do simple maths: currentValue / max
|
||||
|[setProgressBar](objects/Progressbar/setProgressBar.md)|Changes the progress design
|
||||
|[setBackgroundSymbol](objects/Progressbar/setBackgroundSymbol.md)|Sets the background symbol
|
||||
|
||||
# Events
|
||||
|
||||
This is a list of all available events for progressbars:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[onDone](objects/Progressbar/onDone.md)|Fires when a progress has finished
|
||||
|
||||
19
docs/objects/Progressbar/onDone.md
Normal file
19
docs/objects/Progressbar/onDone.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# onDone
|
||||
|
||||
`onDone(self, err)`<br>
|
||||
This is a custom event which gets triggered as soon as the progress is done.
|
||||
|
||||
Here is a example on how to add a onDone event to your progressbar:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local aProgressbar = main:addProgressbar()
|
||||
|
||||
local function onProgressDone()
|
||||
basalt.debug("Progress is done")
|
||||
end
|
||||
|
||||
aProgressbar:onDone(onProgressDone)
|
||||
```
|
||||
398
docs/packager.lua
Normal file
398
docs/packager.lua
Normal file
@@ -0,0 +1,398 @@
|
||||
-- The minify part is fully made by stravant and can be found here: https://github.com/stravant/LuaMinify/blob/master/RobloxPlugin/Minify.lua
|
||||
-- Thanks to him for his awesome work!
|
||||
--
|
||||
--
|
||||
-- A compilation of all of the neccesary code to Minify a source file, all into one single
|
||||
-- script for usage on Roblox. Needed to deal with Roblox' lack of `require`.
|
||||
--
|
||||
function lookupify(cd)for dd,__a in pairs(cd)do cd[__a]=true end;return cd end
|
||||
function CountTable(cd)local dd=0;for __a in pairs(cd)do dd=dd+1 end;return dd end
|
||||
function PrintTable(cd,dd)if cd.Print then return cd.Print()end;dd=dd or 0
|
||||
local __a=(CountTable(cd)>1)local a_a=string.rep(' ',dd+1)
|
||||
local b_a="{".. (__a and'\n'or'')
|
||||
for c_a,d_a in pairs(cd)do
|
||||
if type(d_a)~='function'then
|
||||
b_a=b_a.. (__a and a_a or'')
|
||||
if type(c_a)=='number'then elseif type(c_a)=='string'and
|
||||
c_a:match("^[A-Za-z_][A-Za-z0-9_]*$")then b_a=b_a..c_a.." = "elseif
|
||||
type(c_a)=='string'then b_a=b_a.."[\""..c_a.."\"] = "else b_a=b_a.."["..
|
||||
tostring(c_a).."] = "end
|
||||
if type(d_a)=='string'then b_a=b_a.."\""..d_a.."\""elseif type(d_a)==
|
||||
'number'then b_a=b_a..d_a elseif type(d_a)=='table'then b_a=b_a..
|
||||
PrintTable(d_a,dd+ (__a and 1 or 0))else
|
||||
b_a=b_a..tostring(d_a)end;if next(cd,c_a)then b_a=b_a..","end;if __a then b_a=b_a..'\n'end end end;b_a=b_a..
|
||||
(__a and string.rep(' ',dd)or'').."}"return b_a end;local bb=lookupify{' ','\n','\t','\r'}
|
||||
local cb={['\r']='\\r',['\n']='\\n',['\t']='\\t',['"']='\\"',["'"]="\\'"}
|
||||
local db=lookupify{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
|
||||
local _c=lookupify{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
|
||||
local ac=lookupify{'0','1','2','3','4','5','6','7','8','9'}
|
||||
local bc=lookupify{'0','1','2','3','4','5','6','7','8','9','A','a','B','b','C','c','D','d','E','e','F','f'}
|
||||
local cc=lookupify{'+','-','*','/','^','%',',','{','}','[',']','(',')',';','#'}
|
||||
local dc=lookupify{'and','break','do','else','elseif','end','false','for','function','goto','if','in','local','nil','not','or','repeat','return','then','true','until','while'}
|
||||
function LexLua(cd)local dd={}
|
||||
local __a,a_a=pcall(function()local _aa=1;local aaa=1;local baa=1
|
||||
local function caa()local cba=cd:sub(_aa,_aa)if cba=='\n'then baa=1
|
||||
aaa=aaa+1 else baa=baa+1 end;_aa=_aa+1;return cba end
|
||||
local function daa(cba)cba=cba or 0;return cd:sub(_aa+cba,_aa+cba)end;local function _ba(cba)local dba=daa()
|
||||
for i=1,#cba do if dba==cba:sub(i,i)then return caa()end end end;local function aba(cba)
|
||||
return error(">> :"..aaa..":"..
|
||||
baa..": "..cba,0)end
|
||||
local function bba()local cba=_aa
|
||||
if daa()=='['then local dba=0;while
|
||||
daa(dba+1)=='='do dba=dba+1 end
|
||||
if daa(dba+1)=='['then for _=0,dba+1 do caa()end
|
||||
local _ca=_aa
|
||||
while true do if daa()==''then
|
||||
aba("Expected `]"..string.rep('=',dba).."]` near <eof>.",3)end;local cca=true;if daa()==']'then for i=1,dba do if daa(i)~='='then
|
||||
cca=false end end
|
||||
if daa(dba+1)~=']'then cca=false end else cca=false end;if cca then break else
|
||||
caa()end end;local aca=cd:sub(_ca,_aa-1)for i=0,dba+1 do caa()end
|
||||
local bca=cd:sub(cba,_aa-1)return aca,bca else return nil end else return nil end end
|
||||
while true do local cba=''
|
||||
while true do local dca=daa()
|
||||
if bb[dca]then cba=cba..caa()elseif
|
||||
dca=='-'and daa(1)=='-'then caa()caa()cba=cba..'--'local _da,ada=bba()
|
||||
if ada then cba=cba..ada else while daa()~='\n'and
|
||||
daa()~=''do cba=cba..caa()end end else break end end;local dba=aaa;local _ca=baa
|
||||
local aca=":"..aaa..":"..baa..":> "local bca=daa()local cca=nil
|
||||
if bca==''then cca={Type='Eof'}elseif
|
||||
_c[bca]or db[bca]or bca=='_'then local dca=_aa;repeat caa()bca=daa()until not
|
||||
(_c[bca]or db[bca]or ac[bca]or bca=='_')
|
||||
local _da=cd:sub(dca,_aa-1)
|
||||
if dc[_da]then cca={Type='Keyword',Data=_da}else cca={Type='Ident',Data=_da}end elseif ac[bca]or(daa()=='.'and ac[daa(1)])then local dca=_aa
|
||||
if bca=='0'and
|
||||
daa(1)=='x'then caa()caa()while bc[daa()]do caa()end;if _ba('Pp')then
|
||||
_ba('+-')while ac[daa()]do caa()end end else
|
||||
while ac[daa()]do caa()end;if _ba('.')then while ac[daa()]do caa()end end;if _ba('Ee')then
|
||||
_ba('+-')while ac[daa()]do caa()end end end;cca={Type='Number',Data=cd:sub(dca,_aa-1)}elseif bca=='\''or bca==
|
||||
'\"'then local dca=_aa;local _da=caa()local ada=_aa;while true do local dda=caa()
|
||||
if dda=='\\'then caa()elseif
|
||||
dda==_da then break elseif dda==''then aba("Unfinished string near <eof>")end end;local bda=cd:sub(ada,
|
||||
_aa-2)local cda=cd:sub(dca,_aa-1)
|
||||
cca={Type='String',Data=cda,Constant=bda}elseif bca=='['then local dca,_da=bba()
|
||||
if _da then cca={Type='String',Data=_da,Constant=dca}else
|
||||
caa()cca={Type='Symbol',Data='['}end elseif _ba('>=<')then if _ba('=')then cca={Type='Symbol',Data=bca..'='}else
|
||||
cca={Type='Symbol',Data=bca}end elseif _ba('~')then
|
||||
if _ba('=')then
|
||||
cca={Type='Symbol',Data='~='}else aba("Unexpected symbol `~` in source.",2)end elseif _ba('.')then
|
||||
if _ba('.')then if _ba('.')then cca={Type='Symbol',Data='...'}else
|
||||
cca={Type='Symbol',Data='..'}end else cca={Type='Symbol',Data='.'}end elseif _ba(':')then if _ba(':')then cca={Type='Symbol',Data='::'}else
|
||||
cca={Type='Symbol',Data=':'}end elseif cc[bca]then caa()
|
||||
cca={Type='Symbol',Data=bca}else local dca,_da=bba()if dca then cca={Type='String',Data=_da,Constant=dca}else
|
||||
aba("Unexpected Symbol `"..
|
||||
bca.."` in source.",2)end end;cca.LeadingWhite=cba;cca.Line=dba;cca.Char=_ca
|
||||
cca.Print=function()
|
||||
return"<".. (cca.Type..string.rep(' ',7 -#
|
||||
cca.Type))..
|
||||
" ".. (cca.Data or'').." >"end;dd[#dd+1]=cca;if cca.Type=='Eof'then break end end end)if not __a then return false,a_a end;local b_a={}local c_a={}local d_a=1
|
||||
function b_a:Peek(_aa)_aa=_aa or 0;return dd[math.min(
|
||||
#dd,d_a+_aa)]end
|
||||
function b_a:Get()local _aa=dd[d_a]d_a=math.min(d_a+1,#dd)return _aa end;function b_a:Is(_aa)return b_a:Peek().Type==_aa end;function b_a:Save()c_a[
|
||||
#c_a+1]=d_a end
|
||||
function b_a:Commit()c_a[#c_a]=nil end;function b_a:Restore()d_a=c_a[#c_a]c_a[#c_a]=nil end
|
||||
function b_a:ConsumeSymbol(_aa)
|
||||
local aaa=self:Peek()
|
||||
if aaa.Type=='Symbol'then if _aa then
|
||||
if aaa.Data==_aa then self:Get()return true else return nil end else self:Get()return aaa end else return
|
||||
nil end end
|
||||
function b_a:ConsumeKeyword(_aa)local aaa=self:Peek()if
|
||||
aaa.Type=='Keyword'and aaa.Data==_aa then self:Get()return true else return nil end end;function b_a:IsKeyword(_aa)local aaa=b_a:Peek()return
|
||||
aaa.Type=='Keyword'and aaa.Data==_aa end
|
||||
function b_a:IsSymbol(_aa)
|
||||
local aaa=b_a:Peek()return aaa.Type=='Symbol'and aaa.Data==_aa end
|
||||
function b_a:IsEof()return b_a:Peek().Type=='Eof'end;return true,b_a end
|
||||
function ParseLua(cd)local dd,__a=LexLua(cd)if not dd then return false,__a end
|
||||
local function a_a(ada)local bda=">> :"..
|
||||
|
||||
__a:Peek().Line..":"..__a:Peek().Char..": "..ada.."\n"local cda=0
|
||||
for dda in
|
||||
cd:gmatch("[^\n]*\n?")do if dda:sub(-1,-1)=='\n'then dda=dda:sub(1,-2)end;cda=
|
||||
cda+1
|
||||
if cda==__a:Peek().Line then bda=bda..">> `"..
|
||||
dda:gsub('\t',' ').."`\n"for i=1,__a:Peek().Char
|
||||
do local __b=dda:sub(i,i)
|
||||
if __b=='\t'then bda=bda..' 'else bda=bda..' 'end end
|
||||
bda=bda.." ^---"break end end;return bda end;local b_a=0;local c_a={}local d_a={'_','a','b','c','d'}
|
||||
local function _aa(ada)local bda={}bda.Parent=ada
|
||||
bda.LocalList={}bda.LocalMap={}
|
||||
function bda:RenameVars()
|
||||
for cda,dda in pairs(bda.LocalList)do local __b;b_a=0
|
||||
repeat b_a=b_a+1;local a_b=b_a
|
||||
__b=''while a_b>0 do local b_b=a_b%#d_a;a_b=(a_b-b_b)/#d_a
|
||||
__b=__b..d_a[b_b+1]end until
|
||||
not c_a[__b]and
|
||||
not ada:GetLocal(__b)and not bda.LocalMap[__b]dda.Name=__b;bda.LocalMap[__b]=dda end end
|
||||
function bda:GetLocal(cda)local dda=bda.LocalMap[cda]if dda then return dda end;if bda.Parent then
|
||||
local __b=bda.Parent:GetLocal(cda)if __b then return __b end end;return nil end
|
||||
function bda:CreateLocal(cda)local dda={}dda.Scope=bda;dda.Name=cda;dda.CanRename=true;bda.LocalList[#
|
||||
bda.LocalList+1]=dda
|
||||
bda.LocalMap[cda]=dda;return dda end;bda.Print=function()return"<Scope>"end;return bda end;local aaa;local baa
|
||||
local function caa(ada)local bda=_aa(ada)if not __a:ConsumeSymbol('(')then return false,
|
||||
a_a("`(` expected.")end;local cda={}local dda=false
|
||||
while not
|
||||
__a:ConsumeSymbol(')')do
|
||||
if __a:Is('Ident')then
|
||||
local c_b=bda:CreateLocal(__a:Get().Data)cda[#cda+1]=c_b;if not __a:ConsumeSymbol(',')then
|
||||
if
|
||||
__a:ConsumeSymbol(')')then break else return false,a_a("`)` expected.")end end elseif
|
||||
__a:ConsumeSymbol('...')then dda=true
|
||||
if not __a:ConsumeSymbol(')')then return false,
|
||||
a_a("`...` must be the last argument of a function.")end;break else return false,a_a("Argument name or `...` expected")end end;local __b,a_b=baa(bda)if not __b then return false,a_b end;if not
|
||||
__a:ConsumeKeyword('end')then
|
||||
return false,a_a("`end` expected after function body")end;local b_b={}
|
||||
b_b.AstType='Function'b_b.Scope=bda;b_b.Arguments=cda;b_b.Body=a_b;b_b.VarArg=dda;return true,b_b end
|
||||
local function daa(ada)
|
||||
if __a:ConsumeSymbol('(')then local bda,cda=aaa(ada)
|
||||
if not bda then return false,cda end
|
||||
if not __a:ConsumeSymbol(')')then return false,a_a("`)` Expected.")end;cda.ParenCount=(cda.ParenCount or 0)+1;return true,cda elseif
|
||||
__a:Is('Ident')then local bda=__a:Get()local cda=ada:GetLocal(bda.Data)if not cda then
|
||||
c_a[bda.Data]=true end;local dda={}dda.AstType='VarExpr'dda.Name=bda.Data
|
||||
dda.Local=cda;return true,dda else return false,a_a("primary expression expected")end end
|
||||
local function _ba(ada,bda)local cda,dda=daa(ada)if not cda then return false,dda end
|
||||
while true do
|
||||
if __a:IsSymbol('.')or
|
||||
__a:IsSymbol(':')then local __b=__a:Get().Data;if not __a:Is('Ident')then return false,
|
||||
a_a("<Ident> expected.")end;local a_b=__a:Get()
|
||||
local b_b={}b_b.AstType='MemberExpr'b_b.Base=dda;b_b.Indexer=__b;b_b.Ident=a_b;dda=b_b elseif not
|
||||
bda and __a:ConsumeSymbol('[')then local __b,a_b=aaa(ada)if not __b then
|
||||
return false,a_b end;if not __a:ConsumeSymbol(']')then
|
||||
return false,a_a("`]` expected.")end;local b_b={}b_b.AstType='IndexExpr'
|
||||
b_b.Base=dda;b_b.Index=a_b;dda=b_b elseif not bda and __a:ConsumeSymbol('(')then local __b={}
|
||||
while not
|
||||
__a:ConsumeSymbol(')')do local b_b,c_b=aaa(ada)if not b_b then return false,c_b end
|
||||
__b[#__b+1]=c_b
|
||||
if not __a:ConsumeSymbol(',')then if __a:ConsumeSymbol(')')then break else return false,
|
||||
a_a("`)` Expected.")end end end;local a_b={}a_b.AstType='CallExpr'a_b.Base=dda;a_b.Arguments=__b;dda=a_b elseif not bda and
|
||||
__a:Is('String')then local __b={}__b.AstType='StringCallExpr'__b.Base=dda
|
||||
__b.Arguments={__a:Get()}dda=__b elseif not bda and __a:IsSymbol('{')then local __b,a_b=aaa(ada)if not __b then
|
||||
return false,a_b end;local b_b={}b_b.AstType='TableCallExpr'b_b.Base=dda
|
||||
b_b.Arguments={a_b}dda=b_b else break end end;return true,dda end
|
||||
local function aba(ada)
|
||||
if __a:Is('Number')then local bda={}bda.AstType='NumberExpr'bda.Value=__a:Get()return
|
||||
true,bda elseif __a:Is('String')then local bda={}bda.AstType='StringExpr'
|
||||
bda.Value=__a:Get()return true,bda elseif __a:ConsumeKeyword('nil')then local bda={}bda.AstType='NilExpr'
|
||||
return true,bda elseif __a:IsKeyword('false')or __a:IsKeyword('true')then local bda={}
|
||||
bda.AstType='BooleanExpr'bda.Value=(__a:Get().Data=='true')return true,bda elseif
|
||||
__a:ConsumeSymbol('...')then local bda={}bda.AstType='DotsExpr'return true,bda elseif __a:ConsumeSymbol('{')then local bda={}
|
||||
bda.AstType='ConstructorExpr'bda.EntryList={}
|
||||
while true do
|
||||
if __a:IsSymbol('[')then __a:Get()local cda,dda=aaa(ada)
|
||||
if not cda then return
|
||||
false,a_a("Key Expression Expected")end
|
||||
if not __a:ConsumeSymbol(']')then return false,a_a("`]` Expected")end
|
||||
if not __a:ConsumeSymbol('=')then return false,a_a("`=` Expected")end;local __b,a_b=aaa(ada)if not __b then
|
||||
return false,a_a("Value Expression Expected")end
|
||||
bda.EntryList[#bda.EntryList+1]={Type='Key',Key=dda,Value=a_b}elseif __a:Is('Ident')then local cda=__a:Peek(1)
|
||||
if
|
||||
cda.Type=='Symbol'and cda.Data=='='then local dda=__a:Get()if not __a:ConsumeSymbol('=')then
|
||||
return false,a_a("`=` Expected")end;local __b,a_b=aaa(ada)if not __b then return false,
|
||||
a_a("Value Expression Expected")end
|
||||
bda.EntryList[
|
||||
#bda.EntryList+1]={Type='KeyString',Key=dda.Data,Value=a_b}else local dda,__b=aaa(ada)
|
||||
if not dda then return false,a_a("Value Exected")end
|
||||
bda.EntryList[#bda.EntryList+1]={Type='Value',Value=__b}end elseif __a:ConsumeSymbol('}')then break else local cda,dda=aaa(ada)
|
||||
bda.EntryList[#bda.EntryList+1]={Type='Value',Value=dda}if not cda then return false,a_a("Value Expected")end end
|
||||
if __a:ConsumeSymbol(';')or __a:ConsumeSymbol(',')then elseif
|
||||
__a:ConsumeSymbol('}')then break else return false,a_a("`}` or table entry Expected")end end;return true,bda elseif __a:ConsumeKeyword('function')then local bda,cda=caa(ada)if not bda then
|
||||
return false,cda end;cda.IsLocal=true;return true,cda else return _ba(ada)end end;local bba=lookupify{'-','not','#'}local cba=8
|
||||
local dba={['+']={6,6},['-']={6,6},['%']={7,7},['/']={7,7},['*']={7,7},['^']={10,9},['..']={5,4},['==']={3,3},['<']={3,3},['<=']={3,3},['~=']={3,3},['>']={3,3},['>=']={3,3},['and']={2,2},['or']={1,1}}
|
||||
local function _ca(ada,bda)local cda,dda
|
||||
if bba[__a:Peek().Data]then local __b=__a:Get().Data
|
||||
cda,dda=_ca(ada,cba)if not cda then return false,dda end;local a_b={}a_b.AstType='UnopExpr'
|
||||
a_b.Rhs=dda;a_b.Op=__b;dda=a_b else cda,dda=aba(ada)if not cda then return false,dda end end
|
||||
while true do local __b=dba[__a:Peek().Data]
|
||||
if __b and __b[1]>bda then
|
||||
local a_b=__a:Get().Data;local b_b,c_b=_ca(ada,__b[2])if not b_b then return false,c_b end;local d_b={}
|
||||
d_b.AstType='BinopExpr'd_b.Lhs=dda;d_b.Op=a_b;d_b.Rhs=c_b;dda=d_b else break end end;return true,dda end;aaa=function(ada)return _ca(ada,0)end
|
||||
local function aca(ada)local bda=nil
|
||||
if
|
||||
__a:ConsumeKeyword('if')then local cda={}cda.AstType='IfStatement'cda.Clauses={}
|
||||
repeat local dda,__b=aaa(ada)if not dda then
|
||||
return false,__b end;if not __a:ConsumeKeyword('then')then return false,
|
||||
a_a("`then` expected.")end
|
||||
local a_b,b_b=baa(ada)if not a_b then return false,b_b end
|
||||
cda.Clauses[#cda.Clauses+1]={Condition=__b,Body=b_b}until not __a:ConsumeKeyword('elseif')
|
||||
if __a:ConsumeKeyword('else')then local dda,__b=baa(ada)
|
||||
if not dda then return false,__b end;cda.Clauses[#cda.Clauses+1]={Body=__b}end;if not __a:ConsumeKeyword('end')then
|
||||
return false,a_a("`end` expected.")end;bda=cda elseif __a:ConsumeKeyword('while')then
|
||||
local cda={}cda.AstType='WhileStatement'local dda,__b=aaa(ada)
|
||||
if not dda then return false,__b end;if not __a:ConsumeKeyword('do')then
|
||||
return false,a_a("`do` expected.")end;local a_b,b_b=baa(ada)
|
||||
if not a_b then return false,b_b end;if not __a:ConsumeKeyword('end')then
|
||||
return false,a_a("`end` expected.")end;cda.Condition=__b;cda.Body=b_b;bda=cda elseif
|
||||
__a:ConsumeKeyword('do')then local cda,dda=baa(ada)if not cda then return false,dda end
|
||||
if not
|
||||
__a:ConsumeKeyword('end')then return false,a_a("`end` expected.")end;local __b={}__b.AstType='DoStatement'__b.Body=dda;bda=__b elseif
|
||||
__a:ConsumeKeyword('for')then
|
||||
if not __a:Is('Ident')then return false,a_a("<ident> expected.")end;local cda=__a:Get()
|
||||
if __a:ConsumeSymbol('=')then local dda=_aa(ada)
|
||||
local __b=dda:CreateLocal(cda.Data)local a_b,b_b=aaa(ada)if not a_b then return false,b_b end
|
||||
if not
|
||||
__a:ConsumeSymbol(',')then return false,a_a("`,` Expected")end;local c_b,d_b=aaa(ada)if not c_b then return false,d_b end;local _ab,aab
|
||||
if
|
||||
__a:ConsumeSymbol(',')then _ab,aab=aaa(ada)if not _ab then return false,aab end end;if not __a:ConsumeKeyword('do')then
|
||||
return false,a_a("`do` expected")end;local bab,cab=baa(dda)
|
||||
if not bab then return false,cab end;if not __a:ConsumeKeyword('end')then
|
||||
return false,a_a("`end` expected")end;local dab={}
|
||||
dab.AstType='NumericForStatement'dab.Scope=dda;dab.Variable=__b;dab.Start=b_b;dab.End=d_b;dab.Step=aab
|
||||
dab.Body=cab;bda=dab else local dda=_aa(ada)
|
||||
local __b={dda:CreateLocal(cda.Data)}
|
||||
while __a:ConsumeSymbol(',')do if not __a:Is('Ident')then return false,
|
||||
a_a("for variable expected.")end
|
||||
__b[#__b+1]=dda:CreateLocal(__a:Get().Data)end;if not __a:ConsumeKeyword('in')then
|
||||
return false,a_a("`in` expected.")end;local a_b={}local b_b,c_b=aaa(ada)if not b_b then
|
||||
return false,c_b end;a_b[#a_b+1]=c_b
|
||||
while __a:ConsumeSymbol(',')do
|
||||
local bab,cab=aaa(ada)if not bab then return false,cab end;a_b[#a_b+1]=cab end;if not __a:ConsumeKeyword('do')then
|
||||
return false,a_a("`do` expected.")end;local d_b,_ab=baa(dda)
|
||||
if not d_b then return false,_ab end;if not __a:ConsumeKeyword('end')then
|
||||
return false,a_a("`end` expected.")end;local aab={}
|
||||
aab.AstType='GenericForStatement'aab.Scope=dda;aab.VariableList=__b;aab.Generators=a_b;aab.Body=_ab;bda=aab end elseif __a:ConsumeKeyword('repeat')then local cda,dda=baa(ada)
|
||||
if not cda then return false,dda end;if not __a:ConsumeKeyword('until')then
|
||||
return false,a_a("`until` expected.")end;local __b,a_b=aaa(ada)
|
||||
if not __b then return false,a_b end;local b_b={}b_b.AstType='RepeatStatement'b_b.Condition=a_b;b_b.Body=dda;bda=b_b elseif
|
||||
__a:ConsumeKeyword('function')then if not __a:Is('Ident')then
|
||||
return false,a_a("Function name expected")end;local cda,dda=_ba(ada,true)if not cda then
|
||||
return false,dda end;local __b,a_b=caa(ada)if not __b then return false,a_b end
|
||||
a_b.IsLocal=false;a_b.Name=dda;bda=a_b elseif __a:ConsumeKeyword('local')then
|
||||
if __a:Is('Ident')then
|
||||
local cda={__a:Get().Data}while __a:ConsumeSymbol(',')do if not __a:Is('Ident')then return false,
|
||||
a_a("local var name expected")end
|
||||
cda[#cda+1]=__a:Get().Data end;local dda={}if
|
||||
__a:ConsumeSymbol('=')then
|
||||
repeat local a_b,b_b=aaa(ada)if not a_b then return false,b_b end
|
||||
dda[#dda+1]=b_b until not __a:ConsumeSymbol(',')end;for a_b,b_b in
|
||||
pairs(cda)do cda[a_b]=ada:CreateLocal(b_b)end
|
||||
local __b={}__b.AstType='LocalStatement'__b.LocalList=cda;__b.InitList=dda;bda=__b elseif
|
||||
__a:ConsumeKeyword('function')then if not __a:Is('Ident')then
|
||||
return false,a_a("Function name expected")end;local cda=__a:Get().Data
|
||||
local dda=ada:CreateLocal(cda)local __b,a_b=caa(ada)if not __b then return false,a_b end;a_b.Name=dda
|
||||
a_b.IsLocal=true;bda=a_b else
|
||||
return false,a_a("local var or function def expected")end elseif __a:ConsumeSymbol('::')then if not __a:Is('Ident')then return false,
|
||||
a_a('Label name expected')end
|
||||
local cda=__a:Get().Data
|
||||
if not __a:ConsumeSymbol('::')then return false,a_a("`::` expected")end;local dda={}dda.AstType='LabelStatement'dda.Label=cda;bda=dda elseif
|
||||
__a:ConsumeKeyword('return')then local cda={}
|
||||
if not __a:IsKeyword('end')then local __b,a_b=aaa(ada)
|
||||
if __b then cda[1]=a_b;while
|
||||
__a:ConsumeSymbol(',')do local b_b,c_b=aaa(ada)if not b_b then return false,c_b end
|
||||
cda[#cda+1]=c_b end end end;local dda={}dda.AstType='ReturnStatement'dda.Arguments=cda;bda=dda elseif
|
||||
__a:ConsumeKeyword('break')then local cda={}cda.AstType='BreakStatement'bda=cda elseif __a:IsKeyword('goto')then
|
||||
if not
|
||||
__a:Is('Ident')then return false,a_a("Label expected")end;local cda=__a:Get().Data;local dda={}dda.AstType='GotoStatement'
|
||||
dda.Label=cda;bda=dda else local cda,dda=_ba(ada)if not cda then return false,dda end
|
||||
if
|
||||
__a:IsSymbol(',')or __a:IsSymbol('=')then
|
||||
if(dda.ParenCount or 0)>0 then return false,
|
||||
a_a("Can not assign to parenthesized expression, is not an lvalue")end;local __b={dda}
|
||||
while __a:ConsumeSymbol(',')do local _ab,aab=_ba(ada)
|
||||
if not _ab then return false,aab end;__b[#__b+1]=aab end
|
||||
if not __a:ConsumeSymbol('=')then return false,a_a("`=` Expected.")end;local a_b={}local b_b,c_b=aaa(ada)if not b_b then return false,c_b end;a_b[1]=c_b;while
|
||||
__a:ConsumeSymbol(',')do local _ab,aab=aaa(ada)if not _ab then return false,aab end
|
||||
a_b[#a_b+1]=aab end;local d_b={}
|
||||
d_b.AstType='AssignmentStatement'd_b.Lhs=__b;d_b.Rhs=a_b;bda=d_b elseif
|
||||
dda.AstType=='CallExpr'or
|
||||
dda.AstType=='TableCallExpr'or dda.AstType=='StringCallExpr'then local __b={}__b.AstType='CallStatement'__b.Expression=dda;bda=__b else return false,
|
||||
a_a("Assignment Statement Expected")end end;bda.HasSemicolon=__a:ConsumeSymbol(';')return true,bda end
|
||||
local bca=lookupify{'end','else','elseif','until'}
|
||||
baa=function(ada)local bda={}bda.Scope=_aa(ada)bda.AstType='Statlist'local cda={}
|
||||
while not
|
||||
bca[__a:Peek().Data]and not __a:IsEof()do
|
||||
local dda,__b=aca(bda.Scope)if not dda then return false,__b end;cda[#cda+1]=__b end;bda.Body=cda;return true,bda end;local function cca()local ada=_aa()return baa(ada)end;local dca,_da=cca()
|
||||
return dca,_da end
|
||||
local _d=lookupify{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
|
||||
local ad=lookupify{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
|
||||
local bd=lookupify{'0','1','2','3','4','5','6','7','8','9'}
|
||||
function Format_Mini(cd)local dd,__a;local a_a=0
|
||||
local function b_a(d_a,_aa,aaa)
|
||||
if a_a>150 then a_a=0;return d_a.."\n".._aa end;aaa=aaa or' 'local baa,caa=d_a:sub(-1,-1),_aa:sub(1,1)
|
||||
if
|
||||
ad[baa]or _d[baa]or baa=='_'then
|
||||
if not
|
||||
(ad[caa]or _d[caa]or caa=='_'or bd[caa])then return d_a.._aa elseif caa=='('then
|
||||
return d_a..aaa.._aa else return d_a..aaa.._aa end elseif bd[baa]then
|
||||
if caa=='('then return d_a.._aa else return d_a..aaa.._aa end elseif baa==''then return d_a.._aa else
|
||||
if caa=='('then return d_a..aaa.._aa else return d_a.._aa end end end
|
||||
__a=function(d_a)local _aa=string.rep('(',d_a.ParenCount or 0)
|
||||
if
|
||||
d_a.AstType=='VarExpr'then if d_a.Local then _aa=_aa..d_a.Local.Name else
|
||||
_aa=_aa..d_a.Name end elseif d_a.AstType=='NumberExpr'then _aa=_aa..
|
||||
d_a.Value.Data elseif d_a.AstType=='StringExpr'then
|
||||
_aa=_aa..d_a.Value.Data elseif d_a.AstType=='BooleanExpr'then _aa=_aa..tostring(d_a.Value)elseif
|
||||
d_a.AstType=='NilExpr'then _aa=b_a(_aa,"nil")elseif d_a.AstType=='BinopExpr'then
|
||||
_aa=b_a(_aa,__a(d_a.Lhs))_aa=b_a(_aa,d_a.Op)_aa=b_a(_aa,__a(d_a.Rhs))elseif d_a.AstType==
|
||||
'UnopExpr'then _aa=b_a(_aa,d_a.Op)
|
||||
_aa=b_a(_aa,__a(d_a.Rhs))elseif d_a.AstType=='DotsExpr'then _aa=_aa.."..."elseif d_a.AstType=='CallExpr'then _aa=_aa..
|
||||
__a(d_a.Base)_aa=_aa.."("for i=1,#d_a.Arguments do _aa=_aa..
|
||||
__a(d_a.Arguments[i])
|
||||
if i~=#d_a.Arguments then _aa=_aa..","end end;_aa=_aa..")"elseif d_a.AstType==
|
||||
'TableCallExpr'then _aa=_aa..__a(d_a.Base)_aa=_aa..
|
||||
__a(d_a.Arguments[1])elseif d_a.AstType=='StringCallExpr'then
|
||||
_aa=_aa..__a(d_a.Base)_aa=_aa..d_a.Arguments[1].Data elseif
|
||||
d_a.AstType=='IndexExpr'then
|
||||
_aa=_aa..__a(d_a.Base).."["..__a(d_a.Index).."]"elseif d_a.AstType=='MemberExpr'then _aa=_aa..__a(d_a.Base)..
|
||||
d_a.Indexer..d_a.Ident.Data elseif
|
||||
d_a.AstType=='Function'then d_a.Scope:RenameVars()
|
||||
_aa=_aa.."function("
|
||||
if#d_a.Arguments>0 then for i=1,#d_a.Arguments do
|
||||
_aa=_aa..d_a.Arguments[i].Name
|
||||
if i~=#d_a.Arguments then _aa=_aa..","elseif d_a.VarArg then _aa=_aa..",..."end end elseif
|
||||
d_a.VarArg then _aa=_aa.."..."end;_aa=_aa..")"_aa=b_a(_aa,dd(d_a.Body))
|
||||
_aa=b_a(_aa,"end")elseif d_a.AstType=='ConstructorExpr'then _aa=_aa.."{"
|
||||
for i=1,#d_a.EntryList do
|
||||
local aaa=d_a.EntryList[i]
|
||||
if aaa.Type=='Key'then _aa=_aa.."["..
|
||||
__a(aaa.Key).."]="..__a(aaa.Value)elseif aaa.Type==
|
||||
'Value'then _aa=_aa..__a(aaa.Value)elseif aaa.Type=='KeyString'then
|
||||
_aa=_aa..
|
||||
aaa.Key.."="..__a(aaa.Value)end;if i~=#d_a.EntryList then _aa=_aa..","end end;_aa=_aa.."}"end
|
||||
_aa=_aa..string.rep(')',d_a.ParenCount or 0)a_a=a_a+#_aa;return _aa end
|
||||
local c_a=function(d_a)local _aa=''
|
||||
if d_a.AstType=='AssignmentStatement'then
|
||||
for i=1,#d_a.Lhs do
|
||||
_aa=_aa..__a(d_a.Lhs[i])if i~=#d_a.Lhs then _aa=_aa..","end end;if#d_a.Rhs>0 then _aa=_aa.."="
|
||||
for i=1,#d_a.Rhs do
|
||||
_aa=_aa..__a(d_a.Rhs[i])if i~=#d_a.Rhs then _aa=_aa..","end end end elseif
|
||||
d_a.AstType=='CallStatement'then _aa=__a(d_a.Expression)elseif d_a.AstType=='LocalStatement'then
|
||||
_aa=_aa.."local "
|
||||
for i=1,#d_a.LocalList do _aa=_aa..d_a.LocalList[i].Name;if i~=#
|
||||
d_a.LocalList then _aa=_aa..","end end
|
||||
if#d_a.InitList>0 then _aa=_aa.."="for i=1,#d_a.InitList do _aa=_aa..
|
||||
__a(d_a.InitList[i])
|
||||
if i~=#d_a.InitList then _aa=_aa..","end end end elseif d_a.AstType=='IfStatement'then
|
||||
_aa=b_a("if",__a(d_a.Clauses[1].Condition))_aa=b_a(_aa,"then")
|
||||
_aa=b_a(_aa,dd(d_a.Clauses[1].Body))
|
||||
for i=2,#d_a.Clauses do local aaa=d_a.Clauses[i]
|
||||
if aaa.Condition then
|
||||
_aa=b_a(_aa,"elseif")_aa=b_a(_aa,__a(aaa.Condition))
|
||||
_aa=b_a(_aa,"then")else _aa=b_a(_aa,"else")end;_aa=b_a(_aa,dd(aaa.Body))end;_aa=b_a(_aa,"end")elseif d_a.AstType=='WhileStatement'then
|
||||
_aa=b_a("while",__a(d_a.Condition))_aa=b_a(_aa,"do")_aa=b_a(_aa,dd(d_a.Body))
|
||||
_aa=b_a(_aa,"end")elseif d_a.AstType=='DoStatement'then _aa=b_a(_aa,"do")
|
||||
_aa=b_a(_aa,dd(d_a.Body))_aa=b_a(_aa,"end")elseif d_a.AstType=='ReturnStatement'then _aa="return"
|
||||
for i=1,#d_a.Arguments
|
||||
do _aa=b_a(_aa,__a(d_a.Arguments[i]))if i~=
|
||||
#d_a.Arguments then _aa=_aa..","end end elseif d_a.AstType=='BreakStatement'then _aa="break"elseif d_a.AstType=='RepeatStatement'then
|
||||
_aa="repeat"_aa=b_a(_aa,dd(d_a.Body))_aa=b_a(_aa,"until")
|
||||
_aa=b_a(_aa,__a(d_a.Condition))elseif d_a.AstType=='Function'then d_a.Scope:RenameVars()if d_a.IsLocal then
|
||||
_aa="local"end;_aa=b_a(_aa,"function ")if d_a.IsLocal then
|
||||
_aa=_aa..d_a.Name.Name else _aa=_aa..__a(d_a.Name)end;_aa=
|
||||
_aa.."("
|
||||
if#d_a.Arguments>0 then
|
||||
for i=1,#d_a.Arguments do _aa=_aa..
|
||||
d_a.Arguments[i].Name;if i~=#d_a.Arguments then _aa=_aa..","elseif d_a.VarArg then
|
||||
_aa=_aa..",..."end end elseif d_a.VarArg then _aa=_aa.."..."end;_aa=_aa..")"_aa=b_a(_aa,dd(d_a.Body))
|
||||
_aa=b_a(_aa,"end")elseif d_a.AstType=='GenericForStatement'then d_a.Scope:RenameVars()
|
||||
_aa="for "
|
||||
for i=1,#d_a.VariableList do
|
||||
_aa=_aa..d_a.VariableList[i].Name;if i~=#d_a.VariableList then _aa=_aa..","end end;_aa=_aa.." in"
|
||||
for i=1,#d_a.Generators do
|
||||
_aa=b_a(_aa,__a(d_a.Generators[i]))if i~=#d_a.Generators then _aa=b_a(_aa,',')end end;_aa=b_a(_aa,"do")_aa=b_a(_aa,dd(d_a.Body))
|
||||
_aa=b_a(_aa,"end")elseif d_a.AstType=='NumericForStatement'then _aa="for "_aa=_aa..
|
||||
d_a.Variable.Name.."="_aa=_aa..
|
||||
__a(d_a.Start)..","..__a(d_a.End)if d_a.Step then
|
||||
_aa=_aa..","..__a(d_a.Step)end;_aa=b_a(_aa,"do")
|
||||
_aa=b_a(_aa,dd(d_a.Body))_aa=b_a(_aa,"end")end;a_a=a_a+#_aa;return _aa end
|
||||
dd=function(d_a)local _aa=''d_a.Scope:RenameVars()for aaa,baa in pairs(d_a.Body)do
|
||||
_aa=b_a(_aa,c_a(baa),';')end;return _aa end;cd.Scope:RenameVars()return dd(cd)end
|
||||
return function(cd)local dd,__a=ParseLua(cd)if not dd then return false,__a end
|
||||
return true,Format_Mini(__a)end
|
||||
@@ -29,8 +29,8 @@ local anim = main:addAnimation()
|
||||
:setObject(sub)
|
||||
:move(2,4,1.5)
|
||||
:setObject(button)
|
||||
:move(2,9,1,1.5):
|
||||
setObject(button2)
|
||||
:move(2,9,1,1.5)
|
||||
:setObject(button2)
|
||||
:move(sub:getWidth()-12,9,1,1.5)
|
||||
:play()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
You question yourself how you can execute your own logic while basalt is also active? There are multiple ways of doing that:
|
||||
|
||||
## Parallel
|
||||
|
||||
Using parallel.waitForAll or parallel.waitForAny
|
||||
|
||||
```lua
|
||||
@@ -21,9 +22,11 @@ end
|
||||
|
||||
parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalt's handlers at the same time using parallel's API
|
||||
```
|
||||
|
||||
[Here (tweaked.cc)](https://tweaked.cc/module/parallel.html) you can find out more about the parallel API.
|
||||
|
||||
## Threads
|
||||
|
||||
Using basalt's thread implementation.
|
||||
|
||||
```lua
|
||||
@@ -47,6 +50,7 @@ thread:start(yourCustomHandler) -- here we start the thread and pass the functio
|
||||
```
|
||||
|
||||
## Timers
|
||||
|
||||
Using basalt's implementation of timers.
|
||||
Remember, timers don't run asynchronly which means if you're using sleep somewhere this will freeze basalt's event system too.
|
||||
|
||||
@@ -67,4 +71,25 @@ end
|
||||
timer:onCall(yourCustomHandler)
|
||||
:setTime(1, -1)
|
||||
:start() -- this will call your function every second until you :cancel() the timer
|
||||
```
|
||||
```
|
||||
|
||||
## Schedule
|
||||
|
||||
Using basalt's schedule implementation.
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local main = basalt.createFrame() -- we need a base frame
|
||||
main:addButton() -- just a button
|
||||
:onClick(function()
|
||||
basalt.debug("Button got clicked")
|
||||
end)
|
||||
|
||||
local yourCustomHandler = basalt.schedule(function() -- create a new schedule task
|
||||
-- add your logic here
|
||||
end)
|
||||
|
||||
yourCustomHandler() -- execute the schedule task
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user