1 /**
2 An abstraction of a serialized scene.
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.packedscene;
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.classdb;
23 import godot.resource;
24 import godot.node;
25 import godot.scenestate;
26 import godot.reference;
27 /**
28 An abstraction of a serialized scene.
29 
30 A simplified interface to a scene file. Provides access to operations and checks that can be performed on the scene resource itself.
31 Can be used to save a node to a file. When saving, the node as well as all the node it owns get saved (see `owner` property on $(D Node)). Note that the node doesn't need to own itself.
32 Example of saving a node with different owners: The following example creates 3 objects: `Node2D` (`node`), `RigidBody2D` (`rigid`) and `CollisionObject2D` (`collision`). `collision` is a child of `rigid` which is a child of `node`. Only `rigid` is owned by `node` and `pack` will therefore only save those two nodes, but not `collision`.
33 
34 
35 # create the objects
36 var node = Node2D.new()
37 var rigid = RigidBody2D.new()
38 var collision = CollisionShape2D.new()
39 
40 # create the object hierachy
41 rigid.add_child(collision)
42 node.add_child(rigid)
43 
44 # change owner of rigid, but not of collision
45 rigid.set_owner(node)
46 
47 var scene = PackedScene.new()
48 # only node and rigid are now packed
49 var result = scene.pack(node)
50 if result == OK:
51     ResourceSaver.save("res://path/name.scn", scene) # or user://...
52 
53 
54 */
55 @GodotBaseClass struct PackedScene
56 {
57 	enum string _GODOT_internal_name = "PackedScene";
58 public:
59 @nogc nothrow:
60 	union { godot_object _godot_object; Resource _GODOT_base; }
61 	alias _GODOT_base this;
62 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
63 	package(godot) __gshared bool _classBindingInitialized = false;
64 	package(godot) static struct _classBinding
65 	{
66 		__gshared:
67 		@GodotName("pack") GodotMethod!(GodotError, GodotObject) pack;
68 		@GodotName("instance") GodotMethod!(Node, long) instance;
69 		@GodotName("can_instance") GodotMethod!(bool) canInstance;
70 		@GodotName("_set_bundled_scene") GodotMethod!(void, Dictionary) _setBundledScene;
71 		@GodotName("_get_bundled_scene") GodotMethod!(Dictionary) _getBundledScene;
72 		@GodotName("get_state") GodotMethod!(SceneState) getState;
73 	}
74 	bool opEquals(in PackedScene other) const { return _godot_object.ptr is other._godot_object.ptr; }
75 	PackedScene opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
76 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
77 	mixin baseCasts;
78 	static PackedScene _new()
79 	{
80 		static godot_class_constructor constructor;
81 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PackedScene");
82 		if(constructor is null) return typeof(this).init;
83 		return cast(PackedScene)(constructor());
84 	}
85 	@disable new(size_t s);
86 	/// 
87 	enum GenEditState : int
88 	{
89 		/**
90 		If passed to $(D instance), blocks edits to the scene state.
91 		*/
92 		genEditStateDisabled = 0,
93 		/**
94 		If passed to $(D instance), provides local scene resources to the local scene. Requires tools compiled.
95 		*/
96 		genEditStateInstance = 1,
97 		/**
98 		If passed to $(D instance), provides local scene resources to the local scene. Only the main scene should receive the main edit state. Requires tools compiled.
99 		*/
100 		genEditStateMain = 2,
101 	}
102 	/// 
103 	enum Constants : int
104 	{
105 		genEditStateDisabled = 0,
106 		genEditStateInstance = 1,
107 		genEditStateMain = 2,
108 	}
109 	/**
110 	Pack will ignore any sub-nodes not owned by given node. See $(D Node.setOwner).
111 	*/
112 	GodotError pack(GodotObject path)
113 	{
114 		checkClassBinding!(typeof(this))();
115 		return ptrcall!(GodotError)(_classBinding.pack, _godot_object, path);
116 	}
117 	/**
118 	Instantiates the scene's node hierarchy. Triggers child scene instantiation(s). Triggers $(D Node)'s `NOTIFICATION_INSTANCED` notification on the root node.
119 	*/
120 	Node instance(in long edit_state = 0) const
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(Node)(_classBinding.instance, _godot_object, edit_state);
124 	}
125 	/**
126 	Returns `true` if the scene file has nodes.
127 	*/
128 	bool canInstance() const
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(bool)(_classBinding.canInstance, _godot_object);
132 	}
133 	/**
134 	
135 	*/
136 	void _setBundledScene(in Dictionary arg0)
137 	{
138 		Array _GODOT_args = Array.empty_array;
139 		_GODOT_args.append(arg0);
140 		String _GODOT_method_name = String("_set_bundled_scene");
141 		this.callv(_GODOT_method_name, _GODOT_args);
142 	}
143 	/**
144 	
145 	*/
146 	Dictionary _getBundledScene() const
147 	{
148 		Array _GODOT_args = Array.empty_array;
149 		String _GODOT_method_name = String("_get_bundled_scene");
150 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary);
151 	}
152 	/**
153 	Returns the `SceneState` representing the scene file contents.
154 	*/
155 	Ref!SceneState getState()
156 	{
157 		checkClassBinding!(typeof(this))();
158 		return ptrcall!(SceneState)(_classBinding.getState, _godot_object);
159 	}
160 	/**
161 	A dictionary representation of the scene contents.
162 	Available keys include "rnames" and "variants" for resources, "node_count", "nodes", "node_paths" for nodes, "editable_instances" for base scene children overrides, "conn_count" and "conns" for signal connections, and "version" for the format style of the PackedScene.
163 	*/
164 	@property Dictionary _bundled()
165 	{
166 		return _getBundledScene();
167 	}
168 	/// ditto
169 	@property void _bundled(Dictionary v)
170 	{
171 		_setBundledScene(v);
172 	}
173 }