Skip to content

Commit

Permalink
Merge pull request #2965 from MoritzBrueckner/debug-console-props
Browse files Browse the repository at this point in the history
Show object properties in debug console
  • Loading branch information
luboslenco committed Nov 7, 2023
2 parents dcda14c + a933ea1 commit 83598ee
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions Sources/armory/trait/internal/DebugConsole.hx
Expand Up @@ -502,6 +502,19 @@ class DebugConsole extends Trait {
ui.unindent();
}

if (selectedObject.properties != null) {
ui.text("Properties:");
ui.indent();

for (name => value in selectedObject.properties) {
ui.row([1/2, 1/2]);
ui.text(name);
ui.text(dynamicToUIString(value), Align.Right);
}

ui.unindent();
}

if (selectedObject.name == "Scene") {
selectedType = "(Scene)";
if (iron.Scene.active.world != null) {
Expand Down Expand Up @@ -936,21 +949,8 @@ class DebugConsole extends Trait {
ui.text(fieldName + "");

var fieldValue = Reflect.field(trait, fieldName);
var fieldClass = Type.getClass(fieldValue);

// Treat objects differently (VERY bad performance otherwise)
if (Reflect.isObject(fieldValue) && fieldClass != String) {

if (fieldClass != null) {
ui.text('<${Type.getClassName(fieldClass)}>', Align.Right);
} else {
// Anonymous data structures for example
ui.text("<???>", Align.Right);
}
} else {
ui.text(Std.string(fieldValue), Align.Right);
}

ui.text(dynamicToUIString(fieldValue), Align.Right);
}

ui.unindent();
Expand All @@ -961,6 +961,22 @@ class DebugConsole extends Trait {
if (bindG) g.begin(false);
}

function dynamicToUIString(value: Dynamic): String {
final valueClass = Type.getClass(value);

// Don't convert objects to string, Haxe includes _all_ object fields
// (recursively) by default which does not fit in the UI and can cause performance issues
if (Reflect.isObject(value) && valueClass != String) {
if (valueClass != null) {
return '<${Type.getClassName(valueClass)}>';
}
// Given value has no class, anonymous data structures for example
return "<???>";
}

return Std.string(value);
}

function update() {
armory.trait.WalkNavigation.enabled = !(ui.isScrolling || ui.dragHandle != null);
updateTime += iron.App.updateTime;
Expand Down

0 comments on commit 83598ee

Please sign in to comment.