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