Godot: Godot should be able to import a CSV without forcing it to be used for translation

Created on 18 Jun 2018  路  15Comments  路  Source: godotengine/godot

Godot version:

3.0.3

OS/device including version:

N/A (all)

Issue description:

Importing a CSV appears to only be possible if it's used for translation, I think most people coming to Godot from other engines would assume they could import a CSV as just a container for simple data by default (especially as there appears to be functions for working with CSV files! importing as another extension just seems like a hack, not a solution) - with an option in the import menu to mark it to be used for translations if that's the actual purpose

import menu

Steps to reproduce:
Add csv to project
Click it, go to import menu
Expected an option to import it as a normal CSV, but can only be used for translation

Minimal reproduction project:

N/A (blank project with an added csv file)

enhancement import usability

Most helpful comment

I went ahead and started writing a new Godot module for a Spreadsheet resource class that would be able to load CSV files, but also presumably support other spreadsheet-like file formats. Would also ideally be able to fulfill a similar purpose as UE4's DataTable types (a table of StringName-Script/Dictionary pairs).

Link to WIP godot branch.

All 15 comments

Which kind of resource a CSV is?

I think there is only this choice in the importer because a Translation is a resource with some format requirements, whereas raw CSV data doesn't need to be imported, it can just be loaded as is using file functions (same story for JSON and TXT btw).
The confusing part is, you are tempted to use load, but load only works on imported files and actual resource files (.tres) that have a matching Resource type, so load doesn't work on json, csv or txt files as is (they are just arrays, dictionaries and strings, these aren't resources).

To be fair, I'm not specifically requesting csv be "importable" (might be cool to display them as a simple resource with a little viewer in the inspector, but i assume this is easy enough to do custom, just might be a nice addition but out of scope of this issue) but it is very misleading or confusing seeing a bunch of red error-stuff on it if you're trying to use a csv in your project, perhaps an option in the import menu to just say something like "this isn't a translation csv, just a normal one, so don't try and import it" or something along those lines
(it'd be nice to have non-translation csvs, json files and txt files appear by default in the file browser too, but this might have good reason for not happening that I don't know about, so that isn't really something I care much about as much, but would be nice to change this or something)

I still have a lot of import error for CSV files each time I switch from editor to running project and switch back to editor while debugging.

And, most big issue: Editor goes deadlock (and only way out is closing the editor) while debugging the project at any breakpoint following CSV.open(path,WRITE) and before executing CSV.close().

Is it bad to have an option to import "as is"?

@burstina As a workaround, you can change the file extension to something else like .txt.

The benefit of using CSV would be to quickly change and edit and manage larger amounts of data in a spreadsheet like Open Office Calc. Being forced to change the extension to .txt sucks because it's like throwing a brick in the designers flow, but if you don't iterate over your data often (aka not really doing design or balancing work), it at at least kinda works. It won't show up in the file manager and I haven't tested yet if it will get exported, though.

From my recent comment on reddit concerning the same subject:

CSV is far easier to edit (unlike JSON, you can easily open and read CSV in any text editor to make quick, small edits) and much easier manage large amount of data (using spreadsheets outside of Godot). Open Office Calc is free, open source and capable of everything EXEL can do. Anyone who ever touched EXEL will know how to create and edit large csv files as functionality is extremely similar and wide spread in all spreadsheet editors.

Spreadsheet software like Calc and Exel is an incredible powerful tool in the hands of a game designer. Both have been documented since many many years and have endless tutorials for it, even for the rarest of use cases.

In contrast it's really hard to find a good free JSON editor. Those I did find were mostly viewers. No tutorial or documentation to find and no features compared to these well established spreadsheet programs.

If Godot had .ods support, or at least better csv support, it would become even more of an open source powerhouse for designers.

I really hope the Godot devs consider closer and more open CSV integration. From balancing FPS to strategy games or data driven games like card games, I can see this benefiting all kinds of games with larger data structures.

Looks like the only problem here is to tell Godot to NOT run the importer on these files. Apart from that, they can be loaded just fine with the CSV API.

@Zylann Where is this CSV class? I don't see it in the latest docs and a search in the source code doesn't turn up a dedicated class for it (that I can find)...

Edit: Oh, nevermind. I see that the File API includes CSV file type methods for reading/writing data. Gotcha.

On second thought, I'm not entirely sure if my PR is the best solution for this Issue.

If someone were to open up the "CSV Translation" import options and see an option to "toggle on the actual parsing of this file as a translation CSV" not checked by default...it'd be really weird. But you can't make the importer NOT get pulled into the list of importers that match the file extension so...as far as I can tell, this is the only way, given the current system, to make it not do it by default.

Perhaps a better solution(?) would be to add an entirely new importer for the .csv extension that doesn't consider CSV files to be translation files? But we don't really have a resource that we plan to parse the file into, so it doesn't make sense to write a ResourceImporter just to make the dropdown not use CSV Translation by default.

Thoughts?

Edit: I mean, I'm not entirely opposed to creating a dedicated resource for CSVFile types and then writing an importer for it that is set as the default. Would that be acceptable to everyone? I already have a partial implementation as a CSVFile class (modeled like the ConfigFile class) in godot-next.

If someone were to open up the "CSV Translation" import options and see an option to "toggle on the actual parsing of this file as a translation CSV" not checked by default...it'd be really weird.

Why not just rename them from "CSV Translation" import options to "CSV" and then have the checkbox toggle underneath called "import as language translation" (_language translation_ in order not to confuse it with geometric translation)

Maybe someone in future writes an importer feature to also have checkboxes for "Import as Array of Arrays" and "Import as Dictionary" ... would be really cool and a lot more accessible for designers.

It's kind of an odd lie, within the source code anyway, since, regardless of whether it is actually parsed into a translation resource, the "resource_type" that will be affiliated with the CSV file is "Translation". And the importer itself is literally ResourceImporterCSVTranslation, lol. The simplest way to fix it would be to just write a whole different importer (and would presumably grant more usability for CSV files overall that way). I mean, I could just refactor the CSV import to have no mention of translation whatsoever aside from the boolean toggle I added and the logic not exiting early and doing translation stuff, but that would be a really hacky way to do it which I would rather avoid. If I did that, anyone who looked at the code would be like, "What the heck? Why was this written this way?"

I... And the importer itself is literally ResourceImporterCSVTranslation, lol. The simplest way to fix it would be to just write a whole different importer (and would presumably grant more usability for CSV files overall that way)....

That sounds like a clean solution

"What the heck? Why was this written this way?"

This soulds like something somebody already said while crawling godot source code :)

This soulds like something somebody already said while crawling godot source code :)

Haha! Especially because the importer has this drop down menu rn with "Import as..." and CSV Translation being the only option. Almost like a prank. Well, actually exactly like a prank. :)

I went ahead and started writing a new Godot module for a Spreadsheet resource class that would be able to load CSV files, but also presumably support other spreadsheet-like file formats. Would also ideally be able to fulfill a similar purpose as UE4's DataTable types (a table of StringName-Script/Dictionary pairs).

Link to WIP godot branch.

Fixed by #31927.

Was this page helpful?
0 / 5 - 0 ratings