-
Notifications
You must be signed in to change notification settings - Fork 247
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,19 +10,16 @@ int maxCount = 1; | |
|
||
EnsureDataLoaded(); | ||
|
||
if (Data?.GeneralInfo?.DisplayName?.Content.ToLower() == "deltarune chapter 1 & 2") | ||
var displayName = Data.GeneralInfo?.DisplayName?.Content.ToLower(); | ||
|
||
if (displayName == "deltarune chapter 1 & 2" || displayName == "deltarune chapter 1&2") | ||
{ | ||
ScriptError("Error 0: Incompatible with the new Deltarune Chapter 1 & 2 demo"); | ||
return; | ||
} | ||
else if (Data?.GeneralInfo?.DisplayName?.Content.ToLower() == "deltarune chapter 1&2") | ||
{ | ||
ScriptError("Error 1: Incompatible with the new Deltarune Chapter 1 & 2 demo"); | ||
return; | ||
} | ||
|
||
|
||
string langFolder = GetFolder(FilePath) + "lang" + Path.DirectorySeparatorChar; | ||
string langFolder = Path.Combine(Path.GetDirectoryName(FilePath), "lang"); | ||
ThreadLocal<GlobalDecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<GlobalDecompileContext>(() => new GlobalDecompileContext(Data, false)); | ||
|
||
if (Directory.Exists(langFolder)) | ||
|
@@ -58,44 +55,27 @@ void IncProgressLocal() | |
IncrementProgress(); | ||
} | ||
|
||
string GetFolder(string path) { | ||
return Path.GetDirectoryName(path) + Path.DirectorySeparatorChar; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
ImportGMLString("gml_Script_scr_change_language", @""); | ||
ImportGMLString("gml_Script_scr_84_load_map_json", @""); | ||
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"");"); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// 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"");"); | ||
|
||
////////////////////////////////////////////////////// | ||
|
||
Data.GameObjects.ByName("obj_time").EventHandlerFor(EventType.KeyPress, EventSubtypeKey.vk_f11, Data.Strings, Data.Code, Data.CodeLocals).ReplaceGML(@" | ||
scr_change_language() | ||
", Data); | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
Data.GameObjects.ByName("obj_time").EventHandlerFor(EventType.KeyPress, EventSubtypeKey.vk_f12, Data.Strings, Data.Code, Data.CodeLocals).ReplaceGML(@" | ||
if (global.language == ""en"") | ||
|
@@ -104,10 +84,10 @@ else | |
textdata_ja() | ||
", Data); | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
ImportGMLString("gml_Script_scr_change_language", @" | ||
//Read the language from the INI file | ||
ImportGMLString("gml_Script_scr_change_language", @" | ||
// Read the language from the INI file | ||
if (global.language == ""en"") | ||
global.language = ""ja"" | ||
else | ||
|
@@ -117,9 +97,9 @@ ini_write_string(""General"", ""lang"", global.language) | |
ossafe_ini_close() | ||
"); | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
ImportGMLString("gml_Script_scr_84_load_map_json", @" | ||
ImportGMLString("gml_Script_scr_84_load_map_json", @" | ||
var filename = argument0 | ||
var file = file_text_open_read(filename) | ||
var json = """" | ||
|
@@ -132,14 +112,14 @@ return json_decode(json); | |
HideProgressBar(); | ||
ScriptMessage("Complete."); | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
void DumpJSON(string language) | ||
{ | ||
var lang_file = Data.Code.ByName("gml_Script_textdata_" + language); | ||
try | ||
{ | ||
File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), (lang_file != null ? Decompiler.Decompile(lang_file, DECOMPILE_CONTEXT.Value) : "")); | ||
File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), (lang_file is not null ? Decompiler.Decompile(lang_file, DECOMPILE_CONTEXT.Value) : "")); | ||
} | ||
catch (Exception e) | ||
{ | ||
|
@@ -150,72 +130,49 @@ void DumpJSON(string language) | |
UpdateProgressValue(GetProgress()); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
////////////////////////////////////////////////////// | ||
|
||
void MakeJSON(string language) | ||
{ | ||
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); | ||
Comment on lines
-157
to
-216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question here as for lines 69-90 |
||
|
||
IncProgressLocal(); | ||
UpdateProgressValue(GetProgress()); | ||
} | ||
} | ||
|
||
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()); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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 pathsprogram_directory/lang
orprogram_directory/////lang
are the same.