#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
{
///
/// 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.
///
/// レイアウトツールから出力したデータを読み込みます
/// パターングループから、パターンオブジェクトを作成した後、
/// シーケンスバンク、グループ、オブジェクトを読み込みます。
///
public class SceneDataReader : ContentTypeReader
{
///
/// Generates pattern objects.
/// Reads position information, textures, and color settings.
///
/// パターンオブジェクトの生成をします。
/// 配置情報や、テクスチャ、色の設定を読み込みます。
///
///
/// Content reader
///
/// コンテントリーダー
///
///
/// Generated pattern object
///
/// 生成したパターンオブジェクト
///
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;
}
///
/// Generates a pattern group.
/// Creates pattern objects contained in this pattern group and
/// adds them to the list.
///
/// パターングループの生成をします。
/// 含まれるパターンオブジェクトを作成し、リストに追加していきます。
///
///
///
private static PatternGroupData ReadPatternGroup(ContentReader input)
{
PatternGroupData group = new PatternGroupData();
//Obtains the number of pattern objects.
//
//パターンオブジェクトの数を取得
int nPatPartsCount = input.ReadInt32();
List listPatParts = group.PatternObjectList;
//Creates and registers pattern objects one by one.
//
//一つ一つ作成しながら登録
for (int i = 0; i < nPatPartsCount; i++)
listPatParts.Add(ReadPatternObject(input));
return group;
}
///
/// 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.
///
/// シーケンスオブジェクトを生成します。
/// 参照するパターングループ名を設定し、その実体を検索します。
/// パターングループ、パターンオブジェクトはシーケンスデータよりも
/// 先にシーンデータに含まれているため、
/// データに整合性がある場合、発見できないということはありません。
///
///
///
///
private static SequenceObjectData ReadSequenceObjectData(ContentReader input,
Dictionary 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;
}
///
/// Generates a sequence group.
/// Creates objects contained in this group and adds them to the list.
///
/// シーケンスグループを生成します。
/// グループに含まれるオブジェクトを作成し、リストに追加します。
///
///
///
///
private static SequenceGroupData ReadSequenceGroupData(ContentReader input,
Dictionary 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 listSeqParts = group.SequenceObjectList;
//Creates sequence objects.
//
//オブジェクトを作成します。
for (int i = 0; i < nSeqPartsCount; i++)
listSeqParts.Add(ReadSequenceObjectData(input, listPatBody));
return group;
}
///
/// Generates sequence banks.
/// Generates groups belonging to these banks.
///
/// シーケンスバンクを生成します。
/// バンクに属するグループの生成を行います。
///
///
///
///
private static SequenceBankData ReadSequenceBankData(ContentReader input,
Dictionary listPatBody)
{
SequenceBankData bank = new SequenceBankData();
//Sets the display priority.
//
//表示優先順位の設定
bank.ZPos = input.ReadInt32();
//Obtains the number of sequence groups.
//
//シーケンスグループの数を取得
int nSeqBodyCount = input.ReadInt32();
List 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;
}
///
/// Generates scene data.
/// Creates pattern data, and then creates sequence data.
///
/// シーンデータを生成します。
/// パターンデータと、シーケンスデータの作成を順に行います。
///
///
///
///
protected override SceneData Read(ContentReader input,
SceneData existingInstance)
{
SceneData dataScene = new SceneData();
//The number of pattern groups
//
//パターングループの数
int nPatBodyCount = input.ReadInt32();
Dictionary 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 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;
}
}
}