1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

SCons: Make builders prettier, utilize constexpr

This commit is contained in:
Thaddeus Crews
2024-10-29 14:23:08 -05:00
parent 7893202fba
commit be429eb404
21 changed files with 510 additions and 723 deletions

View File

@@ -1,60 +1,42 @@
"""Functions used to generate source files during build time"""
import methods
def make_splash(target, source, env):
src = str(source[0])
dst = str(target[0])
buffer = methods.get_buffer(str(source[0]))
with open(src, "rb") as f:
buf = f.read()
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef BOOT_SPLASH_H\n")
g.write("#define BOOT_SPLASH_H\n")
with methods.generated_wrapper(str(target[0])) as file:
# Use a neutral gray color to better fit various kinds of projects.
g.write("static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);\n")
g.write("static const unsigned char boot_splash_png[] = {\n")
for i in range(len(buf)):
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")
file.write(f"""\
static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);
inline constexpr const unsigned char boot_splash_png[] = {{
{methods.format_buffer(buffer, 1)}
}};
""")
def make_splash_editor(target, source, env):
src = str(source[0])
dst = str(target[0])
buffer = methods.get_buffer(str(source[0]))
with open(src, "rb") as f:
buf = f.read()
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef BOOT_SPLASH_EDITOR_H\n")
g.write("#define BOOT_SPLASH_EDITOR_H\n")
with methods.generated_wrapper(str(target[0])) as file:
# The editor splash background color is taken from the default editor theme's background color.
# This helps achieve a visually "smoother" transition between the splash screen and the editor.
g.write("static const Color boot_splash_editor_bg_color = Color(0.125, 0.145, 0.192);\n")
g.write("static const unsigned char boot_splash_editor_png[] = {\n")
for i in range(len(buf)):
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")
file.write(f"""\
static const Color boot_splash_editor_bg_color = Color(0.125, 0.145, 0.192);
inline constexpr const unsigned char boot_splash_editor_png[] = {{
{methods.format_buffer(buffer, 1)}
}};
""")
def make_app_icon(target, source, env):
src = str(source[0])
dst = str(target[0])
buffer = methods.get_buffer(str(source[0]))
with open(src, "rb") as f:
buf = f.read()
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef APP_ICON_H\n")
g.write("#define APP_ICON_H\n")
g.write("static const unsigned char app_icon_png[] = {\n")
for i in range(len(buf)):
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")
with methods.generated_wrapper(str(target[0])) as file:
# Use a neutral gray color to better fit various kinds of projects.
file.write(f"""\
inline constexpr const unsigned char app_icon_png[] = {{
{methods.format_buffer(buffer, 1)}
}};
""")