| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- #region File Description
- //-----------------------------------------------------------------------------
- // SceneDataReader.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- #endregion
- namespace SceneDataLibrary
- {
- /// <summary>
- /// This class reads the data generated by the layout tool.
- /// After creating pattern objects from a pattern group, this class reads
- /// sequence banks, groups, and objects.
- ///
- /// レイアウトツールから出力したデータを読み込みます
- /// パターングループから、パターンオブジェクトを作成した後、
- /// シーケンスバンク、グループ、オブジェクトを読み込みます。
- /// </summary>
- public class SceneDataReader : ContentTypeReader<SceneData>
- {
- /// <summary>
- /// Generates pattern objects.
- /// Reads position information, textures, and color settings.
- ///
- /// パターンオブジェクトの生成をします。
- /// 配置情報や、テクスチャ、色の設定を読み込みます。
- /// </summary>
- /// <param name="input">
- /// Content reader
- ///
- /// コンテントリーダー
- /// </param>
- /// <returns>
- /// Generated pattern object
- ///
- /// 生成したパターンオブジェクト
- /// </returns>
- private static PatternObjectData ReadPatternObject(ContentReader input)
- {
- //Creates pattern objects.
- //
- //パターンオブジェクトを作成
- PatternObjectData patternObject = new PatternObjectData();
- int nX, nY, nW, nH;
- byte nR, nG, nB, nA;
- //Obtains the texture name.
- //
- //テクスチャ名の取得
- patternObject.TextureName = input.ReadString();
-
- //Obtains the cut position and range.
- //
- //切り出し位置と大きさの取得
- nX = input.ReadInt32();
- nY = input.ReadInt32();
- nW = input.ReadInt32();
- nH = input.ReadInt32();
- patternObject.Rect = new Rectangle(nX, nY, nW, nH);
- //Obtains the flip information.
- //
- //反転情報の取得
- patternObject.FlipH = input.ReadBoolean();
- patternObject.FlipV = input.ReadBoolean();
- //Obtains the display position.
- //
- //表示位置の取得
- nX = input.ReadInt32();
- nY = input.ReadInt32();
- patternObject.Data.Position = new Point(nX, nY);
- //Obtains the color information.
- //
- //色情報の取得
- nR = input.ReadByte();
- nG = input.ReadByte();
- nB = input.ReadByte();
- nA = input.ReadByte();
- patternObject.Data.Color = new Color(nR, nG, nB, nA);
- //Obtains the scale.
- //
- //スケールの取得
- patternObject.Data.Scale = input.ReadVector2();
- //Obtains the center point.
- //
- //中心点の取得
- nX = input.ReadInt32();
- nY = input.ReadInt32();
- patternObject.Data.Center = new Point(nX, nY);
- //Obtains the rotation value.
- //
- //回転量の取得
- patternObject.Data.RotateZ = input.ReadSingle();
- //Sets the texture.
- //
- //テクスチャの設定
- patternObject.Init(input.ContentManager);
- return patternObject;
- }
- /// <summary>
- /// Generates a pattern group.
- /// Creates pattern objects contained in this pattern group and
- /// adds them to the list.
- ///
- /// パターングループの生成をします。
- /// 含まれるパターンオブジェクトを作成し、リストに追加していきます。
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- private static PatternGroupData ReadPatternGroup(ContentReader input)
- {
- PatternGroupData group = new PatternGroupData();
- //Obtains the number of pattern objects.
- //
- //パターンオブジェクトの数を取得
- int nPatPartsCount = input.ReadInt32();
- List<PatternObjectData> listPatParts = group.PatternObjectList;
- //Creates and registers pattern objects one by one.
- //
- //一つ一つ作成しながら登録
- for (int i = 0; i < nPatPartsCount; i++)
- listPatParts.Add(ReadPatternObject(input));
- return group;
- }
- /// <summary>
- /// Generates sequence objects.
- /// Specifies the name of the pattern group to be referred to
- /// and searches its substance. Because pattern groups and pattern objects
- /// were stored in the scene data before sequence data was stored,
- /// they can be always found as long as there is consistency
- /// between each data.
- ///
- /// シーケンスオブジェクトを生成します。
- /// 参照するパターングループ名を設定し、その実体を検索します。
- /// パターングループ、パターンオブジェクトはシーケンスデータよりも
- /// 先にシーンデータに含まれているため、
- /// データに整合性がある場合、発見できないということはありません。
- /// </summary>
- /// <param name="input"></param>
- /// <param name="listPatBody"></param>
- /// <returns></returns>
- private static SequenceObjectData ReadSequenceObjectData(ContentReader input,
- Dictionary<String, PatternGroupData> listPatBody)
- {
- SequenceObjectData sequenceObject = new SequenceObjectData();
- //The number of frames to be displayed
- //
- //表示フレーム数
- sequenceObject.Frame = input.ReadInt32();
- //The name of the pattern group to be displayed
- //
- //表示するパターングループ名
- sequenceObject.PatternGroupName = input.ReadString();
- //Configures the setting so that the substance of data can be referred to
- //from the group name.
- //
- //グループ名からデータの実体を参照するように設定する。
- sequenceObject.Init(listPatBody);
- return sequenceObject;
- }
- /// <summary>
- /// Generates a sequence group.
- /// Creates objects contained in this group and adds them to the list.
- ///
- /// シーケンスグループを生成します。
- /// グループに含まれるオブジェクトを作成し、リストに追加します。
- /// </summary>
- /// <param name="input"></param>
- /// <param name="listPatBody"></param>
- /// <returns></returns>
- private static SequenceGroupData ReadSequenceGroupData(ContentReader input,
- Dictionary<String, PatternGroupData> listPatBody)
- {
- SequenceGroupData group = new SequenceGroupData();
- //Sets the start frame.
- //
- //スタートフレームの設定
- group.StartFrame = input.ReadInt32();
- //Sets the loop count.
- //
- //ループ数の設定
- group.LoopNumber = input.ReadInt32();
- //Sets the interpolation type.
- //
- //補間タイプの設定
- group.InterpolationType = (SequenceGroupData.Interpolation)input.ReadByte();
- //Sets the parameters for spline interpolation.
- //
- //スプライン補間のパラメータ設定
- group.SplineParamT = input.ReadInt32();
- group.SplineParamC = input.ReadInt32();
- group.SplineParamB = input.ReadInt32();
- //Obtains the number of sequence objects.
- //
- //シーケンスオブジェクトの数を取得
- int nSeqPartsCount = input.ReadInt32();
- List<SequenceObjectData> listSeqParts = group.SequenceObjectList;
- //Creates sequence objects.
- //
- //オブジェクトを作成します。
- for (int i = 0; i < nSeqPartsCount; i++)
- listSeqParts.Add(ReadSequenceObjectData(input, listPatBody));
- return group;
- }
- /// <summary>
- /// Generates sequence banks.
- /// Generates groups belonging to these banks.
- ///
- /// シーケンスバンクを生成します。
- /// バンクに属するグループの生成を行います。
- /// </summary>
- /// <param name="input"></param>
- /// <param name="listPatBody"></param>
- /// <returns></returns>
- private static SequenceBankData ReadSequenceBankData(ContentReader input,
- Dictionary<String, PatternGroupData> listPatBody)
- {
- SequenceBankData bank = new SequenceBankData();
- //Sets the display priority.
- //
- //表示優先順位の設定
- bank.ZPos = input.ReadInt32();
- //Obtains the number of sequence groups.
- //
- //シーケンスグループの数を取得
- int nSeqBodyCount = input.ReadInt32();
- List<SequenceGroupData> listSeqBody = bank.SequenceGroupList;
- //Creates sequence groups and adds them to the list.
- //
- //シーケンスグループを作成し、リストに追加
- for (int i = 0; i < nSeqBodyCount; i++)
- listSeqBody.Add(ReadSequenceGroupData(input, listPatBody));
- return bank;
- }
- /// <summary>
- /// Generates scene data.
- /// Creates pattern data, and then creates sequence data.
- ///
- /// シーンデータを生成します。
- /// パターンデータと、シーケンスデータの作成を順に行います。
- /// </summary>
- /// <param name="input"></param>
- /// <param name="existingInstance"></param>
- /// <returns></returns>
- protected override SceneData Read(ContentReader input,
- SceneData existingInstance)
- {
- SceneData dataScene = new SceneData();
- //The number of pattern groups
- //
- //パターングループの数
- int nPatBodyCount = input.ReadInt32();
- Dictionary<String, PatternGroupData> listPatBody =
- dataScene.PatternGroupDictionary;
- //Creates pattern groups one by one and adds them to the list.
- //
- //パターングループを順に作成し、リストに追加します。
- for (int i = 0; i < nPatBodyCount; i++)
- {
- String strPatBodyName = input.ReadString();
- listPatBody.Add(strPatBodyName, ReadPatternGroup(input));
- }
- //The number of sequence banks
- //
- //シーケンスバンクの数
- int nSequenceDataCount = input.ReadInt32();
-
- Dictionary<String, SequenceBankData> dicSeqData =
- dataScene.SequenceBankDictionary;
- //Creates sequence banks one by one and adds them to the list.
- //
- //シーケンスバンクを順次作成し、リストに追加します。
- for (int i = 0; i < nSequenceDataCount; i++)
- {
- String strSeqDataName = input.ReadString();
- dicSeqData.Add(strSeqDataName,
- ReadSequenceBankData(input, listPatBody));
- }
- return dataScene;
- }
- }
- }
|