public void FloorData_InsertFDEntryWriteReadTest() { //Read Dragons Lair data TR2LevelReader reader = new TR2LevelReader(); TR2Level lvl = reader.ReadLevel("xian.tr2"); //Parse the floordata using FDControl FDControl fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); //Add a music trigger to index 9 fdataReader.Entries[9].Add(new FDTriggerEntry { Setup = new FDSetup(FDFunctions.Trigger), TrigSetup = new FDTrigSetup(), TrigActionList = new List <FDActionListItem> { new FDActionListItem { TrigAction = FDTrigAction.PlaySoundtrack, Parameter = 40 } } }); //Write the data back fdataReader.WriteToLevel(lvl); //Save it and read it back in TR2LevelWriter writer = new TR2LevelWriter(); writer.WriteLevelToFile(lvl, "TEST.tr2"); lvl = reader.ReadLevel("TEST.tr2"); fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); //Verify index 9 has two entries, that its first entry //does not have EndData set, but that its second does Assert.AreEqual(fdataReader.Entries[9].Count, 2); Assert.IsFalse(fdataReader.Entries[9][0].Setup.EndData); Assert.IsTrue(fdataReader.Entries[9][1].Setup.EndData); //Verify the trigger we added matches what we expect FDEntry entry = fdataReader.Entries[9][1]; Assert.IsTrue(entry is FDTriggerEntry); FDTriggerEntry triggerEntry = entry as FDTriggerEntry; Assert.IsTrue(triggerEntry.Setup.Function == (byte)FDFunctions.Trigger); Assert.IsTrue(triggerEntry.TrigActionList.Count == 1); Assert.IsTrue(triggerEntry.TrigActionList[0].TrigAction == FDTrigAction.PlaySoundtrack); Assert.IsTrue(triggerEntry.TrigActionList[0].Parameter == 40); }
public void FloorData_InsertFDTest() { //Read Dragons Lair data TR2LevelReader reader = new TR2LevelReader(); TR2Level lvl = reader.ReadLevel("xian.tr2"); //Parse the floordata using FDControl FDControl fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); //Find a sector that currently has no floor data int room, roomSector = -1; for (room = 0; room < lvl.NumRooms; room++) { roomSector = lvl.Rooms[room].SectorList.ToList().FindIndex(s => s.FDIndex == 0); if (roomSector != -1) { break; } } if (roomSector == -1) { Assert.Fail("Could not locate a Room Sector that does not have floor data associated with it."); } TRRoomSector sector = lvl.Rooms[room].SectorList[roomSector]; // Create a slot in the FD for this sector fdataReader.CreateFloorData(sector); Assert.AreNotEqual(sector.FDIndex, 0, "Sector does not have FD allocated."); // Add a music trigger fdataReader.Entries[sector.FDIndex].Add(new FDTriggerEntry { Setup = new FDSetup(FDFunctions.Trigger), TrigSetup = new FDTrigSetup(), TrigActionList = new List <FDActionListItem> { new FDActionListItem { TrigAction = FDTrigAction.PlaySoundtrack, Parameter = 40 } } }); //Write the data back fdataReader.WriteToLevel(lvl); //Save it and read it back in TR2LevelWriter writer = new TR2LevelWriter(); writer.WriteLevelToFile(lvl, "TEST.tr2"); lvl = reader.ReadLevel("TEST.tr2"); //Reassign the sector sector = lvl.Rooms[room].SectorList[roomSector]; fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); //Ensure the sector still has FD associated with it Assert.AreNotEqual(sector.FDIndex, 0, "Sector no longer has FD after write/read."); //Verify there is one entry for this sector Assert.AreEqual(fdataReader.Entries[sector.FDIndex].Count, 1); //Verify the trigger we added matches what we expect FDEntry entry = fdataReader.Entries[sector.FDIndex][0]; Assert.IsTrue(entry is FDTriggerEntry); FDTriggerEntry triggerEntry = entry as FDTriggerEntry; Assert.IsTrue(triggerEntry.Setup.Function == (byte)FDFunctions.Trigger); Assert.IsTrue(triggerEntry.TrigActionList.Count == 1); Assert.IsTrue(triggerEntry.TrigActionList[0].TrigAction == FDTrigAction.PlaySoundtrack); Assert.IsTrue(triggerEntry.TrigActionList[0].Parameter == 40); }