Skip to content

Commit

Permalink
add testing client display elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jul 8, 2024
1 parent b543c3f commit 725d462
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions newmodels_reborn/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<export function="getElementModel" type="shared"/>

<!-- Testing -->
<script src="optional/c_testing.lua" type="client"/>
<script src="optional/s_testing.lua" type="server"/>

<!-- Backwards compatibility with newmodels 3.3.0 -->
Expand Down
39 changes: 39 additions & 0 deletions newmodels_reborn/optional/c_testing.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local enabled = false
local SW, SH = guiGetScreenSize()
local drawStr = ""

local function getElementInfoStr(element, level)
local spaces = string.rep("----- ", level)
if isValidElement(element) then
return ("%s%s | model: %s\n"):format(spaces, inspect(element), getElementModel(element))
else
return ("%s%s\n"):format(spaces, inspect(element))
end
end

local function getElementChidrenStr(element, level)
local str = ""
local children = getElementChildren(element) or {}
for i=1, #children do
str = str .. getElementInfoStr(children[i], level)
str = str .. getElementChidrenStr(children[i], level + 1)
end
return str
end

setTimer(function()
drawStr = getElementChidrenStr(resourceRoot, 0)
end, 1000, 0)

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

addCommandHandler("newmodelstest", function()
if not enabled then
addEventHandler("onClientRender", root, drawElements, false)
else
removeEventHandler("onClientRender", root, drawElements)
end
enabled = not enabled
end, false)

0 comments on commit 725d462

Please sign in to comment.