1 /++
2 Attributes for specifying how Godot-D should register the marked classes,
3 properties, methods, and signals into Godot.
4 +/
5 module godot.d.udas;
6 
7 import godot.core, godot.c;
8 import godot.d.traits;
9 
10 import std.meta, std.traits;
11 
12 /++
13 A UDA to enable a script class to run in the Godot editor even without the game
14 running. Required for $(D EditorPlugin)s and other tools used in the editor.
15 +/
16 enum Tool;
17 
18 /// 
19 enum RPCMode
20 {
21 	disabled,
22 	remote,
23 	sync,
24 	master,
25 	slave,
26 }
27 
28 /++
29 A UDA to change the Godot name of a method, property, or signal. Useful for
30 overloads, which D supports but Godot does not.
31 +/
32 struct Rename
33 {
34 	string name;
35 }
36 
37 /++
38 A UDA to mark a method that should be registered into Godot
39 +/
40 struct Method
41 {
42 	RPCMode rpcMode = RPCMode.disabled;
43 }
44 
45 /++
46 A UDA to mark a signal. The signal should be a static function/delegate
47 variable that defines the signal's arguments.
48 +/
49 struct Signal { }
50 
51 /++
52 
53 +/
54 struct OnReady(alias arg)
55 {
56 	
57 }
58 
59 /++
60 A UDA to mark a public variable OR accessor methods as a property in Godot.
61 
62 Using just the type as a UDA uses default configuration. The UDA can also be
63 constructed at compile-time to customize how the property should be registered
64 into Godot.
65 +/
66 struct Property
67 {
68 	/// 
69 	enum Hint
70 	{
71 		none, /// no hint provided.
72 		range, /// hintText = "min,max,step,slider; //slider is optional"
73 		expRange, /// hintText = "min,max,step", exponential edit
74 		enumType, /// hintText= "val1,val2,val3,etc"
75 		expEasing, /// exponential easing funciton (math::ease)
76 		length, /// hintText= "length" (as integer)
77 		spriteFrame,
78 		keyAccel, /// hintText= "length" (as integer)
79 		flags, /// hintText= "flag1,flag2,etc" (as bit flags)
80 		layers2DRender,
81 		layers2DPhysics,
82 		layers3DRender,
83 		layers3DPhysics,
84 		file, /// a file path must be passed, hintText (optionally) is a filter "*.png,*.wav,*.doc,"
85 		dir, /// a directort path must be passed
86 		globalFile, /// a file path must be passed, hintText (optionally) is a filter "*.png,*.wav,*.doc,"
87 		globalDir, /// a directort path must be passed
88 		resourceType, /// a resource object type
89 		multilineText, /// used for string properties that can contain multiple lines
90 		colorNoAlpha, /// used for ignoring alpha component when editing a color
91 		imageCompressLossy,
92 		imageCompressLossless,
93 		objectId,
94 		typeString, /// a type string, the hint is the base type to choose
95 		nodePathToEditedNode, /// so something else can provide this (used in scripts)
96 		methodOfVariantType, /// a method of a type
97 		methodOfBaseType, /// a method of a base type
98 		methodOfInstance, /// a method of an instance
99 		methodOfScript, /// a method of a script & base
100 		propertyOfVariantType, /// a property of a type
101 		propertyOfBaseType, /// a property of a base type
102 		propertyOfInstance, /// a property of an instance
103 		propertyOfScript, /// a property of a script & base
104 	}
105 	
106 	/// 
107 	enum Usage
108 	{
109 		storage = 1,
110 		editor = 2,
111 		network = 4,
112 		editorHelper = 8,
113 		checkable = 16, /// used for editing global variables
114 		checked = 32, /// used for editing global variables
115 		internationalized = 64, /// hint for internationalized strings
116 		group = 128, /// used for grouping props in the editor
117 		category = 256,
118 		storeIfNonZero = 512, /// only store if nonzero
119 		storeIfNonOne = 1024, /// only store if false
120 		noInstanceState = 2048,
121 		restartIfChanged = 4096,
122 		scriptVariable = 8192,
123 		storeIfNull = 16384,
124 		animateAsTrigger = 32768,
125 		updateAllIfModified = 65536,
126 		
127 		defaultUsage = storage | editor | network, /// storage | editor | network
128 		defaultIntl = storage | editor | network | internationalized, /// storage | editor | network | internationalized
129 		noEditor = storage | network, /// storage | network
130 	}
131 	
132 	Hint hint = Hint.none; /// 
133 	string hintString = null; /// 
134 	Usage usage = Usage.defaultUsage; /// 
135 	RPCMode rpcMode = RPCMode.disabled; /// 
136 	
137 	/// 
138 	this(Hint hint, string hintString = null, Usage usage = Usage.defaultUsage,
139 		RPCMode rpcMode = RPCMode.disabled)
140 	{
141 		this.hint = hint;
142 		this.hintString = hintString;
143 		this.usage = usage;
144 		this.rpcMode = rpcMode;
145 	}
146 	
147 	/// 
148 	this(Usage usage, Hint hint = Hint.none, string hintString = null,
149 		RPCMode rpcMode = RPCMode.disabled)
150 	{
151 		this.hint = hint;
152 		this.hintString = hintString;
153 		this.usage = usage;
154 		this.rpcMode = rpcMode;
155 	}
156 }
157 
158 /++
159 A UDA for explicitly specifying the default value of a Property.
160 
161 This UDA works with getter/setter functions. It should be attached to only one
162 of the two functions.
163 
164 The normal D default value will still be used if no `@DefaultValue` UDA is
165 attached.
166 
167 Example:
168 ---
169 class S : GodotScript!Node
170 {
171 	// UDA is needed to give getter/setter functions a default value
172 	@Property @DefaultValue!5
173 	int number() const
174 	{
175 		// ...
176 	}
177 	void number(int val)
178 	{
179 		// ...
180 	}
181 	
182 	// plain variable; no UDA is needed
183 	@Property int simpler = 6;
184 }
185 ---
186 +/
187 struct DefaultValue(Expression...) {}
188 
189 /++
190 A UDA for marking script variables that should be automatically created when
191 the script is created, right before _init() is called.
192 
193 Options for automatically deleting or adding as child node the tagged variable
194 can be set in the UDA.
195 +/
196 struct OnInit
197 {
198 	bool autoCreate = true; /// create it when the script is created
199 	bool autoDelete = true; /// delete it when the script is destroyed
200 	bool autoAddChild = true; /// add it as a child (only for Node types)
201 	
202 	private import godot.node;
203 	package(godot) enum bool canAddChild(R, Owner) = extends!(GodotClass!R, Node)
204 		&& extends!(GodotClass!Owner, Node);
205 	
206 	static OnInit makeDefault(R, Owner)()
207 	{
208 		import godot.reference, godot.node, godot.resource;
209 		OnInit ret;
210 		static if( is(GodotClass!R : Reference) ) ret.autoDelete = false; // ref-counted
211 		static if( canAddChild!(R, Owner) )
212 		{
213 			ret.autoAddChild = true;
214 			ret.autoDelete = false; // owned by parent node
215 		}
216 		return ret;
217 	}
218 }
219 // TODO: support static arrays
220 
221 deprecated alias RAII = OnInit;
222