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

Slightly clean up externalizeUTWithJson #1531

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Miepee
Copy link
Contributor

@Miepee Miepee commented Nov 15, 2023

Description

See title

Caveats

I did not test this at all

Comment on lines -69 to -90
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1)
{
ImportGMLString("gml_Script_textdata_en", @"
if (variable_global_exists(""text_data_en""))
ds_map_destroy(global.text_data_en);
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_en.json"");");
ImportGMLString("gml_Script_textdata_ja", @"
if (variable_global_exists(""text_data_ja""))
ds_map_destroy(global.text_data_ja);
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_ja.json"");");
}
else
{
ImportGMLString("gml_Script_textdata_en", @"
if (variable_global_exists(""text_data_en""))
ds_map_destroy(global.text_data_en);
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_en.json"");");
ImportGMLString("gml_Script_textdata_ja", @"
if (variable_global_exists(""text_data_ja""))
ds_map_destroy(global.text_data_ja);
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_ja.json"");");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if ""\lang\\"" can be ""\lang\"" for GMS 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldnt matter.
it essentially wants to do program directory + \lang\ + lang_ja.json (or lang_en). Hence why I replaced it with a slash, as that then also works for all operating systems properly instead of just Windows. and these two paths program_directory/lang or program_directory/////lang are the same.

Comment on lines -157 to -216
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1)
// Undertale PC (GMS1)
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

// Undertale Switch/Probs other consoles (GMS2)
if (Data.GeneralInfo.Major >= 2)
{
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

pattern = @"\\";
replacement = @"\\";
input = Regex.Replace(input, pattern, replacement);

pattern = @""" \+ '""' \+ """;
replacement = @"\""";
input = Regex.Replace(input, pattern, replacement);


pattern = @"'""' \+ """;
replacement = @"""\""";
input = Regex.Replace(input, pattern, replacement);


pattern = @""" \+ '""'";
replacement = @"\""""";
input = Regex.Replace(input, pattern, replacement);


pattern = @"'""'";
replacement = @"\""";
input = Regex.Replace(input, pattern, replacement);


input = input.Replace(@"\"",", @"\"""",");

pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)";
replacement = @" $1: $2,";
input = Regex.Replace(input, pattern, replacement);

pattern = @",\n\Z";
replacement = "\n}";
input = Regex.Replace(input, pattern, replacement);

File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input);

IncProgressLocal();
UpdateProgressValue(GetProgress());
}
else // Undertale Switch/Probs other consoles (GMS2)
{
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)";
replacement = @" $1: $2,";
input = Regex.Replace(input, pattern, replacement);

pattern = @",\n\Z";
replacement = "\n}";
input = Regex.Replace(input, pattern, replacement);

File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question here as for lines 69-90

Miepee and others added 2 commits June 2, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants