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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow EditorImportPlugin to skip files in import() #2636

Open
cgbeutler opened this issue Apr 23, 2021 · 1 comment
Open

Allow EditorImportPlugin to skip files in import() #2636

cgbeutler opened this issue Apr 23, 2021 · 1 comment

Comments

@cgbeutler
Copy link

cgbeutler commented Apr 23, 2021

Describe the project you are working on

Json importer using gdscript's EditorImportPlugin

Describe the problem or limitation you are having in your project

I would like to be able to quietly bail on importing a file after doing a bit of parsing.
In my project, I first look to see if a script is provided in the import options. If it's not there then I read the json file and look for a 'script' member. If neither of those exist, I would like to just skip the file without any errors.
If there is a way to do this, I cannot find it anywhere. If I return OK without saving, I get the cryptic error: core/os/file_access.cpp:671 - Condition "!f" is true. Continuing. If I return any other error code, I get the "import failed" message. I cannot find a way to silently bail on importing a file short of writing a blank file to the .import folder (gross.)

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

Allow users to skip a file from the import(...) function. (If this already exists, let me know and I will open a docs proposal instead.)
I would propose one of two solutions: Allow the returning of OK without saving to "skip" a file. Allow the returning of ERR_SKIP to skip importing a file.

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

Example usage:

func import(source_file, save_path, options, r_platform_variants, r_gen_files) -> int:#Error
  
  ... #read and parse json file return real errors if those fail
  
  # If it is a valid json, but doesn't have our script variable, then silently bail on the file
  if not json.has("script"):
    return ERR_SKIP
  
  ... # save stuff
  
  return OK

I don't know enough about the back-end to comment there. The new "Keep File (No Import)" option could maybe be some help, but I don't actually know.

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

An error can be returned and the console will just be spammed each time out leave and re-focus the editor. Not ideal, but things do keep working.

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

I think the code in question is in core.

@cgbeutler cgbeutler changed the title Allow EditorImportPlugin to skip files in import Allow EditorImportPlugin to skip files in import() Apr 23, 2021
@cgbeutler
Copy link
Author

cgbeutler commented Apr 23, 2021

Tracked down what looks like the a possible spot for this. Checking for "ERR_SKIP" before checking for "OK" would maybe allow you to skip printing errors:
https://github.com/godotengine/godot/blob/c7b97f077a0f62d9e280adbddddc901f35e4f40f/editor/editor_file_system.cpp#L1781-L1783

As for the md5 error printed out if you return OK without saving anything, looks like dest_paths get filled with what it thinks will be the path. Then later the md5's are generated, giving an error, since that path doesn't exist. This section does skip dest_paths if the extension is empty. Would need to also skip when it gets ERR_SKIP or something.
https://github.com/godotengine/godot/blob/c7b97f077a0f62d9e280adbddddc901f35e4f40f/editor/editor_file_system.cpp#L1802-L1823
If not that, then the md5 section later could check for the file first or something. Regardless, that code seems like a decent entry point to figuring it out.

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

No branches or pull requests

2 participants