Skip to content

Commit

Permalink
Update c_testing.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jul 31, 2024
1 parent 725d462 commit 2eb0832
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions newmodels_reborn/optional/c_testing.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local enabled = false
local SW, SH = guiGetScreenSize()
local SW = guiGetScreenSize()

local debugTimer = nil
local drawStr = ""

local function getElementInfoStr(element, level)
Expand All @@ -21,19 +23,51 @@ local function getElementChidrenStr(element, level)
return str
end

setTimer(function()
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
table.insert(a, n)
end
table.sort(a)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
return iter
end

local function updateDebugStr()
local loadedModelsStr = ""
for customModel, v in pairsByKeys(loadedModels) do
if loadedModelsStr == "" then
loadedModelsStr = ("%d (%d)"):format(customModel, v.baseModel)
else
loadedModelsStr = loadedModelsStr .. (", %d (%d)"):format(customModel, v.baseModel)
end
end
drawStr = getElementChidrenStr(resourceRoot, 0)
end, 1000, 0)
if loadedModelsStr ~= "" then
drawStr = "Loaded models:\n" .. loadedModelsStr .. "\n\n" .. drawStr
end
end

local function drawElements()
local function drawDebug()
dxDrawText(drawStr, SW/2, 30, SW, 0, 0xFFFFFFFF, 1, "default-bold")
end

addCommandHandler("newmodelstest", function()
addCommandHandler("newmodelsdebug", function(cmd)
if not enabled then
addEventHandler("onClientRender", root, drawElements, false)
if not (debugTimer) or (not isTimer(debugTimer)) then debugTimer = setTimer(updateDebugStr, 1000, 0) end
addEventHandler("onClientRender", root, drawDebug, false)
else
removeEventHandler("onClientRender", root, drawElements)
if debugTimer and isTimer(debugTimer) then killTimer(debugTimer); debugTimer = nil end
removeEventHandler("onClientRender", root, drawDebug)
end
enabled = not enabled
outputChatBox(cmd .. " => " .. tostring(enabled))
end, false)

0 comments on commit 2eb0832

Please sign in to comment.