Skip to content

Commit

Permalink
Fixed: Some runtime errors
Browse files Browse the repository at this point in the history
Updated: Category sorting and population
Optimized: `ChecheQueryPanel` and its data structure
Added: Category sort/export into separate functions
  • Loading branch information
dvdvideo1234 committed Oct 16, 2024
1 parent 0e04c0c commit 3b9c81f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 91 deletions.
2 changes: 1 addition & 1 deletion lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

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

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

Expand Down
104 changes: 50 additions & 54 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function InitBase(sName, sPurp)
local uC = (u.C or {})
local vC = (v.C or {})
local uM, vM = #uC, #vC
for i = 1, math.max(uM, vM) do
for i = 1, mathMax(uM, vM) do
local uS = tostring(uC[i] or "")
local vS = tostring(vC[i] or "")
if(uS ~= vS) then return uS < vS end
Expand Down Expand Up @@ -3305,67 +3305,63 @@ end
----------------------- PANEL QUERY -------------------------------

--[[
* Exports panel information to dedicated DB file
* stPanel > The actual panel information to export
* bExp > Export panel data into a DB file
* makTab > Table maker object
* Export tool panel contents as a sync file
* stPanel > The actual tool panel information handled
* sFunc > Export requestor ( CacheQueryPanel )
* bExp > Control flag. Export when enabled
]]
function ExportPanelDB(stPanel, bExp, makTab, sFunc)
if(bExp) then
local sMiss = GetOpVar("MISS_NOAV")
local sBase = GetOpVar("DIRPATH_BAS")
local sExpo = GetOpVar("DIRPATH_EXP")
local sMoDB = GetOpVar("MODE_DATABASE")
local symSep, cT = GetOpVar("OPSYM_SEPARATOR")
if(not fileExists(sBase, "DATA")) then fileCreateDir(sBase) end
local fName = (sBase..sExpo..GetOpVar("NAME_LIBRARY").."_db.txt")
local F = fileOpen(fName, "wb" ,"DATA"), sMiss; if(not F) then
LogInstance("Open fail "..GetReport(fName)); return stPanel end
F:Write("# "..sFunc..":("..tostring(bExp)..") "..GetDateTime().." [ "..sMoDB.." ]\n")
local coMo = makTab:GetColumnName(1)
local coTy = makTab:GetColumnName(2)
local coNm = makTab:GetColumnName(3)
for iCnt = 1, stPanel.Size do
local vPanel = stPanel[iCnt]
local sM, sT, sN = vPanel[coMo], vPanel[coTy], vPanel[coNm]
if(not cT or cT ~= sT) then -- Category has been changed
F:Write("# Categorize [ "..sMoDB.." ]("..sT.."): "..tostring(WorkshopID(sT) or sMiss))
F:Write("\n"); cT = sT -- Cache category name
end -- Otherwise just write down the piece active point
F:Write("\""..sM.."\""..symSep)
F:Write("\""..sT.."\""..symSep)
F:Write("\""..sN.."\""); F:Write("\n")
end; F:Flush(); F:Close()
end; return stPanel
local function DumpCategory(stPanel, sFunc, bExp)
if(SERVER) then return stPanel end
if(not bExp) then return stPanel end
local sFunc = tostring(sFunc or "")
local sMiss = GetOpVar("MISS_NOAV")
local sBase = GetOpVar("DIRPATH_BAS")
local sExpo = GetOpVar("DIRPATH_EXP")
local sMoDB = GetOpVar("MODE_DATABASE")
local symSep, cT = GetOpVar("OPSYM_SEPARATOR")
if(not fileExists(sBase, "DATA")) then fileCreateDir(sBase) end
local fName = (sBase..sExpo..GetOpVar("NAME_LIBRARY").."_db.txt")
local F = fileOpen(fName, "wb" ,"DATA"), sMiss; if(not F) then
LogInstance("Open fail "..GetReport(fName)); return stPanel end
F:Write("# "..sFunc..":("..stPanel.Size..") "..GetDateTime().." [ "..sMoDB.." ]\n")
for iCnt = 1, stPanel.Size do
local vRec = stPanel[iCnt]
local sM, sT, sN = vRec.M, vRec.T, vRec.N
if(not cT or cT ~= sT) then -- Category has been changed
F:Write("# Categorize [ "..sMoDB.." ]("..sT.."): "..tostring(WorkshopID(sT) or sMiss))
F:Write("\n"); cT = sT -- Cache category name
end -- Otherwise just write down the piece active point
F:Write("\""..sM.."\""..symSep)
F:Write("\""..sT.."\""..symSep)
F:Write("\""..sN.."\""); F:Write("\n")
end; F:Flush(); F:Close(); return stPanel
end

--[[
* Updates panel category to dedicated hash
* stPanel > The actual panel information to export
* stPanel > The actual panel information to populate
]]
function UpdatePanelCategory(stPanel)
local function SortCategory(stPanel)
local tCat = GetOpVar("TABLE_CATEGORIES")
for iCnt = 1, stPanel.Size do local vRec = stPanel[iCnt]
-- Register the category if definition functional is given
if(tCat[vRec.T]) then -- There is a category definition
local bS, vC, vN = pcall(tCat[vRec.T].Cmp, sMod)
local bS, vC, vN = pcall(tCat[vRec.T].Cmp, vRec.M)
if(bS) then -- When the call is successful in protected mode
if(vN and not IsBlank(vN)) then
vRec.N = GetBeautifyName(vN)
end -- Custom name override when the addon requests
if(vN and not IsBlank(vN)) then vRec.N = GetBeautifyName(vN) end
-- Custom name override when the addon requests
if(IsBlank(vC)) then vC = nil end
if(IsHere(vC)) then
if(not istable(vC)) then vC = {tostring(vC or "")} end
vRec.C = vC -- Make output category to point to local one
for iD = 1, #vC do -- Create category tree path
local vC[iD] = tostring(vC[iD] or ""):lower():Trim()
vRec.C = vC; vC.Size = #vC -- Make output category to point to local one
for iD = 1, vC.Size do -- Create category tree path
vC[iD] = tostring(vC[iD] or ""):lower():Trim()
if(IsBlank(vC[iD])) then vC[iD] = "other" end
vC[iD] = GetBeautifyName(vC[iD]) -- Beautify the category
end -- When the category has at least one element
end -- Is there is any category apply it. When available process it now
else -- When there is an error in the category execution report it
LogInstance("Category "..GetReport(vRec.T, vRec.M).." execution error: "..vC,sLog)
LogInstance("Process "..GetReport(vRec.T, vRec.M).." [[["..tCat[vRec.T].Txt.."]]] execution error: "..vC,sLog)
end -- Category factory has been executed and sub-folders are created
end -- Category definition has been processed and nothing more to be done
end; tableSort(stPanel, GetOpVar("VCOMPARE_SPAN")); return stPanel
Expand Down Expand Up @@ -3408,19 +3404,19 @@ function CacheQueryPanel(bExp)
for iCnt = 1, stPanel.Size do local qRow = qData[iCnt]
stPanel[iCnt] = {M = qRow[coMo], T = qRow[coTy], N = qRow[coNm]}
end
stPanel = makTab:TimerAttach(sFunc, keyPan)
return UpdatePanelCategory(ExportPanelDB(stPanel, bExp, makTab, sFunc))
SortCategory(stPanel)
DumpCategory(stPanel, sFunc, bExp)
return makTab:TimerAttach(sFunc, keyPan)
elseif(sMoDB == "LUA") then
local tCache = libCache[defTab.Name] -- Sort directly by the model
local tSort = PrioritySort(tCache, "Type", "Slot"); if(not tSort) then
LogInstance("Cannot sort cache data"); return nil end
for iCnt = 1, tSort.Size do stPanel[iCnt] = {}
local vSort, vPanel = tSort[iCnt], stPanel[iCnt]
vPanel.M = vSort.Key
vPanel.T = vSort.Rec.Type
vPanel.N = vSort.Rec.Name
end; stPanel.Size = tSort.Size -- Store the amount sort rows
return UpdatePanelCategory(ExportPanelDB(stPanel, bExp, makTab, sFunc))
local tCache, stPanel = libCache[defTab.Name], {Size = 0}
for mod, rec in pairs(tCache) do
local iCnt = stPanel.Size; iCnt = iCnt + 1
stPanel[iCnt] = {M = rec.Slot, T = rec.Type, N = rec.Name}
stPanel.Size = iCnt -- Store the amount of rows
end
SortCategory(stPanel)
DumpCategory(stPanel, sFunc, bExp)
return stPanel
else LogInstance("Unsupported mode "..GetReport(sMoDB)); return nil end
end
end
Expand Down
52 changes: 16 additions & 36 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2317,14 +2317,10 @@ function TOOL.BuildCPanel(CPanel)
pTree:UpdateColours(drmSkin) -- Apply current skin
CPanel:AddItem(pTree) -- Register it to the panel
local defTable = makTab:GetDefinition()
local catTypes = asmlib.GetOpVar("TABLE_CATEGORIES")
local pTypes, pCateg, pNode = {}, {}
local coMo = makTab:GetColumnName(1)
local coTy = makTab:GetColumnName(2)
local coNm = makTab:GetColumnName(3)
local pTypes, pCateg, pNode = {}, {}, {}
for iC = 1, qPanel.Size do
local vRec, bNow = qPanel[iC], true
local sMod, sTyp, sNam = vRec[coMo], vRec[coTy], vRec[coNm]
local sMod, sTyp, sNam = vRec.M, vRec.T, vRec.N
if(asmlib.IsModel(sMod)) then
if(not (asmlib.IsBlank(sTyp) or pTypes[sTyp])) then
local pRoot = pTree:AddNode(sTyp) -- No type folder made already
Expand All @@ -2342,37 +2338,21 @@ function TOOL.BuildCPanel(CPanel)
pTypes[sTyp] = pRoot
end -- Reset the primary tree node pointer
if(pTypes[sTyp]) then pItem = pTypes[sTyp] else pItem = pTree end
-- Register the category if definition functional is given
if(catTypes[sTyp]) then -- There is a category definition
local bSuc, vCat, vNam = pcall(catTypes[sTyp].Cmp, sMod)
if(bSuc) then -- When the call is successful in protected mode
if(vNam and not asmlib.IsBlank(vNam)) then
sNam = asmlib.GetBeautifyName(vNam)
end -- Custom name override when the addon requests
local pCur = pCateg[sTyp]
if(not asmlib.IsHere(pCur)) then
pCateg[sTyp] = {}; pCur = pCateg[sTyp] end
if(asmlib.IsBlank(vCat)) then vCat = nil end
if(asmlib.IsHere(vCat)) then
if(not istable(vCat)) then vCat = {vCat} end
for iD = 1, #vCat do -- Create category tree path
local sCat = tostring(vCat[iD] or ""):lower():Trim()
if(asmlib.IsBlank(sCat)) then sCat = "other" end
sCat = asmlib.GetBeautifyName(sCat) -- Beautify the category
if(pCur[sCat]) then -- Jump next if already created
pCur, pItem = asmlib.GetDirectory(pCur, sCat)
else -- Create a new sub-category for the incoming content
pCur, pItem = asmlib.SetDirectory(pItem, pCur, sCat)
end -- Create the last needed node regarding pItem
end -- When the category has at least one element
else -- Store the creation information of the ones without category for later
tableInsert(pCateg[sTyp], {sNam, sMod}); bNow = false
end -- Is there is any category apply it. When available process it now
else -- When there is an error in the category execution report it
asmlib.LogInstance("Category "..asmlib.GetReport(sTyp, sMod).." execution error: "..vCat,sLog)
end -- Category factory has been executed and sub-folders are created
end -- Category definition has been processed and nothing more to be done
-- Register the node associated with the track piece when is intended for later
local pCur = pCateg[sTyp]; if(not asmlib.IsHere(pCur)) then
pCateg[sTyp] = {}; pCur = pCateg[sTyp] end -- Create category tree path
if(vRec.C) then -- When category for the track type is available
for iD = 1, vRec.C.Size do -- Generate the path to the track piece
local sCat = vRec.C[iD] -- Read the category name
if(pCur[sCat]) then -- Jump next if already created
pCur, pItem = asmlib.GetDirectory(pCur, sCat)
else -- Create a new sub-category for the incoming content
pCur, pItem = asmlib.SetDirectory(pItem, pCur, sCat)
end -- Create the last needed node regarding pItem
end -- When the category has at least one element
else
tableInsert(pCateg[sTyp], {sNam, sMod}); bNow = false
end
if(bNow) then asmlib.SetDirectoryNode(pItem, sNam, sMod) end
-- SnapReview is ignored because a query must be executed for points count
else asmlib.LogInstance("Ignoring item "..asmlib.GetReport(sTyp, sNam, sMod),sLog) end
Expand Down

0 comments on commit 3b9c81f

Please sign in to comment.