#!/usr/bin/python3 import os import sys import subprocess import os.path as path import shutil from glob import glob olddir = os.curdir print("Entering assets directory to begin asset conversion...") os.chdir(path.realpath(path.dirname(__file__))) ASSETS = [] def run_btcc(args: list[str], outpath: str): with open(outpath + ".h", "wt+") as f: actual_args = ["./btcc"] for arg in args: actual_args += [arg] actual_args += [outpath] subprocess.call(actual_args, stdout=f) def add_basic(input: str, output: str, ASSETS = ASSETS): ASSETS += [output + ".h"] run_btcc(["-nocompress", input], output) def add_base85(input: str, output: str, ASSETS = ASSETS): ASSETS += [output + ".h"] run_btcc(["-base85", input], output) def add_font(input: str, output: str|None = None): if output == None: FONT=path.basename(input).removesuffix(".ttf").lower().replace('-', '_') else: FONT=output print("Adding font '%s' from file '%s'" % (FONT, path.abspath(input))) add_base85(input, FONT) def add_graphic(input: str): GRAPHIC=path.basename(input).removesuffix(".png").lower().replace('-', '_') print("Adding graphic '%s' from file '%s'" % (GRAPHIC, input)) add_base85(input, GRAPHIC) def add_license(input: str, output: str): LICENSE = output + "_license" print("Adding license '%s' (C identifier: '%s') from file '%s'" % (output, LICENSE, input)) add_basic(input, LICENSE) def compile_program(file: str, output: str): print("Compiling file '%s' to '%s'" % (path.abspath(file), path.abspath(output))) subprocess.call([os.environ.get("CXX", "c++"), file, "-o", output]) def add_css(file: str, output: str): CSS_FILE = output + ".h" print("Adding CSS file '%s' (C identifier '%s') from file '%s'" % (file, output, CSS_FILE)) add_basic(file, output) compile_program("../backends/ui/imgui/imgui/misc/fonts/binary_to_compressed_c.cpp", "btcc") for i in glob("Noto_Sans/*.ttf"): add_font(i) for i in glob("Noto_Sans_JP/*.ttf"): add_font(i) add_font("forkawesome-webfont.ttf", "forkawesome") add_graphic("icon.png") add_license("Noto_Sans/OFL.txt", "notosans") add_license("Noto_Sans_JP/OFL.txt", "notosansjp") add_license("../LICENSE.MIT", "looper_mit") add_license("../LICENSE.GPL", "looper_gpl") add_license("../COPYING.md", "looper") add_license("../subprojects/jsoncpp/LICENSE", "jsoncpp") add_license("../subprojects/SDL-Mixer-X/COPYING.txt", "sdl_mixer_x") add_license("../backends/ui/imgui/imgui-filebrowser/LICENSE", "imgui_filebrowser") add_license("../backends/ui/imgui/imgui/LICENSE.txt", "imgui") add_license("licenses/lgpl-3.0.txt", "lgpl_3_0") add_license("licenses/lgpl-2.1.txt", "lgpl_2_1") add_license("licenses/lgpl-2.0.txt", "lgpl_2_0") add_license("licenses/ForkAwesome.txt", "forkawesome") add_license("licenses/cli11.txt", "cli11") add_license("licenses/TomlPlusPlus.txt", "tomlplusplus") add_license("../backends/ui/imgui/IconFontCppHeaders/licence.txt", "icnfntcpphdrs") add_css("gtk-frontend.css", "gtk_frontend_css") def finalize(output: str, ASSETS = ASSETS): print("Writing a header including all previous asset headers and writing it to '%s'..." % output) with open(output, "wt+") as f: f.write("#pragma once\n") for asset in ASSETS: print("Adding include for '%s'..." % (asset)) f.write("#include \"%s\"\n" % asset) ASSETS = [] finalize("assets.h") os.remove("btcc") print("Returning to previous directory, now that we're done!") os.chdir(olddir)