Skip to content

Commit

Permalink
refactorings:
Browse files Browse the repository at this point in the history
- moved Json handling to a dedicated class
- removed underscore from all enum names
- added help, json and text command
- cleaned up skill level
- moved opened SaveGame-path to an attribute
- fixed all paths
- fixed crashes saving json
- fixed quickslots
  • Loading branch information
tolik518 committed Oct 21, 2023
1 parent a8f8984 commit 9d4c1b8
Show file tree
Hide file tree
Showing 17 changed files with 1,677 additions and 1,529 deletions.
42 changes: 21 additions & 21 deletions SoG_SGreader.Test/DataReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Xunit;
using Moq;
using SoG_SGreader.Wrapper;

namespace SoG_SGreader.Test
{
Expand All @@ -13,8 +14,7 @@ public class DataReaderTests

private static Player GetSaveGame(int saveGameNumber)
{
DataReader dataReader = new DataReader();
var txtConsoleMock = new Mock<ITextBoxWrapper>().Object;
var fakeTextBox = new FakeTextBox();

string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName;

Expand All @@ -25,7 +25,7 @@ private static Player GetSaveGame(int saveGameNumber)

string filePath = Path.Combine(projectDirectory, "SoG_SGreader.Test", "SaveGames", saveGameNumber + ".cha");

return dataReader.ReadFromFile(filePath, txtConsoleMock);
return DataReader.ReadFromFile(filePath, fakeTextBox);
}

private static IEnumerable<object[]> Nicknames()
Expand Down Expand Up @@ -91,15 +91,15 @@ private void TestCanReadBirthday(int birthdayDay, int birthdayMonth, Player play

private static IEnumerable<object[]> FirstItem()
{
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 189755), GetSaveGame(0).Inventory };
yield return new object[] { new Item(SogItems._KeyItem_DivaMirror, 0, 158319), GetSaveGame(1).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 46623), GetSaveGame(2).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 16756), GetSaveGame(3).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 25026), GetSaveGame(4).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 18895), GetSaveGame(5).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 16634), GetSaveGame(6).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 14455), GetSaveGame(7).Inventory };
yield return new object[] { new Item(SogItems._Usable_CardAlbum, 1, 96617), GetSaveGame(8).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 189755), GetSaveGame(0).Inventory };
yield return new object[] { new Item(SogItems.KeyItem_DivaMirror, 0, 158319), GetSaveGame(1).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 46623), GetSaveGame(2).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 16756), GetSaveGame(3).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 25026), GetSaveGame(4).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 18895), GetSaveGame(5).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 16634), GetSaveGame(6).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 14455), GetSaveGame(7).Inventory };
yield return new object[] { new Item(SogItems.Usable_CardAlbum, 1, 96617), GetSaveGame(8).Inventory };
}

[Theory]
Expand All @@ -111,15 +111,15 @@ private void TestCanGetFirstItemFromInventory(Item firstItem, List<Item> invento

private static IEnumerable<object[]> LastItem()
{
yield return new object[] { new Item(SogItems._Furniture_Decoration_ArcadeChallengeTrophyF08, 1, 189760), GetSaveGame(0).Inventory };
yield return new object[] { new Item(SogItems._KeyItem_CatalystOfPower, 1, 159243), GetSaveGame(1).Inventory };
yield return new object[] { new Item(SogItems._KeyItem_CatalystOfPower, 1, 46457), GetSaveGame(2).Inventory };
yield return new object[] { new Item(SogItems._Shoes_MushroomSlippers, 1, 16738), GetSaveGame(3).Inventory };
yield return new object[] { new Item(SogItems._TwoHanded_BugNet, 0, 25025), GetSaveGame(4).Inventory };
yield return new object[] { new Item(SogItems._TwoHanded_BugNet, 0, 18894), GetSaveGame(5).Inventory };
yield return new object[] { new Item(SogItems._Furniture_Carpet_MasterHQRed, 0, 16614), GetSaveGame(6).Inventory };
yield return new object[] { new Item(SogItems._TwoHanded_BugNet, 0, 14454), GetSaveGame(7).Inventory };
yield return new object[] { new Item(SogItems._OneHanded_UgrasScroll, 1, 96375), GetSaveGame(8).Inventory };
yield return new object[] { new Item(SogItems.Furniture_Decoration_ArcadeChallengeTrophyF08, 1, 189760), GetSaveGame(0).Inventory };
yield return new object[] { new Item(SogItems.KeyItem_CatalystOfPower, 1, 159243), GetSaveGame(1).Inventory };
yield return new object[] { new Item(SogItems.KeyItem_CatalystOfPower, 1, 46457), GetSaveGame(2).Inventory };
yield return new object[] { new Item(SogItems.Shoes_MushroomSlippers, 1, 16738), GetSaveGame(3).Inventory };
yield return new object[] { new Item(SogItems.TwoHanded_BugNet, 0, 25025), GetSaveGame(4).Inventory };
yield return new object[] { new Item(SogItems.TwoHanded_BugNet, 0, 18894), GetSaveGame(5).Inventory };
yield return new object[] { new Item(SogItems.Furniture_Carpet_MasterHQRed, 0, 16614), GetSaveGame(6).Inventory };
yield return new object[] { new Item(SogItems.TwoHanded_BugNet, 0, 14454), GetSaveGame(7).Inventory };
yield return new object[] { new Item(SogItems.OneHanded_UgrasScroll, 1, 96375), GetSaveGame(8).Inventory };
}

[Theory]
Expand Down
10 changes: 6 additions & 4 deletions SoG_SGreader/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace SoG_SGreader
{
public class DataReader
{
private readonly Player playerObject = new Player();

public Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
Player playerObject = new Player();

using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
{
BinaryReader readBinary = new BinaryReader(fileStream);
Expand Down Expand Up @@ -285,7 +286,7 @@ public Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
txtConsole.AppendText("\r\n" + "KilledEnemiesCount: " + playerObject.KilledEnemiesCount);

playerObject.PotionsMax = readBinary.ReadByte();
txtConsole.AppendText("\r\n" + " PotionsMax: " + playerObject.PotionsMax);
txtConsole.AppendText("\r\n" + "PotionsMax: " + playerObject.PotionsMax);
playerObject.PotionsEquipped = readBinary.ReadByte();
txtConsole.AppendText("\r\n" + "PotionsEquipped: " + playerObject.PotionsEquipped);

Expand Down Expand Up @@ -361,7 +362,8 @@ public Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
readBinary.Close();
fileStream.Close();
}

txtConsole.AppendText("\r\n");

return playerObject;
}
}
Expand Down
Loading

0 comments on commit 9d4c1b8

Please sign in to comment.