-
-
Notifications
You must be signed in to change notification settings - Fork 99
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing text_file.cpp as a Resource with ResourceFormatLoaderText #9077
Comments
That FileAccess note only applies to resources. Since text files are not resources, they can be safely loaded using the FileAccess methods. |
It'd have to have another name as |
I appreciate your response and insight into the issue. However, the problem persists even when attempting to load text files using FileAccess, like in issues: godotengine/godot#37646 and godotengine/godot#56737
But the exported project throws an error indicating a null instance when attempting to call functions such as get_as_text().
I proposed the use of ResourceLoader because ResourceLoader does handle these issues under the hood I'm not sure, but perhaps I'm overlooking something. I'm relatively new to this, so I'm unsure. |
How I missed that? haha. Thank you!!. Perhaps this should be made clearer in the documentation. |
You can test it by exporting a ZIP file and inspecting its contents. |
@KoBeWi Thank you! |
Thanks! That works! Have been searching for a while. |
Done in godotengine/godot#97906. Feel free to take a look at the PR's changes 🙂 |
Describe the project you are working on
Creating a typing game requiring runtime loading of numerous text files.
Describe the problem or limitation you are having in your project
Unable to utilize FileAccess, load, or preload for reading text files in an exported project due to godotengine/godot#21787 (comment)
FileAccess
docs:Describe the feature / enhancement and how it helps to overcome the problem or limitation
Expose text_file.cpp as a Resource and implement a ResourceFormatLoaderText to allow straightforward loading of text files using ResourceLoader. This enhancement will simplify text file loading, overcoming the current limitations.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I've devised a solution to streamline the process of accessing text data within Godot. Initially, I convert text files to JSON format using an external tool. Subsequently, within Godot, the JSON files are loaded using ResourceLoader.load(json_path). However, the current method of converting the JSON data into an array to extract the text from the original text file is proving to be inefficient
Convert Text files to Json in an external tool → Code reads that Json with ResourceLoader.load(json_path) → Custom function extracts the original text from the JSON Resource
Additionally, with the proposed enhancement of ResourceLoaderTextFile, the workflow becomes even more straightforward:
Read textFiles with ResourceLoader.load(txt_path) → text_file.get_text() DONE!!!!!
If this enhancement will not be used often, can it be worked around with a few lines of script?
As previously mentioned, one could bypass the need for this enhancement by converting the text file to an already implemented resource format like JSON. However, this approach is a very slow workflow and necessitates the creation of a custom function to extract the text from the JSON file.
Is there a reason why this should be core and not an add-on in the asset library?
The text_file.cpp already exists as a Resource within Godot, albeit not yet exposed in the engine. Hence, the integration of this enhancement merely involves exposing it and implementing the ResourceFormatLoader abstract class.
The text was updated successfully, but these errors were encountered: