Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lua/entities/gmod_wire_expression2/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ end
---@param args { [1]: string, [2]: string }[]?
---@param constructor fun(self: table)? # Constructor to run when E2 initially starts listening to this event. Passes E2 context
---@param destructor fun(self: table)? # Destructor to run when E2 stops listening to this event. Passes E2 context
function E2Lib.registerEvent(name, args, constructor, destructor)
---@param description string
function E2Lib.registerEvent(name, args, constructor, destructor, description)
-- Ensure event starts with lowercase letter
-- assert(not E2Lib.Env.Events[name], "Possible addon conflict: Trying to override existing E2 event '" .. name .. "'")

Expand Down Expand Up @@ -231,6 +232,8 @@ function E2Lib.registerEvent(name, args, constructor, destructor)
E2Lib.Env.Events[name] = {
name = name,
args = args or {},
extension = E2Lib.currentextension,
description = description,

constructor = constructor,
destructor = destructor,
Expand Down Expand Up @@ -311,7 +314,9 @@ if SERVER then
for evt, data in pairs(E2Lib.Env.Events) do
events_sanitized[evt] = {
name = data.name,
args = data.args
args = data.args,
extension = data.extension,
description = data.description
}
end

Expand Down
64 changes: 56 additions & 8 deletions lua/wire/client/e2helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ function E2Helper.Create(reset)
E2Helper.Resize()
end

-- holds all the lines describing a constant
-- holds all the lines describing a constant and events
E2Helper.constants = {}
E2Helper.events = {}

E2Helper.DescriptionEntry = vgui.Create("DTextEntry", E2Helper.Frame)
E2Helper.DescriptionEntry:SetPos(5, 330)
Expand Down Expand Up @@ -198,6 +199,7 @@ function E2Helper.Create(reset)
self:SelectItem(line)

local const = E2Helper.constants[line]

if const then
E2Helper.FuncEntry:SetText(line:GetValue(1) .. " (" .. const.type .. ")")

Expand All @@ -208,16 +210,45 @@ function E2Helper.Create(reset)
E2Helper.DescriptionEntry:SetText("No description found :(")
E2Helper.DescriptionEntry:SetTextColor(Color(128, 128, 128))
end
else
E2Helper.FuncEntry:SetText(E2Helper.GetFunctionSyntax(line:GetValue(1), line:GetValue(3), line:GetValue(4)))
local desc = getdesc(line:GetValue(1), line:GetValue(3))
if desc then
E2Helper.DescriptionEntry:SetText(desc)
E2Helper.DescriptionEntry:SetTextColor(Color(0, 0, 0))

return
end

local event = E2Helper.events[line]

if event then
local argnames = {}

for _, arg in ipairs(event.args) do
local typename = wire_expression_types2[arg.type][1]:lower()
if typename == "normal" then typename = "number" end

table.insert(argnames, typename .. " " .. string.lower(arg.placeholder))
end

E2Helper.FuncEntry:SetText(string.format("event %s(%s)", event.name, table.concat(argnames, ",")))

if event.description then
E2Helper.DescriptionEntry:SetText(event.description)
E2Helper.DescriptionEntry:SetTextColor(color_black)
else
E2Helper.DescriptionEntry:SetText("No description found :(")
E2Helper.DescriptionEntry:SetTextColor(Color(128, 128, 128))
end

return
end

E2Helper.FuncEntry:SetText(E2Helper.GetFunctionSyntax(line:GetValue(1), line:GetValue(3), line:GetValue(4)))

local description = getdesc(line:GetValue(1), line:GetValue(3))

if description then
E2Helper.DescriptionEntry:SetText(description)
E2Helper.DescriptionEntry:SetTextColor(color_black)
else
E2Helper.DescriptionEntry:SetText("No description found :(")
E2Helper.DescriptionEntry:SetTextColor(Color(128, 128, 128))
end
end

Expand Down Expand Up @@ -350,8 +381,10 @@ function E2Helper.Update()
local maxcount = E2Helper.MaxEntry:GetValue()
local tooltip = E2Helper.Tooltip:GetChecked(true)

-- add E2 constants
-- add E2 constants and events
E2Helper.constants = {}
E2Helper.events = {}

if E2Helper.CurrentMode == "E2" then
for k, v in pairs(wire_expression2_constants) do
-- constants have no arguments and no cost
Expand All @@ -363,6 +396,21 @@ function E2Helper.Update()
if count >= maxcount then break end
end
end

for k, event in pairs(E2Lib.Env.Events) do
local rets = ""

for _, arg in ipairs(event.args) do
rets = rets .. arg.type
end

if event.name:lower():find(search_name, 1, true) and search_args == "" and rets:find(search_rets, 1, true) and string.find("events", search_from, 1, true) then
local line = E2Helper.ResultFrame:AddLine(event.name, event.extension, nil, rets, 0)
E2Helper.events[line] = event
count = count + 1
if count >= maxcount then break end
end
end
end

if count < maxcount then
Expand Down
Loading