Skip to content

Commit

Permalink
Utilize library functions for type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdvideo1234 committed May 17, 2024
1 parent 95681ac commit 7e1e502
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 176 deletions.
14 changes: 8 additions & 6 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local pcall = pcall
local Time = CurTime
local IsValid = IsValid
local tobool = tobool
local istable = istable
local isfunction = isfunction
local tonumber = tonumber
local tostring = tostring
local SetClipboardText = SetClipboardText
Expand Down Expand Up @@ -84,7 +86,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.768")
asmlib.SetOpVar("TOOL_VERSION","8.769")

------------ CONFIGURE GLOBAL INIT OPVARS ------------

Expand Down Expand Up @@ -906,7 +908,7 @@ if(CLIENT) then
local tInfo = pnSheet:AddSheet(defTab.Nick, pnTable, asmlib.ToIcon(defTab.Name))
tInfo.Tab:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".pn_externdb").." "..defTab.Nick)
local tFile = fileFind(fDSV:format("*", defTab.Nick), "DATA")
if(asmlib.IsTable(tFile) and tFile[1]) then
if(istable(tFile) and tFile[1]) then
local nF, nW, nH = #tFile, pnFrame:GetSize()
xySiz.x, xyPos.x, xyPos.y = (nW - 6 * xyDsz.x), xyDsz.x, xyDsz.y
xySiz.y = (((nH - 6 * xyDsz.y) - ((nF -1) * xyDsz.y) - 52) / nF)
Expand Down Expand Up @@ -1318,7 +1320,7 @@ if(CLIENT) then
asmlib.LogInstance("Fail subfolder "..asmlib.GetReport2(sSub, lSub), sLog); return end
local sKey = tDat.Key:format(sDir, sSub)
if(asmlib.IsHere(fFoo)) then
if(not asmlib.IsFunction(fFoo)) then
if(not isfunction(fFoo)) then
asmlib.LogInstance("Miss function "..asmlib.GetReport3(sDir, sSub, fFoo), sLog); return end
if(not asmlib.IsHere(tDat.Bar[sDir])) then tDat.Bar[sDir] = {} end; tDat.Bar[sDir][sSub] = fFoo
asmlib.LogInstance("Store "..asmlib.GetReport3(sDir, sSub, fFoo), sLog)
Expand All @@ -1329,7 +1331,7 @@ if(CLIENT) then
asmlib.LogInstance("Miss folder "..asmlib.GetReport1(sDir), sLog); return end
fFoo = tDat.Bar[sDir][sSub]; if(not asmlib.IsHere(fFoo)) then
asmlib.LogInstance("Miss subfolder "..asmlib.GetReport2(sDir, sSub), sLog); return end
if(not asmlib.IsFunction(fFoo)) then
if(not isfunction(fFoo)) then
asmlib.LogInstance("Miss function "..asmlib.GetReport3(sDir, sSub, fFoo), sLog); return end
asmlib.LogInstance("Cache "..asmlib.GetReport3(sDir, sSub, fFoo), sLog); return fFoo
end
Expand Down Expand Up @@ -1599,11 +1601,11 @@ gtOptionsCM.MenuOpen = function(self, opt, ent, tr)
local sKey , fDraw = tLine[1], tLine[4]
local wDraw, sIcon = tLine[5], sKey:match(fHash)
local sName = languageGetPhrase(sKey.."_con"):Trim():Trim(":")
if(asmlib.IsFunction(fDraw)) then
if(isfunction(fDraw)) then
local bS, vE = pcall(fDraw, ent, oPly, tr, sKey); if(not bS) then
asmlib.LogInstance("Request "..asmlib.GetReport2(sKey,iD).." fail: "..vE,gsOptionsLG); return end
sName = sName..": "..tostring(vE) -- Attach client value ( CLIENT )
elseif(asmlib.IsFunction(wDraw)) then
elseif(isfunction(wDraw)) then
sName = sName..": "..ent:GetNWString(sKey) -- Attach networked value ( SERVER )
end; local fEval = function() self:Evaluate(ent,iD,tr,sKey) end
local pnOpt = pnSub:AddOption(sName, fEval); if(not IsValid(pnOpt)) then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ local Angle = Angle
local Color = Color
local tonumber = tonumber
local tostring = tostring
local istable = istable
local isnumber = isnumber
local mathClamp = math and math.Clamp
local cvarsAddChangeCallback = cvars and cvars.AddChangeCallback
local cvarsRemoveChangeCallback = cvars and cvars.RemoveChangeCallback
Expand Down Expand Up @@ -282,9 +284,9 @@ local function newPiece(oPly, oEnt, sModel, vPos, aAng, nMass, sBgpID, nR, nG, n
if(not (oEnt and oEnt:IsValid())) then sBsID = "0/0" else -- Use bodygroup and skin
sBsID = asmlib.GetPropBodyGroup(oEnt)..sDir..asmlib.GetPropSkin(oEnt) end
end -- Color handling. Apply color based on the conditions
if(asmlib.IsNumber(oCol)) then -- Color specifier is a number
if(isnumber(oCol)) then -- Color specifier is a number
oCol = asmlib.GetColor(nR,nG,nB,nA) -- Try last 4 arguments as numbers
elseif(asmlib.IsTable(oCol)) then -- Attempt to extract keys information from the table
elseif(istable(oCol)) then -- Attempt to extract keys information from the table
oCol = asmlib.GetColor((oCol[1] or oCol["r"]), -- Numerical indices are with priority to hash
(oCol[2] or oCol["g"]), -- Numerical indices are with priority to hash
(oCol[3] or oCol["b"]), -- Numerical indices are with priority to hash
Expand Down
Loading

0 comments on commit 7e1e502

Please sign in to comment.