Skip to content

Commit

Permalink
replaced sogItem
Browse files Browse the repository at this point in the history
  • Loading branch information
tolik518 committed Aug 14, 2024
1 parent 0152134 commit fd4f950
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 1,290 deletions.
14 changes: 7 additions & 7 deletions SoG_SGreader/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
switch (quickSlotType)
{
case 1:
playerObject.Quickslots.Add((SogItem)readBinary.ReadInt32());
playerObject.Quickslots.Add(readBinary.ReadInt32());
break;
case 2:
playerObject.Quickslots.Add((SogSkill)readBinary.ReadUInt16());
playerObject.Quickslots.Add(readBinary.ReadUInt16());
break;
default:
playerObject.Quickslots.Add(0);
Expand Down Expand Up @@ -82,7 +82,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.Inventory.Add(new Item
{
ItemID = (SogItem)readBinary.ReadInt32(),
ItemID = readBinary.ReadInt32(),
ItemCount = readBinary.ReadInt32(),
ItemPos = readBinary.ReadUInt32()
});
Expand Down Expand Up @@ -292,7 +292,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.ItemsSeen.Add(new ItemSeen
{
ItemID = (SogItem) readBinary.ReadInt32()
ItemID = readBinary.ReadInt32()
});
}

Expand All @@ -305,7 +305,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.ItemsCrafted.Add(new ItemCrafted
{
ItemID = (SogItem) readBinary.ReadInt32()
ItemID = readBinary.ReadInt32()
});
}

Expand All @@ -318,7 +318,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.FishCaught.Add(new FishCaught
{
FishID = (SogItem) readBinary.ReadInt32()
FishID = readBinary.ReadInt32()
});
}

Expand Down Expand Up @@ -349,7 +349,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.Potions.Add(new Potion
{
PotionID = (SogItem)readBinary.ReadInt32()
PotionID = readBinary.ReadInt32()
});
}

Expand Down
2 changes: 1 addition & 1 deletion SoG_SGreader/DataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void WriteToFile(string fileName)

writeBinary.Write(playerObject.PlayTimeTotal); // check for overflow

writeBinary.Write((byte )playerObject.PhaseShiftStuff);
writeBinary.Write((byte)playerObject.PhaseShiftStuff);

writeBinary.Write((ushort) playerObject.CharacterFlags.Count);
for (int i = 0; i != playerObject.CharacterFlags.Count; i++)
Expand Down
63 changes: 63 additions & 0 deletions SoG_SGreader/Enum/DynamicEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoG_SGreader.Enum
{
public class DynamicEnum
{
private readonly string filePath;
private Dictionary<string, int> nameToValue = new Dictionary<string, int>();
private Dictionary<int, string> valueToName = new Dictionary<int, string>();

public DynamicEnum(string filePath, string key)
{
var jsonData = File.ReadAllText(filePath);
var items = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, int>>>(jsonData);
if (items != null && items.ContainsKey(key))
{
foreach (var item in items[key])
{
nameToValue[RemoveLeadingUnderscore(item.Key)] = item.Value;
valueToName[item.Value] = RemoveLeadingUnderscore(item.Key);
}
}
else
{
throw new KeyNotFoundException($"The key '{key}' is not found in the JSON data.");
}
}

public int GetValue(string name)
{
if (nameToValue.ContainsKey(name))
{
return nameToValue[name];
}
throw new KeyNotFoundException($"The name '{name}' is not found in the {filePath} enum.");
}

public string GetName(int value)
{
if (valueToName.ContainsKey(value))
{
return valueToName[value];
}
throw new KeyNotFoundException($"The value '{value}' is not found in the {filePath} enum.");
}

public IEnumerable<string> GetNames()
{
return nameToValue.Keys;
}

private static string RemoveLeadingUnderscore(string input)
{
return input.StartsWith("_") ? input.Substring(1) : input;

Check notice on line 60 in SoG_SGreader/Enum/DynamicEnum.cs

View check run for this annotation

codefactor.io / CodeFactor

SoG_SGreader/Enum/DynamicEnum.cs#L60

Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char. (CA1865)
}
}
}
18 changes: 18 additions & 0 deletions SoG_SGreader/Enum/GameEnums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoG_SGreader.Enum
{
public static class GameEnums
{
public static DynamicEnum SogItem;

public static void InitializeEnums()
{
SogItem = new DynamicEnum("ItemTypes.json", "ItemTypes");
}
}
}
53 changes: 0 additions & 53 deletions SoG_SGreader/Enum/SogFish.cs

This file was deleted.

Loading

0 comments on commit fd4f950

Please sign in to comment.