1 /** 2 Sprite frame library for AnimatedSprite. 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.spriteframes; 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.texture; 25 import godot.reference; 26 /** 27 Sprite frame library for AnimatedSprite. 28 29 Sprite frame library for $(D AnimatedSprite). Contains frames and animation data for playback. 30 */ 31 @GodotBaseClass struct SpriteFrames 32 { 33 enum string _GODOT_internal_name = "SpriteFrames"; 34 public: 35 @nogc nothrow: 36 union { godot_object _godot_object; Resource _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct _classBinding 41 { 42 __gshared: 43 @GodotName("add_animation") GodotMethod!(void, String) addAnimation; 44 @GodotName("has_animation") GodotMethod!(bool, String) hasAnimation; 45 @GodotName("remove_animation") GodotMethod!(void, String) removeAnimation; 46 @GodotName("rename_animation") GodotMethod!(void, String, String) renameAnimation; 47 @GodotName("get_animation_names") GodotMethod!(PoolStringArray) getAnimationNames; 48 @GodotName("set_animation_speed") GodotMethod!(void, String, double) setAnimationSpeed; 49 @GodotName("get_animation_speed") GodotMethod!(double, String) getAnimationSpeed; 50 @GodotName("set_animation_loop") GodotMethod!(void, String, bool) setAnimationLoop; 51 @GodotName("get_animation_loop") GodotMethod!(bool, String) getAnimationLoop; 52 @GodotName("add_frame") GodotMethod!(void, String, Texture, long) addFrame; 53 @GodotName("get_frame_count") GodotMethod!(long, String) getFrameCount; 54 @GodotName("get_frame") GodotMethod!(Texture, String, long) getFrame; 55 @GodotName("set_frame") GodotMethod!(void, String, long, Texture) setFrame; 56 @GodotName("remove_frame") GodotMethod!(void, String, long) removeFrame; 57 @GodotName("clear") GodotMethod!(void, String) clear; 58 @GodotName("clear_all") GodotMethod!(void) clearAll; 59 @GodotName("_set_frames") GodotMethod!(void, Array) _setFrames; 60 @GodotName("_get_frames") GodotMethod!(Array) _getFrames; 61 @GodotName("_set_animations") GodotMethod!(void, Array) _setAnimations; 62 @GodotName("_get_animations") GodotMethod!(Array) _getAnimations; 63 } 64 bool opEquals(in SpriteFrames other) const { return _godot_object.ptr is other._godot_object.ptr; } 65 SpriteFrames opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 66 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 67 mixin baseCasts; 68 static SpriteFrames _new() 69 { 70 static godot_class_constructor constructor; 71 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("SpriteFrames"); 72 if(constructor is null) return typeof(this).init; 73 return cast(SpriteFrames)(constructor()); 74 } 75 @disable new(size_t s); 76 /** 77 Adds a new animation to the library. 78 */ 79 void addAnimation(StringArg0)(in StringArg0 anim) 80 { 81 checkClassBinding!(typeof(this))(); 82 ptrcall!(void)(_classBinding.addAnimation, _godot_object, anim); 83 } 84 /** 85 If `true` the named animation exists. 86 */ 87 bool hasAnimation(StringArg0)(in StringArg0 anim) const 88 { 89 checkClassBinding!(typeof(this))(); 90 return ptrcall!(bool)(_classBinding.hasAnimation, _godot_object, anim); 91 } 92 /** 93 Removes the given animation. 94 */ 95 void removeAnimation(StringArg0)(in StringArg0 anim) 96 { 97 checkClassBinding!(typeof(this))(); 98 ptrcall!(void)(_classBinding.removeAnimation, _godot_object, anim); 99 } 100 /** 101 Changes the animation's name to `newname`. 102 */ 103 void renameAnimation(StringArg0, StringArg1)(in StringArg0 anim, in StringArg1 newname) 104 { 105 checkClassBinding!(typeof(this))(); 106 ptrcall!(void)(_classBinding.renameAnimation, _godot_object, anim, newname); 107 } 108 /** 109 Returns an array containing the names associated to each animation. Values are placed in alphabetical order. 110 */ 111 PoolStringArray getAnimationNames() const 112 { 113 checkClassBinding!(typeof(this))(); 114 return ptrcall!(PoolStringArray)(_classBinding.getAnimationNames, _godot_object); 115 } 116 /** 117 The animation's speed in frames per second. 118 */ 119 void setAnimationSpeed(StringArg0)(in StringArg0 anim, in double speed) 120 { 121 checkClassBinding!(typeof(this))(); 122 ptrcall!(void)(_classBinding.setAnimationSpeed, _godot_object, anim, speed); 123 } 124 /** 125 The animation's speed in frames per second. 126 */ 127 double getAnimationSpeed(StringArg0)(in StringArg0 anim) const 128 { 129 checkClassBinding!(typeof(this))(); 130 return ptrcall!(double)(_classBinding.getAnimationSpeed, _godot_object, anim); 131 } 132 /** 133 If `true` the animation will loop. 134 */ 135 void setAnimationLoop(StringArg0)(in StringArg0 anim, in bool loop) 136 { 137 checkClassBinding!(typeof(this))(); 138 ptrcall!(void)(_classBinding.setAnimationLoop, _godot_object, anim, loop); 139 } 140 /** 141 If `true` the given animation will loop. 142 */ 143 bool getAnimationLoop(StringArg0)(in StringArg0 anim) const 144 { 145 checkClassBinding!(typeof(this))(); 146 return ptrcall!(bool)(_classBinding.getAnimationLoop, _godot_object, anim); 147 } 148 /** 149 Adds a frame to the given animation. 150 */ 151 void addFrame(StringArg0)(in StringArg0 anim, Texture frame, in long at_position = -1) 152 { 153 checkClassBinding!(typeof(this))(); 154 ptrcall!(void)(_classBinding.addFrame, _godot_object, anim, frame, at_position); 155 } 156 /** 157 Returns the number of frames in the animation. 158 */ 159 long getFrameCount(StringArg0)(in StringArg0 anim) const 160 { 161 checkClassBinding!(typeof(this))(); 162 return ptrcall!(long)(_classBinding.getFrameCount, _godot_object, anim); 163 } 164 /** 165 Returns the animation's selected frame. 166 */ 167 Ref!Texture getFrame(StringArg0)(in StringArg0 anim, in long idx) const 168 { 169 checkClassBinding!(typeof(this))(); 170 return ptrcall!(Texture)(_classBinding.getFrame, _godot_object, anim, idx); 171 } 172 /** 173 Sets the texture of the given frame. 174 */ 175 void setFrame(StringArg0)(in StringArg0 anim, in long idx, Texture txt) 176 { 177 checkClassBinding!(typeof(this))(); 178 ptrcall!(void)(_classBinding.setFrame, _godot_object, anim, idx, txt); 179 } 180 /** 181 Removes the animation's selected frame. 182 */ 183 void removeFrame(StringArg0)(in StringArg0 anim, in long idx) 184 { 185 checkClassBinding!(typeof(this))(); 186 ptrcall!(void)(_classBinding.removeFrame, _godot_object, anim, idx); 187 } 188 /** 189 Removes all frames from the given animation. 190 */ 191 void clear(StringArg0)(in StringArg0 anim) 192 { 193 checkClassBinding!(typeof(this))(); 194 ptrcall!(void)(_classBinding.clear, _godot_object, anim); 195 } 196 /** 197 Removes all animations. A "default" animation will be created. 198 */ 199 void clearAll() 200 { 201 checkClassBinding!(typeof(this))(); 202 ptrcall!(void)(_classBinding.clearAll, _godot_object); 203 } 204 /** 205 206 */ 207 void _setFrames(in Array arg0) 208 { 209 Array _GODOT_args = Array.empty_array; 210 _GODOT_args.append(arg0); 211 String _GODOT_method_name = String("_set_frames"); 212 this.callv(_GODOT_method_name, _GODOT_args); 213 } 214 /** 215 216 */ 217 Array _getFrames() const 218 { 219 Array _GODOT_args = Array.empty_array; 220 String _GODOT_method_name = String("_get_frames"); 221 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 222 } 223 /** 224 225 */ 226 void _setAnimations(in Array arg0) 227 { 228 Array _GODOT_args = Array.empty_array; 229 _GODOT_args.append(arg0); 230 String _GODOT_method_name = String("_set_animations"); 231 this.callv(_GODOT_method_name, _GODOT_args); 232 } 233 /** 234 235 */ 236 Array _getAnimations() const 237 { 238 Array _GODOT_args = Array.empty_array; 239 String _GODOT_method_name = String("_get_animations"); 240 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 241 } 242 /** 243 244 */ 245 @property Array frames() 246 { 247 return _getFrames(); 248 } 249 /// ditto 250 @property void frames(Array v) 251 { 252 _setFrames(v); 253 } 254 /** 255 256 */ 257 @property Array animations() 258 { 259 return _getAnimations(); 260 } 261 /// ditto 262 @property void animations(Array v) 263 { 264 _setAnimations(v); 265 } 266 }