SceneDataReader.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // SceneDataReader.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Content;
  15. using Microsoft.Xna.Framework.Graphics;
  16. #endregion
  17. namespace SceneDataLibrary
  18. {
  19. /// <summary>
  20. /// This class reads the data generated by the layout tool.
  21. /// After creating pattern objects from a pattern group, this class reads
  22. /// sequence banks, groups, and objects.
  23. ///
  24. /// レイアウトツールから出力したデータを読み込みます
  25. /// パターングループから、パターンオブジェクトを作成した後、
  26. /// シーケンスバンク、グループ、オブジェクトを読み込みます。
  27. /// </summary>
  28. public class SceneDataReader : ContentTypeReader<SceneData>
  29. {
  30. /// <summary>
  31. /// Generates pattern objects.
  32. /// Reads position information, textures, and color settings.
  33. ///
  34. /// パターンオブジェクトの生成をします。
  35. /// 配置情報や、テクスチャ、色の設定を読み込みます。
  36. /// </summary>
  37. /// <param name="input">
  38. /// Content reader
  39. ///
  40. /// コンテントリーダー
  41. /// </param>
  42. /// <returns>
  43. /// Generated pattern object
  44. ///
  45. /// 生成したパターンオブジェクト
  46. /// </returns>
  47. private static PatternObjectData ReadPatternObject(ContentReader input)
  48. {
  49. //Creates pattern objects.
  50. //
  51. //パターンオブジェクトを作成
  52. PatternObjectData patternObject = new PatternObjectData();
  53. int nX, nY, nW, nH;
  54. byte nR, nG, nB, nA;
  55. //Obtains the texture name.
  56. //
  57. //テクスチャ名の取得
  58. patternObject.TextureName = input.ReadString();
  59. //Obtains the cut position and range.
  60. //
  61. //切り出し位置と大きさの取得
  62. nX = input.ReadInt32();
  63. nY = input.ReadInt32();
  64. nW = input.ReadInt32();
  65. nH = input.ReadInt32();
  66. patternObject.Rect = new Rectangle(nX, nY, nW, nH);
  67. //Obtains the flip information.
  68. //
  69. //反転情報の取得
  70. patternObject.FlipH = input.ReadBoolean();
  71. patternObject.FlipV = input.ReadBoolean();
  72. //Obtains the display position.
  73. //
  74. //表示位置の取得
  75. nX = input.ReadInt32();
  76. nY = input.ReadInt32();
  77. patternObject.Data.Position = new Point(nX, nY);
  78. //Obtains the color information.
  79. //
  80. //色情報の取得
  81. nR = input.ReadByte();
  82. nG = input.ReadByte();
  83. nB = input.ReadByte();
  84. nA = input.ReadByte();
  85. patternObject.Data.Color = new Color(nR, nG, nB, nA);
  86. //Obtains the scale.
  87. //
  88. //スケールの取得
  89. patternObject.Data.Scale = input.ReadVector2();
  90. //Obtains the center point.
  91. //
  92. //中心点の取得
  93. nX = input.ReadInt32();
  94. nY = input.ReadInt32();
  95. patternObject.Data.Center = new Point(nX, nY);
  96. //Obtains the rotation value.
  97. //
  98. //回転量の取得
  99. patternObject.Data.RotateZ = input.ReadSingle();
  100. //Sets the texture.
  101. //
  102. //テクスチャの設定
  103. patternObject.Init(input.ContentManager);
  104. return patternObject;
  105. }
  106. /// <summary>
  107. /// Generates a pattern group.
  108. /// Creates pattern objects contained in this pattern group and
  109. /// adds them to the list.
  110. ///
  111. /// パターングループの生成をします。
  112. /// 含まれるパターンオブジェクトを作成し、リストに追加していきます。
  113. /// </summary>
  114. /// <param name="input"></param>
  115. /// <returns></returns>
  116. private static PatternGroupData ReadPatternGroup(ContentReader input)
  117. {
  118. PatternGroupData group = new PatternGroupData();
  119. //Obtains the number of pattern objects.
  120. //
  121. //パターンオブジェクトの数を取得
  122. int nPatPartsCount = input.ReadInt32();
  123. List<PatternObjectData> listPatParts = group.PatternObjectList;
  124. //Creates and registers pattern objects one by one.
  125. //
  126. //一つ一つ作成しながら登録
  127. for (int i = 0; i < nPatPartsCount; i++)
  128. listPatParts.Add(ReadPatternObject(input));
  129. return group;
  130. }
  131. /// <summary>
  132. /// Generates sequence objects.
  133. /// Specifies the name of the pattern group to be referred to
  134. /// and searches its substance. Because pattern groups and pattern objects
  135. /// were stored in the scene data before sequence data was stored,
  136. /// they can be always found as long as there is consistency
  137. /// between each data.
  138. ///
  139. /// シーケンスオブジェクトを生成します。
  140. /// 参照するパターングループ名を設定し、その実体を検索します。
  141. /// パターングループ、パターンオブジェクトはシーケンスデータよりも
  142. /// 先にシーンデータに含まれているため、
  143. /// データに整合性がある場合、発見できないということはありません。
  144. /// </summary>
  145. /// <param name="input"></param>
  146. /// <param name="listPatBody"></param>
  147. /// <returns></returns>
  148. private static SequenceObjectData ReadSequenceObjectData(ContentReader input,
  149. Dictionary<String, PatternGroupData> listPatBody)
  150. {
  151. SequenceObjectData sequenceObject = new SequenceObjectData();
  152. //The number of frames to be displayed
  153. //
  154. //表示フレーム数
  155. sequenceObject.Frame = input.ReadInt32();
  156. //The name of the pattern group to be displayed
  157. //
  158. //表示するパターングループ名
  159. sequenceObject.PatternGroupName = input.ReadString();
  160. //Configures the setting so that the substance of data can be referred to
  161. //from the group name.
  162. //
  163. //グループ名からデータの実体を参照するように設定する。
  164. sequenceObject.Init(listPatBody);
  165. return sequenceObject;
  166. }
  167. /// <summary>
  168. /// Generates a sequence group.
  169. /// Creates objects contained in this group and adds them to the list.
  170. ///
  171. /// シーケンスグループを生成します。
  172. /// グループに含まれるオブジェクトを作成し、リストに追加します。
  173. /// </summary>
  174. /// <param name="input"></param>
  175. /// <param name="listPatBody"></param>
  176. /// <returns></returns>
  177. private static SequenceGroupData ReadSequenceGroupData(ContentReader input,
  178. Dictionary<String, PatternGroupData> listPatBody)
  179. {
  180. SequenceGroupData group = new SequenceGroupData();
  181. //Sets the start frame.
  182. //
  183. //スタートフレームの設定
  184. group.StartFrame = input.ReadInt32();
  185. //Sets the loop count.
  186. //
  187. //ループ数の設定
  188. group.LoopNumber = input.ReadInt32();
  189. //Sets the interpolation type.
  190. //
  191. //補間タイプの設定
  192. group.InterpolationType = (SequenceGroupData.Interpolation)input.ReadByte();
  193. //Sets the parameters for spline interpolation.
  194. //
  195. //スプライン補間のパラメータ設定
  196. group.SplineParamT = input.ReadInt32();
  197. group.SplineParamC = input.ReadInt32();
  198. group.SplineParamB = input.ReadInt32();
  199. //Obtains the number of sequence objects.
  200. //
  201. //シーケンスオブジェクトの数を取得
  202. int nSeqPartsCount = input.ReadInt32();
  203. List<SequenceObjectData> listSeqParts = group.SequenceObjectList;
  204. //Creates sequence objects.
  205. //
  206. //オブジェクトを作成します。
  207. for (int i = 0; i < nSeqPartsCount; i++)
  208. listSeqParts.Add(ReadSequenceObjectData(input, listPatBody));
  209. return group;
  210. }
  211. /// <summary>
  212. /// Generates sequence banks.
  213. /// Generates groups belonging to these banks.
  214. ///
  215. /// シーケンスバンクを生成します。
  216. /// バンクに属するグループの生成を行います。
  217. /// </summary>
  218. /// <param name="input"></param>
  219. /// <param name="listPatBody"></param>
  220. /// <returns></returns>
  221. private static SequenceBankData ReadSequenceBankData(ContentReader input,
  222. Dictionary<String, PatternGroupData> listPatBody)
  223. {
  224. SequenceBankData bank = new SequenceBankData();
  225. //Sets the display priority.
  226. //
  227. //表示優先順位の設定
  228. bank.ZPos = input.ReadInt32();
  229. //Obtains the number of sequence groups.
  230. //
  231. //シーケンスグループの数を取得
  232. int nSeqBodyCount = input.ReadInt32();
  233. List<SequenceGroupData> listSeqBody = bank.SequenceGroupList;
  234. //Creates sequence groups and adds them to the list.
  235. //
  236. //シーケンスグループを作成し、リストに追加
  237. for (int i = 0; i < nSeqBodyCount; i++)
  238. listSeqBody.Add(ReadSequenceGroupData(input, listPatBody));
  239. return bank;
  240. }
  241. /// <summary>
  242. /// Generates scene data.
  243. /// Creates pattern data, and then creates sequence data.
  244. ///
  245. /// シーンデータを生成します。
  246. /// パターンデータと、シーケンスデータの作成を順に行います。
  247. /// </summary>
  248. /// <param name="input"></param>
  249. /// <param name="existingInstance"></param>
  250. /// <returns></returns>
  251. protected override SceneData Read(ContentReader input,
  252. SceneData existingInstance)
  253. {
  254. SceneData dataScene = new SceneData();
  255. //The number of pattern groups
  256. //
  257. //パターングループの数
  258. int nPatBodyCount = input.ReadInt32();
  259. Dictionary<String, PatternGroupData> listPatBody =
  260. dataScene.PatternGroupDictionary;
  261. //Creates pattern groups one by one and adds them to the list.
  262. //
  263. //パターングループを順に作成し、リストに追加します。
  264. for (int i = 0; i < nPatBodyCount; i++)
  265. {
  266. String strPatBodyName = input.ReadString();
  267. listPatBody.Add(strPatBodyName, ReadPatternGroup(input));
  268. }
  269. //The number of sequence banks
  270. //
  271. //シーケンスバンクの数
  272. int nSequenceDataCount = input.ReadInt32();
  273. Dictionary<String, SequenceBankData> dicSeqData =
  274. dataScene.SequenceBankDictionary;
  275. //Creates sequence banks one by one and adds them to the list.
  276. //
  277. //シーケンスバンクを順次作成し、リストに追加します。
  278. for (int i = 0; i < nSequenceDataCount; i++)
  279. {
  280. String strSeqDataName = input.ReadString();
  281. dicSeqData.Add(strSeqDataName,
  282. ReadSequenceBankData(input, listPatBody));
  283. }
  284. return dataScene;
  285. }
  286. }
  287. }