DataParser.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System.Collections.Generic;
  24. namespace DragonBones
  25. {
  26. /// <internal/>
  27. /// <private/>
  28. public abstract class DataParser
  29. {
  30. protected const string DATA_VERSION_2_3 = "2.3";
  31. protected const string DATA_VERSION_3_0 = "3.0";
  32. protected const string DATA_VERSION_4_0 = "4.0";
  33. protected const string DATA_VERSION_4_5 = "4.5";
  34. protected const string DATA_VERSION_5_0 = "5.0";
  35. protected const string DATA_VERSION_5_5 = "5.5";
  36. protected const string DATA_VERSION = DATA_VERSION_5_5;
  37. protected static readonly List<string> DATA_VERSIONS = new List<string>()
  38. {
  39. DATA_VERSION_5_5,
  40. DATA_VERSION_5_0,
  41. DATA_VERSION_4_5,
  42. DATA_VERSION_4_0,
  43. DATA_VERSION_3_0,
  44. DATA_VERSION_2_3
  45. };
  46. protected const string TEXTURE_ATLAS = "textureAtlas";
  47. protected const string SUB_TEXTURE = "SubTexture";
  48. protected const string FORMAT = "format";
  49. protected const string IMAGE_PATH = "imagePath";
  50. protected const string WIDTH = "width";
  51. protected const string HEIGHT = "height";
  52. protected const string ROTATED = "rotated";
  53. protected const string FRAME_X = "frameX";
  54. protected const string FRAME_Y = "frameY";
  55. protected const string FRAME_WIDTH = "frameWidth";
  56. protected const string FRAME_HEIGHT = "frameHeight";
  57. protected const string DRADON_BONES = "dragonBones";
  58. protected const string USER_DATA = "userData";
  59. protected const string ARMATURE = "armature";
  60. protected const string BONE = "bone";
  61. protected const string SLOT = "slot";
  62. protected const string CONSTRAINT = "constraint";
  63. protected const string IK = "ik";
  64. protected const string SKIN = "skin";
  65. protected const string DISPLAY = "display";
  66. protected const string ANIMATION = "animation";
  67. protected const string Z_ORDER = "zOrder";
  68. protected const string FFD = "ffd";
  69. protected const string FRAME = "frame";
  70. protected const string TRANSLATE_FRAME = "translateFrame";
  71. protected const string ROTATE_FRAME = "rotateFrame";
  72. protected const string SCALE_FRAME = "scaleFrame";
  73. protected const string DISPLAY_FRAME = "displayFrame";
  74. protected const string COLOR_FRAME = "colorFrame";
  75. protected const string DEFAULT_ACTIONS = "defaultActions";
  76. protected const string ACTIONS = "actions";
  77. protected const string EVENTS = "events";
  78. protected const string INTS = "ints";
  79. protected const string FLOATS = "floats";
  80. protected const string STRINGS = "strings";
  81. protected const string CANVAS = "canvas";
  82. protected const string TRANSFORM = "transform";
  83. protected const string PIVOT = "pivot";
  84. protected const string AABB = "aabb";
  85. protected const string COLOR = "color";
  86. protected const string VERSION = "version";
  87. protected const string COMPATIBLE_VERSION = "compatibleVersion";
  88. protected const string FRAME_RATE = "frameRate";
  89. protected const string TYPE = "type";
  90. protected const string SUB_TYPE = "subType";
  91. protected const string NAME = "name";
  92. protected const string PARENT = "parent";
  93. protected const string TARGET = "target";
  94. protected const string STAGE = "stage";
  95. protected const string SHARE = "share";
  96. protected const string PATH = "path";
  97. protected const string LENGTH = "length";
  98. protected const string DISPLAY_INDEX = "displayIndex";
  99. protected const string BLEND_MODE = "blendMode";
  100. protected const string INHERIT_TRANSLATION = "inheritTranslation";
  101. protected const string INHERIT_ROTATION = "inheritRotation";
  102. protected const string INHERIT_SCALE = "inheritScale";
  103. protected const string INHERIT_REFLECTION = "inheritReflection";
  104. protected const string INHERIT_ANIMATION = "inheritAnimation";
  105. protected const string INHERIT_DEFORM = "inheritDeform";
  106. protected const string BEND_POSITIVE = "bendPositive";
  107. protected const string CHAIN = "chain";
  108. protected const string WEIGHT = "weight";
  109. protected const string FADE_IN_TIME = "fadeInTime";
  110. protected const string PLAY_TIMES = "playTimes";
  111. protected const string SCALE = "scale";
  112. protected const string OFFSET = "offset";
  113. protected const string POSITION = "position";
  114. protected const string DURATION = "duration";
  115. protected const string TWEEN_TYPE = "tweenType";
  116. protected const string TWEEN_EASING = "tweenEasing";
  117. protected const string TWEEN_ROTATE = "tweenRotate";
  118. protected const string TWEEN_SCALE = "tweenScale";
  119. protected const string CLOCK_WISE = "clockwise";
  120. protected const string CURVE = "curve";
  121. protected const string SOUND = "sound";
  122. protected const string EVENT = "event";
  123. protected const string ACTION = "action";
  124. protected const string X = "x";
  125. protected const string Y = "y";
  126. protected const string SKEW_X = "skX";
  127. protected const string SKEW_Y = "skY";
  128. protected const string SCALE_X = "scX";
  129. protected const string SCALE_Y = "scY";
  130. protected const string VALUE = "value";
  131. protected const string ROTATE = "rotate";
  132. protected const string SKEW = "skew";
  133. protected const string ALPHA_OFFSET = "aO";
  134. protected const string RED_OFFSET = "rO";
  135. protected const string GREEN_OFFSET = "gO";
  136. protected const string BLUE_OFFSET = "bO";
  137. protected const string ALPHA_MULTIPLIER = "aM";
  138. protected const string RED_MULTIPLIER = "rM";
  139. protected const string GREEN_MULTIPLIER = "gM";
  140. protected const string BLUE_MULTIPLIER = "bM";
  141. protected const string UVS = "uvs";
  142. protected const string VERTICES = "vertices";
  143. protected const string TRIANGLES = "triangles";
  144. protected const string WEIGHTS = "weights";
  145. protected const string SLOT_POSE = "slotPose";
  146. protected const string BONE_POSE = "bonePose";
  147. protected const string GOTO_AND_PLAY = "gotoAndPlay";
  148. protected const string DEFAULT_NAME = "default";
  149. protected static ArmatureType _GetArmatureType(string value)
  150. {
  151. switch (value.ToLower())
  152. {
  153. case "stage":
  154. return ArmatureType.Stage;
  155. case "armature":
  156. return ArmatureType.Armature;
  157. case "movieclip":
  158. return ArmatureType.MovieClip;
  159. default:
  160. return ArmatureType.None;
  161. }
  162. }
  163. protected static DisplayType _GetDisplayType(string value)
  164. {
  165. switch (value.ToLower())
  166. {
  167. case "image":
  168. return DisplayType.Image;
  169. case "mesh":
  170. return DisplayType.Mesh;
  171. case "armature":
  172. return DisplayType.Armature;
  173. case "boundingbox":
  174. return DisplayType.BoundingBox;
  175. default:
  176. return DisplayType.None;
  177. }
  178. }
  179. protected static BoundingBoxType _GetBoundingBoxType(string value)
  180. {
  181. switch (value.ToLower())
  182. {
  183. case "rectangle":
  184. return BoundingBoxType.Rectangle;
  185. case "ellipse":
  186. return BoundingBoxType.Ellipse;
  187. case "polygon":
  188. return BoundingBoxType.Polygon;
  189. default:
  190. return BoundingBoxType.Rectangle;
  191. }
  192. }
  193. protected static ActionType _GetActionType(string value)
  194. {
  195. switch (value.ToLower())
  196. {
  197. case "play":
  198. return ActionType.Play;
  199. case "frame":
  200. return ActionType.Frame;
  201. case "sound":
  202. return ActionType.Sound;
  203. default:
  204. return ActionType.Play;
  205. }
  206. }
  207. protected static BlendMode _GetBlendMode(string value)
  208. {
  209. switch (value.ToLower())
  210. {
  211. case "normal":
  212. return BlendMode.Normal;
  213. case "add":
  214. return BlendMode.Add;
  215. case "alpha":
  216. return BlendMode.Alpha;
  217. case "darken":
  218. return BlendMode.Darken;
  219. case "difference":
  220. return BlendMode.Difference;
  221. case "erase":
  222. return BlendMode.Erase;
  223. case "hardlight":
  224. return BlendMode.HardLight;
  225. case "invert":
  226. return BlendMode.Invert;
  227. case "layer":
  228. return BlendMode.Layer;
  229. case "lighten":
  230. return BlendMode.Lighten;
  231. case "multiply":
  232. return BlendMode.Multiply;
  233. case "overlay":
  234. return BlendMode.Overlay;
  235. case "screen":
  236. return BlendMode.Screen;
  237. case "subtract":
  238. return BlendMode.Subtract;
  239. default:
  240. return BlendMode.Normal;
  241. }
  242. }
  243. public DataParser()
  244. {
  245. }
  246. public abstract DragonBonesData ParseDragonBonesData(object rawData, float scale);
  247. public abstract bool ParseTextureAtlasData(object rawData, TextureAtlasData textureAtlasData, float scale);
  248. }
  249. }