From 2eb08324998a353590a576020803fd41420371c5 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Wed, 31 Jul 2024 13:14:36 +0100 Subject: [PATCH] Update c_testing.lua --- newmodels_reborn/optional/c_testing.lua | 48 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/newmodels_reborn/optional/c_testing.lua b/newmodels_reborn/optional/c_testing.lua index 93af508..4021561 100644 --- a/newmodels_reborn/optional/c_testing.lua +++ b/newmodels_reborn/optional/c_testing.lua @@ -1,5 +1,7 @@ local enabled = false -local SW, SH = guiGetScreenSize() +local SW = guiGetScreenSize() + +local debugTimer = nil local drawStr = "" local function getElementInfoStr(element, level) @@ -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)