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