diff --git a/Mods/DefaultSkins/Skins/badeline.json b/Mods/DefaultSkins/Skins/badeline.json index 5b24d4c1..6a6c6360 100644 --- a/Mods/DefaultSkins/Skins/badeline.json +++ b/Mods/DefaultSkins/Skins/badeline.json @@ -2,9 +2,9 @@ "Model": "badeline", "HideHair": false, "Name": "Badeline", - "HairNormal" : 10174389, - "HairNoDash" : 7258367, - "HairTwoDash" : 16421375, - "HairRefillFlash" : 16777215, - "HairFeather" : 15914064 + "HairNormal" : "9B3FB5", + "HairNoDash" : "6EC0FF", + "HairTwoDash" : "FA91FF", + "HairRefillFlash" : "FFFFFF", + "HairFeather" : "F2D450" } \ No newline at end of file diff --git a/Mods/DefaultSkins/Skins/granny.json b/Mods/DefaultSkins/Skins/granny.json index 0a4ea856..4c7b895d 100644 --- a/Mods/DefaultSkins/Skins/granny.json +++ b/Mods/DefaultSkins/Skins/granny.json @@ -2,9 +2,9 @@ "Model": "granny", "HideHair": true, "Name": "Granny", - "HairNormal" : 16777215, - "HairNoDash" : 7258367, - "HairTwoDash" : 16421375, - "HairRefillFlash" : 16777215, - "HairFeather" : 15914064 + "HairNormal" : "FFFFFF", + "HairNoDash" : "6EC0FF", + "HairTwoDash" : "FA91FF", + "HairRefillFlash" : "FFFFFF", + "HairFeather" : "F2D450" } \ No newline at end of file diff --git a/Mods/DefaultSkins/Skins/player-short-hair.json b/Mods/DefaultSkins/Skins/player-short-hair.json index b0f4ee87..2c2c7582 100644 --- a/Mods/DefaultSkins/Skins/player-short-hair.json +++ b/Mods/DefaultSkins/Skins/player-short-hair.json @@ -1,10 +1,5 @@ { "Model": "player", "HideHair": true, - "Name": "Short Hair", - "HairNormal" : 14363648, - "HairNoDash" : 7258367, - "HairTwoDash" : 16421375, - "HairRefillFlash" : 16777215, - "HairFeather" : 15914064 + "Name": "Short Hair" } \ No newline at end of file diff --git a/Mods/DefaultSkins/Skins/theo.json b/Mods/DefaultSkins/Skins/theo.json index fae7ff61..d6485955 100644 --- a/Mods/DefaultSkins/Skins/theo.json +++ b/Mods/DefaultSkins/Skins/theo.json @@ -2,9 +2,5 @@ "Model": "theo", "HideHair": true, "Name": "Theo", - "HairNormal" : 4530968, - "HairNoDash" : 7258367, - "HairTwoDash" : 16421375, - "HairRefillFlash" : 16777215, - "HairFeather" : 15914064 + "HairNormal" : "452318" } \ No newline at end of file diff --git a/Source/Mod/Helpers/SkinInfo.cs b/Source/Mod/Helpers/SkinInfo.cs index cb29f941..0dc9948b 100644 --- a/Source/Mod/Helpers/SkinInfo.cs +++ b/Source/Mod/Helpers/SkinInfo.cs @@ -1,4 +1,5 @@ +using System.Text.Json; using System.Text.Json.Serialization; namespace Celeste64; @@ -12,11 +13,17 @@ public class SkinInfo public virtual string Model { get; set; } = ""; public virtual bool HideHair { get; set; } = false; public virtual string CollectableId { get; set; } = ""; - public virtual int HairNormal { get; set; } = 0; - public virtual int HairNoDash { get; set; } = 0; - public virtual int HairTwoDash { get; set; } = 0; - public virtual int HairRefillFlash { get; set; } = 0; - public virtual int HairFeather { get; set; } = 0; + + [JsonConverter(typeof(DecimalOrHexConverter))] + public virtual int HairNormal { get; set; } = 0xdb2c00; + [JsonConverter(typeof(DecimalOrHexConverter))] + public virtual int HairNoDash { get; set; } = 0x6ec0ff; + [JsonConverter(typeof(DecimalOrHexConverter))] + public virtual int HairTwoDash { get; set; } = 0xfa91ff; + [JsonConverter(typeof(DecimalOrHexConverter))] + public virtual int HairRefillFlash { get; set; } = 0xffffff; + [JsonConverter(typeof(DecimalOrHexConverter))] + public virtual int HairFeather { get; set; } = 0xf2d450; public bool IsValid() { @@ -32,6 +39,39 @@ public virtual void OnEquipped(Player player, Model m) { } public virtual void OnRemoved(Player player, Model m) { } } +// This allows us to support either decimal integers or hex strings. +public class DecimalOrHexConverter : JsonConverter +{ + public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Number) + { + return reader.TryGetInt32(out var i) ? i : 0; + } + else if (reader.TokenType == JsonTokenType.String) + { + try + { + return Convert.ToInt32(reader.GetString(), 16); + } + catch (Exception ex) + { + Log.Error("Error: Could not parse value in skin file: " + ex.ToString()); + return 0; + } + } + else + { + return 0; + } + } + + public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, value.GetType()); + } +} + [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(SkinInfo))] internal partial class SkinInfoContext : JsonSerializerContext { }