summaryrefslogtreecommitdiff
path: root/editor/editor_builders.py
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_builders.py')
-rw-r--r--editor/editor_builders.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/editor/editor_builders.py b/editor/editor_builders.py
index 910c53e2ff..ea32e24f6e 100644
--- a/editor/editor_builders.py
+++ b/editor/editor_builders.py
@@ -6,26 +6,26 @@ All such functions are invoked in a subprocess on Windows to prevent build flaki
import os
import os.path
from platform_methods import subprocess_main
-from compat import encode_utf8, byte_to_str, open_utf8
def make_doc_header(target, source, env):
dst = target[0]
- g = open_utf8(dst, "w")
+ g = open(dst, "w", encoding="utf-8")
buf = ""
docbegin = ""
docend = ""
for src in source:
if not src.endswith(".xml"):
continue
- with open_utf8(src, "r") as f:
+ with open(src, "r", encoding="utf-8") as f:
content = f.read()
buf += content
- buf = encode_utf8(docbegin + buf + docend)
+ buf = (docbegin + buf + docend).encode("utf-8")
decomp_size = len(buf)
import zlib
+
buf = zlib.compress(buf)
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
@@ -35,7 +35,7 @@ def make_doc_header(target, source, env):
g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n")
g.write("static const unsigned char _doc_data_compressed[] = {\n")
for i in range(len(buf)):
- g.write("\t" + byte_to_str(buf[i]) + ",\n")
+ g.write("\t" + str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")
@@ -47,7 +47,7 @@ def make_fonts_header(target, source, env):
dst = target[0]
- g = open_utf8(dst, "w")
+ g = open(dst, "w", encoding="utf-8")
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _EDITOR_FONTS_H\n")
@@ -56,7 +56,7 @@ def make_fonts_header(target, source, env):
# saving uncompressed, since freetype will reference from memory pointer
xl_names = []
for i in range(len(source)):
- with open(source[i], "rb")as f:
+ with open(source[i], "rb") as f:
buf = f.read()
name = os.path.splitext(os.path.basename(source[i]))[0]
@@ -64,7 +64,7 @@ def make_fonts_header(target, source, env):
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
g.write("static const unsigned char _font_" + name + "[] = {\n")
for j in range(len(buf)):
- g.write("\t" + byte_to_str(buf[j]) + ",\n")
+ g.write("\t" + str(buf[j]) + ",\n")
g.write("};\n")
@@ -73,15 +73,15 @@ def make_fonts_header(target, source, env):
g.close()
-def make_translations_header(target, source, env):
+def make_translations_header(target, source, env, category):
dst = target[0]
- g = open_utf8(dst, "w")
+ g = open(dst, "w", encoding="utf-8")
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
- g.write("#ifndef _EDITOR_TRANSLATIONS_H\n")
- g.write("#define _EDITOR_TRANSLATIONS_H\n")
+ g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
+ g.write("#define _{}_TRANSLATIONS_H\n".format(category.upper()))
import zlib
import os.path
@@ -96,29 +96,40 @@ def make_translations_header(target, source, env):
buf = zlib.compress(buf)
name = os.path.splitext(os.path.basename(sorted_paths[i]))[0]
- g.write("static const unsigned char _translation_" + name + "_compressed[] = {\n")
+ g.write("static const unsigned char _{}_translation_{}_compressed[] = {{\n".format(category, name))
for j in range(len(buf)):
- g.write("\t" + byte_to_str(buf[j]) + ",\n")
+ g.write("\t" + str(buf[j]) + ",\n")
g.write("};\n")
xl_names.append([name, len(buf), str(decomp_size)])
- g.write("struct EditorTranslationList {\n")
+ g.write("struct {}TranslationList {{\n".format(category.capitalize()))
g.write("\tconst char* lang;\n")
g.write("\tint comp_size;\n")
g.write("\tint uncomp_size;\n")
g.write("\tconst unsigned char* data;\n")
g.write("};\n\n")
- g.write("static EditorTranslationList _editor_translations[] = {\n")
+ g.write("static {}TranslationList _{}_translations[] = {{\n".format(category.capitalize(), category))
for x in xl_names:
- g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ", _translation_" + x[0] + "_compressed},\n")
- g.write("\t{NULL, 0, 0, NULL}\n")
+ g.write(
+ '\t{{ "{}", {}, {}, _{}_translation_{}_compressed }},\n'.format(x[0], str(x[1]), str(x[2]), category, x[0])
+ )
+ g.write("\t{nullptr, 0, 0, nullptr}\n")
g.write("};\n")
g.write("#endif")
g.close()
-if __name__ == '__main__':
+
+def make_editor_translations_header(target, source, env):
+ make_translations_header(target, source, env, "editor")
+
+
+def make_doc_translations_header(target, source, env):
+ make_translations_header(target, source, env, "doc")
+
+
+if __name__ == "__main__":
subprocess_main(globals())