Skip to content

Commit

Permalink
Added: Unified version for empty string defaulting with vararg
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdvideo1234 committed Apr 24, 2024
1 parent b83a92a commit 54ff61c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
12 changes: 6 additions & 6 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.766")
asmlib.SetOpVar("TOOL_VERSION","8.767")

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

Expand Down Expand Up @@ -1659,10 +1659,10 @@ asmlib.CreateTable("PIECES",{
local noTY = asmlib.GetOpVar("MISS_NOTP")
local noSQL = asmlib.GetOpVar("MISS_NOSQL")
local trCls = asmlib.GetOpVar("TRACE_CLASS")
arLine[2] = asmlib.GetVacant(arLine[2], true, noTY, asmlib.Categorize())
arLine[3] = asmlib.GetVacant(arLine[3], true, noMD, asmlib.ModelToName(arLine[1]))
arLine[8] = asmlib.GetVacant(arLine[8], true, noSQL, noSQL)
if(not (asmlib.IsNull(arLine[8]) or trCls[arLine[8]] or asmlib.IsBlank(arLine[8]))) then
arLine[2] = asmlib.GetEmpty(arLine[2], nil, 2, asmlib.Categorize(), noTY)
arLine[3] = asmlib.GetEmpty(arLine[3], nil, 2, asmlib.ModelToName(arLine[1]), noMD)
arLine[8] = asmlib.GetEmpty(arLine[8], nil, 2, noSQL, noSQL)
if(not (asmlib.IsNull(arLine[8]) or asmlib.IsBlank(arLine[8]) or trCls[arLine[8]])) then
asmlib.LogInstance("Register trace "..asmlib.GetReport2(arLine[8],arLine[1]),vSrc)
trCls[arLine[8]] = true; -- Register the class provided to the trace hit list
end; return true
Expand Down Expand Up @@ -1786,7 +1786,7 @@ asmlib.CreateTable("PHYSPROPERTIES",{
Trigs = {
Record = function(arLine, vSrc)
local noTY = asmlib.GetOpVar("MISS_NOTP")
arLine[1] = asmlib.GetVacant(arLine[1],true,noTY,asmlib.Categorize()); return true
arLine[1] = asmlib.GetEmpty(arLine[1],nil,asmlib.Categorize(),noTY); return true
end
},
Cache = {
Expand Down
47 changes: 14 additions & 33 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ function NewPOA()
return (mRaw and mRaw or sE)
end
function self:Decode(sStr, ...)
local bV, sS = GetVacant(sStr) -- Default to string
local bV, sS = GetEmpty(sStr) -- Default to string
if(bV) then -- Check when entry data is vacant
self:Set(...) -- Override with the default value provided
else -- Entry data is missing use default otherwise decode the value
Expand Down Expand Up @@ -1820,8 +1820,8 @@ function SetComboBoxClipboard(pnCombo)
local sV = pnCombo:GetValue()
local iD = pnCombo:GetSelectedID()
local sT = pnCombo:GetOptionText(iD)
local sS = GetVacant(tostring(sT or ""), true, sS)
SetClipboardText(GetVacant(sS, true, gsNoAV))
local sS = GetEmpty(sT, nil, 2, sV, gsNoAV)
SetClipboardText(sS)
end

function SetComboBoxList(cPanel, sVar)
Expand Down Expand Up @@ -2324,25 +2324,6 @@ end

------------- VARIABLE INTERFACES --------------

--[[
* Returns a string term whenever it is missing or disabled
* If these conditions are not met the function returns missing token
* sBas > The string to check whenever it is disabled or missing
* vDef > The default value to return when base is not string
* vDsb > The disable value to return when the base is disabled string
]]
function GetVacant(sBas, bTer, vDef, vDsb)
local sD = GetOpVar("OPSYM_DISABLE")
local sS = tostring(sBas or "") -- Default to string
local bD = (sS:sub(1,1) == sD) -- Disabled string
local bE = (IsBlank(sS) or IsNull(sS) or bD)
if(not bTer) then return bE, sS end -- Data to be decoded
local sM = GetOpVar("MISS_NOAV") -- Not available
if(bD) then return tostring(vDsb or sM) end
if(bE) then return tostring(vDef or sM) end
return sS -- Return the base string
end

--[[
* Returns a string term whenever it is missing or disabled
* If these conditions are not met the function returns missing token
Expand Down Expand Up @@ -2628,10 +2609,11 @@ function CreateTable(sTable,defTab,bDelete,bReload)
defRow[1], defRow[2] = sN, sT -- Convert settings to string and store back
end
local self, tabDef, tabCmd = {}, defTab, {}
local symDis, sMoDB = GetOpVar("OPSYM_DISABLE"), GetOpVar("MODE_DATABASE")
local sMoDB = GetOpVar("MODE_DATABASE")
local symDis = GetOpVar("OPSYM_DISABLE")
for iCnt = 1, defTab.Size do local defCol = defTab[iCnt]
defCol[3] = GetVacant(tostring(defCol[3] or symDis), true, symDis)
defCol[4] = GetVacant(tostring(defCol[4] or symDis), true, symDis)
defCol[3] = GetEmpty(defCol[3], nil, 1, symDis)
defCol[4] = GetEmpty(defCol[4], nil, 1, symDis)
end; tableInsert(libQTable, defTab.Nick)
libCache[defTab.Name] = {}; libQTable[defTab.Nick] = self
-- Read table definition
Expand Down Expand Up @@ -4489,28 +4471,27 @@ function AttachAdditions(ePiece)
LogInstance("Model skip <"..sMoc..">"); return true end
local makTab, iCnt = GetBuilderNick("ADDITIONS"), 1; if(not IsHere(makTab)) then
LogInstance("Missing table definition"); return nil end
local sD, oPOA = GetOpVar("OPSYM_DISABLE"), NewPOA()
LogInstance("PIECE:MODEL("..sMoc..")")
LogInstance("PIECE:MODEL("..sMoc..")") -- Start adding attachments
while(stData[iCnt]) do -- While additions are present keep adding them
local arRec = stData[iCnt]; LogInstance("PIECE:ADDITION("..iCnt..")")
local bVac, sCas = GetVacant(arRec[makTab:GetColumnName(3)])
if(bVac) then sCas = GetOpVar("ENTITY_DEFCLASS") end
local eBonus = entsCreate(sCas); LogInstance("ents.Create("..sCas..")")
local dCass, oPOA = GetOpVar("ENTITY_DEFCLASS"), NewPOA()
local sCass = GetEmpty(arRec[makTab:GetColumnName(3)], nil, 1, dCass)
local eBonus = entsCreate(sCass); LogInstance("ents.Create("..sCass..")")
if(eBonus and eBonus:IsValid()) then
local sMoa = tostring(arRec[makTab:GetColumnName(2)])
if(not IsModel(sMoa, true)) then
LogInstance("Invalid attachment "..GetReport3(iCnt, sMoc, sMoa)); return false end
eBonus:SetModel(sMoa) LogInstance("ENT:SetModel("..sMoa..")")
local oPos = arRec[makTab:GetColumnName(5)]; if(not IsString(oPos)) then
LogInstance("Position mismatch "..GetReport3(iCnt, sMoc, oPos)); return false end
if(not GetVacant(oPos)) then -- Scan the extracted entry for data
if(not GetEmpty(oPos)) then -- Scan the extracted entry for data
vPos:SetUnpacked(oPOA:Decode(oPos):Get())
vPos:Set(ePiece:LocalToWorld(vPos))
eBonus:SetPos(vPos); LogInstance("ENT:SetPos(DB)")
else eBonus:SetPos(ePos); LogInstance("ENT:SetPos(PIECE:POS)") end
local oAng = arRec[makTab:GetColumnName(6)]; if(not IsString(oAng)) then
LogInstance("Angle mismatch "..GetReport(iCnt, sMoc, oAng)); return false end
if(not GetVacant(oAng)) then -- Scan the extracted entry for data
if(not GetEmpty(oAng)) then -- Scan the extracted entry for data
aAng:SetUnpacked(oPOA:Decode(oAng):Get())
aAng:Set(ePiece:LocalToWorldAngles(aAng))
eBonus:SetAngles(aAng); LogInstance("ENT:SetAngles(DB)")
Expand Down Expand Up @@ -4676,7 +4657,7 @@ function NewPiece(pPly,sModel,vPos,aAng,nMass,sBgSkIDs,clColor,sMode)
if(InSpawnMargin(pPly, stData, vPos, aAng)) then
LogInstance("Spawn margin stop <"..sModel..">"); return nil end
local sClass = GetOpVar("ENTITY_DEFCLASS")
local ePiece = entsCreate(GetVacant(stData.Unit, true, sClass, sClass))
local ePiece = entsCreate(GetEmpty(stData.Unit, nil, 1, sClass))
if(not (ePiece and ePiece:IsValid())) then -- Create the piece unit
LogInstance("Piece invalid <"..tostring(ePiece)..">"); return nil end
ePiece:SetCollisionGroup(COLLISION_GROUP_NONE)
Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ function TOOL.BuildCPanel(CPanel)

local pComboPhysName = CPanel:ComboBox(languageGetPhrase("tool."..gsToolNameL..".phyname_con"), sName)
pComboPhysName:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".phyname"))
pComboPhysName:SetValue(asmlib.GetVacant(asmlib.GetAsmConvar("physmater","STR"), true,
pComboPhysName:SetValue(asmlib.GetEmpty(asmlib.GetAsmConvar("physmater","STR"), nil, 1,
languageGetPhrase("tool."..gsToolNameL..".phyname_def")))
pComboPhysName.DoRightClick = function(pnSelf) asmlib.SetComboBoxClipboard(pnSelf) end
pComboPhysName:Dock(TOP) -- Setting tallness gets ignored otherwise
Expand Down Expand Up @@ -2437,7 +2437,7 @@ function TOOL.BuildCPanel(CPanel)
local sName = asmlib.GetAsmConvar("bgskids", "NAM")
local pText = CPanel:TextEntry(languageGetPhrase("tool."..gsToolNameL..".bgskids_con"), sName)
pText:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".bgskids"))
pText:SetText(asmlib.GetVacant(asmlib.GetAsmConvar("bgskids", "STR"), true,
pText:SetText(asmlib.GetEmpty(asmlib.GetAsmConvar("bgskids", "STR"), nil, 1,
languageGetPhrase("tool."..gsToolNameL..".bgskids_def")))
pText:SetEnabled(false); pText:SetTall(22)

Expand Down

0 comments on commit 54ff61c

Please sign in to comment.