public static void CharaChipDrawTypeTest(bool isNull, bool isError) { var instance = new MapEventPageGraphicInfo(); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var errorOccured = false; try { instance.CharaChipDrawType = isNull ? null : PictureDrawType.Add; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); // 意図したとおりプロパティ変更通知が発火していること if (errorOccured) { Assert.AreEqual(changedPropertyList.Count, 0); } else { Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageGraphicInfo.CharaChipDrawType))); } }
public static void SerializeTest() { var target = new MapEventPageGraphicInfo { InitDirection = CharaChipDirection.LeftDown }; var changedPropertyList = new List <string>(); target.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var clone = DeepCloner.DeepClone(target); Assert.IsTrue(clone.Equals(target)); // プロパティ変更通知が発火していないこと Assert.AreEqual(changedPropertyList.Count, 0); }
public static void SetGraphicFileNameTest(string fileName, bool beforeIsGraphicTileChip, bool isError) { var instance = new MapEventPageGraphicInfo(); instance.IsGraphicTileChip = beforeIsGraphicTileChip; var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var charaChipFileName = (CharaChipFilePath)fileName; var errorOccured = false; try { instance.SetGraphicFileName(charaChipFileName); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); if (!errorOccured) { // タイルチップ使用フラグがfalseであること Assert.IsFalse(instance.IsGraphicTileChip); } // 意図したとおりプロパティ変更通知が発火していること if (errorOccured) { Assert.AreEqual(changedPropertyList.Count, 0); } else { Assert.AreEqual(changedPropertyList.Count, 2); Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageGraphicInfo.IsGraphicTileChip))); Assert.IsTrue(changedPropertyList[1].Equals(nameof(MapEventPageGraphicInfo.CharaChipFilePath))); } }
public static void SetGraphicTileIdTest(int tileId, bool beforeIsGraphicTileChip, bool afterIsGraphicTileChip) { var instance = new MapEventPageGraphicInfo(); instance.IsGraphicTileChip = beforeIsGraphicTileChip; var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var mapEventTileId = (MapEventTileId)tileId; var errorOccured = false; try { instance.SetGraphicTileId(mapEventTileId); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); // タイルチップ使用フラグが一致すること Assert.AreEqual(instance.IsGraphicTileChip, afterIsGraphicTileChip); // 意図したとおりプロパティ変更通知が発火していること if (mapEventTileId == MapEventTileId.NotUse) { Assert.AreEqual(changedPropertyList.Count, 3); Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageGraphicInfo.GraphicTileId))); Assert.IsTrue(changedPropertyList[1].Equals(nameof(MapEventPageGraphicInfo.IsGraphicTileChip))); Assert.IsTrue(changedPropertyList[2].Equals(nameof(MapEventPageGraphicInfo.CharaChipFilePath))); } else { Assert.AreEqual(changedPropertyList.Count, 2); Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageGraphicInfo.GraphicTileId))); Assert.IsTrue(changedPropertyList[1].Equals(nameof(MapEventPageGraphicInfo.IsGraphicTileChip))); } }
public static void GraphicTileIdSetTest(bool isGraphicTileChip, int tileId, bool isError) { var instance = new MapEventPageGraphicInfo(); instance.IsGraphicTileChip = isGraphicTileChip; var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var graphicTileId = (MapEventTileId)tileId; var errorOccured = false; try { instance.GraphicTileId = graphicTileId; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); // 意図したとおりプロパティ変更通知が発火していること if (errorOccured) { Assert.AreEqual(changedPropertyList.Count, 0); } else { Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(MapEventPageGraphicInfo.GraphicTileId))); } }
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); }