Skip to content

Commit

Permalink
Use a different strategy for path remaps, try loading from a remap fi…
Browse files Browse the repository at this point in the history
…le instead.

This ensures multiple PCK exports still work.
  • Loading branch information
reduz committed Dec 18, 2017
1 parent d9f7fa4 commit b3a1bf3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
44 changes: 44 additions & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "print_string.h"
#include "project_settings.h"
#include "translation.h"
#include "variant_parser.h"
ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS];

int ResourceLoader::loader_count = 0;
Expand Down Expand Up @@ -454,6 +455,49 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
if (path_remaps.has(new_path)) {
new_path = path_remaps[new_path];
}

if (new_path == p_path) { //did not remap
//try file remap
Error err;
FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err);

if (f) {

VariantParser::StreamFile stream;
stream.f = f;

String assign;
Variant value;
VariantParser::Tag next_tag;

int lines = 0;
String error_text;
while (true) {

assign = Variant();
next_tag.fields.clear();
next_tag.name = String();

err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
if (err == ERR_FILE_EOF) {
break;
} else if (err != OK) {
ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text);
break;
}

if (assign == "path") {
new_path = value;
break;
} else if (next_tag.name != "remap") {
break;
}
}

memdelete(f);
}
}

return new_path;
}

Expand Down
19 changes: 18 additions & 1 deletion editor/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,24 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &

ProjectSettings::CustomMap custom_map;
if (path_remaps.size()) {
custom_map["path_remap/remapped_paths"] = path_remaps;
if (1) { //new remap mode, use always as it's friendlier with multiple .pck exports

This comment has been minimized.

Copy link
@Sslaxx

Sslaxx Dec 18, 2017

1 is always true, isn't it? So the else statement never executes.

This comment has been minimized.

Copy link
@akien-mga

akien-mga Dec 18, 2017

Member

Well the comments explain it all.

This comment has been minimized.

Copy link
@akien-mga

akien-mga Dec 18, 2017

Member

But yeah it might have been just as well to just drop the old code and keep only the new one.

This comment has been minimized.

Copy link
@Sslaxx

Sslaxx Dec 18, 2017

I got the comments, but they made no sense to me due to the "else" statement being present.

This comment has been minimized.

Copy link
@akien-mga

akien-mga Dec 18, 2017

Member

Well it means that if you want to use the old code, you can change 1 to 0.

This comment has been minimized.

Copy link
@Sslaxx

Sslaxx Dec 18, 2017

Assuming there'd be a reason to want to do it the old way, wouldn't it be better served as some kind of editor/project setting?

This comment has been minimized.

Copy link
@reduz

reduz Dec 18, 2017

Author Member

It's there because I'm not certain there is a reason yet and feature needs to be tested. If there isn't, it will eventually be removed.

for (int i = 0; i < path_remaps.size(); i += 2) {
String from = path_remaps[i];
String to = path_remaps[i + 1];
String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
CharString utf8 = remap_file.utf8();
Vector<uint8_t> new_file;
new_file.resize(utf8.length());
for (int j = 0; j < utf8.length(); j++) {
new_file[j] = utf8[j];
}

p_func(p_udata, from + ".remap", new_file, idx, total);
}
} else {
//old remap mode, will still work, but it's unused because it's not multiple pck export friendly
custom_map["path_remap/remapped_paths"] = path_remaps;
}
}

// Store icon and splash images directly, they need to bypass the import system and be loaded as images
Expand Down

0 comments on commit b3a1bf3

Please sign in to comment.