0.2.0-dev Download ZIP
44 lines ·1.6 KB Raw
| 1 | import methods |
| 2 | |
| 3 | |
| 4 | def run(target, source, env): |
| 5 | buffer = methods.get_buffer(str(source[0])) |
| 6 | decomp_size = len(buffer) |
| 7 | buffer = methods.compress_buffer_zstd(buffer, env) |
| 8 | |
| 9 | with methods.generated_wrapper(str(target[0])) as file: |
| 10 | file.write(f"""\ |
| 11 | #ifdef TOOLS_ENABLED |
| 12 | |
| 13 | #include "core/io/compression.h" |
| 14 | #include "core/io/file_access.h" |
| 15 | #include "core/string/ustring.h" |
| 16 | |
| 17 | inline constexpr int _gdextension_interface_data_compressed_size = {len(buffer)}; |
| 18 | inline constexpr int _gdextension_interface_data_uncompressed_size = {decomp_size}; |
| 19 | inline constexpr unsigned char _gdextension_interface_data_compressed[] = {{ |
| 20 | {methods.format_buffer(buffer, 1)} |
| 21 | }}; |
| 22 | |
| 23 | class GDExtensionInterfaceDump {{ |
| 24 | public: |
| 25 | static Vector<uint8_t> load_gdextension_interface_file() {{ |
| 26 | Vector<uint8_t> data; |
| 27 | data.resize(_gdextension_interface_data_uncompressed_size); |
| 28 | int ret = Compression::decompress(data.ptrw(), _gdextension_interface_data_uncompressed_size, _gdextension_interface_data_compressed, _gdextension_interface_data_compressed_size, Compression::MODE_ZSTD); |
| 29 | ERR_FAIL_COND_V_MSG(ret == -1, Vector<uint8_t>(), "Compressed file is corrupt."); |
| 30 | return data; |
| 31 | }} |
| 32 | |
| 33 | static void generate_gdextension_interface_file(const String &p_path) {{ |
| 34 | Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE); |
| 35 | ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path)); |
| 36 | Vector<uint8_t> data = load_gdextension_interface_file(); |
| 37 | if (data.size() > 0) {{ |
| 38 | fa->store_buffer(data.ptr(), data.size()); |
| 39 | }} |
| 40 | }} |
| 41 | }}; |
| 42 | |
| 43 | #endif // TOOLS_ENABLED |
| 44 | """) |