godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Provide a function that parses text into resource/scene types. #9670

Open donte5405 opened 2 weeks ago

donte5405 commented 2 weeks ago

Describe the project you are working on

Games that rely on content delivery network & server-side responses.

Describe the problem or limitation you are having in your project

Godot has the potential to become a game engine that's designed to be a user-friendly engine for games that require server-side content delivery. Even with GDScript, it's already possible with Script::set_source_code() and Script::reload(), which helps on a total server-side content-delivered script. However, the main container to store the content and get it delivered to Godot is still via GDResource (aka., tscn/tres) files. However, Godot doesn't provide any of the ways to parse strings into GDResource.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

With this feature implemented, users can build GDResource string templates and use them to generate resource strings and deliver them to Godot-based game clients. This helps a lot with server-side content-delivery or even server-side rendering games since it also provides other ways to construct in-game data with resource template strings using other conventional tools for other developers in the team. Enhancing the development process and making server-side games with Godot a whole lot easier because template engines are inherently easier to deploy than parsing other portable data types into Godot and having another maintenance element in the project.

Plus, this paradigm introduces a way to keep resources in the server, since Godot is pretty notorious for all clear-text resources that are perfectly readable and editable, making it a lot less desirable to even store non-critical client-side references into the game and letting hackers using the "rendering shell" games to be operated illegally or privately (especially with games that core-logic are well-known or simple enough, and can be implemented in matters of weeks).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Provide a function ResourceLoader::parse_from_string(const String* &p_string) that parses the string and returns any Resource types. This provides a way to parse downloaded strings into a resource.

If this enhancement will not be used often, can it be worked around with a few lines of script?

This could work out with some GDScript-based implementations that simply write files into user:// space and load them that way, but it's not fool-proof since it's still somewhat difficult to make sense of the way to sweep leftover resources without some of software engineering skills, and Godot is supposed to be easy to use for anyone who want to make games easily.

Is there a reason why this should be core and not an add-on in the asset library?

This is an addon that interferes directly with how resources are loaded. I took some time to make sense of how resources are loaded in Godot's source and couldn't come up with a good way to create a parser without resulting in a wrapper that also needs another set of procedures to take care of leftover files.

RedMser commented 2 weeks ago

Doesn't str_to_var do what you want? Or the upcoming JSON serialization suppport?

https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-str-to-var https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-bytes-to-var

https://github.com/godotengine/godot/pull/91503

Though note that there currently is no sandboxing for the former of these two, meaning that files over the internet should not be trusted as they could contain malicious script code. The JSON PR seems to include an option to disable script loading.

donte5405 commented 2 weeks ago

Doesn't str_to_var do what you want? Or the upcoming JSON serialization suppport?

Yes, and no. The problem with it is that the structure isn't friendly to comprehend visually, unless there's an option to beautify the string, which seems to not be there.

My main goal is to have GDResource files imported to a server directly and ready to be used as a template for rendering, without extra steps to port resources from the development build of the client into the server environment.

JSON support seems promising since it's widely-adopted standard, but I need to look forward on how contributors will adapt it out, and how difficult it is to backport the feature back to 3.x (because 4.x is extremely buggy at the moment with web platform)

dalexeev commented 2 weeks ago

I think a more universal solution would be to add support for an in-memory filesystem, say memory://. Then you could use any file operations (FileAccess, DirAccess, ResourceSaver, ResourceLoader, etc.) without the need to use user:// and absolute paths.