1 /** 2 Creates packages that can be loaded into a running project. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.pckpacker; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.reference; 25 /** 26 Creates packages that can be loaded into a running project. 27 28 The $(D PCKPacker) is used to create packages that can be loaded into a running project using $(D ProjectSettings.loadResourcePack). 29 30 31 var packer = PCKPacker.new() 32 packer.pck_start("test.pck") 33 packer.add_file("res://text.txt", "text.txt") 34 packer.flush() 35 36 37 The above $(D PCKPacker) creates package `test.pck`, then adds a file named `text.txt` at the root of the package. 38 */ 39 @GodotBaseClass struct PCKPacker 40 { 41 package(godot) enum string _GODOT_internal_name = "PCKPacker"; 42 public: 43 @nogc nothrow: 44 union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; } 45 alias _GODOT_base this; 46 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 47 package(godot) __gshared bool _classBindingInitialized = false; 48 package(godot) static struct GDNativeClassBinding 49 { 50 __gshared: 51 @GodotName("add_file") GodotMethod!(GodotError, String, String) addFile; 52 @GodotName("flush") GodotMethod!(GodotError, bool) flush; 53 @GodotName("pck_start") GodotMethod!(GodotError, String, long) pckStart; 54 } 55 /// 56 pragma(inline, true) bool opEquals(in PCKPacker other) const 57 { return _godot_object.ptr is other._godot_object.ptr; } 58 /// 59 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 60 { _godot_object.ptr = n; return null; } 61 /// 62 pragma(inline, true) bool opEquals(typeof(null) n) const 63 { return _godot_object.ptr is n; } 64 /// 65 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 66 mixin baseCasts; 67 /// Construct a new instance of PCKPacker. 68 /// Note: use `memnew!PCKPacker` instead. 69 static PCKPacker _new() 70 { 71 static godot_class_constructor constructor; 72 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PCKPacker"); 73 if(constructor is null) return typeof(this).init; 74 return cast(PCKPacker)(constructor()); 75 } 76 @disable new(size_t s); 77 /** 78 Adds the `source_path` file to the current PCK package at the `pck_path` internal path (should start with `res://`). 79 */ 80 GodotError addFile(in String pck_path, in String source_path) 81 { 82 checkClassBinding!(typeof(this))(); 83 return ptrcall!(GodotError)(GDNativeClassBinding.addFile, _godot_object, pck_path, source_path); 84 } 85 /** 86 Writes the files specified using all $(D addFile) calls since the last flush. If `verbose` is `true`, a list of files added will be printed to the console for easier debugging. 87 */ 88 GodotError flush(in bool verbose = false) 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(GodotError)(GDNativeClassBinding.flush, _godot_object, verbose); 92 } 93 /** 94 Creates a new PCK file with the name `pck_name`. The `.pck` file extension isn't added automatically, so it should be part of `pck_name` (even though it's not required). 95 */ 96 GodotError pckStart(in String pck_name, in long alignment = 0) 97 { 98 checkClassBinding!(typeof(this))(); 99 return ptrcall!(GodotError)(GDNativeClassBinding.pckStart, _godot_object, pck_name, alignment); 100 } 101 }