コード例 #1
0
        public static void SetOptionFlagTest(
            bool isWaitAnimationOn, bool isMoveAnimationOn, bool isFixedDirection,
            bool isSkipThrough, bool isAboveHero, bool isHitBox,
            bool isPlaceHalfStepUp, byte optionCode)
        {
            var instance            = new MapEventPageOption();
            var changedPropertyList = new List <string>();

            instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            instance.SetOptionFlag(optionCode);

            // 各フラグが一致すること
            Assert.AreEqual(instance.IsWaitAnimationOn, isWaitAnimationOn);
            Assert.AreEqual(instance.IsMoveAnimationOn, isMoveAnimationOn);
            Assert.AreEqual(instance.IsFixedDirection, isFixedDirection);
            Assert.AreEqual(instance.IsSkipThrough, isSkipThrough);
            Assert.AreEqual(instance.IsAboveHero, isAboveHero);
            Assert.AreEqual(instance.IsHitBox, isHitBox);
            Assert.AreEqual(instance.IsPlaceHalfStepUp, isPlaceHalfStepUp);

            // 意図したとおりプロパティ変更通知が発火していること
            Assert.AreEqual(changedPropertyList.Count, 7);
            Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageOption.IsWaitAnimationOn)));
            Assert.IsTrue(changedPropertyList[1].Equals(nameof(MapEventPageOption.IsMoveAnimationOn)));
            Assert.IsTrue(changedPropertyList[2].Equals(nameof(MapEventPageOption.IsFixedDirection)));
            Assert.IsTrue(changedPropertyList[3].Equals(nameof(MapEventPageOption.IsSkipThrough)));
            Assert.IsTrue(changedPropertyList[4].Equals(nameof(MapEventPageOption.IsAboveHero)));
            Assert.IsTrue(changedPropertyList[5].Equals(nameof(MapEventPageOption.IsHitBox)));
            Assert.IsTrue(changedPropertyList[6].Equals(nameof(MapEventPageOption.IsPlaceHalfStepUp)));
        }
コード例 #2
0
ファイル: MpsFileReader.cs プロジェクト: sono8stream/UniWolf
        private void ReadMapEventOnePage(ICollection <MapEventPage> mapEventPages)
        {
            var result = new MapEventPage();

            // ヘッダチェック
            foreach (var b in MapEventPage.Header)
            {
                if (ReadStatus.ReadByte() != b)
                {
                    throw new InvalidOperationException(
                              $"マップイベントページのヘッダが異なります。(offset: {ReadStatus.Offset})");
                }

                ReadStatus.IncreaseByteOffset();
            }

            var graphicInfo = new MapEventPageGraphicInfo();

            // タイル画像ID
            var graphicTileId = (MapEventTileId)ReadStatus.ReadInt();

            if (graphicTileId != MapEventTileId.NotUse)
            {
                graphicInfo.IsGraphicTileChip = true;
                graphicInfo.GraphicTileId     = graphicTileId;
            }

            ReadStatus.IncreaseIntOffset();

            // キャラチップ名
            var charaChipString = ReadStatus.ReadString();

            if (!graphicInfo.IsGraphicTileChip)
            {
                graphicInfo.CharaChipFilePath = charaChipString.String;
            }

            ReadStatus.AddOffset(charaChipString.ByteLength);

            // 初期キャラ向き
            var initDirection = ReadStatus.ReadByte();

            graphicInfo.InitDirection = CharaChipDirection.FromByte(initDirection);
            ReadStatus.IncreaseByteOffset();

            // 初期アニメーション番号
            graphicInfo.InitAnimationId = ReadStatus.ReadByte();
            ReadStatus.IncreaseByteOffset();

            // キャラチップ透過度
            graphicInfo.CharaChipOpacity = ReadStatus.ReadByte();
            ReadStatus.IncreaseByteOffset();

            // キャラチップ表示形式
            graphicInfo.CharaChipDrawType = PictureDrawType.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            result.GraphicInfo = graphicInfo;

            var bootInfo = new MapEventPageBootInfo();

            // 起動条件
            bootInfo.MapEventBootType = MapEventBootType.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            // 条件1~4演算子 & 使用フラグ
            var conditions = new List <MapEventBootCondition>
            {
                new MapEventBootCondition(),
                new MapEventBootCondition(),
                new MapEventBootCondition(),
                new MapEventBootCondition(),
            };

            for (var i = 0; i < 4; i++)
            {
                conditions[i].Operation    = CriteriaOperator.FromByte((byte)(ReadStatus.ReadByte() & 0xF0));
                conditions[i].UseCondition = (byte)(ReadStatus.ReadByte() & 0x0F) != 0;
                ReadStatus.IncreaseByteOffset();
            }

            // 条件1~4左辺
            for (var i = 0; i < 4; i++)
            {
                conditions[i].LeftSide = ReadStatus.ReadInt();
                ReadStatus.IncreaseIntOffset();
            }

            // 条件1~4右辺
            for (var i = 0; i < 4; i++)
            {
                conditions[i].RightSide = ReadStatus.ReadInt();
                ReadStatus.IncreaseIntOffset();
                bootInfo.SetEventBootCondition(i, conditions[i]);
            }

            result.BootInfo = bootInfo;

            var moveRouteInfo = new MapEventPageMoveRouteInfo();

            // アニメ速度
            moveRouteInfo.AnimateSpeed = AnimateSpeed.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            // 移動速度
            moveRouteInfo.MoveSpeed = MoveSpeed.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            // 移動頻度
            moveRouteInfo.MoveFrequency = MoveFrequency.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            // 移動ルート
            moveRouteInfo.MoveType = MoveType.FromByte(ReadStatus.ReadByte());
            ReadStatus.IncreaseByteOffset();

            var option = new MapEventPageOption();

            // オプション
            var optionByte = ReadStatus.ReadByte();

            option.SetOptionFlag(optionByte);
            ReadStatus.IncreaseByteOffset();

            result.Option = option;

            // カスタム移動ルートフラグ
            var actionEntry         = new ActionEntry();
            var customMoveRouteFlag = ReadStatus.ReadByte();

            actionEntry.SetOptionFlag(customMoveRouteFlag);
            ReadStatus.IncreaseByteOffset();

            // 動作指定コマンド数
            actionEntry.CommandList = ReadCharaMoveCommand();

            moveRouteInfo.CustomMoveRoute = actionEntry;
            result.MoveRouteInfo          = moveRouteInfo;

            // イベント行数
            var eventLength = ReadStatus.ReadInt();

            ReadStatus.IncreaseIntOffset();

            // イベントコマンド
            var eventCommandListReader = new EventCommandListReader();

            result.EventCommands = eventCommandListReader.Read(eventLength, ReadStatus);

            // イベントコマンド終端チェック
            foreach (var b in EventCommandList.EndEventCommand)
            {
                if (ReadStatus.ReadByte() != b)
                {
                    throw new InvalidOperationException(
                              $"イベントコマンド後の値が異なります。(offset: {ReadStatus.Offset})");
                }

                ReadStatus.IncreaseByteOffset();
            }

            // 影グラフィック番号
            result.ShadowGraphicId = ReadStatus.ReadByte();
            ReadStatus.IncreaseByteOffset();

            // 接触範囲拡張X
            var rangeWidth = ReadStatus.ReadByte();

            ReadStatus.IncreaseByteOffset();

            // 接触範囲拡張Y
            var rangeHeight = ReadStatus.ReadByte();

            ReadStatus.IncreaseByteOffset();

            result.HitExtendRange = (rangeWidth, rangeHeight);

            // イベントページ末尾チェック
            foreach (var b in MapEventPage.Footer)
            {
                if (ReadStatus.ReadByte() != b)
                {
                    throw new InvalidOperationException(
                              $"イベントページ末尾の値が異なります。(offset: {ReadStatus.Offset})");
                }

                ReadStatus.IncreaseByteOffset();
            }

            // 完了
            mapEventPages.Add(result);
        }