From 0d75e21f63229e71a0e41cecf10aba06a44c24ec Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:48:36 -0400 Subject: [PATCH 1/9] Refactor objectcontrol.lua Rewrote EGPLib init Moved EGP to a subtable of E2Lib(?) Modified E2Lib init to merge any preexisting value --- .../lib/egplib/objectcontrol.lua | 393 +++++++++++------- lua/entities/gmod_wire_egp/lib/init.lua | 58 +-- .../gmod_wire_expression2/core/e2lib.lua | 4 +- 3 files changed, 290 insertions(+), 165 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua b/lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua index 67ee1274a9..abb41480df 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua @@ -1,53 +1,78 @@ --------------------------------------------------------- --- Objects --------------------------------------------------------- -local EGP = EGP - -local egpObjects = {} -egpObjects.Names = {} -egpObjects.Names_Inverted = {} -EGP.Objects = egpObjects - --- This object is not used. It's only a base -local baseObj = {} -baseObj.ID = 0 -baseObj.x = 0 -baseObj.y = 0 -baseObj.angle = 0 -baseObj.r = 255 -baseObj.g = 255 -baseObj.b = 255 -baseObj.a = 255 -baseObj.filtering = TEXFILTER.ANISOTROPIC -baseObj.parent = 0 +local EGP = E2Lib.EGP +---@type { [string]: EGPObject, [integer]: EGPObject } +local objects = {} +--- All implemented objects. The array part represents EGP Object IDs. The table part represents EGP Object names. +EGP.Objects = objects + +local validEGP +local maxObjects + +---@class EGPObject +---@field ID integer? nil when NULL +---@field index integer +local baseObj = { + ID = 0, + x = 0, + y = 0, + angle = 0, + r = 255, + g = 255, + b = 255, + a = 255, + filtering = TEXFILTER.ANISOTROPIC, + parent = 0 +} if SERVER then baseObj.material = "" - baseObj.EGP = NULL -- EGP entity parent + baseObj.EGP = NULL --[[@as Entity]] -- EGP entity parent else baseObj.material = false end + +--- Used in a net writing context to transmit the object's entire data. +---@see EGPObject.Receive function baseObj:Transmit() EGP.SendPosAng(self) - EGP:SendColor( self ) - EGP:SendMaterial(self) - if self.filtering then net.WriteUInt(math.Clamp(self.filtering,0,3), 2) end - net.WriteInt( self.parent, 16 ) + EGP.SendColor(nil, self) + EGP.SendMaterial(nil, self) + if self.filtering then net.WriteUInt(math.Clamp(self.filtering, 0, 3), 2) end + net.WriteInt(self.parent, 16) end +--- Used in a net reading context to read the object's entire data. +---@see EGPObject.Transmit function baseObj:Receive() local tbl = {} EGP.ReceivePosAng(tbl) - EGP:ReceiveColor( tbl, self ) - EGP:ReceiveMaterial( tbl ) + EGP.ReceiveColor(nil, tbl, self) + EGP.ReceiveMaterial(nil, tbl) if self.filtering then tbl.filtering = net.ReadUInt(2) end tbl.parent = net.ReadInt(16) return tbl end + +--- Returns a table of data that needs to be transferred in EGP messages. function baseObj:DataStreamInfo() - return { x = self.x, y = self.y, angle = self.angle, w = self.w, h = self.h, r = self.r, g = self.g, b = self.b, a = self.a, material = self.material, parent = self.parent } + return { x = self.x, y = self.y, angle = self.angle, r = self.r, g = self.g, b = self.b, a = self.a, material = self.material, parent = self.parent } end +--- Returns `true` if the object contains the point. +---@param x number +---@param y number +---@return boolean function baseObj:Contains(x, y) return false end + +if false then + --- Called when the object is removed. + function baseObj:OnRemove() end +end + +--- Edits the fields of the EGPObject with the given table. Returns `true` if a field changed. +--- Use `SetPos` for setting position directly. Use `Set` to set a single field. +---@param args { [string]: any } The fields to edit on the object. Values are *not* guaranteed to be type checked or sanity checked! +---@return boolean # Whether the object changed +---@see EGPObject.SetPos +---@see EGPObject.Set function baseObj:EditObject(args) local ret = false if args.x or args.y or args.angle then @@ -62,7 +87,19 @@ function baseObj:EditObject(args) end return ret end -baseObj.Initialize = baseObj.EditObject + +--- A helper method for objects that may need to do something on initialization. Calls `EditObject` by default. +---@param args { [string]: any } +---@see EGPObject.EditObject +function baseObj:Initialize(args) self:EditObject(args) end + +--- Sets the position of the EGPObject directly. This method should be overridden if special behavior is needed. +--- Call this method when you need to change position. +---@param x number +---@param y number +---@param angle number In degrees +---@return boolean # Whether the position changed +---@see EGPObject.EditObject function baseObj:SetPos(x, y, angle) local ret = false if x and self.x ~= x then self.x, ret = x, true end @@ -71,126 +108,189 @@ function baseObj:SetPos(x, y, angle) angle = angle % 360 if self.angle ~= angle then self.angle, ret = angle, true end end - if SERVER and self._x then - if x then self._x = x end - if y then self._y = y end - if angle then self._angle = angle end - end return ret end -function baseObj:Set(member, value) - if self[member] and self[member] ~= value then - self[member] = value + +--- Sets a single field of the EGP Object. Do **not** use this for position. Use `SetPos` instead. +---@param k string +---@param v any +---@return boolean # Whether the field changed +function baseObj:Set(k, v) + local kx, ky, ka = k == "x", k == "y", k == "angle" + if kx or ky or ka then + return self:SetPos(kx and v or self.x, ky and v or self.y, ka and v or self.angle) + end + if self[k] and self[k] ~= v then + self[k] = v return true else return false end end -local M_EGPObject = {__tostring = function(self) return "[EGPObject] ".. self.Name end} -setmetatable(baseObj, M_EGPObject) -EGP.Objects.Base = baseObj -local M_NULL_EGPOBJECT = { __tostring = function(self) return "[EGPObject] NULL" end, __eq = function(a, b) return getmetatable(a) == getmetatable(b) end } -local NULL_EGPOBJECT = setmetatable({}, M_NULL_EGPOBJECT) -EGP.NULL_EGPOBJECT = NULL_EGPOBJECT +local EGPObject = {} +EGPObject.__index = EGPObject +function EGPObject:__tostring() + return "[EGPObject] ".. (self.Name or "NULL") +end +function EGPObject:__eq(a, b) + return a.ID == b.ID +end +function EGPObject:IsValid() + return self.ID ~= nil +end + +-- The EGPObject metatable +EGP.EGPObject = EGPObject +setmetatable(baseObj, EGPObject) +objects.Base = baseObj ----------------------------- --- Get Object ----------------------------- +---@type EGPObject +local NULL_EGPOBJECT = setmetatable({}, EGPObject) +--- An invalid EGPObject +EGP.Objects.NULL_EGPOBJECT = NULL_EGPOBJECT -function EGP:GetObjectByID( ID ) - for _, v in pairs( EGP.Objects ) do - if (v.ID == ID) then return table.Copy( v ) end - end - ErrorNoHalt( "[EGP] Error! Object with ID '" .. ID .. "' does not exist. Please post this bug message in the EGP thread on the wiremod forums.\n" ) +--- Returns true if the input is an EGP Object +local function isEGPObject(obj) + return istable(obj) and getmetatable(obj) == EGPObject end +EGP.IsEGPObject = isEGPObject ---------------------------- -- Load all objects ---------------------------- +do + local yielded = {} -function EGP:NewObject(name, super) - local lower = name:lower() -- Makes my life easier - if not super then super = baseObj end - if self.Objects[lower] then return self.Objects[lower] end + ---@generic NewEGPObject:EGPObject + --- Creates a new EGPObject class and returns it reference. If you want to inherit from another class, see `EGP.ObjectInherit`, which properly handles out-of-order loading. + ---@param name string The name of the class. Case sensitive. + ---@param super EGPObject? The superclass of the class. If nil, defaults to base object. + ---@return NewEGPObject # The EGPObject class + ---@see EGP.ObjectInherit + local function newObject(name, super) + if objects[name] then return objects[name] end - -- Create table - self.Objects[lower] = {} - -- Set info - self.Objects[lower].Name = name - table.Inherit(self.Objects[lower], super) + if not super then super = baseObj end - -- Create lookup table - local ID = table.Count(self.Objects) - self.Objects[lower].ID = ID - self.Objects.Names[name] = ID + local newObj = {} - -- Inverted lookup table - self.Objects.Names_Inverted[ID] = lower + newObj.Name = name + table.Inherit(newObj, super) - return setmetatable(self.Objects[lower], M_EGPObject) -end + local ID = #objects + 1 + newObj.ID = ID -local folder = "entities/gmod_wire_egp/lib/objects/" + newObj = setmetatable(newObj, EGPObject) -function EGP.ObjectInherit(to, from) - local super = egpObjects[from:lower()] - if super then - return EGP:NewObject(to, super) - else - local path = folder .. from .. ".lua" - if file.Exists(path, "LUA") then - super = include(path) - AddCSLuaFile(path) - return EGP:NewObject(to, super) + objects[name] = newObj + objects[ID] = newObj + + return newObj + end + EGP.NewObject = newObject + + ---@generic NewEGPObject:EGPObject + --- Used to inherit from another EGPObject class. This uses EGP.NewObject internally, so you should not call that. + ---@param to string The new class name + ---@param from string The superclass name + ---@return NewEGPObject # The EGPObject class with inheritance + function EGP.ObjectInherit(to, from) + local super = objects[from] + if super then + return newObject(to, super) else - ErrorNoHalt(string.format("EGP couldn't find object '%s' to inherit from (to object '%s').\n", from, to)) + error({ from }) end end -end -do - local files = file.Find(folder.."*.lua", "LUA") + local FOLDER = "entities/gmod_wire_egp/lib/objects/" + local files = file.Find(FOLDER .. "*.lua", "LUA") for _, v in ipairs(files) do - if not egpObjects[v:sub(1, #v - 4):lower()] then -- Remove the extension and check if the object already exists. - include(folder .. v) - AddCSLuaFile(folder .. v) + local p = FOLDER .. v + local fn = CompileFile(p) + local wrap = function() + local ok, super = pcall(fn) + if ok then + AddCSLuaFile(p) + return + else + return super[1] + end + end + local ret = wrap() + if ret ~= nil then + local t = yielded[ret] + if not t then + t = {} + yielded[ret] = t + end + table.insert(t, wrap) + end + end + + for name, t in pairs(yielded) do + if objects[name] then + for _, v in ipairs(t) do + if yielded[name] then + v() + end + end + else + ErrorNoHalt("EGP Error: Missing dependency " .. name .. ". " .. #t .. " objects will not be loaded.\n") end end end ----------------------------- --- Object existance check ----------------------------- -function EGP:HasObject( Ent, index ) - if not EGP:ValidEGP(Ent) then return false end - if SERVER then index = math.Round(math.Clamp(index or 1, 1, self.ConVars.MaxObjects:GetInt())) end - if not Ent.RenderTable or #Ent.RenderTable == 0 then return false end - for k,v in pairs( Ent.RenderTable ) do - if (v.index == index) then +--- Checks if the object exists on the screen. +---@param egp Entity +---@param index EGPObject|integer The EGPObject or EGP index to find +---@return boolean found Whether the object exists +---@return integer? index The Render Table index if it exists +---@return EGPObject? object The found EGPObject if it exists +local function hasObject(egp, index) + if not validEGP(nil, egp) then return false end + local renderTable = egp.RenderTable + if not renderTable or #renderTable == 0 then return false end + + if isEGPObject(index) then + if index.EGP == egp then + index = index.index + else + return false + end + end + ---@cast index -EGPObject + + if SERVER then index = math.Round(math.Clamp(index or 1, 1, maxObjects:GetInt())) end + + for k, v in ipairs(renderTable) do + if v.index == index then return true, k, v end end return false end +EGP.HasObject = hasObject ---------------------------- -- Object order changing ---------------------------- -function EGP:SetOrder(ent, from, to, dir) + +function EGP.SetOrder(ent, from, to, dir) if not ent.RenderTable or #ent.RenderTable == 0 then return false end dir = dir or 0 if ent.RenderTable[from] then - to = math.Clamp(math.Round(to or 1),1,#ent.RenderTable) - if SERVER then ent.RenderTable[from].ChangeOrder = {target=to,dir=dir} end + to = math.Clamp(math.Round(to or 1), 1, #ent.RenderTable) + if SERVER then ent.RenderTable[from].ChangeOrder = { target = to, dir = dir } end return true end return false end local already_reordered = {} -function EGP:PerformReorder_Ex(ent, originIdx, maxn) +local function performReorder_ex(ent, originIdx, maxn) local obj = ent.RenderTable[originIdx] local idx = obj.index if obj then @@ -213,10 +313,10 @@ function EGP:PerformReorder_Ex(ent, originIdx, maxn) targetIdx = target else -- target is relative position - local bool, k = self:HasObject(ent, target) + local bool, k = hasObject(ent, target) if bool then -- Check for order dependencies - k = self:PerformReorder_Ex(ent, k, maxn) or k + k = performReorder_ex(ent, k, maxn) or k targetIdx = k + dir else @@ -245,14 +345,14 @@ function EGP:PerformReorder_Ex(ent, originIdx, maxn) end end -function EGP:PerformReorder(ent) +function EGP.PerformReorder(ent) -- Reset, just to be sure already_reordered = {} -- Now we remove and create at the same time! local maxn = #ent.RenderTable for i, _ in ipairs(ent.RenderTable) do - self:PerformReorder_Ex(ent, i, maxn) + performReorder_ex(ent, i, maxn) end -- Clear some memory @@ -263,47 +363,57 @@ end -- Create / edit objects ---------------------------- -function EGP:CreateObject( Ent, ObjID, Settings ) - if not self:ValidEGP(Ent) then return false, NULL_EGPOBJECT end - - if not self.Objects.Names_Inverted[ObjID] then - ErrorNoHalt("Trying to create nonexistant object! Please report this error to Divran at wiremod.com. ObjID: " .. ObjID .. "\n") +--- Attempts to create an instance of an EGPObject. Returns `true` and the object if the operation succeeded. +---@param id string|integer The EGPObject class name or ID +---@param settings { [string]: any } The data to initialize the object with +---@param egp Entity The EGP to create the object on +---@return boolean +---@return EGPObject +local function create(id, settings, egp) + if not validEGP(nil, egp) then return false, NULL_EGPOBJECT end + + local class = objects[id] + if not class then + ErrorNoHalt(string.format("Trying to create nonexistant object! Object %s: %s\n", isnumber(id) and "ID" or "name", + isnumber(id) and tostring(id) or id)) return false, NULL_EGPOBJECT end - if SERVER then Settings.index = math.Round(math.Clamp(Settings.index or 1, 1, self.ConVars.MaxObjects:GetInt())) end - Settings.EGP = Ent - - local bool, k, v = self:HasObject( Ent, Settings.index ) - if (bool) then -- Already exists. Change settings: - if v.ID ~= ObjID then -- Not the same kind of object, create new - local Obj = self:GetObjectByID( ObjID ) - Obj:Initialize(Settings) - Obj.index = Settings.index - Ent.RenderTable[k] = Obj - return true, Obj + if SERVER then settings.index = math.Round(math.Clamp(settings.index or 1, 1, maxObjects:GetInt())) end + settings.EGP = egp + + local index = settings.index + settings.index = nil + + local bool, k, obj = hasObject(egp, index) + if bool then -- Already exists. Change settings: + ---@cast obj -? + if obj.ID ~= class.ID then -- Not the same kind of object, create new + obj = table.Copy(class) + obj:Initialize(settings) + obj.index = index + egp.RenderTable[k] = obj + return true, obj else - return v:EditObject(Settings), v + return obj:EditObject(settings), obj end else -- Did not exist. Create: - local Obj = self:GetObjectByID( ObjID ) - Obj:Initialize(Settings) - Obj.index = Settings.index - table.insert( Ent.RenderTable, Obj ) - return true, Obj + ---@type EGPObject + obj = table.Copy(class) + obj:Initialize(settings) + obj.index = index + table.insert(egp.RenderTable, obj) + return true, obj end end - -function EGP:EditObject(obj, settings) - return obj:EditObject(settings) -end - - +EGP.Create = create -------------------------------------------------------- -- Homescreen -------------------------------------------------------- +--- The EGP homescreen that appears when you first create an EGP +---@type EGPObject[] EGP.HomeScreen = {} local mat @@ -311,8 +421,8 @@ if CLIENT then mat = Material else mat = function( str ) return str end end -- Create table local tbl = { - { ID = EGP.Objects.Names["Box"], Settings = { x = 256, y = 256, h = 356, w = 356, material = mat("expression 2/cog"), r = 150, g = 34, b = 34, a = 255 } }, - { ID = EGP.Objects.Names["Text"], Settings = {x = 256, y = 256, text = "EGP 3", font = "WireGPU_ConsoleFont", valign = 1, halign = 1, size = 50, r = 135, g = 135, b = 135, a = 255 } } + { objects.Box, { x = 256, y = 256, h = 356, w = 356, material = mat("expression 2/cog"), r = 150, g = 34, b = 34, a = 255 } }, + { objects.Text, {x = 256, y = 256, text = "EGP 3", font = "WireGPU_ConsoleFont", valign = 1, halign = 1, size = 50, r = 135, g = 135, b = 135, a = 255 } } } --[[ Old homescreen (EGP v2 home screen design contest winner) @@ -333,11 +443,16 @@ local tbl = { ]] -- Convert table -for k,v in pairs( tbl ) do - local obj = EGP:GetObjectByID( v.ID ) +for k, v in ipairs(tbl) do + local obj = table.Copy(v[1]) obj.index = k - for k2,v2 in pairs( v.Settings ) do + for k2, v2 in pairs(v[2]) do if obj[k2] ~= nil then obj[k2] = v2 end end - table.insert( EGP.HomeScreen, obj ) + table.insert(EGP.HomeScreen, obj) +end + +return function() + validEGP = EGP.ValidEGP + maxObjects = EGP.ConVars.MaxObjects end diff --git a/lua/entities/gmod_wire_egp/lib/init.lua b/lua/entities/gmod_wire_egp/lib/init.lua index 6852e36958..f362140932 100644 --- a/lua/entities/gmod_wire_egp/lib/init.lua +++ b/lua/entities/gmod_wire_egp/lib/init.lua @@ -1,30 +1,40 @@ -EGP = {} - --------------------------------------------------------- --- Include all other files --------------------------------------------------------- - -function EGP:Initialize() - local Folder = "entities/gmod_wire_egp/lib/egplib/" - local entries = file.Find( Folder .. "*.lua", "LUA") - for _, entry in ipairs( entries ) do - if (SERVER) then - AddCSLuaFile( Folder .. entry ) - end - include( Folder .. entry ) - end +E2Lib = E2Lib or { EGP = {} } +--- The EGP library +local EGP = E2Lib.EGP +if not EGP then + EGP = {} + E2Lib.EGP = EGP end -EGP:Initialize() +_G.EGP = EGP -- To be after refactor is done -local EGP = EGP +EGP.ConVars = { + MaxObjects = CreateConVar("wire_egp_max_objects", 300, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Maximum objects on EGP screen"), + MaxPerSec = CreateConVar("wire_egp_max_bytes_per_sec", 10000, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Maximum amount of data to transfer for EGP updates"), -- Keep between 2500-40000 + MaxVertices = CreateConVar("wire_egp_max_poly_vertices", 1024, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Maximum amount of vertices on a polygon"), + AllowEmitter = CreateConVar("wire_egp_allow_emitter", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Should EGP emitters be allowed?"), + AllowHUD = CreateConVar("wire_egp_allow_hud", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Should EGP HUDs be allowed?"), + AllowScreen = CreateConVar("wire_egp_allow_screen", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE }, "Should EGP screens be allowed?"), +} -EGP.ConVars = {} -EGP.ConVars.MaxObjects = CreateConVar( "wire_egp_max_objects", 300, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) -EGP.ConVars.MaxPerSec = CreateConVar( "wire_egp_max_bytes_per_sec", 10000, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) -- Keep between 2500-40000 +-- Include all other files +local postinit = {} +local j = 0 +local FOLDER = "entities/gmod_wire_egp/lib/egplib/" +local entries = file.Find(FOLDER .. "*.lua", "LUA") -EGP.ConVars.MaxVertices = CreateConVar( "wire_egp_max_poly_vertices", 1024, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) +for _, entry in ipairs(entries) do + local p = FOLDER .. entry + if SERVER then + AddCSLuaFile(p) + end + local r = include(p) + if r then + j = table.insert(postinit, r) + end +end -EGP.ConVars.AllowEmitter = CreateConVar( "wire_egp_allow_emitter", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) -EGP.ConVars.AllowHUD = CreateConVar( "wire_egp_allow_hud", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) -EGP.ConVars.AllowScreen = CreateConVar( "wire_egp_allow_screen", 1, { FCVAR_NOTIFY, FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE } ) +-- Run PostInit callbacks +for i = 1, j do + postinit[i]() +end diff --git a/lua/entities/gmod_wire_expression2/core/e2lib.lua b/lua/entities/gmod_wire_expression2/core/e2lib.lua index 4530b57fd3..e267a8cb58 100644 --- a/lua/entities/gmod_wire_expression2/core/e2lib.lua +++ b/lua/entities/gmod_wire_expression2/core/e2lib.lua @@ -31,12 +31,12 @@ AddCSLuaFile() ---@field Functions table ---@field Methods table> -E2Lib = { +E2Lib = table.Merge(E2Lib or {}, { Env = { ---@type EnvEvent[] Events = {} } -} +}) local type = type local function checkargtype(argn, value, argtype) From e212b90be5611bc7ff80d5d2fb003435b5738575 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 01:34:55 -0400 Subject: [PATCH 2/9] Rename objectcontrol.lua to objects.lua --- .../gmod_wire_egp/lib/egplib/{objectcontrol.lua => objects.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lua/entities/gmod_wire_egp/lib/egplib/{objectcontrol.lua => objects.lua} (100%) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua similarity index 100% rename from lua/entities/gmod_wire_egp/lib/egplib/objectcontrol.lua rename to lua/entities/gmod_wire_egp/lib/egplib/objects.lua From e9c446e6b18d15d58ceeee08ff2797b0f3625c99 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 01:35:06 -0400 Subject: [PATCH 3/9] Update API usage --- .../gmod_wire_egp/lib/egplib/parenting.lua | 18 +- .../gmod_wire_egp/lib/egplib/queuesystem.lua | 4 +- .../lib/egplib/transmitreceive.lua | 45 ++-- .../gmod_wire_egp/lib/egplib/umsgsystem.lua | 2 +- .../lib/egplib/usefulfunctions.lua | 10 +- .../gmod_wire_egp/lib/objects/3dtracker.lua | 3 +- .../gmod_wire_egp/lib/objects/box.lua | 5 +- .../gmod_wire_egp/lib/objects/boxoutline.lua | 2 +- .../gmod_wire_egp/lib/objects/line.lua | 2 +- .../gmod_wire_egp/lib/objects/linestrip.lua | 3 +- .../gmod_wire_egp/lib/objects/poly.lua | 2 +- .../lib/objects/roundedboxoutline.lua | 2 +- .../gmod_wire_egp/lib/objects/text.lua | 2 +- .../gmod_wire_egp/lib/objects/textlayout.lua | 2 +- .../gmod_wire_egp/lib/objects/wedge.lua | 2 +- .../lib/objects/wedgeoutline.lua | 2 +- .../core/egpfunctions.lua | 227 ++++++++---------- .../gmod_wire_expression2/core/egpobjects.lua | 65 +++-- 18 files changed, 196 insertions(+), 202 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua b/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua index d2722f3ff7..883d63149a 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua @@ -1,9 +1,11 @@ -------------------------------------------------------- -- Parenting functions -------------------------------------------------------- -local EGP = EGP +local EGP = E2Lib.EGP EGP.ParentingFuncs = {} +local hasObject + local function addUV( v, t ) -- Polygon u v fix if (v.verticesindex) then local t2 = v[v.verticesindex] @@ -97,7 +99,7 @@ local function GetGlobalPos(self, Ent, index) obj = index bool = true else - bool, _, obj = self:HasObject(Ent, index) + bool, _, obj = hasObject(Ent, index) end if bool then if obj.parent and obj.parent ~= 0 then -- Object is parented @@ -111,7 +113,7 @@ local function GetGlobalPos(self, Ent, index) local vec, ang = LocalToWorld(Vector(obj._x, obj._y, 0), Angle(0, obj._angle or 0, 0), Vector(x, y, 0), angle_zero) return obj.verticesindex ~= nil, { x = vec.x, y = vec.y, angle = -ang.y } else - local _, data = GetGlobalPos(Ent, select(3, EGP:HasObject(Ent, obj.parent))) + local _, data = GetGlobalPos(Ent, select(3, hasObject(Ent, obj.parent))) local vec, ang = LocalToWorld(Vector(obj._x, obj._y, 0), Angle(0, -(obj._angle or 0), 0), Vector(data.x, data.y, 0), Angle(0, -(data.angle or 0), 0)) return obj.verticesindex ~= nil, { x = vec.x, y = vec.y, angle = -ang.y } end @@ -205,7 +207,7 @@ end function EGP:SetParent( Ent, index, parentindex ) local bool, v if isnumber(index) then - bool, _, v = self:HasObject(Ent, index) + bool, _, v = hasObject(Ent, index) else bool, v = index ~= nil, index end @@ -214,7 +216,7 @@ function EGP:SetParent( Ent, index, parentindex ) if (self:EditObject( v, { parent = parentindex } )) then return true, v end else if isnumber(parentindex) then - bool = self:HasObject(Ent, parentindex) + bool = hasObject(Ent, parentindex) else bool, parentindex = parentindex ~= nil, parentindex.index end @@ -257,7 +259,7 @@ end function EGP:UnParent( Ent, index ) local bool, v = false if isnumber(index) then - bool, _, v = self:HasObject( Ent, index ) + bool, _, v = hasObject(Ent, index) else bool = istable(index) v = index @@ -274,3 +276,7 @@ function EGP:UnParent( Ent, index ) if v:EditObject(data) then return true, v end end end + +return function() + hasObject = E2Lib.EGP.HasObject +end \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/egplib/queuesystem.lua b/lua/entities/gmod_wire_egp/lib/egplib/queuesystem.lua index 16acff3cc0..05c7552a62 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/queuesystem.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/queuesystem.lua @@ -1,7 +1,7 @@ -------------------------------------------------------- -- EGP Queue System -------------------------------------------------------- -local EGP = EGP +local EGP = E2Lib.EGP EGP.Queue = WireLib.RegisterPlayerTable() @@ -18,7 +18,7 @@ function EGP:AddQueueObject( Ent, ply, Function, Object ) table.remove( LastItem.Args[1], k ) elseif (v.ID ~= Object.ID) then -- Not the same kind of object, create new if (v.OnRemove) then v:OnRemove() end - local Obj = self:GetObjectByID( Object.ID ) + local Obj = table.Copy(EGP.Objects[Object.ID]) Obj:EditObject(Object:DataStreamInfo()) Obj.index = v.index if (Obj.OnCreate) then Obj:OnCreate() end diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 05812e7579..436be5177c 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -1,7 +1,9 @@ -------------------------------------------------------- -- Queue Functions -------------------------------------------------------- -local EGP = EGP +local EGP = E2Lib.EGP + +local hasObject if (SERVER) then util.AddNetworkString( "EGP_Transmit_Data" ) @@ -91,7 +93,7 @@ if (SERVER) then return end - local bool, _, v = EGP:HasObject( Ent, index ) + local bool, _, v = hasObject(Ent, index) if (bool) then if not EGP.umsg.Start("EGP_Transmit_Data", ply) then return end net.WriteEntity( Ent ) @@ -123,7 +125,7 @@ if (SERVER) then return end - local bool, _, v = EGP:HasObject( Ent, index ) + local bool, _, v = hasObject(Ent, index) if (bool) then if not EGP.umsg.Start("EGP_Transmit_Data", ply) then return end net.WriteEntity( Ent ) @@ -154,7 +156,7 @@ if (SERVER) then return end - if EGP:HasObject(Ent, index) then + if hasObject(Ent, index) then if not EGP.umsg.Start("EGP_Transmit_Data", ply) then return end net.WriteEntity( Ent ) net.WriteString( "AddText" ) @@ -175,7 +177,7 @@ if (SERVER) then return end - if EGP:HasObject(Ent, index) then + if hasObject(Ent, index) then if not EGP.umsg.Start("EGP_Transmit_Data", ply) then return end net.WriteEntity( Ent ) net.WriteString( "SetText" ) @@ -239,16 +241,11 @@ if (SERVER) then net.WriteUInt( #DataToSend, 16 ) -- Send estimated number of objects to be sent for k,v in ipairs( DataToSend ) do - -- Check if the object doesn't exist serverside anymore (It may have been removed by a command in the queue before this, like egpClear or egpRemove) - --if not EGP:HasObject( Ent, v.index ) then - -- EGP:CreateObject( Ent, v.ID, v ) - --end - net.WriteInt( v.index, 16 ) -- Send index of object if (v.remove == true) then net.WriteUInt(0, 8) -- Object is to be removed, send a 0 - local bool, k, v = EGP:HasObject( Ent, v.index ) + local bool, k, v = hasObject(Ent, v.index) if (bool) then -- Unparent all objects parented to this object for k2,v2 in pairs( Ent.RenderTable ) do @@ -294,7 +291,7 @@ if (SERVER) then -- Change order now if order_was_changed then - EGP:PerformReorder( Ent ) + EGP.PerformReorder(Ent) end EGP:SendQueueItem( ply ) @@ -409,20 +406,20 @@ else -- SERVER/CLIENT elseif (Action == "SetText") then local index = net.ReadInt(16) local text = net.ReadString() - local bool,_,v = EGP:HasObject( Ent, index ) + local bool,_,v = hasObject(Ent, index) if (bool) then if (EGP:EditObject( v, { text = text } )) then Ent:EGP_Update() end end elseif (Action == "AddText") then local index = net.ReadInt(16) local text = net.ReadString() - local bool,_,v = EGP:HasObject( Ent, index ) + local bool,_,v = hasObject(Ent, index) if (bool) then if (EGP:EditObject( v, { text = v.text .. text } )) then Ent:EGP_Update() end end elseif (Action == "SetVertex") then local index = net.ReadInt(16) - local bool, _, v = EGP:HasObject( Ent, index ) + local bool, _, v = hasObject(Ent, index) if (bool) then local vertices = {} @@ -442,7 +439,7 @@ else -- SERVER/CLIENT end elseif (Action == "AddVertex") then local index = net.ReadInt(16) - local bool, _, v = EGP:HasObject( Ent, index ) + local bool, _, v = hasObject(Ent, index) if (bool) then local vertices = table.Copy(v.vertices) @@ -474,7 +471,7 @@ else -- SERVER/CLIENT local ID = net.ReadUInt(8) if (ID == 0) then -- Remove object - local bool, k, v = EGP:HasObject( Ent, index ) + local bool, k, v = hasObject(Ent, index) if (bool) then if (v.OnRemove) then v:OnRemove() end @@ -497,11 +494,11 @@ else -- SERVER/CLIENT end local current_obj - local bool, k, v = self:HasObject( Ent, index ) + local bool, k, v = hasObject(Ent, index) if (bool) then -- Object already exists if (v.ID ~= ID) then -- Not the same kind of object, create new if (v.OnRemove) then v:OnRemove() end - local Obj = self:GetObjectByID( ID ) + local Obj = table.Copy(EGP.Objects[ID]) local data = Obj:Receive() Obj:Initialize(data) Obj.index = index @@ -522,7 +519,7 @@ else -- SERVER/CLIENT -- For EGP HUD v.res = nil else -- Object does not exist. Create new - local Obj = self:GetObjectByID( ID ) + local Obj = table.Copy(EGP.Objects[ID]) Obj:Initialize(Obj:Receive()) Obj.index = index if (Obj.OnCreate) then Obj:OnCreate() end @@ -542,7 +539,7 @@ else -- SERVER/CLIENT -- Change order now if order_was_changed then - self:PerformReorder( Ent ) + EGP.PerformReorder(Ent) end Ent:EGP_Update() @@ -673,7 +670,7 @@ else Ent.GPU.texture_filtering = decoded.Filtering or TEXFILTER.ANISOTROPIC end for _,v in pairs( Objects ) do - local Obj = self:GetObjectByID(v.ID) + local Obj = table.Copy(EGP.Objects[v.ID]) Obj:Initialize(v.Settings) -- If parented, reset the parent indexes if (Obj.parent and Obj.parent ~= 0) then @@ -693,3 +690,7 @@ else EGP:ReceiveDataStream(net.ReadTable()) end) end + +return function() + hasObject = E2Lib.EGP.HasObject +end \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/egplib/umsgsystem.lua b/lua/entities/gmod_wire_egp/lib/egplib/umsgsystem.lua index 4bb797dda7..7f4b5552f7 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/umsgsystem.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/umsgsystem.lua @@ -1,7 +1,7 @@ -------------------------------------------------------- -- Custom umsg System -------------------------------------------------------- -local EGP = EGP +local EGP = E2Lib.EGP local CurSender = NULL local LastErrorTime = 0 diff --git a/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua b/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua index c5d74c278a..f9be643b57 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua @@ -1,7 +1,9 @@ -------------------------------------------------------- -- e2function Helper functions -------------------------------------------------------- -local EGP = EGP +local EGP = E2Lib.EGP + +local hasObject ---------------------------- -- Table IsEmpty @@ -90,7 +92,7 @@ function EGP.MoveTopLeft(ent, obj) if obj.angle then t.angle = -ang.yaw end end if obj.IsParented then - local bool, _, parent = EGP:HasObject(ent, obj.parent) + local bool, _, parent = hasObject(ent, obj.parent) if bool and parent.CanTopLeft and parent.w and parent.h then if not t then t = { x = obj.x, y = obj.y, angle = obj.angle } end t.x = t.x - parent.w / 2 @@ -514,3 +516,7 @@ function EGP.Draw(ent) EGP:FixMaterial(oldtex) end end + +return function() + hasObject = E2Lib.EGP.HasObject +end diff --git a/lua/entities/gmod_wire_egp/lib/objects/3dtracker.lua b/lua/entities/gmod_wire_egp/lib/objects/3dtracker.lua index 2d6478368a..29b8eb3df9 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/3dtracker.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/3dtracker.lua @@ -1,5 +1,6 @@ -- Author: Divran -local Obj = EGP:NewObject( "3DTracker" ) + +local Obj = E2Lib.EGP.NewObject("3DTracker") Obj.material = nil Obj.filtering = nil Obj.target_x = 0 diff --git a/lua/entities/gmod_wire_egp/lib/objects/box.lua b/lua/entities/gmod_wire_egp/lib/objects/box.lua index d4a7815e3d..ea0ab8d886 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/box.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/box.lua @@ -1,5 +1,6 @@ -- Author: Divran -local Obj = EGP:NewObject( "Box" ) + +local Obj = E2Lib.EGP.NewObject("Box") Obj.CanTopLeft = true Obj.w = 0 Obj.h = 0 @@ -38,7 +39,7 @@ function Obj:Contains(x, y) if self.EGP.TopLeft then x, y = x - w, y - h end return -w <= x and x <= w and - -h <= y and y <= h + -h <= y and y <= h end return Obj \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/objects/boxoutline.lua b/lua/entities/gmod_wire_egp/lib/objects/boxoutline.lua index cee45e7c2b..5257862056 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/boxoutline.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/boxoutline.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP.ObjectInherit("BoxOutline", "Box") +local Obj = E2Lib.EGP.ObjectInherit("BoxOutline", "Box") Obj.size = 1 local base = Obj.BaseClass diff --git a/lua/entities/gmod_wire_egp/lib/objects/line.lua b/lua/entities/gmod_wire_egp/lib/objects/line.lua index c482f7a605..739b92fa1f 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/line.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/line.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP:NewObject( "Line" ) +local Obj = E2Lib.EGP.NewObject("Line") Obj.material = nil Obj.filtering = nil Obj.x2 = 0 diff --git a/lua/entities/gmod_wire_egp/lib/objects/linestrip.lua b/lua/entities/gmod_wire_egp/lib/objects/linestrip.lua index 02102fd448..e9a8dc79b0 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/linestrip.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/linestrip.lua @@ -1,5 +1,6 @@ -- Author: sk8 (& Divran) -local Obj = EGP.ObjectInherit("LineStrip", "PolyOutline") + +local Obj = E2Lib.EGP.ObjectInherit("LineStrip", "PolyOutline") Obj.Draw = function( self ) local n = #self.vertices diff --git a/lua/entities/gmod_wire_egp/lib/objects/poly.lua b/lua/entities/gmod_wire_egp/lib/objects/poly.lua index 0c0353f50e..241fd7a12a 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/poly.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/poly.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP:NewObject("Poly") +local Obj = E2Lib.EGP.NewObject("Poly") Obj.vertices = {} Obj.verticesindex = "vertices" Obj.HasUV = true diff --git a/lua/entities/gmod_wire_egp/lib/objects/roundedboxoutline.lua b/lua/entities/gmod_wire_egp/lib/objects/roundedboxoutline.lua index 0b7e7ca42e..9900c0b87a 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/roundedboxoutline.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/roundedboxoutline.lua @@ -1,5 +1,5 @@ -- Author: sk8 (& Divran) -local Obj = EGP.ObjectInherit("RoundedBoxOutline", "RoundedBox") +local Obj = E2Lib.EGP.ObjectInherit("RoundedBoxOutline", "RoundedBox") Obj.size = 1 Obj.filtering = nil diff --git a/lua/entities/gmod_wire_egp/lib/objects/text.lua b/lua/entities/gmod_wire_egp/lib/objects/text.lua index 155a26131f..730705870e 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/text.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/text.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP:NewObject( "Text" ) +local Obj = E2Lib.EGP.NewObject("Text") Obj.material = nil Obj.text = "" Obj.font = "WireGPU_ConsoleFont" diff --git a/lua/entities/gmod_wire_egp/lib/objects/textlayout.lua b/lua/entities/gmod_wire_egp/lib/objects/textlayout.lua index e0216a5edd..c0c7b44762 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/textlayout.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/textlayout.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP.ObjectInherit("TextLayout", "Text") +local Obj = E2Lib.EGP.ObjectInherit("TextLayout", "Text") Obj.h = 512 Obj.w = 512 Obj.CanTopLeft = true diff --git a/lua/entities/gmod_wire_egp/lib/objects/wedge.lua b/lua/entities/gmod_wire_egp/lib/objects/wedge.lua index 8728737343..9bb3ecea57 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/wedge.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/wedge.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP.ObjectInherit("Wedge", "Circle") +local Obj = E2Lib.EGP.ObjectInherit("Wedge", "Circle") Obj.size = 45 local rad, cos, sin = math.rad, math.cos, math.sin diff --git a/lua/entities/gmod_wire_egp/lib/objects/wedgeoutline.lua b/lua/entities/gmod_wire_egp/lib/objects/wedgeoutline.lua index f1f45172db..c806e6f629 100644 --- a/lua/entities/gmod_wire_egp/lib/objects/wedgeoutline.lua +++ b/lua/entities/gmod_wire_egp/lib/objects/wedgeoutline.lua @@ -1,5 +1,5 @@ -- Author: Divran -local Obj = EGP.ObjectInherit("WedgeOutline", "Wedge") +local Obj = E2Lib.EGP.ObjectInherit("WedgeOutline", "Wedge") local rad, cos, sin = math.rad, math.cos, math.sin Obj.Draw = function( self ) diff --git a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua index 951c9830d5..ba3bd165c0 100644 --- a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua +++ b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua @@ -1,5 +1,8 @@ - -local NULL_EGPOBJECT = EGP.NULL_EGPOBJECT +local EGP = E2Lib.EGP +local NULL_EGPOBJECT = EGP.Objects.NULL_EGPOBJECT +local hasObject = EGP.HasObject +local isAllowed = EGP.IsAllowed +local egp_create = EGP.Create local function Update(self,this) self.data.EGP.UpdatesNeeded[this] = true @@ -70,51 +73,46 @@ end -- Order -------------------------------------------------------- -e2function void wirelink:egpOrder( number index, number order ) - if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) - if (bool) then - local bool2 = EGP:SetOrder( this, k, order ) - if (bool2) then - EGP:DoAction( this, self, "SendObject", v ) +e2function void wirelink:egpOrder(number index, number order) + if not isAllowed(nil, self, this) then return end + local bool, k, v = hasObject(this, index) + if bool then + if EGP.SetOrder(this, k, order) then + EGP:DoAction(this, self, "SendObject", v) Update(self,this) end end end e2function number wirelink:egpOrder( number index ) - if (!EGP:IsAllowed( self, this )) then return -1 end - local bool, k, v = EGP:HasObject( this, index ) - if (bool) then + if not isAllowed(nil, self, this) then return -1 end + local bool, k = hasObject(this, index) + if bool then return k end return -1 end -e2function void wirelink:egpOrderAbove( number index, number abovethis ) - if not EGP:IsAllowed( self, this ) then return end - local bool, k, v = EGP:HasObject( this, index ) +e2function void wirelink:egpOrderAbove(number index, number abovethis) + if not isAllowed(nil, self, this) then return end + local bool, k, v = hasObject(this, index) if bool then - local bool2, k2, v2 = EGP:HasObject( this, abovethis ) - if bool2 then - local bool3 = EGP:SetOrder( this, k, abovethis, 1 ) - if bool3 then - EGP:DoAction( this, self, "SendObject", v ) - Update(self,this) + if hasObject(this, abovethis) then + if EGP.SetOrder(this, k, abovethis, 1) then + EGP:DoAction(this, self, "SendObject", v) + Update(self, this) end end end end e2function void wirelink:egpOrderBelow( number index, number belowthis ) - if not EGP:IsAllowed( self, this ) then return end - local bool, k, v = EGP:HasObject( this, index ) + if not isAllowed(nil, self, this) then return end + local bool, k, v = hasObject(this, index) if bool then - local bool2, k2, v2 = EGP:HasObject( this, belowthis ) - if bool2 then - local bool3 = EGP:SetOrder( this, k, belowthis, -1 ) - if bool3 then - EGP:DoAction( this, self, "SendObject", v ) + if hasObject(this, belowthis) then + if EGP.SetOrder(this, k, belowthis, -1) then + EGP:DoAction(this, self, "SendObject", v) Update(self,this) end end @@ -128,7 +126,7 @@ __e2setcost(15) -------------------------------------------------------- e2function egpobject wirelink:egpBox( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Box"], { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, self.player ) + local bool, obj = egp_create("Box", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -138,7 +136,7 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpBoxOutline( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["BoxOutline"], { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, self.player ) + local bool, obj = egp_create("BoxOutline", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -148,16 +146,16 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpRoundedBox( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["RoundedBox"], { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, self.player ) + local bool, obj = egp_create("RoundedBox", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end e2function void wirelink:egpRadius( number index, number radius ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { radius = radius } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ radius = radius }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -166,7 +164,7 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpRoundedBoxOutline( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["RoundedBoxOutline"], { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, self.player ) + local bool, obj = egp_create("RoundedBoxOutline", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -176,14 +174,14 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpText( number index, string text, vector2 pos ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Text"], { index = index, text = text, x = pos[1], y = pos[2] }, self.player ) + local bool, obj = egp_create("Text", { index = index, text = text, x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end e2function egpobject wirelink:egpTextLayout( number index, string text, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["TextLayout"], { index = index, text = text, x = pos[1], y = pos[2], w = size[1], h = size[2] }, self.player ) + local bool, obj = egp_create("TextLayout", { index = index, text = text, x = pos[1], y = pos[2], w = size[1], h = size[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -195,9 +193,9 @@ __e2setcost(10) ---------------------------- e2function void wirelink:egpSetText( number index, string text ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { text = text } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ text = text }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -206,17 +204,17 @@ end ---------------------------- e2function void wirelink:egpAlign( number index, number halign ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { halign = math.Clamp(halign,0,2) } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ halign = math.Clamp(halign,0,2) }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpAlign( number index, number halign, number valign ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { valign = math.Clamp(valign,0,2), halign = math.Clamp(halign,0,2) } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ valign = math.Clamp(valign,0,2), halign = math.Clamp(halign,0,2) }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -225,9 +223,9 @@ end ---------------------------- e2function void wirelink:egpFiltering( number index, number filtering ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { filtering = math.Clamp(filtering,0,3) } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ filtering = math.Clamp(filtering,0,3) }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -254,18 +252,18 @@ end e2function void wirelink:egpFont( number index, string font ) if (!EGP:IsAllowed( self, this )) then return end if #font > 30 then return self:throw("Font string is too long!", nil) end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { font = font } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ font = font }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpFont( number index, string font, number size ) if (!EGP:IsAllowed( self, this )) then return end if #font > 30 then return self:throw("Font string is too long!", nil) end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { font = font, size = size } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ font = font, size = size }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -298,7 +296,7 @@ e2function egpobject wirelink:egpPoly( number index, ...args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Poly"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("Poly", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -324,7 +322,7 @@ e2function egpobject wirelink:egpPoly( number index, array args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Poly"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("Poly", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -354,7 +352,7 @@ e2function egpobject wirelink:egpPolyOutline( number index, ...args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["PolyOutline"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("PolyOutline", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -380,7 +378,7 @@ e2function egpobject wirelink:egpPolyOutline( number index, array args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["PolyOutline"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("PolyOutline", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -390,7 +388,7 @@ e2function void wirelink:egpAddVertices( number index, array args ) if (!EGP:ValidEGP( this )) then return self:throw("Invalid wirelink!", nil) end if (#args<3) then return end -- No less than 3 - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then local max = maxvertices() @@ -441,7 +439,7 @@ e2function egpobject wirelink:egpLineStrip( number index, ...args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["LineStrip"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("LineStrip", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -467,7 +465,7 @@ e2function egpobject wirelink:egpLineStrip( number index, array args ) end end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["LineStrip"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("LineStrip", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -479,7 +477,7 @@ __e2setcost(15) -------------------------------------------------------- e2function egpobject wirelink:egpLine( number index, vector2 pos1, vector2 pos2 ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Line"], { index = index, x = pos1[1], y = pos1[2], x2 = pos2[1], y2 = pos2[2] }, self.player ) + local bool, obj = egp_create("Line", { index = index, x = pos1[1], y = pos1[2], x2 = pos2[1], y2 = pos2[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -489,7 +487,7 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpCircle( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Circle"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, self.player ) + local bool, obj = egp_create("Circle", { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -499,7 +497,7 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpCircleOutline( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["CircleOutline"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, self.player ) + local bool, obj = egp_create("CircleOutline", { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -510,7 +508,7 @@ end e2function egpobject wirelink:egpTriangle( number index, vector2 v1, vector2 v2, vector2 v3 ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end local vertices = { { x = v1[1], y = v1[2] }, { x = v2[1], y = v2[2] }, { x = v3[1], y = v3[2] } } - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Poly"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("Poly", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -521,7 +519,7 @@ end e2function egpobject wirelink:egpTriangleOutline( number index, vector2 v1, vector2 v2, vector2 v3 ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end local vertices = { { x = v1[1], y = v1[2] }, { x = v2[1], y = v2[2] }, { x = v3[1], y = v3[2] } } - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["PolyOutline"], { index = index, vertices = vertices }, self.player ) + local bool, obj = egp_create("PolyOutline", { index = index, vertices = vertices }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -531,43 +529,28 @@ end -------------------------------------------------------- e2function egpobject wirelink:egpWedge( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Wedge"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, self.player ) + local bool, obj = egp_create("Wedge", { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end ---[[ I'm sticking to my policy of not spamming pointless functions. -e2function void wirelink:egpWedge( number index, vector2 pos, vector2 size, number angle, number mouthsize ) - if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["Wedge"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2], size = mouthsize, angle = angle }, self.player ) - if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end -end -]] - -------------------------------------------------------- -- Wedge Outline -------------------------------------------------------- e2function egpobject wirelink:egpWedgeOutline( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["WedgeOutline"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, self.player ) + local bool, obj = egp_create("WedgeOutline", { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end ---[[ I'm sticking to my policy of not spamming pointless functions. -e2function void wirelink:egpWedgeOutline( number index, vector2 pos, vector2 size, number angle, number mouthsize ) - if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["WedgeOutline"], { index = index, x = pos[1], y = pos[2], w = size[1], h = size[2], size = mouthsize, angle = angle }, self.player ) - if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end -end -]] -------------------------------------------------------- -- 3DTracker -------------------------------------------------------- e2function egpobject wirelink:egp3DTracker( number index, vector pos ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["3DTracker"], { index = index, target_x = pos[1], target_y = pos[2], target_z = pos[3], directionality = 0 }, self.player ) + local bool, obj = egp_create("3DTracker", { index = index, target_x = pos[1], target_y = pos[2], target_z = pos[3], directionality = 0 }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -581,7 +564,7 @@ e2function egpobject wirelink:egp3DTracker( number index, vector pos, number dir directionality = -1 end - local bool, obj = EGP:CreateObject( this, EGP.Objects.Names["3DTracker"], { index = index, target_x = pos[1], target_y = pos[2], target_z = pos[3], directionality = directionality }, self.player ) + local bool, obj = egp_create("3DTracker", { index = index, target_x = pos[1], target_y = pos[2], target_z = pos[3], directionality = directionality }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -590,7 +573,7 @@ __e2setcost(10) e2function void wirelink:egpPos( number index, vector pos ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v:EditObject({ target_x = pos[1], target_y = pos[2], target_z = pos[3] })) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end @@ -607,7 +590,7 @@ __e2setcost(10) ---------------------------- e2function void wirelink:egpSize( number index, vector2 size ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if v:EditObject({ w = size[1], h = size[2] }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end @@ -615,9 +598,9 @@ end e2function void wirelink:egpSize( number index, number size ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { size = size } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ size = size }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -626,7 +609,7 @@ end ---------------------------- e2function void wirelink:egpPos( number index, vector2 pos ) if (!EGP:IsAllowed( self, this )) then return end - local bool, _, v = EGP:HasObject(this, index) + local bool, _, v = hasObject(this, index) if bool and v:SetPos(pos[1], pos[2]) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end @@ -636,7 +619,7 @@ end e2function void wirelink:egpAngle( number index, number angle ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if v:SetPos(nil, nil, angle) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end @@ -648,7 +631,7 @@ end e2function void wirelink:egpAngle( number index, vector2 worldpos, vector2 axispos, number angle ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.x and v.y) then @@ -672,33 +655,33 @@ end ---------------------------- e2function void wirelink:egpColor( number index, vector4 color ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { r = color[1], g = color[2], b = color[3], a = color[4] } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ r = color[1], g = color[2], b = color[3], a = color[4] }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpColor( number index, vector color ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { r = color[1], g = color[2], b = color[3] } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ r = color[1], g = color[2], b = color[3] }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpColor( number index, r,g,b,a ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, _, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { r = r, g = g, b = b, a = a } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ r = r, g = g, b = b, a = a }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpAlpha( number index, number a ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { a = a } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ a = a }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -709,17 +692,17 @@ end e2function void wirelink:egpMaterial( number index, string material ) if (!EGP:IsAllowed( self, this )) then return end material = WireLib.IsValidMaterial(material) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { material = material } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ material = material }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function void wirelink:egpMaterialFromScreen( number index, entity gpu ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool and gpu and gpu:IsValid()) then - if (EGP:EditObject( v, { material = gpu } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ material = gpu }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end @@ -728,15 +711,15 @@ end ---------------------------- e2function void wirelink:egpFidelity( number index, number fidelity ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then - if (EGP:EditObject( v, { fidelity = math.Clamp(fidelity,3,180) } )) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end + if v:EditObject({ fidelity = math.Clamp(fidelity,3,180) }) then EGP:DoAction( this, self, "SendObject", v ) Update(self,this) end end end e2function number wirelink:egpFidelity( number index ) if (!EGP:IsAllowed( self, this )) then return -1 end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.fidelity) then return v.fidelity @@ -759,7 +742,7 @@ e2function void wirelink:egpParent( number index, entity parent ) if not parent or not parent:IsValid() then return end if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if bool and v.NeedsConstantUpdate then if v.parententity == parent then return end -- Already parented to that v.parententity = parent @@ -771,7 +754,7 @@ end -- Returns the entity a tracker is parented to e2function entity wirelink:egpTrackerParent( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if bool and v.NeedsConstantUpdate then return (v.parententity and v.parententity:IsValid()) and v.parententity or nil end @@ -790,7 +773,7 @@ e2function void wirelink:egpUnParent( number index ) end e2function number wirelink:egpParent( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.parent) then return v.parent @@ -812,7 +795,7 @@ end e2function void wirelink:egpRemove( number index ) if (!EGP:IsAllowed( self, this )) then return end - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then EGP:DoAction( this, self, "RemoveObject", index ) Update(self,this) @@ -826,7 +809,7 @@ end __e2setcost(5) e2function vector2 wirelink:egpPos( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.x and v.y) then return {v.x, v.y} @@ -842,7 +825,7 @@ e2function vector wirelink:egpGlobalPos( number index ) end e2function array wirelink:egpGlobalVertices( number index ) - local hasobject, _, object = EGP:HasObject(this, index) + local hasobject, _, object = hasObject(this, index) if hasobject and object.verticesindex then local data = EGP:GetGlobalVertices(object) if data.vertices then @@ -865,7 +848,7 @@ end __e2setcost(5) e2function vector2 wirelink:egpSize( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.w and v.h) then return {v.w, v.h} @@ -875,7 +858,7 @@ e2function vector2 wirelink:egpSize( number index ) end e2function number wirelink:egpSizeNum( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.size) then return v.size @@ -885,7 +868,7 @@ e2function number wirelink:egpSizeNum( number index ) end e2function vector4 wirelink:egpColor4( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.r and v.g and v.b and v.a) then return {v.r,v.g,v.b,v.a} @@ -895,7 +878,7 @@ e2function vector4 wirelink:egpColor4( number index ) end e2function vector wirelink:egpColor( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.r and v.g and v.b) then return Vector(v.r, v.g, v.b) @@ -905,7 +888,7 @@ e2function vector wirelink:egpColor( number index ) end e2function number wirelink:egpAlpha( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.a) then return v.a @@ -915,7 +898,7 @@ e2function number wirelink:egpAlpha( number index ) end e2function number wirelink:egpAngle( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.angle) then return v.angle @@ -925,12 +908,12 @@ e2function number wirelink:egpAngle( number index ) end e2function string wirelink:egpMaterial( number index ) - local bool, _, v = EGP:HasObject( this, index ) + local bool, _, v = hasObject(this, index) return bool and v.material and tostring(v.material) or "" end e2function number wirelink:egpRadius( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.radius) then return v.radius @@ -942,7 +925,7 @@ end __e2setcost(10) e2function array wirelink:egpVertices( number index ) - local bool, k, v = EGP:HasObject( this, index ) + local bool, k, v = hasObject(this, index) if (bool) then if (v.vertices) then local ret = {} @@ -993,9 +976,9 @@ end __e2setcost(10) e2function string wirelink:egpObjectType(number index) - local bool, _, v = EGP:HasObject(this, index) + local bool, _, v = hasObject(this, index) if bool then - return EGP.Objects.Names_Inverted[v.ID] or "" + return EGP.Objects[v.ID].Name or "" end return "" end @@ -1008,11 +991,11 @@ __e2setcost(15) e2function egpobject wirelink:egpCopy( index, fromindex ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end - local bool, k, v = EGP:HasObject( this, fromindex ) + local bool, k, v = hasObject(this, fromindex) if (bool) then local copy = table.Copy( v ) copy.index = index - local bool2, obj = EGP:CreateObject( this, v.ID, copy, self.player ) + local bool2, obj = egp_create(v.ID, copy, this) if (bool2) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end return obj end @@ -1045,7 +1028,7 @@ end __e2setcost(15) e2function number wirelink:egpHasObject( index ) - local bool, _, _ = EGP:HasObject( this, index ) + local bool, _, _ = hasObject(this, index) return bool and 1 or 0 end @@ -1053,7 +1036,7 @@ __e2setcost(20) --- Returns 1 if the object with specified index contains the specified point. e2function number wirelink:egpObjectContainsPoint(number index, vector2 point) - local _, _, object = EGP:HasObject(this, index) + local _, _, object = hasObject(this, index) return object and object:Contains(point[1], point[2]) and 1 or 0 end diff --git a/lua/entities/gmod_wire_expression2/core/egpobjects.lua b/lua/entities/gmod_wire_expression2/core/egpobjects.lua index d8df483a1b..70b70146a0 100644 --- a/lua/entities/gmod_wire_expression2/core/egpobjects.lua +++ b/lua/entities/gmod_wire_expression2/core/egpobjects.lua @@ -2,10 +2,12 @@ -- File for EGP Object handling in E2. -- --- Dumb but simple -local NULL_EGPOBJECT = EGP.NULL_EGPOBJECT -local M_NULL_EGPOBJECT = getmetatable(NULL_EGPOBJECT) -local M_EGPObject = getmetatable(EGP.Objects.Base) +local EGP = E2Lib.EGP + +local NULL_EGPOBJECT = EGP.Objects.NULL_EGPOBJECT +local isValid = EGP.EGPObject.IsValid +local hasObject = EGP.HasObject +local egp_create = EGP.Create -- Table of allowed arguments and their types local EGP_ALLOWED_ARGS = @@ -36,10 +38,6 @@ local function Update(self, this) self.data.EGP.UpdatesNeeded[this] = true end -local function isValid(this) - if this and getmetatable(this) ~= M_NULL_EGPOBJECT then return true else return false end -end - ---- Type defintion registerType("egpobject", "xeo", NULL_EGPOBJECT, @@ -47,7 +45,7 @@ registerType("egpobject", "xeo", NULL_EGPOBJECT, nil, nil, function(v) - return not istable(v) or getmetatable(v) ~= M_EGPObject + return not isValid(v) end ) @@ -64,7 +62,7 @@ registerOperator("ass", "xeo", "xeo", function(self, args) end) e2function number operator_is(egpobject egpo) - return (getmetatable(egpo) == M_EGPObject) and 1 or 0 + return isValid(egpo) and 1 or 0 end e2function number operator==(egpobject lhs, egpobject rhs) @@ -100,7 +98,7 @@ __e2setcost(15) e2function void egpobject:setOrder(order) local egp = this.EGP if not EGP:IsAllowed(self, egp) then return end - local bool, k = EGP:HasObject(egp, this.index) + local bool, k = hasObject(egp, this.index) if (bool) then if EGP:SetOrder(egp, k, order) then EGP:DoAction(egp, self, "SendObject", this) @@ -112,18 +110,18 @@ end e2function number egpobject:getOrder() local egp = this.EGP if not EGP:IsAllowed(self, egp) then return -1 end - local bool, k = EGP:HasObject(egp, this.index) + local bool, k = hasObject(egp, this.index) return bool and k or -1 end e2function void egpobject:setOrderAbove(egpobject abovethis) local egp = this.EGP - if not EGP:IsAllowed(self, egp) then return end + if not isAllowed(nil, self, egp) then return end if not (isValid(this) or isValid(abovethis)) then self:throw("Invalid EGP Object") end - local bool, k = EGP:HasObject(egp, this.index) + local bool, k = hasObject(egp, this.index) if bool then - if EGP:HasObject(egp, abovethis.index) then - if EGP:SetOrder(egp, k, abovethis.index, 1) then + if hasObject(egp, abovethis.index) then + if EGP.SetOrder(egp, k, abovethis.index, 1) then EGP:DoAction(egp, self, "SendObject", this) Update(self, egp) end @@ -133,12 +131,12 @@ end e2function void egpobject:setOrderBelow(egpobject belowthis) local egp = this.EGP - if not EGP:IsAllowed(self, egp) then return end + if not isAllowed(self, egp) then return end if not (isValid(this) or isValid(belowthis)) then self:throw("Invalid EGP Object") end - local bool, k = EGP:HasObject(egp, this.index) + local bool, k = hasObject(egp, this.index) if bool then - if EGP:HasObject(egp, belowthis.index) then - if EGP:SetOrder(egp, k, belowthis.index, -1) then + if hasObject(egp, belowthis.index) then + if EGP.SetOrder(egp, k, belowthis.index, -1) then EGP:DoAction(egp, self, "SendObject", this) Update(self, egp) end @@ -512,7 +510,7 @@ end [nodiscard] e2function egpobject egpobject:parent() if not isValid(this) then return self:throw("Invalid EGP Object", NULL_EGPOBJECT) end - local _, _, v = EGP:HasObject(this.EGP, this.parent) + local _, _, v = hasObject(this.EGP, this.parent) return v or NULL_EGPOBJECT end @@ -525,7 +523,6 @@ e2function void wirelink:egpRemove(egpobject obj) if isValid(obj) then EGP:DoAction(this, self, "RemoveObject", obj.index) table.Empty(obj) - setmetatable(obj, M_NULL_EGPOBJECT) Update(self, this) end end @@ -534,10 +531,9 @@ e2function void egpobject:remove() if not isValid(this) then return end local egp = this.EGP if not EGP:IsAllowed(self, egp) then return end - + EGP:DoAction(egp, self, "RemoveObject", this.index) - table.Empty(this) - setmetatable(this, M_NULL_EGPOBJECT) -- In an ideal scenario we would probably want this = NULL_EGPOBJECT instead + table.Empty(this) -- In an ideal scenario we would probably want this = NULL_EGPOBJECT instead Update(self, egp) end @@ -552,7 +548,7 @@ e2function void egpobject:draw() args[k] = v end - if EGP:CreateObject(egp, this.ID, args) then + if egp_create(egp, this.ID, args) then EGP:DoAction(egp, self, "SendObject", this) Update(self, egp) end @@ -719,7 +715,7 @@ e2function egpobject wirelink:egpCopy(number index, egpobject from) if from then local copy = table.Copy(from) copy.index = index - local bool, obj = EGP:CreateObject(this, from.ID, copy, self.player) + local bool, obj = egp_create(from.ID, copy, this) if bool then EGP:DoAction(this, self, "SendObject", obj) Update(self, this) return obj end end end @@ -731,7 +727,7 @@ e2function void egpobject:copyFrom(egpobject from) local copy = table.Copy(from) copy.index = this.index copy.EGP = this.EGP - local bool, obj = EGP:CreateObject(copy.EGP, from.ID, copy, self.player) + local bool, obj = egp_create(from.ID, copy, copy.EGP) if bool then EGP:DoAction(this, self, "SendObject", obj) Update(self, this) return end end end @@ -747,9 +743,9 @@ __e2setcost(5) [nodiscard] e2function egpobject wirelink:egpobject(number index) - if not EGP:IsAllowed(self, this) then return NULL_EGPOBJECT end + if not isAllowed(nil, self, this) then return NULL_EGPOBJECT end if not EGP:ValidEGP(this) then return self:throw("Invalid wirelink!", NULL_EGPOBJECT) end - local _, _, obj = EGP:HasObject(this, index) + local _, _, obj = hasObject(this, index) return obj or NULL_EGPOBJECT end @@ -822,9 +818,8 @@ registerCallback("postinit", function() end) end - local egpCreate = EGP.CreateObject - local workingSet = table.Copy(EGP.Objects.Names) - for name, id in pairs(workingSet) do + for _, v in ipairs(EGP.Objects) do + local name = v.Name -- Indexed table "constructor" registerFunction("egp" .. name, "xwl:nt", "xeo", function(self, args) local this, index, args = args[1], args[2], args[3] @@ -838,7 +833,7 @@ registerCallback("postinit", function() converted.index = index - local bool, obj = egpCreate(EGP, this, id, converted) + local bool, obj = egp_create(name, converted, this) if bool then EGP:DoAction(this, self, "SendObject", obj) Update(self, this) @@ -859,7 +854,7 @@ registerCallback("postinit", function() converted.index = EGP.GetNextIndex(this) - local bool, obj = egpCreate(this, id, converted) + local bool, obj = egp_create(name, converted, this) if bool then EGP:DoAction(this, self, "SendObject", obj) Update(self, this) From a14132e5e5b210ec7a27be3d4e523c9d60e69674 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 02:39:41 -0400 Subject: [PATCH 4/9] Somehow removed this by accident --- lua/entities/gmod_wire_egp/lib/egplib/objects.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua index abb41480df..8e06e5e268 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua @@ -108,6 +108,11 @@ function baseObj:SetPos(x, y, angle) angle = angle % 360 if self.angle ~= angle then self.angle, ret = angle, true end end + if SERVER and self._x then + if x then self._x = x end + if y then self._y = y end + if angle then self._angle = angle end + end return ret end From 40d2b4e8291ced907fdc4f854bb091ee62d40fab Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 02:47:17 -0400 Subject: [PATCH 5/9] Fix improper function call --- lua/entities/gmod_wire_expression2/core/egpobjects.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/egpobjects.lua b/lua/entities/gmod_wire_expression2/core/egpobjects.lua index 70b70146a0..2ddddef88e 100644 --- a/lua/entities/gmod_wire_expression2/core/egpobjects.lua +++ b/lua/entities/gmod_wire_expression2/core/egpobjects.lua @@ -548,7 +548,7 @@ e2function void egpobject:draw() args[k] = v end - if egp_create(egp, this.ID, args) then + if egp_create(this.ID, args, egp) then EGP:DoAction(egp, self, "SendObject", this) Update(self, egp) end From 0a85914167a2942010aec8564cea884036097069 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 02:49:02 -0400 Subject: [PATCH 6/9] Add missing `isAllowed` local --- lua/entities/gmod_wire_expression2/core/egpobjects.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/entities/gmod_wire_expression2/core/egpobjects.lua b/lua/entities/gmod_wire_expression2/core/egpobjects.lua index 2ddddef88e..ded87d6587 100644 --- a/lua/entities/gmod_wire_expression2/core/egpobjects.lua +++ b/lua/entities/gmod_wire_expression2/core/egpobjects.lua @@ -8,6 +8,7 @@ local NULL_EGPOBJECT = EGP.Objects.NULL_EGPOBJECT local isValid = EGP.EGPObject.IsValid local hasObject = EGP.HasObject local egp_create = EGP.Create +local isAllowed = EGP.IsAllowed -- Table of allowed arguments and their types local EGP_ALLOWED_ARGS = From fc93ce5352628865f2f6e6d6a34cba990a3e57c7 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 03:01:20 -0400 Subject: [PATCH 7/9] Possibly insufficient check if error is legitimate --- lua/entities/gmod_wire_egp/lib/egplib/objects.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua index 8e06e5e268..50d3135150 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua @@ -219,8 +219,10 @@ do if ok then AddCSLuaFile(p) return - else + elseif istable(super) then return super[1] + else + ErrorNoHalt(super .. "\n") -- Rethrow the error end end local ret = wrap() From ea1d5c5869caca390c0567f312299e96d00ea009 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 04:28:28 -0400 Subject: [PATCH 8/9] Add nil checks --- lua/entities/gmod_wire_egp/lib/egplib/objects.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua index 50d3135150..1ffb6141d0 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua @@ -139,10 +139,10 @@ function EGPObject:__tostring() return "[EGPObject] ".. (self.Name or "NULL") end function EGPObject:__eq(a, b) - return a.ID == b.ID + return a and b and a.ID == b.ID end function EGPObject:IsValid() - return self.ID ~= nil + return self and self.ID ~= nil end -- The EGPObject metatable From 756e4b25c171375d4c77f2005f9bd33efb67243d Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:03:15 -0400 Subject: [PATCH 9/9] Change EGP postinit handling --- .../gmod_wire_egp/lib/egplib/objects.lua | 11 +++++----- .../gmod_wire_egp/lib/egplib/parenting.lua | 7 +++---- .../lib/egplib/transmitreceive.lua | 7 +++---- .../lib/egplib/usefulfunctions.lua | 7 +++---- lua/entities/gmod_wire_egp/lib/init.lua | 21 ++++++++++++------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua index 1ffb6141d0..5e36965e8f 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/objects.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/objects.lua @@ -6,6 +6,10 @@ EGP.Objects = objects local validEGP local maxObjects +EGP.HookPostInit(function() + validEGP = EGP.ValidEGP + maxObjects = EGP.ConVars.MaxObjects +end) ---@class EGPObject ---@field ID integer? nil when NULL @@ -457,9 +461,4 @@ for k, v in ipairs(tbl) do if obj[k2] ~= nil then obj[k2] = v2 end end table.insert(EGP.HomeScreen, obj) -end - -return function() - validEGP = EGP.ValidEGP - maxObjects = EGP.ConVars.MaxObjects -end +end \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua b/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua index 883d63149a..20a400331d 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/parenting.lua @@ -5,6 +5,9 @@ local EGP = E2Lib.EGP EGP.ParentingFuncs = {} local hasObject +EGP.HookPostInit(function() + hasObject = EGP.HasObject +end) local function addUV( v, t ) -- Polygon u v fix if (v.verticesindex) then @@ -275,8 +278,4 @@ function EGP:UnParent( Ent, index ) if v:EditObject(data) then return true, v end end -end - -return function() - hasObject = E2Lib.EGP.HasObject end \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 436be5177c..ecc71f8b6d 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -4,6 +4,9 @@ local EGP = E2Lib.EGP local hasObject +EGP.HookPostInit(function() + hasObject = EGP.HasObject +end) if (SERVER) then util.AddNetworkString( "EGP_Transmit_Data" ) @@ -689,8 +692,4 @@ else net.Receive("EGP_Request_Transmit", function(len,ply) EGP:ReceiveDataStream(net.ReadTable()) end) -end - -return function() - hasObject = E2Lib.EGP.HasObject end \ No newline at end of file diff --git a/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua b/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua index f9be643b57..54d7965ecd 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua @@ -4,6 +4,9 @@ local EGP = E2Lib.EGP local hasObject +EGP.HookPostInit(function() + hasObject = EGP.HasObject +end) ---------------------------- -- Table IsEmpty @@ -516,7 +519,3 @@ function EGP.Draw(ent) EGP:FixMaterial(oldtex) end end - -return function() - hasObject = E2Lib.EGP.HasObject -end diff --git a/lua/entities/gmod_wire_egp/lib/init.lua b/lua/entities/gmod_wire_egp/lib/init.lua index f362140932..07e5e1b4f7 100644 --- a/lua/entities/gmod_wire_egp/lib/init.lua +++ b/lua/entities/gmod_wire_egp/lib/init.lua @@ -19,7 +19,16 @@ EGP.ConVars = { -- Include all other files local postinit = {} -local j = 0 +--- Calls argument after EGP library finishes initializing. If initialization already finished, calls callback immediately. +---@param callback function +function EGP.HookPostInit(callback) + if postinit then + table.insert(postinit, callback) + else + callback() + end +end + local FOLDER = "entities/gmod_wire_egp/lib/egplib/" local entries = file.Find(FOLDER .. "*.lua", "LUA") @@ -28,13 +37,11 @@ for _, entry in ipairs(entries) do if SERVER then AddCSLuaFile(p) end - local r = include(p) - if r then - j = table.insert(postinit, r) - end + include(p) end -- Run PostInit callbacks -for i = 1, j do - postinit[i]() +for _, v in ipairs(postinit) do + v() end +postinit = nil