Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of adding the pretty printing of Custom Resources? #2

Open
Metriximor opened this issue Mar 28, 2024 · 4 comments
Open

Comments

@Metriximor
Copy link

Hi, this looks very nifty, learned a lot looking through the code :)

I was wondering if the functionality of pretty printing custom resources would be doable to implement?

Thank you 馃憤

@russmatney
Copy link
Owner

Seems reasonable! I don't use custom resources that much, it's something i really need to learn more about.

I'll dig around for an obvious catch-all for what data should be exposed (e.g. for PackedScenes we now show a resource_path, as it's a bit nicer). Otherwise it'd probably be worth implementing something for each type the custom-resource could be. Feel free to suggest something if you have an idea in mind!

Either way, if you have a custom resource with a script attached, you can already implement to_printable() (or data(), in the current implementation) and return a dict or array to improve the Log.pr output.

@russmatney
Copy link
Owner

Probably makes sense to go through the InheritedBy list here: https://docs.godotengine.org/en/stable/classes/class_resource.html#class-resource

I'll take a shot at adding support for a bunch of these soon!

@Metriximor
Copy link
Author

Metriximor commented Mar 29, 2024

That would be lovely, if I can help out somewhere I'd be glad to contribute

As for the printable that looks useful, I'll look into it, tyvm :D

@russmatney
Copy link
Owner

I haven't gotten to that list of Resource-derived classes yet - hopefully in the next week or two.

In the meantime I've restructured a bit to support more types, which led nicely into an overwrites 'registry' of sorts - on the latest git version you can now register a handler for whatever type.

Right now this looks like this unit test:

func test_custom_resource_register_overwrite():
	var tp = TestPlayer.new()
	tp.name = "Hanz"
	tp.level = 3

	Log.register_overwrite(tp.get_class(), func(msg, _opts):
		return Log.to_pretty({name=msg.name, level=msg.level}))

	var val = Log.to_pretty(tp)
	assert_str(val).is_equal(
		"[color=red]{ [/color][color=magenta]\"name\"[/color]: [color=pink]Hanz[/color][color=red], [/color][color=magenta]\"level\"[/color]: [color=green]3[/color][color=red] }[/color]"
		)

This should let folks add handlers for types they don't own, which should be nice.

I expect to refactor the implementation itself to use this registry as well.

I also decided to support to_pretty() as a to_printable method as well - implementing data() or to_printable() or to_pretty() on a class gets used by Log's printing functions... really I just can't decide on a name.

Feel free to let me know if you think these things are useful, or if you have any related ideas/opinions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants