import os import glob import shutil from pathlib import Path # Simple Script to generate/update Assets license_text = "/**\n* This file is part of RenderD7\n* Copyright (C) 2021-2024 NPI-D7, tobid7\n*\n* This program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation, either version 3 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program. If not, see .\n*/\n\n" def file2array(path, custom_incluse_path): print(path) cip = len(custom_incluse_path) sip = '' if cip > 0: sip = custom_incluse_path name = Path(path).stem filei = open(path, 'rb') buf = filei.read() filei.close() fs = open(name + '.cpp', 'w') fs.write(license_text) fs.write("// THIS FILE WAS GENERATED BY generate_assets.py!!!\n\n") fs.write('#include <'+ sip + name + '.hpp>\n\n') fs.write('// clang-format off\n') fs.write('unsigned char ' + name + '[] = {\n') for byte in buf: fs.write(hex(byte) + ', ') fs.write('\n};\n') fs.write('// clang-format on\n') fs.write('size_t ' + name + '_size = ' + hex(len(buf)) + ';') fs.close() fh = open(name + '.hpp', 'w') fh.write(license_text) fh.write("// THIS FILE WAS GENERATED BY generate_assets.py!!!\n\n") fh.write('#pragma once\n\n') fh.write('#include \n\n') fh.write('extern unsigned char ' + name + '[];\n') fh.write('extern size_t ' + name + '_size;') fh.close() def tex3ds_build(path): p = os.path.dirname(path) n = Path(path).stem os.system('tex3ds -o ' + p + '/' + n + '.t3x -i ' + path) def cleanup(): t3x = glob.glob('assets/resources/*.t3x') for f in t3x: os.remove(f) def install_code(what, where): if Path(what).is_dir: os.error('Must be a file!!!') shutil.move(what, where + Path(what).name) print("Generating...") t3xtg = glob.glob('assets/resources/*.t3s') for object in t3xtg: name = Path(object).stem bp = os.path.dirname(object) tex3ds_build(object) file2array(bp + '/' + name + '.t3x', 'renderd7/') install_code(name + '.cpp', 'source/') install_code(name + '.hpp', 'include/renderd7/') cleanup() print("Done")