1 /** 2 Placeholder for the root $(D Node) of a $(D PackedScene). 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.instanceplaceholder; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.node; 23 import godot.packedscene; 24 /** 25 Placeholder for the root $(D Node) of a $(D PackedScene). 26 27 Turning on the option $(B Load As Placeholder) for an instanced scene in the editor causes it to be replaced by an InstancePlaceholder when running the game. This makes it possible to delay actually loading the scene until calling $(D replaceByInstance). This is useful to avoid loading large scenes all at once by loading parts of it selectively. 28 The InstancePlaceholder does not have a transform. This causes any child nodes to be positioned relatively to the Viewport from point (0,0), rather than their parent as displayed in the editor. Replacing the placeholder with a scene with a transform will transform children relatively to their parent again. 29 */ 30 @GodotBaseClass struct InstancePlaceholder 31 { 32 enum string _GODOT_internal_name = "InstancePlaceholder"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; Node _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("get_stored_values") GodotMethod!(Dictionary, bool) getStoredValues; 43 @GodotName("create_instance") GodotMethod!(Node, bool, PackedScene) createInstance; 44 @GodotName("replace_by_instance") GodotMethod!(void, PackedScene) replaceByInstance; 45 @GodotName("get_instance_path") GodotMethod!(String) getInstancePath; 46 } 47 bool opEquals(in InstancePlaceholder other) const { return _godot_object.ptr is other._godot_object.ptr; } 48 InstancePlaceholder opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 49 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 50 mixin baseCasts; 51 static InstancePlaceholder _new() 52 { 53 static godot_class_constructor constructor; 54 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InstancePlaceholder"); 55 if(constructor is null) return typeof(this).init; 56 return cast(InstancePlaceholder)(constructor()); 57 } 58 @disable new(size_t s); 59 /** 60 61 */ 62 Dictionary getStoredValues(in bool with_order = false) 63 { 64 checkClassBinding!(typeof(this))(); 65 return ptrcall!(Dictionary)(_classBinding.getStoredValues, _godot_object, with_order); 66 } 67 /** 68 69 */ 70 Node createInstance(in bool replace = false, PackedScene custom_scene = PackedScene.init) 71 { 72 checkClassBinding!(typeof(this))(); 73 return ptrcall!(Node)(_classBinding.createInstance, _godot_object, replace, custom_scene); 74 } 75 /** 76 Replace this placeholder by the scene handed as an argument, or the original scene if no argument is given. As for all resources, the scene is loaded only if it's not loaded already. By manually loading the scene beforehand, delays caused by this function can be avoided. 77 */ 78 void replaceByInstance(PackedScene custom_scene = PackedScene.init) 79 { 80 checkClassBinding!(typeof(this))(); 81 ptrcall!(void)(_classBinding.replaceByInstance, _godot_object, custom_scene); 82 } 83 /** 84 Retrieve the path to the $(D PackedScene) resource file that is loaded by default when calling $(D replaceByInstance). 85 */ 86 String getInstancePath() const 87 { 88 checkClassBinding!(typeof(this))(); 89 return ptrcall!(String)(_classBinding.getInstancePath, _godot_object); 90 } 91 }