Annotation Stuff
This commit is contained in:
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -77,6 +77,6 @@ jobs:
|
||||
run: |
|
||||
git config --global user.name 'github-actions[bot]'
|
||||
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||
git add config.lua LuaLS.lua release/basalt.lua CHANGELOG.md
|
||||
git commit -m "Update config, LuaLS definitions, bundle and changelog" || exit 0
|
||||
git add config.lua BasaltLS.lua release/basalt.lua CHANGELOG.md
|
||||
git commit -m "Update config, BasaltLS definitions, bundle and changelog" || exit 0
|
||||
git push
|
||||
@@ -2,7 +2,7 @@ local basalt
|
||||
local releasePath = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/release/basalt.lua"
|
||||
local devPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/src/"
|
||||
local configPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/config.lua"
|
||||
local luaLSPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/LuaLS.lua"
|
||||
local luaLSPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/BasaltLS.lua"
|
||||
|
||||
local basaltRequest = http.get(releasePath)
|
||||
if not basaltRequest then
|
||||
@@ -545,7 +545,7 @@ local function installCustom(installPath, log, progressBar, selectedElements, se
|
||||
if(includeLuaLS)then
|
||||
local luaLS = downloadFile(luaLSPath, "LuaLS", 0)
|
||||
local luaLSDir = fs.getDir(installPath)
|
||||
local file = fs.open(fs.combine(luaLSDir, "LuaLS.lua"), "w")
|
||||
local file = fs.open("BasaltLS.lua", "w")
|
||||
file.write(luaLS)
|
||||
file.close()
|
||||
end
|
||||
@@ -566,8 +566,7 @@ local function installCustom(installPath, log, progressBar, selectedElements, se
|
||||
end
|
||||
if(includeLuaLS)then
|
||||
local luaLS = downloadFile(luaLSPath, "LuaLS", 0)
|
||||
local luaLSDir = fs.combine(installPath, "LuaLS.lua")
|
||||
local file = fs.open(luaLSDir, "w")
|
||||
local file = fs.open("BasaltLS.lua", "w")
|
||||
file.write(luaLS)
|
||||
file.close()
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"})
|
||||
--- @property eventCallbacks table BaseElement The event callbacks for the element
|
||||
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
|
||||
|
||||
---@private
|
||||
--- Registers a new event listener for the element (on class level)
|
||||
function BaseElement.defineEvent(class, eventName, requiredEvent)
|
||||
if not rawget(class, '_eventConfigs') then
|
||||
class._eventConfigs = {}
|
||||
@@ -42,7 +42,7 @@ function BaseElement.defineEvent(class, eventName, requiredEvent)
|
||||
}
|
||||
end
|
||||
|
||||
---@private
|
||||
--- Registers a new event callback for the element (on class level)
|
||||
function BaseElement.registerEventCallback(class, callbackName, ...)
|
||||
local methodName = callbackName:match("^on") and callbackName or "on"..callbackName
|
||||
local events = {...}
|
||||
|
||||
@@ -4,8 +4,8 @@ local tHex = require("libraries/colorHex")
|
||||
---@configDescription An element that displays an image in bimg format
|
||||
---@configDefault false
|
||||
|
||||
--- This is the Image element class which can be used to display bimg format images.
|
||||
--- The bimg format is a universal ComputerCraft image format.
|
||||
--- This is the Image element class which can be used to display bimg formatted images.
|
||||
--- Bimg is a universal ComputerCraft image format.
|
||||
--- See: https://github.com/SkyTheCodeMaster/bimg
|
||||
---@class Image : VisualElement
|
||||
local Image = setmetatable({}, VisualElement)
|
||||
@@ -187,13 +187,19 @@ function Image:setText(x, y, text)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the text at the specified position
|
||||
--- @shortDescription Gets the text at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the text to get
|
||||
--- @return string text The text at the specified position
|
||||
function Image:getText(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local text = frame[y][1]
|
||||
if not text then return end
|
||||
if not text then return "" end
|
||||
|
||||
if length then
|
||||
return text:sub(x, x + length - 1)
|
||||
@@ -231,13 +237,19 @@ function Image:setFg(x, y, pattern)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the foreground color at the specified position
|
||||
--- @shortDescription Gets the foreground color at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the foreground color pattern to get
|
||||
--- @return string fg The foreground color pattern
|
||||
function Image:getFg(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local fg = frame[y][2]
|
||||
if not fg then return end
|
||||
if not fg then return "" end
|
||||
|
||||
if length then
|
||||
return fg:sub(x, x + length - 1)
|
||||
@@ -275,13 +287,19 @@ function Image:setBg(x, y, pattern)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the background color at the specified position
|
||||
--- @shortDescription Gets the background color at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the background color pattern to get
|
||||
--- @return string bg The background color pattern
|
||||
function Image:getBg(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local bg = frame[y][3]
|
||||
if not bg then return end
|
||||
if not bg then return "" end
|
||||
|
||||
if length then
|
||||
return bg:sub(x, x + length - 1)
|
||||
@@ -338,7 +356,11 @@ function Image:addFrame()
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Updates the specified frame with the provided data
|
||||
--- @shortDescription Updates the specified frame with the provided data
|
||||
--- @param frameIndex number The index of the frame to update
|
||||
--- @param frame table The new frame data
|
||||
--- @return Image self The Image instance
|
||||
function Image:updateFrame(frameIndex, frame)
|
||||
local frames = self.get("bimg")
|
||||
frames[frameIndex] = frame
|
||||
@@ -355,6 +377,9 @@ function Image:getFrame(frameIndex)
|
||||
return frames[frameIndex or self.get("currentFrame")]
|
||||
end
|
||||
|
||||
--- Gets the metadata of the image
|
||||
--- @shortDescription Gets the metadata of the image
|
||||
--- @return table metadata The metadata of the image
|
||||
function Image:getMetadata()
|
||||
local metadata = {}
|
||||
local bimg = self.get("bimg")
|
||||
@@ -366,6 +391,11 @@ function Image:getMetadata()
|
||||
return metadata
|
||||
end
|
||||
|
||||
--- Sets the metadata of the image
|
||||
--- @shortDescription Sets the metadata of the image
|
||||
--- @param key string The key of the metadata to set
|
||||
--- @param value string The value of the metadata to set
|
||||
--- @return Image self The Image instance
|
||||
function Image:setMetadata(key, value)
|
||||
if(type(key)=="table")then
|
||||
for k,v in pairs(key)do
|
||||
|
||||
@@ -70,8 +70,8 @@ function Input:char(char)
|
||||
local maxLength = self.get("maxLength")
|
||||
local pattern = self.get("pattern")
|
||||
|
||||
if maxLength and #text >= maxLength then return end
|
||||
if pattern and not char:match(pattern) then return end
|
||||
if maxLength and #text >= maxLength then return false end
|
||||
if pattern and not char:match(pattern) then return false end
|
||||
|
||||
self.set("text", text:sub(1, pos-1) .. char .. text:sub(pos))
|
||||
self.set("cursorPos", pos + 1)
|
||||
|
||||
@@ -127,6 +127,7 @@ function Tree:mouse_click(button, x, y)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Registers a callback for when a node is selected
|
||||
@@ -153,6 +154,7 @@ function Tree:mouse_scroll(direction, x, y)
|
||||
self.set("scrollOffset", newScroll)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Gets the size of the tree
|
||||
|
||||
@@ -78,7 +78,7 @@ VisualElement.combineProperties(VisualElement, "size", "width", "height")
|
||||
---@combinedProperty color {foreground number, background number} Combined foreground, background colors
|
||||
VisualElement.combineProperties(VisualElement, "color", "foreground", "background")
|
||||
|
||||
---@event onClick {button, x, y} Fired on mouse click
|
||||
---@event onClick {button string, x number, y number} Fired on mouse click
|
||||
---@event onMouseUp {button, x, y} Fired on mouse button release
|
||||
---@event onRelease {button, x, y} Fired when mouse leaves while clicked
|
||||
---@event onDrag {button, x, y} Fired when mouse moves while clicked
|
||||
@@ -110,8 +110,6 @@ local max, min = math.max, math.min
|
||||
|
||||
--- Creates a new VisualElement instance
|
||||
--- @shortDescription Creates a new visual element
|
||||
--- @param props table The properties to initialize the element with
|
||||
--- @param basalt table The basalt instance
|
||||
--- @return VisualElement object The newly created VisualElement instance
|
||||
--- @private
|
||||
function VisualElement.new()
|
||||
|
||||
@@ -129,6 +129,18 @@ local function getClassName(content)
|
||||
return split(content:gsub("^%s*", ""):gsub("%s*$", ""):gsub(" ", ""), ":")
|
||||
end
|
||||
|
||||
local function parseEventParams(content)
|
||||
local eventName, paramStr, desc = content:match("^([%w_]+)%s*{([^}]+)}%s*(.*)$")
|
||||
if eventName then
|
||||
local params = {}
|
||||
for name, typ in paramStr:gmatch("([%w_]+)%s+([%w_]+)") do
|
||||
table.insert(params, {name=name, type=typ})
|
||||
end
|
||||
return eventName, params, desc
|
||||
end
|
||||
return nil, nil, nil
|
||||
end
|
||||
|
||||
local function parseFile(content)
|
||||
local fileContent = {}
|
||||
local class = {functions = {}, properties = {}, events = {}, fields = {}}
|
||||
@@ -194,6 +206,28 @@ local function parseFile(content)
|
||||
class.functions[class.class..":get" .. propertyName] = {params={{name="self", type=class.class, desc="self"}}, returns={{type=propertyType, desc=propertyDesc or ""}}, desc="Gets the value of the " .. propertyName .. " property.\n"}
|
||||
class.functions[class.class..":set" .. propertyName] = {params={{name="self", type=class.class, desc="self"}, {name=propertyName, type=propertyType, desc=propertyDesc:gsub("^%S+%s*", "") or ""}}, returns={}, desc="Sets the value of the " .. propertyName .. " property.\n"}
|
||||
end
|
||||
elseif(commentType=="combinedProperty")then
|
||||
local propertyName, propertyType, propertyDesc = content:match("^%s*([%w_]+)%s+([%w_]+)%s*(.*)$")
|
||||
if propertyName then
|
||||
class.fields[propertyName] = {type=propertyType, desc=propertyDesc:gsub("^%S+%s*", "") or ""}
|
||||
propertyName = propertyName:sub(1,1):upper() .. propertyName:sub(2)
|
||||
class.functions[class.class..":get" .. propertyName] = {params={{name="self", type=class.class, desc="self"}}, returns={{type=propertyType, desc=propertyDesc or ""}}, desc="Gets the value of the " .. propertyName .. " property.\n"}
|
||||
class.functions[class.class..":set" .. propertyName] = {params={{name="self", type=class.class, desc="self"}, {name=propertyName, type=propertyType, desc=propertyDesc:gsub("^%S+%s*", "") or ""}}, returns={}, desc="Sets the value of the " .. propertyName .. " property.\n"}
|
||||
end
|
||||
elseif(commentType=="event")then
|
||||
local eventName, params, eventDesc = parseEventParams(content)
|
||||
if eventName then
|
||||
class.events[eventName] = {params=params, desc=eventDesc or ""}
|
||||
local paramStr = ""
|
||||
for _, param in ipairs(params) do
|
||||
paramStr = paramStr .. string.format("---@param %s %s\n", param.name, param.type)
|
||||
end
|
||||
class.functions[class.class..":on" .. eventName:sub(1,1):upper() .. eventName:sub(2)] = {
|
||||
params={{name="self", type=class.class, desc="self"}, {name="func", type="function", desc="The function to be called when the event fires"}},
|
||||
returns={},
|
||||
desc="Registers a function to handle the " .. eventName .. " event.\n" .. paramStr
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
@@ -238,7 +272,7 @@ local function generateLuaLS(finalContent)
|
||||
table.insert(output, string.format("---%s", funcData.desc))
|
||||
end
|
||||
if(funcData.protected)then
|
||||
table.insert(output, string.format("---This function is protected und should not be called outside of basalt, however you can overwrite it if you know what you're doing.\n"))
|
||||
table.insert(output, string.format("---This function is protected and should not be called outside of basalt, however you can overwrite it if you know what you're doing.\n"))
|
||||
end
|
||||
for _, param in ipairs(funcData.params) do
|
||||
table.insert(output, string.format("---@param %s %s %s\n", (param.optional and param.name.."?" or param.name), param.type, param.desc))
|
||||
@@ -290,7 +324,7 @@ local function parseFiles(files)
|
||||
end
|
||||
|
||||
local lualsContent = generateLuaLS(finalContent)
|
||||
local outFile = io.open("LuaLS.lua", "w")
|
||||
local outFile = io.open("BasaltLS.lua", "w")
|
||||
if outFile then
|
||||
outFile:write(lualsContent)
|
||||
outFile:close()
|
||||
|
||||
Reference in New Issue
Block a user