-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading a json of single-spawner data (#2)
Co-authored-by: Lusamine <[email protected]>
- Loading branch information
Showing
7 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Globalization; | ||
|
||
namespace PermuteMMO.Lib; | ||
|
||
public sealed record UserEnteredSpawnInfo | ||
{ | ||
public ushort Species { get; set; } | ||
public string Seed { get; set; } = string.Empty; | ||
|
||
public ulong GetSeed() => ulong.Parse(Seed); | ||
|
||
public int BaseCount { get; set; } | ||
public string BaseTable { get; set; } = string.Empty; | ||
|
||
public int BonusCount { get; set; } | ||
public string BonusTable { get; set; } = string.Empty; | ||
|
||
public SpawnInfo GetSpawn() | ||
{ | ||
var table = Parse(BaseTable); | ||
var bonus = Parse(BonusTable); | ||
if (table < 1000) | ||
table = Species; | ||
|
||
return new SpawnInfo | ||
{ | ||
BaseCount = BaseCount, | ||
BonusCount = BonusCount, | ||
BaseTable = table, | ||
BonusTable = bonus, | ||
Type = bonus is not 0 ? SpawnType.MMO : SpawnType.Outbreak, | ||
}; | ||
} | ||
|
||
private static ulong Parse(string hex) | ||
{ | ||
if (hex.StartsWith("0x")) | ||
hex = hex[2..]; | ||
return ulong.Parse(hex, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using PermuteMMO.Lib; | ||
using PKHeX.Core; | ||
using Xunit; | ||
|
||
namespace PermuteMMO.Tests; | ||
|
||
public static class UtilTests | ||
{ | ||
[Fact] | ||
public static void CreateJson() | ||
{ | ||
var obj = new UserEnteredSpawnInfo | ||
{ | ||
Species = (int)Species.Diglett, | ||
Seed = 0xDEADBABE_BEEFCAFE.ToString(), | ||
BaseCount = 10, | ||
BaseTable = $"0x{0x1122_10F4_7DE9_8115:X16}", | ||
BonusCount = 0, | ||
BonusTable = $"0x{0:X16}", | ||
}; | ||
|
||
var fileName = Path.Combine(Environment.CurrentDirectory, "spawner.json"); | ||
var settings = new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Populate }; | ||
var result = JsonConvert.SerializeObject(obj, Formatting.Indented, settings); | ||
File.WriteAllText(fileName, result); | ||
|
||
string argument = "/select, \"" + fileName + "\""; | ||
Process.Start("explorer.exe", argument); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters