1 // 2 // Copyright (c) 2008-2017 the Urho3D project. 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a copy 5 // of this software and associated documentation files (the "Software"), to deal 6 // in the Software without restriction, including without limitation the rights 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 // copies of the Software, and to permit persons to whom the Software is 9 // furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 // THE SOFTWARE. 21 // 22 23 #pragma once 24 25 namespace pugi 26 { 27 class xml_node; 28 } 29 30 namespace Urho3D 31 { 32 33 namespace Spriter 34 { 35 36 struct Animation; 37 struct BoneTimelineKey; 38 struct CharacterMap; 39 struct Entity; 40 struct File; 41 struct Folder; 42 struct MainlineKey; 43 struct MapInstruction; 44 struct Ref; 45 struct SpatialInfo; 46 struct SpatialTimelineKey; 47 struct SpriterData; 48 struct SpriteTimelineKey; 49 struct Timeline; 50 struct TimelineKey; 51 52 /// Spriter data. 53 struct SpriterData 54 { 55 SpriterData(); 56 ~SpriterData(); 57 58 void Reset(); 59 bool Load(const pugi::xml_node& node); 60 bool Load(const void* data, size_t size); 61 62 int scmlVersion_; 63 String generator_; 64 String generatorVersion_; 65 PODVector<Folder*> folders_; 66 PODVector<Entity*> entities_; 67 }; 68 69 /// Folder. 70 struct Folder 71 { 72 Folder(); 73 ~Folder(); 74 75 void Reset(); 76 bool Load(const pugi::xml_node& node); 77 78 int id_; 79 String name_; 80 PODVector<File*> files_; 81 }; 82 83 /// File. 84 struct File 85 { 86 File(Folder* folder); 87 ~File(); 88 89 bool Load(const pugi::xml_node& node); 90 91 Folder* folder_; 92 int id_; 93 String name_; 94 float width_; 95 float height_; 96 float pivotX_; 97 float pivotY_; 98 }; 99 100 /// Entity. 101 struct Entity 102 { 103 Entity(); 104 ~Entity(); 105 106 void Reset(); 107 bool Load(const pugi::xml_node& node); 108 109 int id_; 110 String name_; 111 PODVector<CharacterMap*> characterMaps_; 112 PODVector<Animation*> animations_; 113 }; 114 115 /// Character map. 116 struct CharacterMap 117 { 118 CharacterMap(); 119 ~CharacterMap(); 120 121 void Reset(); 122 bool Load(const pugi::xml_node& node); 123 124 int id_; 125 String name_; 126 PODVector<MapInstruction*> maps_; 127 }; 128 129 /// Map instruction. 130 struct MapInstruction 131 { 132 MapInstruction(); 133 ~MapInstruction(); 134 135 bool Load(const pugi::xml_node& node); 136 137 int folder_; 138 int file_; 139 int targetFolder_; 140 int targetFile_; 141 }; 142 143 /// Animation. 144 struct Animation 145 { 146 Animation(); 147 ~Animation(); 148 149 void Reset(); 150 bool Load(const pugi::xml_node& node); 151 152 int id_; 153 String name_; 154 float length_; 155 bool looping_; 156 PODVector<MainlineKey*> mainlineKeys_; 157 PODVector<Timeline*> timelines_; 158 }; 159 160 /// Mainline key. 161 struct MainlineKey 162 { 163 MainlineKey(); 164 ~MainlineKey(); 165 166 void Reset(); 167 bool Load(const pugi::xml_node& node); 168 169 int id_; 170 float time_; 171 PODVector<Ref*> boneRefs_; 172 PODVector<Ref*> objectRefs_; 173 }; 174 175 /// Ref. 176 struct Ref 177 { 178 Ref(); 179 ~Ref(); 180 181 bool Load(const pugi::xml_node& node); 182 183 int id_; 184 int parent_; 185 int timeline_; 186 int key_; 187 int zIndex_; 188 }; 189 190 /// Object type. 191 enum ObjectType 192 { 193 BONE = 0, 194 SPRITE 195 }; 196 197 /// Timeline. 198 struct Timeline 199 { 200 Timeline(); 201 ~Timeline(); 202 203 void Reset(); 204 bool Load(const pugi::xml_node& node); 205 206 int id_; 207 String name_; 208 ObjectType objectType_; 209 PODVector<SpatialTimelineKey*> keys_; 210 }; 211 212 /// Curve type. 213 enum CurveType 214 { 215 INSTANT = 0, 216 LINEAR, 217 QUADRATIC, 218 CUBIC 219 }; 220 221 /// Timeline key. 222 struct TimelineKey 223 { 224 TimelineKey(Timeline* timeline); 225 virtual ~TimelineKey(); 226 227 virtual ObjectType GetObjectType() const = 0; 228 virtual TimelineKey* Clone() const = 0; 229 virtual bool Load(const pugi::xml_node& node); 230 virtual void Interpolate(const TimelineKey& other, float t) = 0; 231 TimelineKey& operator=(const TimelineKey& rhs); 232 float GetTByCurveType(float currentTime, float nextTimelineTime) const; 233 234 Timeline* timeline_; 235 int id_; 236 float time_; 237 CurveType curveType_; 238 float c1_; 239 float c2_; 240 }; 241 242 /// Spatial info. 243 struct SpatialInfo 244 { 245 float x_; 246 float y_; 247 float angle_; 248 float scaleX_; 249 float scaleY_; 250 float alpha_; 251 int spin; 252 253 SpatialInfo(float x = 0.0f, float y = 0.0f, float angle = 0.0f, float scale_x = 1, float scale_y = 1, float a = 1, int spin = 1); 254 SpatialInfo UnmapFromParent(const SpatialInfo& parentInfo) const; 255 void Interpolate(const SpatialInfo& other, float t); 256 }; 257 258 /// Spatial timeline key. 259 struct SpatialTimelineKey : TimelineKey 260 { 261 SpatialInfo info_; 262 263 SpatialTimelineKey(Timeline* timeline); 264 virtual ~SpatialTimelineKey(); 265 266 virtual bool Load(const pugi::xml_node& node); 267 virtual void Interpolate(const TimelineKey& other, float t); 268 SpatialTimelineKey& operator=(const SpatialTimelineKey& rhs); 269 }; 270 271 /// Bone timeline key. 272 struct BoneTimelineKey : SpatialTimelineKey 273 { 274 float length_; 275 float width_; 276 277 BoneTimelineKey(Timeline* timeline); 278 virtual ~BoneTimelineKey(); 279 GetObjectTypeBoneTimelineKey280 virtual ObjectType GetObjectType() const { return BONE; } 281 virtual TimelineKey* Clone() const; 282 virtual bool Load(const pugi::xml_node& node); 283 virtual void Interpolate(const TimelineKey& other, float t); 284 BoneTimelineKey& operator=(const BoneTimelineKey& rhs); 285 }; 286 287 /// Sprite timeline key. 288 struct SpriteTimelineKey : SpatialTimelineKey 289 { 290 int folderId_; 291 int fileId_; 292 bool useDefaultPivot_; 293 float pivotX_; 294 float pivotY_; 295 296 /// Run time data. 297 int zIndex_; 298 299 SpriteTimelineKey(Timeline* timeline); 300 virtual ~SpriteTimelineKey(); 301 GetObjectTypeSpriteTimelineKey302 virtual ObjectType GetObjectType() const { return SPRITE; } 303 virtual TimelineKey* Clone() const; 304 virtual bool Load(const pugi::xml_node& node); 305 virtual void Interpolate(const TimelineKey& other, float t); 306 SpriteTimelineKey& operator=(const SpriteTimelineKey& rhs); 307 }; 308 309 } 310 311 } 312