What you want to do is homogenize the interface to that information, so that the debug menu itself need only deal with a single concrete API to get information concerning what it needs to display. Your first step, thus, is to ask yourself "what information do I need?"
At a bare minimum, I would expect a debug menu to display key-value pairs: the name of a property or field and it's corresponding value. Both can be represented as strings, because you're so far only talking about displaying that data. Additionally, you probably want each collection of key-value pairs for a particular object instance to be grouped with the rest of the fields for that object, so you'd want an overall container to represent the key-value pairs for a specific object. Perhaps
class field_debug_info {
string name;
string value;
};
class object_debug_info {
string name;
array<field_debug_info> fields;
};
With these types, you can construct your debug menu from a list of object_debug_info
objects by iterating through each one, adding a section for the object and then adding sections for each field.
debug_menu::debug_menu (array<object_debug_info> objects) {
foreach (object in objects) {
// For each object, add a line with the object's name.
add_line("{0}", object.name);
foreach (field in object.fields) {
// For each field of that object, add a line with the field data.
add_line(" {0}: {1}", field.name, field.value);
}
}
}
The constructor above would let you create a debug_menu
from a list of object debug information. Implementing add_line
(particularly with that C#-style string formatting) is left as a task for the reader. Also note that the above is all pseudo-code.
Now that you've accomplished that (and you can test that by manually creating the debug information objects you send to that constructor to start with), you need to get the information from the classes themselves. Because you are using Java, you can use the built-in reflection features to take any object
instance and query it for all it fields and their values. You can then transfer that data into your object_debug_info
structures (in fact, you could eschew your own object_debug_info
structures entirely and just use the Java reflection API's types if you wanted, and didn't need to add any additional data in the future).
The final part of the solution is to write the code that actually iterates all the live object in the game you want to inspect. There's nothing special or magical here: if you want to inspect all character
objects in the game when you open a debug menu, have your game collect and send the list of characters to the code that opens the debug menu, and so on.
ToString()
method in your class and have it return a string of the values you're interested in. Is that the kind of information you're looking for? This question is pretty vague. (And likely a better fit for Stackoverflow since I don't see any gamedev related content here). \$\endgroup\$