From 9cc9e88318bb3418f58e911ba92ddb87fa2349a6 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 17:23:15 +0100
Subject: [PATCH 01/20] Update attributes.
---
NWN.Anvil/src/main/API/Color.cs | 10 ++--
.../src/main/API/EngineStructures/TileData.cs | 16 +++----
.../src/main/API/Nui/Bindings/NuiBind.cs | 4 +-
.../main/API/Nui/Bindings/NuiBindStrRef.cs | 4 +-
.../src/main/API/Nui/Bindings/NuiValue.cs | 2 +-
.../main/API/Nui/Bindings/NuiValueStrRef.cs | 2 +-
.../Nui/Bindings/NuiValueStrRefConverter.cs | 3 +-
.../src/main/API/Nui/Layout/NuiColumn.cs | 2 +-
NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs | 6 +--
.../src/main/API/Nui/Layout/NuiLayout.cs | 4 +-
NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs | 2 +-
NWN.Anvil/src/main/API/Nui/NuiElement.cs | 47 ++++++++++++-------
NWN.Anvil/src/main/API/Nui/NuiList.cs | 12 ++---
.../src/main/API/Nui/NuiListTemplateCell.cs | 2 +-
NWN.Anvil/src/main/API/Nui/NuiRect.cs | 10 ++--
NWN.Anvil/src/main/API/Nui/NuiVector.cs | 6 +--
NWN.Anvil/src/main/API/Nui/NuiWindow.cs | 25 +++++-----
.../Nui/Widgets/DrawList/NuiDrawListArc.cs | 10 ++--
.../Nui/Widgets/DrawList/NuiDrawListCircle.cs | 4 +-
.../Nui/Widgets/DrawList/NuiDrawListCurve.cs | 10 ++--
.../Nui/Widgets/DrawList/NuiDrawListImage.cs | 14 +++---
.../Nui/Widgets/DrawList/NuiDrawListItem.cs | 16 +++----
.../Nui/Widgets/DrawList/NuiDrawListLine.cs | 6 +--
.../Widgets/DrawList/NuiDrawListPolyLine.cs | 4 +-
.../Nui/Widgets/DrawList/NuiDrawListText.cs | 6 +--
.../src/main/API/Nui/Widgets/NuiButton.cs | 4 +-
.../main/API/Nui/Widgets/NuiButtonImage.cs | 4 +-
.../main/API/Nui/Widgets/NuiButtonSelect.cs | 6 +--
.../src/main/API/Nui/Widgets/NuiChart.cs | 4 +-
.../src/main/API/Nui/Widgets/NuiChartSlot.cs | 10 ++--
.../src/main/API/Nui/Widgets/NuiCheck.cs | 6 +--
.../main/API/Nui/Widgets/NuiColorPicker.cs | 4 +-
.../src/main/API/Nui/Widgets/NuiCombo.cs | 6 +--
.../src/main/API/Nui/Widgets/NuiComboEntry.cs | 2 +-
.../src/main/API/Nui/Widgets/NuiImage.cs | 12 ++---
.../src/main/API/Nui/Widgets/NuiLabel.cs | 8 ++--
.../src/main/API/Nui/Widgets/NuiOptions.cs | 8 ++--
.../src/main/API/Nui/Widgets/NuiProgress.cs | 4 +-
.../src/main/API/Nui/Widgets/NuiSlider.cs | 10 ++--
.../main/API/Nui/Widgets/NuiSliderFloat.cs | 10 ++--
NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs | 8 ++--
.../src/main/API/Nui/Widgets/NuiTextEdit.cs | 12 ++---
.../src/main/API/Nui/Widgets/NuiToggles.cs | 6 +--
NWN.Anvil/src/main/API/Tlk/StrRef.cs | 4 +-
NWN.Anvil/src/main/API/Utils/JsonUtility.cs | 1 -
45 files changed, 186 insertions(+), 170 deletions(-)
diff --git a/NWN.Anvil/src/main/API/Color.cs b/NWN.Anvil/src/main/API/Color.cs
index dd482041c..8865168c9 100644
--- a/NWN.Anvil/src/main/API/Color.cs
+++ b/NWN.Anvil/src/main/API/Color.cs
@@ -1,5 +1,5 @@
using System;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
using NWNX.NET.Native;
namespace Anvil.API
@@ -12,25 +12,25 @@ namespace Anvil.API
///
/// Gets the alpha value of this color as a byte (0-255).
///
- [JsonProperty("a")]
+ [JsonPropertyName("a")]
public readonly byte Alpha;
///
/// Gets the blue value of this color as a byte (0-255).
///
- [JsonProperty("b")]
+ [JsonPropertyName("b")]
public readonly byte Blue;
///
/// Gets the green value of this color as a byte (0-255).
///
- [JsonProperty("g")]
+ [JsonPropertyName("g")]
public readonly byte Green;
///
/// Gets the red value of this color as a byte (0-255).
///
- [JsonProperty("r")]
+ [JsonPropertyName("r")]
public readonly byte Red;
///
diff --git a/NWN.Anvil/src/main/API/EngineStructures/TileData.cs b/NWN.Anvil/src/main/API/EngineStructures/TileData.cs
index d4cfe7d9b..5d9bfecd5 100644
--- a/NWN.Anvil/src/main/API/EngineStructures/TileData.cs
+++ b/NWN.Anvil/src/main/API/EngineStructures/TileData.cs
@@ -1,5 +1,5 @@
using System;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -18,43 +18,43 @@ public sealed class TileData
/// 3 4 5
/// 0 1 2
///
- [JsonProperty("index")]
+ [JsonPropertyName("index")]
public int Index { get; set; }
///
/// The new tile ID to assign.
///
- [JsonProperty("tileid")]
+ [JsonPropertyName("tileid")]
public int TileId { get; set; }
///
/// The rotation of the new tile.
///
- [JsonProperty("orientation")]
+ [JsonPropertyName("orientation")]
public TileRotation Orientation { get; set; }
///
/// The height of the new tile.
///
- [JsonProperty("height")]
+ [JsonPropertyName("height")]
public int Height { get; set; }
///
/// The animation state of the new tile (1/0).
///
- [JsonProperty("animloop1")]
+ [JsonPropertyName("animloop1")]
public int AnimationLoop1 { get; set; }
///
/// The animation state of the new tile (1/0).
///
- [JsonProperty("animloop2")]
+ [JsonPropertyName("animloop2")]
public int AnimationLoop2 { get; set; }
///
/// The animation state of the new tile (1/0).
///
- [JsonProperty("animloop3")]
+ [JsonPropertyName("animloop3")]
public int AnimationLoop3 { get; set; }
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiBind.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiBind.cs
index e7ca11a8a..7b5bd8954 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiBind.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiBind.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
using NWN.Core;
namespace Anvil.API
@@ -11,7 +11,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiBind(string key) : NuiProperty
{
- [JsonProperty("bind")]
+ [JsonPropertyName("bind")]
public string Key { get; init; } = key;
///
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiBindStrRef.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiBindStrRef.cs
index e142df617..7a378557b 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiBindStrRef.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiBindStrRef.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
using NWN.Core;
namespace Anvil.API
@@ -7,7 +7,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiBindStrRef(string key) : NuiProperty
{
- [JsonProperty("bind")]
+ [JsonPropertyName("bind")]
public string Key { get; init; } = key;
///
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
index 676cf983d..bd5230b16 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRef.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRef.cs
index b1fe98a6b..613f7dcda 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRef.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRef.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
index 77310b399..c90b2a820 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
@@ -1,5 +1,6 @@
using System;
-using Newtonsoft.Json;
+using System.Text.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
index 0682cdab6..3d285410f 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
index 58001e3ef..e6f76eee2 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
using NWN.Core;
namespace Anvil.API
@@ -11,7 +11,7 @@ namespace Anvil.API
///
public sealed class NuiGroup : NuiLayout
{
- [JsonProperty("border")]
+ [JsonPropertyName("border")]
public bool Border { get; set; } = true;
[JsonIgnore]
@@ -24,7 +24,7 @@ public NuiLayout? Layout
[JsonIgnore]
public NuiElement? Element { get; set; }
- [JsonProperty("scrollbars")]
+ [JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Auto;
public override string Type => "group";
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
index 6f51754f7..0220bf90e 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
@@ -1,11 +1,11 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
public abstract class NuiLayout : NuiElement
{
- [JsonProperty("children")]
+ [JsonPropertyName("children")]
protected abstract IEnumerable SerializedChildren { get; }
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
index d13ddd5e2..175806003 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/NuiElement.cs b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
index 440c31469..e2431b153 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiElement.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -11,13 +11,15 @@ public abstract class NuiElement
///
/// The aspect ratio (x/y) for this element.
///
- [JsonProperty("aspect", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("aspect")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public float? Aspect { get; set; }
///
/// Toggles if this element is active/interactable, or disabled/greyed out.
///
- [JsonProperty("enabled", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("enabled")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? Enabled { get; set; }
///
@@ -25,70 +27,83 @@ public abstract class NuiElement
/// This is dependent on the widget in question and only supports solid/full colors right now (no texture skinning).
/// For example, labels would style their text color; progress bars would style the bar.
///
- [JsonProperty("foreground_color", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("foreground_color")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? ForegroundColor { get; set; }
///
/// The height of this element, in pixels.
///
- [JsonProperty("height", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("height")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public float? Height { get; set; }
///
/// A unique identifier for this element.
///
- [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("id")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Id { get; set; }
///
/// The margin on the widget. The margin is the spacing outside of the widget.
///
- [JsonProperty("margin", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("margin")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public float? Margin { get; set; }
///
/// The padding on the widget. The padding is the spacing inside of the widget.
///
- [JsonProperty("padding", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("padding")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public float? Padding { get; set; }
///
/// A tooltip to show when hovering over this element.
///
- [JsonProperty("tooltip", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("tooltip")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? Tooltip { get; set; }
- [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("type")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public abstract string Type { get; }
///
/// Toggles if this element should/should not be rendered. Invisible elements still take up layout space, and cannot be clicked through.
///
- [JsonProperty("visible", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("visible")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? Visible { get; set; }
///
/// The width of this element, in pixels.
///
- [JsonProperty("width", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("width")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public float? Width { get; set; }
- [JsonProperty("draw_list", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("draw_list")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List? DrawList { get; set; }
- [JsonProperty("draw_list_scissor", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("draw_list_scissor")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? Scissor { get; set; }
///
/// Tooltips for disabled elements show on mouse hover.
///
- [JsonProperty("disabled_tooltip", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("disabled_tooltip")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? DisabledTooltip { get; set; }
///
/// Encouraged elements have a breathing animated glow inside of it.
///
- [JsonProperty("encouraged", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("encouraged")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? Encouraged { get; set; }
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/NuiList.cs b/NWN.Anvil/src/main/API/Nui/NuiList.cs
index 3316383b1..08840f36c 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiList.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiList.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -12,33 +12,33 @@ public sealed class NuiList(IReadOnlyCollection rowTemplate
///
/// Gets or sets whether a border should be rendered around this list view.
///
- [JsonProperty("border")]
+ [JsonPropertyName("border")]
public bool Border { get; set; } = true;
///
/// Gets or sets the number of rows in this list.
///
- [JsonProperty("row_count")]
+ [JsonPropertyName("row_count")]
public NuiProperty RowCount { get; set; } = rowCount;
///
/// Gets or sets the row height.
///
- [JsonProperty("row_height")]
+ [JsonPropertyName("row_height")]
public float RowHeight { get; set; } = NuiStyle.RowHeight;
///
/// Gets or sets the list of cells composing the row template.
/// A max of 16 cells are supported.
///
- [JsonProperty("row_template")]
+ [JsonPropertyName("row_template")]
public List RowTemplate { get; set; } = [..rowTemplate];
///
/// Gets or sets whether scroll bars should be rendered for this scroll list.
/// is not supported.
///
- [JsonProperty("scrollbars")]
+ [JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Y;
public override string Type => "list";
diff --git a/NWN.Anvil/src/main/API/Nui/NuiListTemplateCell.cs b/NWN.Anvil/src/main/API/Nui/NuiListTemplateCell.cs
index 75ee830c5..78f00af82 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiListTemplateCell.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiListTemplateCell.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/NuiRect.cs b/NWN.Anvil/src/main/API/Nui/NuiRect.cs
index 753f419fe..5edbebedc 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiRect.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiRect.cs
@@ -1,20 +1,20 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
[method: JsonConstructor]
public readonly struct NuiRect(float x, float y, float width, float height)
{
- [JsonProperty("h")]
+ [JsonPropertyName("h")]
public float Height { get; } = height;
- [JsonProperty("w")]
+ [JsonPropertyName("w")]
public float Width { get; } = width;
- [JsonProperty("x")]
+ [JsonPropertyName("x")]
public float X { get; } = x;
- [JsonProperty("y")]
+ [JsonPropertyName("y")]
public float Y { get; } = y;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/NuiVector.cs b/NWN.Anvil/src/main/API/Nui/NuiVector.cs
index a9dc043e0..224ca76f0 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiVector.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiVector.cs
@@ -1,16 +1,16 @@
using System;
using System.Numerics;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
[method: JsonConstructor]
public readonly struct NuiVector(float x, float y) : IEquatable
{
- [JsonProperty("x")]
+ [JsonPropertyName("x")]
public readonly float X = x;
- [JsonProperty("y")]
+ [JsonPropertyName("y")]
public readonly float Y = y;
public static NuiVector operator +(NuiVector a, NuiVector b)
diff --git a/NWN.Anvil/src/main/API/Nui/NuiWindow.cs b/NWN.Anvil/src/main/API/Nui/NuiWindow.cs
index b51d8e959..b799fe83f 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiWindow.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiWindow.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -11,21 +11,21 @@ public sealed class NuiWindow(NuiLayout root, NuiProperty title)
///
/// Gets or sets whether the window border should be rendered.
///
- [JsonProperty("border")]
+ [JsonPropertyName("border")]
public NuiProperty Border { get; set; } = true;
///
/// Gets or sets whether this window can be closed.
/// You must provide a way to close the window if you set this to false.
///
- [JsonProperty("closable")]
+ [JsonPropertyName("closable")]
public NuiProperty Closable { get; set; } = true;
///
/// Gets or sets whether this window is collapsed.
/// Use a static value to force the popup into a collapsed/unfolded state.
///
- [JsonProperty("collapsed")]
+ [JsonPropertyName("collapsed")]
public NuiProperty? Collapsed { get; set; }
///
@@ -34,49 +34,50 @@ public sealed class NuiWindow(NuiLayout root, NuiProperty title)
/// Set x and/or y to -2.0 to position the window's top left at the mouse cursor's position of that axis
/// Set x and/or y to -3.0 to center the window on the mouse cursor's position of that axis
///
- [JsonProperty("geometry")]
+ [JsonPropertyName("geometry")]
public NuiProperty Geometry { get; set; } = new NuiRect(-1, -1, 0, 0);
///
/// Gets or sets the element ID for this window.
///
- [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("id")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Id { get; set; }
///
/// Gets or sets whether this window can be resized.
///
- [JsonProperty("resizable")]
+ [JsonPropertyName("resizable")]
public NuiProperty Resizable { get; set; } = true;
///
/// Gets or sets the root parent layout containing the window content.
///
- [JsonProperty("root")]
+ [JsonPropertyName("root")]
public NuiLayout Root { get; set; } = root;
///
/// Gets or sets the title of this window.
///
- [JsonProperty("title")]
+ [JsonPropertyName("title")]
public NuiProperty Title { get; set; } = title;
///
/// Gets or sets whether the background should be rendered.
///
- [JsonProperty("transparent")]
+ [JsonPropertyName("transparent")]
public NuiProperty Transparent { get; set; } = false;
///
/// Gets the current serialized version of this window.
///
- [JsonProperty("version")]
+ [JsonPropertyName("version")]
public int Version { get; private set; } = 1;
///
/// Set to false to disable all input. All hover, clicks and keypresses will fall through.
///
- [JsonProperty("accepts_input")]
+ [JsonPropertyName("accepts_input")]
public NuiProperty AcceptsInput { get; set; } = true;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
index 681b9d9bc..c0e1f960a 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -17,16 +17,16 @@ public NuiDrawListArc(NuiProperty color, NuiProperty fill, NuiPrope
AngleMax = angleMax;
}
- [JsonProperty("amax")]
+ [JsonPropertyName("amax")]
public NuiProperty AngleMax { get; set; }
- [JsonProperty("amin")]
+ [JsonPropertyName("amin")]
public NuiProperty AngleMin { get; set; }
- [JsonProperty("c")]
+ [JsonPropertyName("c")]
public NuiProperty Center { get; set; }
- [JsonProperty("radius")]
+ [JsonPropertyName("radius")]
public NuiProperty Radius { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Arc;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
index 9a2223933..fe92cc21b 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -13,7 +13,7 @@ public NuiDrawListCircle(NuiProperty color, NuiProperty fill, NuiPr
Rect = rect;
}
- [JsonProperty("rect")]
+ [JsonPropertyName("rect")]
public NuiProperty Rect { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Circle;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
index 765748d21..50fd3cf64 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -16,16 +16,16 @@ public NuiDrawListCurve(NuiProperty color, NuiProperty lineThickne
Control1 = control1;
}
- [JsonProperty("ctrl0")]
+ [JsonPropertyName("ctrl0")]
public NuiProperty Control0 { get; set; }
- [JsonProperty("ctrl1")]
+ [JsonPropertyName("ctrl1")]
public NuiProperty Control1 { get; set; }
- [JsonProperty("a")]
+ [JsonPropertyName("a")]
public NuiProperty PointA { get; set; }
- [JsonProperty("b")]
+ [JsonPropertyName("b")]
public NuiProperty PointB { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Curve;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
index 7f7763ff0..b78f61bef 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
@@ -1,32 +1,32 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
[method: JsonConstructor]
public sealed class NuiDrawListImage(NuiProperty resRef, NuiProperty rect) : NuiDrawListItem
{
- [JsonProperty("image_aspect")]
+ [JsonPropertyName("image_aspect")]
public NuiProperty Aspect { get; set; } = NuiAspect.Exact;
- [JsonProperty("image_halign")]
+ [JsonPropertyName("image_halign")]
public NuiProperty HorizontalAlign { get; set; } = NuiHAlign.Left;
- [JsonProperty("rect")]
+ [JsonPropertyName("rect")]
public NuiProperty Rect { get; set; } = rect;
- [JsonProperty("image")]
+ [JsonPropertyName("image")]
public NuiProperty ResRef { get; set; } = resRef;
///
/// Optionally render a subregion of the image.
/// This property is a NuiRect (x, y, w, h) to indicate the render region inside the image.
///
- [JsonProperty("image_region", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("image_region", NullValueHandling = NullValueHandling.Ignore)]
public NuiProperty? ImageRegion { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Image;
- [JsonProperty("image_valign")]
+ [JsonPropertyName("image_valign")]
public NuiProperty VerticalAlign { get; set; } = NuiVAlign.Top;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
index f297918ee..d4a228c3b 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
@@ -1,28 +1,28 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
public abstract class NuiDrawListItem
{
- [JsonProperty("color", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("color", NullValueHandling = NullValueHandling.Include)]
public NuiProperty? Color { get; set; }
- [JsonProperty("enabled")]
+ [JsonPropertyName("enabled")]
public NuiProperty Enabled { get; set; } = true;
- [JsonProperty("fill", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("fill", NullValueHandling = NullValueHandling.Include)]
public NuiProperty? Fill { get; set; }
- [JsonProperty("line_thickness", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("line_thickness", NullValueHandling = NullValueHandling.Include)]
public NuiProperty? LineThickness { get; set; }
- [JsonProperty("type")]
+ [JsonPropertyName("type")]
public abstract NuiDrawListItemType Type { get; }
- [JsonProperty("order")]
+ [JsonPropertyName("order")]
public NuiDrawListItemOrder Order { get; set; } = NuiDrawListItemOrder.After;
- [JsonProperty("render")]
+ [JsonPropertyName("render")]
public NuiDrawListItemRender Render { get; set; } = NuiDrawListItemRender.Always;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
index 96d445671..e349a62bd 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -14,10 +14,10 @@ public NuiDrawListLine(NuiProperty color, NuiProperty fill, NuiProp
PointB = pointB;
}
- [JsonProperty("a")]
+ [JsonPropertyName("a")]
public NuiProperty PointA { get; set; }
- [JsonProperty("b")]
+ [JsonPropertyName("b")]
public NuiProperty PointB { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Line;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
index ec1b28f1a..4352e505c 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -14,7 +14,7 @@ public NuiDrawListPolyLine(NuiProperty color, NuiProperty fill, Nui
Points = points;
}
- [JsonProperty("points")]
+ [JsonPropertyName("points")]
public List Points { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.PolyLine;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
index a5dbaa4b0..1de53d631 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -12,10 +12,10 @@ public NuiDrawListText(NuiProperty color, NuiProperty rect, NuiP
Text = text;
}
- [JsonProperty("rect")]
+ [JsonPropertyName("rect")]
public NuiProperty Rect { get; set; }
- [JsonProperty("text")]
+ [JsonPropertyName("text")]
public NuiProperty Text { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Text;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
index 2d63fae67..6e7cb563a 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,7 +8,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiButton(NuiProperty label) : NuiWidget
{
- [JsonProperty("label")]
+ [JsonPropertyName("label")]
public NuiProperty Label { get; set; } = label;
public override string Type => "button";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
index a115c1d69..3c957264a 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,7 +8,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiButtonImage(NuiProperty resRef) : NuiWidget
{
- [JsonProperty("label")]
+ [JsonPropertyName("label")]
public NuiProperty ResRef { get; set; } = resRef;
public override string Type => "button_image";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
index 7bd2c2db2..1d81bc24d 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -9,10 +9,10 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiButtonSelect(NuiProperty label, NuiProperty selected) : NuiWidget
{
- [JsonProperty("label")]
+ [JsonPropertyName("label")]
public NuiProperty Label { get; set; } = label;
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = selected;
public override string Type => "button_select";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
index 6fdfbf38a..9131b6ffb 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,7 +8,7 @@ namespace Anvil.API
///
public sealed class NuiChart : NuiWidget
{
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public List? ChartSlots { get; set; }
public override string Type => "chart";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChartSlot.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChartSlot.cs
index 146839dfc..f7062413a 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChartSlot.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChartSlot.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -9,16 +9,16 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiChartSlot(NuiChartType chartType, NuiProperty legend, NuiProperty color, NuiProperty> data)
{
- [JsonProperty("type")]
+ [JsonPropertyName("type")]
public NuiChartType ChartType { get; set; } = chartType;
- [JsonProperty("color")]
+ [JsonPropertyName("color")]
public NuiProperty Color { get; set; } = color;
- [JsonProperty("data")]
+ [JsonPropertyName("data")]
public NuiProperty> Data { get; set; } = data;
- [JsonProperty("legend")]
+ [JsonPropertyName("legend")]
public NuiProperty Legend { get; set; } = legend;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
index d7eb08ed7..21cacb569 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,10 +8,10 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiCheck(NuiProperty label, NuiProperty selected) : NuiWidget
{
- [JsonProperty("label")]
+ [JsonPropertyName("label")]
public NuiProperty Label { get; set; } = label;
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = selected;
public override string Type => "check";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
index ed6d90619..fb460a0aa 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,7 +8,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiColorPicker(NuiProperty color) : NuiWidget
{
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Color { get; set; } = color;
public override string Type => "color_picker";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
index da8ef4f71..49ebde2af 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,10 +8,10 @@ namespace Anvil.API
///
public sealed class NuiCombo : NuiWidget
{
- [JsonProperty("elements")]
+ [JsonPropertyName("elements")]
public NuiProperty> Entries { get; set; } = new List();
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = 0;
public override string Type => "combo";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiComboEntry.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiComboEntry.cs
index f2c172951..7f3a18e3c 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiComboEntry.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiComboEntry.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
index cce0f1576..69d6eaced 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,25 +8,25 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiImage(NuiProperty resRef) : NuiWidget
{
- [JsonProperty("image_halign")]
+ [JsonPropertyName("image_halign")]
public NuiProperty HorizontalAlign { get; set; } = NuiHAlign.Left;
- [JsonProperty("image_aspect")]
+ [JsonPropertyName("image_aspect")]
public NuiProperty ImageAspect { get; set; } = NuiAspect.Exact;
///
/// Optionally render only subregion of jImage.
/// This property is a NuiRect (x, y, w, h) to indicate the render region inside the image.
///
- [JsonProperty("image_region")]
+ [JsonPropertyName("image_region")]
public NuiProperty? ImageRegion { get; set; }
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty ResRef { get; set; } = resRef;
public override string Type => "image";
- [JsonProperty("image_valign")]
+ [JsonPropertyName("image_valign")]
public NuiProperty VerticalAlign { get; set; } = NuiVAlign.Top;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
index fc89376d9..4baa5a77e 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,15 +8,15 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiLabel(NuiProperty label) : NuiWidget
{
- [JsonProperty("text_halign")]
+ [JsonPropertyName("text_halign")]
public NuiProperty HorizontalAlign { get; set; } = NuiHAlign.Left;
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Label { get; set; } = label;
public override string Type => "label";
- [JsonProperty("text_valign")]
+ [JsonPropertyName("text_valign")]
public NuiProperty VerticalAlign { get; set; } = NuiVAlign.Top;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
index fe4f0c6e8..19c39493f 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -9,13 +9,13 @@ namespace Anvil.API
///
public sealed class NuiOptions : NuiWidget
{
- [JsonProperty("direction")]
+ [JsonPropertyName("direction")]
public NuiDirection Direction { get; set; } = NuiDirection.Horizontal;
- [JsonProperty("elements")]
+ [JsonPropertyName("elements")]
public List Options { get; set; } = [];
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Selection { get; set; } = -1;
public override string Type => "options";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
index 3730d2417..0a2295a6e 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -13,7 +13,7 @@ public sealed class NuiProgress(NuiProperty value) : NuiWidget
///
/// The current value of this progress bar (0-1).
///
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Value { get; set; } = value;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
index c3628288d..f3844705f 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,18 +8,18 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiSlider(NuiProperty value, NuiProperty min, NuiProperty max) : NuiWidget
{
- [JsonProperty("max")]
+ [JsonPropertyName("max")]
public NuiProperty Max { get; set; } = max;
- [JsonProperty("min")]
+ [JsonPropertyName("min")]
public NuiProperty Min { get; set; } = min;
- [JsonProperty("step")]
+ [JsonPropertyName("step")]
public NuiProperty Step { get; set; } = 1;
public override string Type => "slider";
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Value { get; set; } = value;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
index da0386bdc..5c90eda97 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,18 +8,18 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiSliderFloat(NuiProperty value, NuiProperty min, NuiProperty max) : NuiWidget
{
- [JsonProperty("max")]
+ [JsonPropertyName("max")]
public NuiProperty Max { get; set; } = max;
- [JsonProperty("min")]
+ [JsonPropertyName("min")]
public NuiProperty Min { get; set; } = min;
- [JsonProperty("step")]
+ [JsonPropertyName("step")]
public NuiProperty StepSize { get; set; } = 0.01f;
public override string Type => "sliderf";
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Value { get; set; } = value;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
index 31a086b00..93f36c3d5 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,13 +8,13 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiText(NuiProperty text) : NuiWidget
{
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Text { get; set; } = text;
- [JsonProperty("border")]
+ [JsonPropertyName("border")]
public bool Border { get; set; } = true;
- [JsonProperty("scrollbars")]
+ [JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Auto;
public override string Type => "text";
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
index f35300a0f..efe9a3a72 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -8,21 +8,21 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiTextEdit(NuiProperty label, NuiProperty value, ushort maxLength, bool multiLine) : NuiWidget
{
- [JsonProperty("label")]
+ [JsonPropertyName("label")]
public NuiProperty Label { get; set; } = label;
- [JsonProperty("max")]
+ [JsonPropertyName("max")]
public ushort MaxLength { get; set; } = maxLength;
- [JsonProperty("multiline")]
+ [JsonPropertyName("multiline")]
public bool MultiLine { get; set; } = multiLine;
public override string Type => "textedit";
- [JsonProperty("value")]
+ [JsonPropertyName("value")]
public NuiProperty Value { get; set; } = value;
- [JsonProperty("wordwrap")]
+ [JsonPropertyName("wordwrap")]
public NuiProperty WordWrap { get; set; } = true;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
index b73c93d95..96c22e69e 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
@@ -7,10 +7,10 @@ public sealed class NuiToggles(NuiDirection direction, List elements) :
{
public override string Type => "tabbar";
- [JsonProperty("direction")]
+ [JsonPropertyName("direction")]
public NuiDirection Direction { get; set; } = direction;
- [JsonProperty("elements")]
+ [JsonPropertyName("elements")]
public List Elements { get; set; } = elements;
}
}
diff --git a/NWN.Anvil/src/main/API/Tlk/StrRef.cs b/NWN.Anvil/src/main/API/Tlk/StrRef.cs
index ef4bf668c..3710b7b8e 100644
--- a/NWN.Anvil/src/main/API/Tlk/StrRef.cs
+++ b/NWN.Anvil/src/main/API/Tlk/StrRef.cs
@@ -1,6 +1,6 @@
+using System.Text.Json.Serialization;
using Anvil.Internal;
using Anvil.Services;
-using Newtonsoft.Json;
using NWN.Native.API;
namespace Anvil.API
@@ -19,7 +19,7 @@ public readonly struct StrRef(uint stringId)
///
/// Gets the index/key for this StrRef.
///
- [JsonProperty("strref")]
+ [JsonPropertyName("strref")]
public readonly uint Id = stringId;
public StrRef(int stringId) : this((uint)stringId) {}
diff --git a/NWN.Anvil/src/main/API/Utils/JsonUtility.cs b/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
index a71043cf6..b00cf2205 100644
--- a/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
+++ b/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
@@ -1,4 +1,3 @@
-using Newtonsoft.Json;
namespace Anvil.API
{
From 1edf099113bea04ee788b06f02c1291c30611267 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 17:23:34 +0100
Subject: [PATCH 02/20] Remove Newtonsoft.Json package.
---
NWN.Anvil/NWN.Anvil.csproj | 1 -
1 file changed, 1 deletion(-)
diff --git a/NWN.Anvil/NWN.Anvil.csproj b/NWN.Anvil/NWN.Anvil.csproj
index ccb5ccf06..52a9c78e6 100644
--- a/NWN.Anvil/NWN.Anvil.csproj
+++ b/NWN.Anvil/NWN.Anvil.csproj
@@ -64,7 +64,6 @@
-
From bc5f7dbd831052180aa6565aa283d81a17c75fbb Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:26:44 +0100
Subject: [PATCH 03/20] Enable polymorphic serialization on abstract NUI types.
---
NWN.Anvil/src/main/API/Nui/Bindings/NuiProperty.cs | 3 +++
NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs | 1 +
NWN.Anvil/src/main/API/Nui/NuiElement.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs | 3 +++
4 files changed, 8 insertions(+)
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiProperty.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiProperty.cs
index f7c043833..4a7e3caf4 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiProperty.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiProperty.cs
@@ -1,9 +1,12 @@
+using System.Text.Json.Serialization;
+
namespace Anvil.API
{
///
/// A NUI property that can be configured as a static readonly value, or a property that can be updated at runtime.
///
/// The underlying type of the property.
+ [JsonPolymorphic]
public abstract class NuiProperty
{
///
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
index 0220bf90e..739287050 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
@@ -3,6 +3,7 @@
namespace Anvil.API
{
+ [JsonPolymorphic]
public abstract class NuiLayout : NuiElement
{
[JsonPropertyName("children")]
diff --git a/NWN.Anvil/src/main/API/Nui/NuiElement.cs b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
index e2431b153..d020d53cc 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiElement.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
@@ -6,6 +6,7 @@ namespace Anvil.API
///
/// A dynamic NUI element with style support.
///
+ [JsonPolymorphic]
public abstract class NuiElement
{
///
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
index 57dbb2ce2..0e3a6a716 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
@@ -1,7 +1,10 @@
+using System.Text.Json.Serialization;
+
namespace Anvil.API
{
///
/// The abstract base for all NUI widgets - the building blocks for creating NUI windows.
///
+ [JsonPolymorphic]
public abstract class NuiWidget : NuiElement;
}
From 40729b514cfce34995515a81a8ac2b35373cb6df Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:27:22 +0100
Subject: [PATCH 04/20] Update JSON serializer methods to use System.Text.Json.
---
NWN.Anvil.Tests/src/main/API/ColorTests.cs | 7 +++----
NWN.Anvil/src/main/API/Utils/JsonUtility.cs | 7 ++++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/NWN.Anvil.Tests/src/main/API/ColorTests.cs b/NWN.Anvil.Tests/src/main/API/ColorTests.cs
index 96f2449a9..1bccf42b7 100644
--- a/NWN.Anvil.Tests/src/main/API/ColorTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/ColorTests.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Anvil.API;
-using Newtonsoft.Json;
using NUnit.Framework;
namespace Anvil.Tests.API
@@ -46,7 +45,7 @@ public void CreateColorTokenContainsNoNullTerminators(Color color)
[TestCase("""{"r":255,"g":100,"b":10,"a":30}""", 255, 100, 10, 30)]
public void DeserializeColorCreatesCorrectColor(string json, byte expectedRed, byte expectedGreen, byte expectedBlue, byte expectedAlpha)
{
- Color color = JsonConvert.DeserializeObject(json);
+ Color color = JsonUtility.FromJson(json);
Assert.That(color, Is.EqualTo(new Color(expectedRed, expectedGreen, expectedBlue, expectedAlpha)));
}
@@ -96,8 +95,8 @@ public void ParseRGBAReturnsCorrectColor(uint packedColor, byte expectedRed, byt
[TestCaseSource(nameof(ColorTestCases))]
public void SerializeColorRetainsColorValues(Color color)
{
- string serializedColor = JsonConvert.SerializeObject(color);
- Color deserializedColor = JsonConvert.DeserializeObject(serializedColor);
+ string serializedColor = JsonUtility.ToJson(color);
+ Color deserializedColor = JsonUtility.FromJson(serializedColor);
Assert.That(deserializedColor, Is.EqualTo(color));
}
diff --git a/NWN.Anvil/src/main/API/Utils/JsonUtility.cs b/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
index b00cf2205..e87526d7e 100644
--- a/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
+++ b/NWN.Anvil/src/main/API/Utils/JsonUtility.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
namespace Anvil.API
{
@@ -14,7 +15,7 @@ public static class JsonUtility
/// The deserialized object.
public static T? FromJson(string json)
{
- return JsonConvert.DeserializeObject(json);
+ return JsonSerializer.Deserialize(json);
}
///
@@ -25,7 +26,7 @@ public static class JsonUtility
/// A JSON string representing the value.
public static string ToJson(T value)
{
- return JsonConvert.SerializeObject(value);
+ return JsonSerializer.Serialize(value);
}
///
@@ -36,7 +37,7 @@ public static string ToJson(T value)
/// The deserialized object.
internal static T? FromJson(Json json)
{
- return JsonConvert.DeserializeObject(json.Dump());
+ return JsonSerializer.Deserialize(json.Dump());
}
///
From a248a5ab466d5abcc1239969452862218354a2e0 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:27:54 +0100
Subject: [PATCH 05/20] Remove Newtonsoft.Json from built in assemblies.
---
NWN.Anvil/src/main/Internal/Assemblies.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/NWN.Anvil/src/main/Internal/Assemblies.cs b/NWN.Anvil/src/main/Internal/Assemblies.cs
index 746567ab6..dead1659a 100644
--- a/NWN.Anvil/src/main/Internal/Assemblies.cs
+++ b/NWN.Anvil/src/main/Internal/Assemblies.cs
@@ -31,7 +31,6 @@ static Assemblies()
NWNXDotNet,
typeof(NLog.Logger).Assembly,
typeof(LightInject.ServiceContainer).Assembly,
- typeof(Newtonsoft.Json.JsonConvert).Assembly,
typeof(Paket.Dependencies).Assembly,
];
From 3669fbcd7ca4f60f7b2178d7ea1a577e9d203d54 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:28:53 +0100
Subject: [PATCH 06/20] Update additional json properties.
---
.../main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs | 3 ++-
.../main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs | 10 +++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
index b78f61bef..fa560208d 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
@@ -21,7 +21,8 @@ public sealed class NuiDrawListImage(NuiProperty resRef, NuiProperty
/// This property is a NuiRect (x, y, w, h) to indicate the render region inside the image.
///
- [JsonPropertyName("image_region", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonPropertyName("image_region")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public NuiProperty? ImageRegion { get; set; }
public override NuiDrawListItemType Type => NuiDrawListItemType.Image;
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
index d4a228c3b..b3f9895a9 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
@@ -2,18 +2,22 @@
namespace Anvil.API
{
+ [JsonPolymorphic]
public abstract class NuiDrawListItem
{
- [JsonPropertyName("color", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("color")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public NuiProperty? Color { get; set; }
[JsonPropertyName("enabled")]
public NuiProperty Enabled { get; set; } = true;
- [JsonPropertyName("fill", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("fill")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public NuiProperty? Fill { get; set; }
- [JsonPropertyName("line_thickness", NullValueHandling = NullValueHandling.Include)]
+ [JsonPropertyName("line_thickness")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public NuiProperty? LineThickness { get; set; }
[JsonPropertyName("type")]
From bf995c48ed2335cbbf9bdd869619443381b71f66 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:29:15 +0100
Subject: [PATCH 07/20] Allow null values in NuiValue constructor.
---
NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
index bd5230b16..867cf4466 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValue.cs
@@ -9,7 +9,7 @@ namespace Anvil.API
[JsonConverter(typeof(NuiValueConverter))]
public sealed class NuiValue : NuiProperty
{
- public NuiValue(T value)
+ public NuiValue(T? value)
{
Value = value;
}
From 650506b1fdd248aaf68197246f0f64a125eea7f6 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 19:29:40 +0100
Subject: [PATCH 08/20] Implement new JsonConverters.
---
.../API/Nui/Bindings/NuiValueConverter.cs | 65 +++----
.../Nui/Bindings/NuiValueStrRefConverter.cs | 14 +-
.../src/main/API/Nui/NuiListTemplateCell.cs | 6 +-
.../API/Nui/NuiListTemplateCellConverter.cs | 50 ++++++
.../main/API/Nui/ObjectToArrayConverter.cs | 160 ------------------
.../src/main/API/Nui/Widgets/NuiComboEntry.cs | 6 +-
.../API/Nui/Widgets/NuiComboEntryConverter.cs | 43 +++++
7 files changed, 139 insertions(+), 205 deletions(-)
create mode 100644 NWN.Anvil/src/main/API/Nui/NuiListTemplateCellConverter.cs
delete mode 100644 NWN.Anvil/src/main/API/Nui/ObjectToArrayConverter.cs
create mode 100644 NWN.Anvil/src/main/API/Nui/Widgets/NuiComboEntryConverter.cs
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
index af0c67011..a824e90e6 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
@@ -1,54 +1,61 @@
using System;
using System.Reflection;
-using Newtonsoft.Json;
+using System.Text.Json;
+using System.Text.Json.Serialization;
namespace Anvil.API
{
- public sealed class NuiValueConverter : JsonConverter
+ public sealed class NuiValueConverter : JsonConverterFactory
{
public override bool CanConvert(Type objectType)
{
- return objectType.GetGenericTypeDefinition() == typeof(NuiValue<>);
- }
-
- public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
- {
- object? retVal = Activator.CreateInstance(objectType, true);
- if (retVal == null)
+ if (!objectType.IsGenericType)
{
- return null;
+ return false;
}
- PropertyInfo? propertyInfo = objectType.GetProperty(nameof(NuiValue
/// The underlying type of the property.
- [JsonPolymorphic]
+ [JsonConverter(typeof(NuiPropertyConverter))]
public abstract class NuiProperty
{
///
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs
new file mode 100644
index 000000000..241d8ef2c
--- /dev/null
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Reflection;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Anvil.API
+{
+ public sealed class NuiPropertyConverter : JsonConverterFactory
+ {
+ public override bool CanConvert(Type objectType)
+ {
+ if (!objectType.IsGenericType)
+ {
+ return false;
+ }
+
+ return objectType.GetGenericTypeDefinition() == typeof(NuiProperty<>);
+ }
+
+ public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
+ {
+ Type valueType = typeToConvert.GetGenericArguments()[0];
+ Type converterType = typeof(NuiPropertyConverterInner<>).MakeGenericType(valueType);
+
+ return (JsonConverter?)Activator.CreateInstance(converterType,
+ BindingFlags.Instance | BindingFlags.Public,
+ null,
+ [options],
+ null);
+ }
+
+ private sealed class NuiPropertyConverterInner(JsonSerializerOptions options) : JsonConverter>
+ {
+ private readonly JsonConverter bindStrRefConverter = (JsonConverter)options.GetConverter(typeof(NuiBindStrRef));
+ private readonly JsonConverter valueStrRefConverter = (JsonConverter)options.GetConverter(typeof(NuiValueStrRef));
+ private readonly JsonConverter> bindConverter = (JsonConverter>)options.GetConverter(typeof(NuiBind));
+ private readonly JsonConverter> valueConverter = (JsonConverter>)options.GetConverter(typeof(NuiValue));
+
+ public override NuiProperty Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Write(Utf8JsonWriter writer, NuiProperty property, JsonSerializerOptions options)
+ {
+ switch (property)
+ {
+ case NuiBind bind:
+ bindConverter.Write(writer, bind, options);
+ break;
+ case NuiValue value:
+ valueConverter.Write(writer, value, options);
+ break;
+ case NuiBindStrRef bindStrRef:
+ bindStrRefConverter.Write(writer, bindStrRef, options);
+ break;
+ case NuiValueStrRef valueStrRef:
+ valueStrRefConverter.Write(writer, valueStrRef, options);
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
index 71ed1e58a..2a9a33a67 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
@@ -4,18 +4,20 @@
namespace Anvil.API
{
- public sealed class NuiValueStrRefConverter(JsonSerializerOptions options) : JsonConverter
+ public sealed class NuiValueStrRefConverter : JsonConverter
{
- private readonly JsonConverter valueConverter = (JsonConverter)options.GetConverter(typeof(StrRef));
-
public override NuiValueStrRef? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
+ JsonConverter valueConverter = (JsonConverter)options.GetConverter(typeof(StrRef));
+
StrRef? value = valueConverter.Read(ref reader, typeof(StrRef?), options);
return value != null ? new NuiValueStrRef(value) : null;
}
public override void Write(Utf8JsonWriter writer, NuiValueStrRef? value, JsonSerializerOptions options)
{
+ JsonConverter valueConverter = (JsonConverter)options.GetConverter(typeof(StrRef));
+
if (value?.Value != null)
{
valueConverter.Write(writer, value.Value.Value, options);
From 1d6e8c1ac83fa7c159a12437f562dc84fc97b9fc Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 23:24:46 +0100
Subject: [PATCH 13/20] Declare derived types.
---
.../src/main/API/Nui/Layout/NuiLayout.cs | 3 +++
NWN.Anvil/src/main/API/Nui/NuiElement.cs | 21 +++++++++++++++++++
.../Nui/Widgets/DrawList/NuiDrawListItem.cs | 7 +++++++
.../src/main/API/Nui/Widgets/NuiWidget.cs | 17 +++++++++++++++
4 files changed, 48 insertions(+)
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
index 739287050..450365105 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
@@ -4,6 +4,9 @@
namespace Anvil.API
{
[JsonPolymorphic]
+ [JsonDerivedType(typeof(NuiColumn))]
+ [JsonDerivedType(typeof(NuiGroup))]
+ [JsonDerivedType(typeof(NuiRow))]
public abstract class NuiLayout : NuiElement
{
[JsonPropertyName("children")]
diff --git a/NWN.Anvil/src/main/API/Nui/NuiElement.cs b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
index d020d53cc..9be9a1e37 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiElement.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiElement.cs
@@ -7,6 +7,27 @@ namespace Anvil.API
/// A dynamic NUI element with style support.
///
[JsonPolymorphic]
+ [JsonDerivedType(typeof(NuiColumn))]
+ [JsonDerivedType(typeof(NuiGroup))]
+ [JsonDerivedType(typeof(NuiRow))]
+ [JsonDerivedType(typeof(NuiList))]
+ [JsonDerivedType(typeof(NuiButton))]
+ [JsonDerivedType(typeof(NuiButtonImage))]
+ [JsonDerivedType(typeof(NuiButtonSelect))]
+ [JsonDerivedType(typeof(NuiChart))]
+ [JsonDerivedType(typeof(NuiCheck))]
+ [JsonDerivedType(typeof(NuiColorPicker))]
+ [JsonDerivedType(typeof(NuiCombo))]
+ [JsonDerivedType(typeof(NuiImage))]
+ [JsonDerivedType(typeof(NuiLabel))]
+ [JsonDerivedType(typeof(NuiOptions))]
+ [JsonDerivedType(typeof(NuiProgress))]
+ [JsonDerivedType(typeof(NuiSlider))]
+ [JsonDerivedType(typeof(NuiSliderFloat))]
+ [JsonDerivedType(typeof(NuiSpacer))]
+ [JsonDerivedType(typeof(NuiText))]
+ [JsonDerivedType(typeof(NuiTextEdit))]
+ [JsonDerivedType(typeof(NuiToggles))]
public abstract class NuiElement
{
///
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
index b3f9895a9..a20d806ed 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListItem.cs
@@ -3,6 +3,13 @@
namespace Anvil.API
{
[JsonPolymorphic]
+ [JsonDerivedType(typeof(NuiDrawListArc))]
+ [JsonDerivedType(typeof(NuiDrawListCircle))]
+ [JsonDerivedType(typeof(NuiDrawListCurve))]
+ [JsonDerivedType(typeof(NuiDrawListImage))]
+ [JsonDerivedType(typeof(NuiDrawListLine))]
+ [JsonDerivedType(typeof(NuiDrawListPolyLine))]
+ [JsonDerivedType(typeof(NuiDrawListText))]
public abstract class NuiDrawListItem
{
[JsonPropertyName("color")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
index 0e3a6a716..e8975d891 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiWidget.cs
@@ -6,5 +6,22 @@ namespace Anvil.API
/// The abstract base for all NUI widgets - the building blocks for creating NUI windows.
///
[JsonPolymorphic]
+ [JsonDerivedType(typeof(NuiButton))]
+ [JsonDerivedType(typeof(NuiButtonImage))]
+ [JsonDerivedType(typeof(NuiButtonSelect))]
+ [JsonDerivedType(typeof(NuiChart))]
+ [JsonDerivedType(typeof(NuiCheck))]
+ [JsonDerivedType(typeof(NuiColorPicker))]
+ [JsonDerivedType(typeof(NuiCombo))]
+ [JsonDerivedType(typeof(NuiImage))]
+ [JsonDerivedType(typeof(NuiLabel))]
+ [JsonDerivedType(typeof(NuiOptions))]
+ [JsonDerivedType(typeof(NuiProgress))]
+ [JsonDerivedType(typeof(NuiSlider))]
+ [JsonDerivedType(typeof(NuiSliderFloat))]
+ [JsonDerivedType(typeof(NuiSpacer))]
+ [JsonDerivedType(typeof(NuiText))]
+ [JsonDerivedType(typeof(NuiTextEdit))]
+ [JsonDerivedType(typeof(NuiToggles))]
public abstract class NuiWidget : NuiElement;
}
From 602de327c27bf9bc2e4033c5af00eb2869f08781 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 23:25:59 +0100
Subject: [PATCH 14/20] Fix missing/duplicate property values.
---
NWN.Anvil/src/main/API/Color.cs | 4 ++++
NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs | 2 ++
NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs | 2 ++
NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs | 1 +
NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs | 2 ++
NWN.Anvil/src/main/API/Nui/NuiList.cs | 1 +
NWN.Anvil/src/main/API/Nui/NuiVector.cs | 2 ++
NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs | 2 +-
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs | 1 +
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs | 1 +
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs | 1 +
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs | 1 +
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs | 1 +
.../src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiSpacer.cs | 3 +++
NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs | 1 +
NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs | 1 +
31 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/NWN.Anvil/src/main/API/Color.cs b/NWN.Anvil/src/main/API/Color.cs
index 8865168c9..a95ed6f24 100644
--- a/NWN.Anvil/src/main/API/Color.cs
+++ b/NWN.Anvil/src/main/API/Color.cs
@@ -13,24 +13,28 @@ namespace Anvil.API
/// Gets the alpha value of this color as a byte (0-255).
///
[JsonPropertyName("a")]
+ [JsonInclude]
public readonly byte Alpha;
///
/// Gets the blue value of this color as a byte (0-255).
///
[JsonPropertyName("b")]
+ [JsonInclude]
public readonly byte Blue;
///
/// Gets the green value of this color as a byte (0-255).
///
[JsonPropertyName("g")]
+ [JsonInclude]
public readonly byte Green;
///
/// Gets the red value of this color as a byte (0-255).
///
[JsonPropertyName("r")]
+ [JsonInclude]
public readonly byte Red;
///
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
index 3d285410f..86fa66980 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiColumn.cs
@@ -11,8 +11,10 @@ public sealed class NuiColumn : NuiLayout
[JsonIgnore]
public List Children { get; set; } = [];
+ [JsonPropertyName("type")]
public override string Type => "col";
+ [JsonPropertyName("children")]
protected override IEnumerable SerializedChildren => Children;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
index e6f76eee2..3bb049761 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs
@@ -27,8 +27,10 @@ public NuiLayout? Layout
[JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Auto;
+ [JsonPropertyName("type")]
public override string Type => "group";
+ [JsonPropertyName("children")]
protected override IEnumerable SerializedChildren => Element.SafeYield();
///
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
index 450365105..d1784e1fd 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiLayout.cs
@@ -10,6 +10,7 @@ namespace Anvil.API
public abstract class NuiLayout : NuiElement
{
[JsonPropertyName("children")]
+ [JsonInclude]
protected abstract IEnumerable SerializedChildren { get; }
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs b/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
index 175806003..9a4d2f4f9 100644
--- a/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
+++ b/NWN.Anvil/src/main/API/Nui/Layout/NuiRow.cs
@@ -11,8 +11,10 @@ public sealed class NuiRow : NuiLayout
[JsonIgnore]
public List Children { get; set; } = [];
+ [JsonPropertyName("type")]
public override string Type => "row";
+ [JsonPropertyName("children")]
protected override IEnumerable SerializedChildren => Children;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/NuiList.cs b/NWN.Anvil/src/main/API/Nui/NuiList.cs
index 08840f36c..81f04e273 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiList.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiList.cs
@@ -41,6 +41,7 @@ public sealed class NuiList(IReadOnlyCollection rowTemplate
[JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Y;
+ [JsonPropertyName("type")]
public override string Type => "list";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/NuiVector.cs b/NWN.Anvil/src/main/API/Nui/NuiVector.cs
index 224ca76f0..4a452e046 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiVector.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiVector.cs
@@ -8,9 +8,11 @@ namespace Anvil.API
public readonly struct NuiVector(float x, float y) : IEquatable
{
[JsonPropertyName("x")]
+ [JsonInclude]
public readonly float X = x;
[JsonPropertyName("y")]
+ [JsonInclude]
public readonly float Y = y;
public static NuiVector operator +(NuiVector a, NuiVector b)
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
index c0e1f960a..331ed9561 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListArc.cs
@@ -4,7 +4,6 @@ namespace Anvil.API
{
public sealed class NuiDrawListArc : NuiDrawListItem
{
- [JsonConstructor]
public NuiDrawListArc(NuiProperty color, NuiProperty fill, NuiProperty lineThickness, NuiProperty center, NuiProperty radius,
NuiProperty angleMin, NuiProperty angleMax)
{
@@ -29,6 +28,7 @@ public NuiDrawListArc(NuiProperty color, NuiProperty fill, NuiPrope
[JsonPropertyName("radius")]
public NuiProperty Radius { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Arc;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
index fe92cc21b..6286c7142 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCircle.cs
@@ -16,6 +16,7 @@ public NuiDrawListCircle(NuiProperty color, NuiProperty fill, NuiPr
[JsonPropertyName("rect")]
public NuiProperty Rect { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Circle;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
index 50fd3cf64..62d9c8288 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListCurve.cs
@@ -28,6 +28,7 @@ public NuiDrawListCurve(NuiProperty color, NuiProperty lineThickne
[JsonPropertyName("b")]
public NuiProperty PointB { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Curve;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
index fa560208d..9f92e3611 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListImage.cs
@@ -25,6 +25,7 @@ public sealed class NuiDrawListImage(NuiProperty resRef, NuiProperty? ImageRegion { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Image;
[JsonPropertyName("image_valign")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
index e349a62bd..7ca40c7a6 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListLine.cs
@@ -20,6 +20,7 @@ public NuiDrawListLine(NuiProperty color, NuiProperty fill, NuiProp
[JsonPropertyName("b")]
public NuiProperty PointB { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Line;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
index 4352e505c..a63cf5e1e 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListPolyLine.cs
@@ -17,6 +17,7 @@ public NuiDrawListPolyLine(NuiProperty color, NuiProperty fill, Nui
[JsonPropertyName("points")]
public List Points { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.PolyLine;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
index 1de53d631..f17b8622b 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/DrawList/NuiDrawListText.cs
@@ -18,6 +18,7 @@ public NuiDrawListText(NuiProperty color, NuiProperty rect, NuiP
[JsonPropertyName("text")]
public NuiProperty Text { get; set; }
+ [JsonPropertyName("type")]
public override NuiDrawListItemType Type => NuiDrawListItemType.Text;
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
index 6e7cb563a..c87209f5e 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButton.cs
@@ -11,6 +11,7 @@ public sealed class NuiButton(NuiProperty label) : NuiWidget
[JsonPropertyName("label")]
public NuiProperty Label { get; set; } = label;
+ [JsonPropertyName("type")]
public override string Type => "button";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
index 3c957264a..fc7c0927d 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonImage.cs
@@ -11,6 +11,7 @@ public sealed class NuiButtonImage(NuiProperty resRef) : NuiWidget
[JsonPropertyName("label")]
public NuiProperty ResRef { get; set; } = resRef;
+ [JsonPropertyName("type")]
public override string Type => "button_image";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
index 1d81bc24d..6d3171038 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiButtonSelect.cs
@@ -15,6 +15,7 @@ public sealed class NuiButtonSelect(NuiProperty label, NuiProperty
[JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = selected;
+ [JsonPropertyName("type")]
public override string Type => "button_select";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
index 9131b6ffb..2ff61ba46 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiChart.cs
@@ -11,6 +11,7 @@ public sealed class NuiChart : NuiWidget
[JsonPropertyName("value")]
public List? ChartSlots { get; set; }
+ [JsonPropertyName("type")]
public override string Type => "chart";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
index 21cacb569..6f4ab2693 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCheck.cs
@@ -14,6 +14,7 @@ public sealed class NuiCheck(NuiProperty label, NuiProperty select
[JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = selected;
+ [JsonPropertyName("type")]
public override string Type => "check";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
index fb460a0aa..9cbaf6cd0 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiColorPicker.cs
@@ -11,6 +11,7 @@ public sealed class NuiColorPicker(NuiProperty color) : NuiWidget
[JsonPropertyName("value")]
public NuiProperty Color { get; set; } = color;
+ [JsonPropertyName("type")]
public override string Type => "color_picker";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
index 49ebde2af..04131c786 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiCombo.cs
@@ -14,6 +14,7 @@ public sealed class NuiCombo : NuiWidget
[JsonPropertyName("value")]
public NuiProperty Selected { get; set; } = 0;
+ [JsonPropertyName("type")]
public override string Type => "combo";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
index 69d6eaced..3f9283b2c 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiImage.cs
@@ -24,6 +24,7 @@ public sealed class NuiImage(NuiProperty resRef) : NuiWidget
[JsonPropertyName("value")]
public NuiProperty ResRef { get; set; } = resRef;
+ [JsonPropertyName("type")]
public override string Type => "image";
[JsonPropertyName("image_valign")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
index 4baa5a77e..a3dfa90c6 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiLabel.cs
@@ -14,6 +14,7 @@ public sealed class NuiLabel(NuiProperty label) : NuiWidget
[JsonPropertyName("value")]
public NuiProperty Label { get; set; } = label;
+ [JsonPropertyName("type")]
public override string Type => "label";
[JsonPropertyName("text_valign")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
index 19c39493f..e5af86e71 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiOptions.cs
@@ -18,6 +18,7 @@ public sealed class NuiOptions : NuiWidget
[JsonPropertyName("value")]
public NuiProperty Selection { get; set; } = -1;
+ [JsonPropertyName("type")]
public override string Type => "options";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
index 0a2295a6e..f5d408600 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiProgress.cs
@@ -8,6 +8,7 @@ namespace Anvil.API
[method: JsonConstructor]
public sealed class NuiProgress(NuiProperty value) : NuiWidget
{
+ [JsonPropertyName("type")]
public override string Type => "progress";
///
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
index f3844705f..ae38faf0a 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSlider.cs
@@ -17,6 +17,7 @@ public sealed class NuiSlider(NuiProperty value, NuiProperty min, NuiP
[JsonPropertyName("step")]
public NuiProperty Step { get; set; } = 1;
+ [JsonPropertyName("type")]
public override string Type => "slider";
[JsonPropertyName("value")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
index 5c90eda97..2f6486887 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSliderFloat.cs
@@ -17,6 +17,7 @@ public sealed class NuiSliderFloat(NuiProperty value, NuiProperty
[JsonPropertyName("step")]
public NuiProperty StepSize { get; set; } = 0.01f;
+ [JsonPropertyName("type")]
public override string Type => "sliderf";
[JsonPropertyName("value")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSpacer.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSpacer.cs
index a8b62e872..29209b28c 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiSpacer.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiSpacer.cs
@@ -1,3 +1,5 @@
+using System.Text.Json.Serialization;
+
namespace Anvil.API
{
///
@@ -6,6 +8,7 @@ namespace Anvil.API
///
public sealed class NuiSpacer : NuiWidget
{
+ [JsonPropertyName("type")]
public override string Type => "spacer";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
index 93f36c3d5..4348fc5f8 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiText.cs
@@ -17,6 +17,7 @@ public sealed class NuiText(NuiProperty text) : NuiWidget
[JsonPropertyName("scrollbars")]
public NuiScrollbars Scrollbars { get; set; } = NuiScrollbars.Auto;
+ [JsonPropertyName("type")]
public override string Type => "text";
}
}
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
index efe9a3a72..4a8963436 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiTextEdit.cs
@@ -17,6 +17,7 @@ public sealed class NuiTextEdit(NuiProperty label, NuiProperty v
[JsonPropertyName("multiline")]
public bool MultiLine { get; set; } = multiLine;
+ [JsonPropertyName("type")]
public override string Type => "textedit";
[JsonPropertyName("value")]
diff --git a/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs b/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
index 96c22e69e..336624808 100644
--- a/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
+++ b/NWN.Anvil/src/main/API/Nui/Widgets/NuiToggles.cs
@@ -5,6 +5,7 @@ namespace Anvil.API
{
public sealed class NuiToggles(NuiDirection direction, List elements) : NuiWidget
{
+ [JsonPropertyName("type")]
public override string Type => "tabbar";
[JsonPropertyName("direction")]
From 3f7ee7c609d2384329d27fb07ad0a3c33beb723e Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 23:26:34 +0100
Subject: [PATCH 15/20] Use options from converter method.
---
.../src/main/API/Nui/NuiListTemplateCellConverter.cs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/NWN.Anvil/src/main/API/Nui/NuiListTemplateCellConverter.cs b/NWN.Anvil/src/main/API/Nui/NuiListTemplateCellConverter.cs
index adc01df8a..975eee908 100644
--- a/NWN.Anvil/src/main/API/Nui/NuiListTemplateCellConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/NuiListTemplateCellConverter.cs
@@ -4,12 +4,12 @@
namespace Anvil.API
{
- internal sealed class NuiListTemplateCellConverter(JsonSerializerOptions options) : JsonConverter
+ internal sealed class NuiListTemplateCellConverter : JsonConverter
{
- private readonly JsonConverter nuiElementConverter = (JsonConverter)options.GetConverter(typeof(NuiElement));
-
public override NuiListTemplateCell? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
+ JsonConverter nuiElementConverter = (JsonConverter)options.GetConverter(typeof(NuiElement));
+
reader.Read();
if (reader.TokenType != JsonTokenType.StartArray)
{
@@ -41,6 +41,8 @@ internal sealed class NuiListTemplateCellConverter(JsonSerializerOptions options
public override void Write(Utf8JsonWriter writer, NuiListTemplateCell value, JsonSerializerOptions options)
{
+ JsonConverter nuiElementConverter = (JsonConverter)options.GetConverter(typeof(NuiElement));
+
writer.WriteStartArray();
nuiElementConverter.Write(writer, value.Element, options);
writer.WriteBooleanValue(value.VariableSize);
From 3b5b37d13a543c3d71bd8fb032dc873127f85113 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Tue, 25 Mar 2025 23:51:03 +0100
Subject: [PATCH 16/20] Add custom converter for StrRef.
---
NWN.Anvil/src/main/API/Tlk/StrRef.cs | 19 +++++---
NWN.Anvil/src/main/API/Tlk/StrRefConverter.cs | 46 +++++++++++++++++++
2 files changed, 58 insertions(+), 7 deletions(-)
create mode 100644 NWN.Anvil/src/main/API/Tlk/StrRefConverter.cs
diff --git a/NWN.Anvil/src/main/API/Tlk/StrRef.cs b/NWN.Anvil/src/main/API/Tlk/StrRef.cs
index 3710b7b8e..5c6381dd4 100644
--- a/NWN.Anvil/src/main/API/Tlk/StrRef.cs
+++ b/NWN.Anvil/src/main/API/Tlk/StrRef.cs
@@ -8,8 +8,8 @@ namespace Anvil.API
///
/// A talk table (tlk) string reference.
///
- [method: JsonConstructor]
- public readonly struct StrRef(uint stringId)
+ [JsonConverter(typeof(StrRefConverter))]
+ public readonly struct StrRef
{
private const uint CustomTlkOffset = 0x1000000;
@@ -19,21 +19,26 @@ public readonly struct StrRef(uint stringId)
///
/// Gets the index/key for this StrRef.
///
- [JsonPropertyName("strref")]
- public readonly uint Id = stringId;
+ public uint Id { get; }
- public StrRef(int stringId) : this((uint)stringId) {}
+ ///
+ /// A talk table (tlk) string reference.
+ ///
+ public StrRef(uint id)
+ {
+ Id = id;
+ }
+
+ public StrRef(int id) : this((uint)id) {}
///
/// Gets the index/key for this StrRef relative to the module's custom talk table. (-16777216)
///
- [JsonIgnore]
public uint CustomId => Id - CustomTlkOffset;
///
/// Gets or sets a string override that this StrRef should return instead of the tlk file definition.
///
- [JsonIgnore]
public string? Override
{
get => TlkTable.GetTlkOverride(this);
diff --git a/NWN.Anvil/src/main/API/Tlk/StrRefConverter.cs b/NWN.Anvil/src/main/API/Tlk/StrRefConverter.cs
new file mode 100644
index 000000000..f4b6d0c2f
--- /dev/null
+++ b/NWN.Anvil/src/main/API/Tlk/StrRefConverter.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Anvil.API
+{
+ internal sealed class StrRefConverter : JsonConverter
+ {
+ public override StrRef Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ CheckToken(ref reader, JsonTokenType.StartObject);
+ reader.Read();
+ CheckToken(ref reader, JsonTokenType.PropertyName);
+
+ string? propertyName = reader.GetString();
+ if (propertyName != "strref")
+ {
+ throw new JsonException($"Expected property name 'strref', got '{propertyName}'");
+ }
+
+ reader.Read();
+ StrRef retVal = new StrRef(reader.GetUInt32());
+
+ reader.Read();
+ CheckToken(ref reader, JsonTokenType.EndObject);
+
+ return retVal;
+ }
+
+ public override void Write(Utf8JsonWriter writer, StrRef value, JsonSerializerOptions options)
+ {
+ writer.WriteStartObject();
+ writer.WritePropertyName("strref");
+ writer.WriteNumberValue(value.Id);
+ writer.WriteEndObject();
+ }
+
+ private void CheckToken(ref Utf8JsonReader reader, JsonTokenType tokenType)
+ {
+ if (reader.TokenType != tokenType)
+ {
+ throw new JsonException($"Expected token type '{tokenType}', got '{reader.TokenType}'");
+ }
+ }
+ }
+}
From bcb0a1dc7b79c79dbd49fd531948304a3ad6f53c Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Fri, 18 Apr 2025 22:49:39 +0200
Subject: [PATCH 17/20] Fix floating point digits in tests.
---
.../src/main/API/Nui/Bindings/NuiBindTests.cs | 6 +-
.../main/API/Nui/Bindings/NuiValueTests.cs | 70 +++++--------------
.../src/main/API/Nui/Layout/NuiColumnTests.cs | 4 +-
.../src/main/API/Nui/Layout/NuiGroupTests.cs | 4 +-
.../src/main/API/Nui/Layout/NuiRowTests.cs | 4 +-
.../src/main/API/Nui/Widgets/NuiChartTests.cs | 4 +-
.../main/API/Nui/Widgets/NuiDrawListTests.cs | 28 ++++----
.../src/main/API/Nui/Widgets/NuiImageTests.cs | 4 +-
.../API/Nui/Widgets/NuiSliderFloatTests.cs | 4 +-
9 files changed, 46 insertions(+), 82 deletions(-)
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
index 48b5c3f80..4a0f87741 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
@@ -30,21 +30,21 @@ public void SerializeNuiBindNuiRectReturnsValidJson()
Assert.That(JsonUtility.ToJson>(bind), Is.EqualTo("""{"bind":"test"}"""));
}
- [Test(Description = "Deerializing a NuiBind creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindStringReturnsValidJson()
{
NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
Assert.That(bind?.Key, Is.EqualTo("test"));
}
- [Test(Description = "Deerializing a NuiBind creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindStrRefReturnsValidJson()
{
NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
Assert.That(bind?.Key, Is.EqualTo("test"));
}
- [Test(Description = "Deerializing a NuiBind creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindNuiRectReturnsValidJson()
{
NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
index 29d3016af..18a4c3b8b 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
@@ -63,21 +63,12 @@ public void SerializeNuiValueNullableIntReturnsValidJson(int? rawValue, string e
}
[Test(Description = "Serializing a NuiValue creates a valid JSON structure.")]
- [TestCase(0f, @"0.0")]
+ [TestCase(0f, @"0")]
[TestCase(0.1f, @"0.1")]
[TestCase(0.125f, @"0.125")]
- [TestCase(2f, @"2.0")]
+ [TestCase(2f, @"2")]
[TestCase(2.5f, @"2.5")]
[TestCase(2.5122f, @"2.5122")]
- [TestCase(float.NaN, """
- "NaN"
- """)]
- [TestCase(float.NegativeInfinity, """
- "-Infinity"
- """)]
- [TestCase(float.PositiveInfinity, """
- "Infinity"
- """)]
public void SerializeNuiValueFloatReturnsValidJson(float rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
@@ -86,22 +77,13 @@ public void SerializeNuiValueFloatReturnsValidJson(float rawValue, string expect
}
[Test(Description = "Serializing a NuiValue creates a valid JSON structure.")]
- [TestCase(0f, @"0.0")]
+ [TestCase(0f, @"0")]
[TestCase(0.1f, @"0.1")]
[TestCase(0.125f, @"0.125")]
- [TestCase(2f, @"2.0")]
+ [TestCase(2f, @"2")]
[TestCase(2.5f, @"2.5")]
[TestCase(2.5122f, @"2.5122")]
[TestCase(null, @"null")]
- [TestCase(float.NaN, """
- "NaN"
- """)]
- [TestCase(float.NegativeInfinity, """
- "-Infinity"
- """)]
- [TestCase(float.PositiveInfinity, """
- "Infinity"
- """)]
public void SerializeNuiValueFloatNullableReturnsValidJson(float? rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
@@ -113,7 +95,7 @@ public void SerializeNuiValueFloatNullableReturnsValidJson(float? rawValue, stri
public void SerializeNuiValueNuiRectReturnsValidJson()
{
NuiValue value = new NuiValue(new NuiRect(100f, 50.251f, 30.11f, 20f));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo("""{"h":20.0,"w":30.11,"x":100.0,"y":50.251}"""));
+ Assert.That(JsonUtility.ToJson>(value), Is.EqualTo("""{"h":20,"w":30.11,"x":100,"y":50.251}"""));
}
[Test(Description = "Serializing a NuiValue> creates a valid JSON structure.")]
@@ -123,7 +105,7 @@ public void SerializeNuiValueIntListReturnsValidJson()
Assert.That(JsonUtility.ToJson>>(value), Is.EqualTo(@"[1,2,3]"));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
[TestCase("test", """
"test"
""")]
@@ -137,7 +119,7 @@ public void DeserializeNuiValueStringReturnsValidJson(string expected, string se
Assert.That(value?.Value, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValueStrRef creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiValueStrRef creates a valid value/object.")]
[TestCase(0u, """{"strref":0}""")]
[TestCase(null, @"null")]
[TestCase(1000u, """{"strref":1000}""")]
@@ -147,7 +129,7 @@ public void DeserializeNuiValueStrRefReturnsValidJson(uint? expected, string ser
Assert.That(value?.Value?.Id, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
[TestCase(0, @"0")]
[TestCase(-0, @"0")]
[TestCase(10, @"10")]
@@ -160,7 +142,7 @@ public void DeserializeNuiValueIntReturnsValidJson(int expected, string serializ
Assert.That(value?.Value, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
[TestCase(0, @"0")]
[TestCase(-0, @"0")]
[TestCase(10, @"10")]
@@ -174,55 +156,37 @@ public void DeserializeNuiValueNullableIntReturnsValidJson(int? expected, string
Assert.That(value?.Value, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
- [TestCase(0f, @"0.0")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
+ [TestCase(0f, @"0")]
[TestCase(0.1f, @"0.1")]
[TestCase(0.125f, @"0.125")]
- [TestCase(2f, @"2.0")]
+ [TestCase(2f, @"2")]
[TestCase(2.5f, @"2.5")]
[TestCase(2.5122f, @"2.5122")]
- [TestCase(float.NaN, """
- "NaN"
- """)]
- [TestCase(float.NegativeInfinity, """
- "-Infinity"
- """)]
- [TestCase(float.PositiveInfinity, """
- "Infinity"
- """)]
public void DeserializeNuiValueFloatReturnsValidJson(float expected, string serialized)
{
NuiValue? value = JsonUtility.FromJson>(serialized);
Assert.That(value?.Value, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
- [TestCase(0f, @"0.0")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
+ [TestCase(0f, @"0")]
[TestCase(0.1f, @"0.1")]
[TestCase(0.125f, @"0.125")]
- [TestCase(2f, @"2.0")]
+ [TestCase(2f, @"2")]
[TestCase(2.5f, @"2.5")]
[TestCase(2.5122f, @"2.5122")]
[TestCase(null, @"null")]
- [TestCase(float.NaN, """
- "NaN"
- """)]
- [TestCase(float.NegativeInfinity, """
- "-Infinity"
- """)]
- [TestCase(float.PositiveInfinity, """
- "Infinity"
- """)]
public void DeserializeNuiValueFloatNullableReturnsValidJson(float? expected, string serialized)
{
NuiValue? value = JsonUtility.FromJson>(serialized);
Assert.That(value?.Value, Is.EqualTo(expected));
}
- [Test(Description = "Deerializing a NuiValue creates a valid value/object.")]
+ [Test(Description = "Deserializing a NuiValue creates a valid value/object.")]
public void DeserializeNuiValueNuiRectReturnsValidJson()
{
- NuiValue? value = JsonUtility.FromJson>("""{"h":20.0,"w":30.11,"x":100.0,"y":50.251}""");
+ NuiValue? value = JsonUtility.FromJson>("""{"h":20,"w":30.11,"x":100,"y":50.251}""");
NuiRect expected = new NuiRect(100.0f, 50.251f, 30.11f, 20.0f);
Assert.That(value?.Value, Is.EqualTo(expected));
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiColumnTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiColumnTests.cs
index eaf90cf98..6e1f17b9a 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiColumnTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiColumnTests.cs
@@ -28,8 +28,8 @@ public void SerializeNuiColumnReturnsValidJson()
],
};
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"col","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_column","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"col","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_column","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"col","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_column","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"col","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_column","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiGroupTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiGroupTests.cs
index 5554932b9..678d9921a 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiGroupTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiGroupTests.cs
@@ -32,8 +32,8 @@ public void SerializeNuiGroupReturnsValidJson()
},
};
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"border":true,"scrollbars":3,"type":"group","children":[{"type":"col","children":[{"text_halign":1,"value":"Test","type":"label","text_valign":1}]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_group","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"border":true,"scrollbars":3,"type":"group","children":[{"type":"col","children":[{"text_halign":1,"value":"Test","type":"label","text_valign":1}]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_group","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"border":true,"scrollbars":3,"type":"group","children":[{"type":"col","children":[{"text_halign":1,"value":"Test","type":"label","text_valign":1}]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_group","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"border":true,"scrollbars":3,"type":"group","children":[{"type":"col","children":[{"text_halign":1,"value":"Test","type":"label","text_valign":1}]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_group","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiRowTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiRowTests.cs
index 511c03bd7..9ea5d754c 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiRowTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Layout/NuiRowTests.cs
@@ -28,8 +28,8 @@ public void SerializeNuiRowReturnsValidJson()
],
};
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"row","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_row","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
- Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"row","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10.0,"id":"test_row","margin":2.0,"padding":3.0,"tooltip":"test_tooltip","visible":false,"width":100.0}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"row","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_row","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
+ Assert.That(JsonUtility.ToJson(layout), Is.EqualTo("""{"type":"row","children":[{"text_halign":1,"value":"test","type":"label","text_valign":1},{"type":"row","children":[]}],"aspect":1.5,"enabled":{"bind":"enabled_bind"},"foreground_color":{"bind":"color_bind"},"height":10,"id":"test_row","margin":2,"padding":3,"tooltip":"test_tooltip","visible":false,"width":100}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiChartTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiChartTests.cs
index 4aca5ad64..2f974344b 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiChartTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiChartTests.cs
@@ -18,8 +18,8 @@ public void SerializeNuiChartReturnsValidJson()
],
};
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"value":[{"type":1,"color":{"a":255,"b":0,"g":0,"r":128},"data":[1.0,2.0,3.0],"legend":"slot1"},{"type":1,"color":{"a":255,"b":128,"g":0,"r":0},"data":[0.0,-1.0,-2.0],"legend":"slot2"}],"type":"chart"}"""));
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"value":[{"type":1,"color":{"a":255,"b":0,"g":0,"r":128},"data":[1.0,2.0,3.0],"legend":"slot1"},{"type":1,"color":{"a":255,"b":128,"g":0,"r":0},"data":[0.0,-1.0,-2.0],"legend":"slot2"}],"type":"chart"}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"value":[{"type":1,"color":{"a":255,"b":0,"g":0,"r":128},"data":[1,2,3],"legend":"slot1"},{"type":1,"color":{"a":255,"b":128,"g":0,"r":0},"data":[0,-1,-2],"legend":"slot2"}],"type":"chart"}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"value":[{"type":1,"color":{"a":255,"b":0,"g":0,"r":128},"data":[1,2,3],"legend":"slot1"},{"type":1,"color":{"a":255,"b":128,"g":0,"r":0},"data":[0,-1,-2],"legend":"slot2"}],"type":"chart"}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiDrawListTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiDrawListTests.cs
index 4bc349d74..8b3a57ff6 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiDrawListTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiDrawListTests.cs
@@ -14,8 +14,8 @@ public void SerializeNuiDrawListReturnsValidJson()
DrawList = [new NuiDrawListText(ColorConstants.Red, new NuiRect(0, 0, 100, 100), "Draw list text")],
};
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"label":"btn_label","type":"button","draw_list":[{"rect":{"h":100.0,"w":100.0,"x":0.0,"y":0.0},"text":"Draw list text","type":4,"color":{"a":255,"b":0,"g":0,"r":255},"enabled":true,"fill":null,"line_thickness":null,"order":1,"render":0}]}"""));
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"label":"btn_label","type":"button","draw_list":[{"rect":{"h":100.0,"w":100.0,"x":0.0,"y":0.0},"text":"Draw list text","type":4,"color":{"a":255,"b":0,"g":0,"r":255},"enabled":true,"fill":null,"line_thickness":null,"order":1,"render":0}]}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"label":"btn_label","type":"button","draw_list":[{"rect":{"h":100,"w":100,"x":0,"y":0},"text":"Draw list text","type":4,"color":{"a":255,"b":0,"g":0,"r":255},"enabled":true,"fill":null,"line_thickness":null,"order":1,"render":0}]}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"label":"btn_label","type":"button","draw_list":[{"rect":{"h":100,"w":100,"x":0,"y":0},"text":"Draw list text","type":4,"color":{"a":255,"b":0,"g":0,"r":255},"enabled":true,"fill":null,"line_thickness":null,"order":1,"render":0}]}"""));
}
[Test(Description = "Serializing a NuiDrawListArc creates a valid JSON structure.")]
@@ -26,8 +26,8 @@ public void SerializeNuiDrawListArcReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"amax":170.0,"amin":90.0,"c":{"x":1.0,"y":2.0},"radius":2.0,"type":3,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1.0,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"amax":170.0,"amin":90.0,"c":{"x":1.0,"y":2.0},"radius":2.0,"type":3,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1.0,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"amax":170,"amin":90,"c":{"x":1,"y":2},"radius":2,"type":3,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"amax":170,"amin":90,"c":{"x":1,"y":2},"radius":2,"type":3,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1,"order":1,"render":0}"""));
}
[Test(Description = "Serializing a NuiDrawListCircle creates a valid JSON structure.")]
@@ -38,8 +38,8 @@ public void SerializeNuiDrawListCircleReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":4.0,"w":3.0,"x":1.0,"y":2.0},"type":2,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1.0,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":4.0,"w":3.0,"x":1.0,"y":2.0},"type":2,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1.0,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":4,"w":3,"x":1,"y":2},"type":2,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":4,"w":3,"x":1,"y":2},"type":2,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":1,"order":1,"render":0}"""));
}
[Test(Description = "Serializing a NuiDrawListCurve creates a valid JSON structure.")]
@@ -50,8 +50,8 @@ public void SerializeNuiDrawListCurveReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"ctrl0":{"x":9.5,"y":3.0},"ctrl1":{"x":22.0,"y":11.3},"a":{"x":10.0,"y":5.0},"b":{"x":6.0,"y":2.0},"type":1,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":false,"line_thickness":1.0,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"ctrl0":{"x":9.5,"y":3.0},"ctrl1":{"x":22.0,"y":11.3},"a":{"x":10.0,"y":5.0},"b":{"x":6.0,"y":2.0},"type":1,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":false,"line_thickness":1.0,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"ctrl0":{"x":9.5,"y":3},"ctrl1":{"x":22,"y":11.3},"a":{"x":10,"y":5},"b":{"x":6,"y":2},"type":1,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":false,"line_thickness":1,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"ctrl0":{"x":9.5,"y":3},"ctrl1":{"x":22,"y":11.3},"a":{"x":10,"y":5},"b":{"x":6,"y":2},"type":1,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":false,"line_thickness":1,"order":1,"render":0}"""));
}
[Test(Description = "Serializing a NuiDrawListImage creates a valid JSON structure.")]
@@ -62,8 +62,8 @@ public void SerializeNuiDrawListImageReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"image_aspect":3,"image_halign":1,"rect":{"h":4.0,"w":3.0,"x":1.0,"y":2.0},"image":"test_img","type":5,"image_valign":1,"color":null,"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"image_aspect":3,"image_halign":1,"rect":{"h":4.0,"w":3.0,"x":1.0,"y":2.0},"image":"test_img","type":5,"image_valign":1,"color":null,"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"image_aspect":3,"image_halign":1,"rect":{"h":4,"w":3,"x":1,"y":2},"image":"test_img","type":5,"image_valign":1,"color":null,"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"image_aspect":3,"image_halign":1,"rect":{"h":4,"w":3,"x":1,"y":2},"image":"test_img","type":5,"image_valign":1,"color":null,"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
}
[Test(Description = "Serializing a NuiDrawListPolyLine creates a valid JSON structure.")]
@@ -74,8 +74,8 @@ public void SerializeNuiDrawListPolyLineReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"points":[2.0,4.0,6.0,11.0],"type":0,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":2.0,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"points":[2.0,4.0,6.0,11.0],"type":0,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":2.0,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"points":[2,4,6,11],"type":0,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":2,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"points":[2,4,6,11],"type":0,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":true,"line_thickness":2,"order":1,"render":0}"""));
}
[Test(Description = "Serializing a NuiDrawListText creates a valid JSON structure.")]
@@ -86,8 +86,8 @@ public void SerializeNuiDrawListTextReturnsValidJson()
Enabled = false,
};
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":8.0,"w":7.0,"x":5.0,"y":6.0},"text":"Test string","type":4,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
- Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":8.0,"w":7.0,"x":5.0,"y":6.0},"text":"Test string","type":4,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":8,"w":7,"x":5,"y":6},"text":"Test string","type":4,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
+ Assert.That(JsonUtility.ToJson(item), Is.EqualTo("""{"rect":{"h":8,"w":7,"x":5,"y":6},"text":"Test string","type":4,"color":{"a":255,"b":170,"g":170,"r":255},"enabled":false,"fill":null,"line_thickness":null,"order":1,"render":0}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiImageTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiImageTests.cs
index da6ceaaf0..ddb7b24a6 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiImageTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiImageTests.cs
@@ -18,8 +18,8 @@ public void SerializeNuiImageReturnsValidJson()
Margin = 0.0f,
};
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"image_halign":2,"image_aspect":4,"image_region":null,"value":"gui_chr_arrowbtn","type":"image","image_valign":0,"height":16.0,"margin":0.0,"width":16.0}"""));
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"image_halign":2,"image_aspect":4,"image_region":null,"value":"gui_chr_arrowbtn","type":"image","image_valign":0,"height":16.0,"margin":0.0,"width":16.0}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"image_halign":2,"image_aspect":4,"image_region":null,"value":"gui_chr_arrowbtn","type":"image","image_valign":0,"height":16,"margin":0,"width":16}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"image_halign":2,"image_aspect":4,"image_region":null,"value":"gui_chr_arrowbtn","type":"image","image_valign":0,"height":16,"margin":0,"width":16}"""));
}
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiSliderFloatTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiSliderFloatTests.cs
index bf3bf12e7..96d0cec5a 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiSliderFloatTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Widgets/NuiSliderFloatTests.cs
@@ -10,8 +10,8 @@ public void SerializeNuiSliderFloatReturnsValidJson()
{
NuiSliderFloat element = new NuiSliderFloat(new NuiBind("value"), 0f, 100f);
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"max":100.0,"min":0.0,"step":0.01,"type":"sliderf","value":{"bind":"value"}}"""));
- Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"max":100.0,"min":0.0,"step":0.01,"type":"sliderf","value":{"bind":"value"}}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"max":100,"min":0,"step":0.01,"type":"sliderf","value":{"bind":"value"}}"""));
+ Assert.That(JsonUtility.ToJson(element), Is.EqualTo("""{"max":100,"min":0,"step":0.01,"type":"sliderf","value":{"bind":"value"}}"""));
}
}
}
From e3fc01e673e42579b3ca6b18b4b1eccbb63a00b5 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Fri, 18 Apr 2025 23:04:04 +0200
Subject: [PATCH 18/20] Hide converter classes.
---
NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs | 2 +-
NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs | 2 +-
NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs
index 241d8ef2c..dd22d85f6 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiPropertyConverter.cs
@@ -5,7 +5,7 @@
namespace Anvil.API
{
- public sealed class NuiPropertyConverter : JsonConverterFactory
+ internal sealed class NuiPropertyConverter : JsonConverterFactory
{
public override bool CanConvert(Type objectType)
{
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
index 514e84200..21e2b1a6a 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueConverter.cs
@@ -5,7 +5,7 @@
namespace Anvil.API
{
- public sealed class NuiValueConverter : JsonConverterFactory
+ internal sealed class NuiValueConverter : JsonConverterFactory
{
public override bool CanConvert(Type objectType)
{
diff --git a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
index 2a9a33a67..e997e712f 100644
--- a/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
+++ b/NWN.Anvil/src/main/API/Nui/Bindings/NuiValueStrRefConverter.cs
@@ -4,7 +4,7 @@
namespace Anvil.API
{
- public sealed class NuiValueStrRefConverter : JsonConverter
+ internal sealed class NuiValueStrRefConverter : JsonConverter
{
public override NuiValueStrRef? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
From 2806351693e0e2a07a2e388af993b1b83b480a68 Mon Sep 17 00:00:00 2001
From: Jhett Black <10942655+jhett12321@users.noreply.github.com>
Date: Fri, 18 Apr 2025 23:22:32 +0200
Subject: [PATCH 19/20] Remove JsonUtility, inline JsonSerializer calls.
---
NWN.Anvil.Tests/src/main/API/ColorTests.cs | 7 ++-
.../main/API/EngineStructures/JsonTests.cs | 2 +-
.../src/main/API/Nui/Bindings/NuiBindTests.cs | 19 ++++---
.../main/API/Nui/Bindings/NuiValueTests.cs | 45 +++++++--------
.../src/main/API/Nui/Layout/NuiColumnTests.cs | 5 +-
.../src/main/API/Nui/Layout/NuiGroupTests.cs | 5 +-
.../src/main/API/Nui/Layout/NuiRowTests.cs | 5 +-
.../API/Nui/Widgets/NuiButtonImageTests.cs | 7 ++-
.../API/Nui/Widgets/NuiButtonSelectTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiButtonTests.cs | 7 ++-
.../src/main/API/Nui/Widgets/NuiChartTests.cs | 5 +-
.../src/main/API/Nui/Widgets/NuiCheckTests.cs | 7 ++-
.../API/Nui/Widgets/NuiColorPickerTests.cs | 7 ++-
.../src/main/API/Nui/Widgets/NuiComboTests.cs | 5 +-
.../main/API/Nui/Widgets/NuiDrawListTests.cs | 29 +++++-----
.../src/main/API/Nui/Widgets/NuiImageTests.cs | 7 ++-
.../src/main/API/Nui/Widgets/NuiLabelTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiOptionsTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiProgressTests.cs | 7 ++-
.../API/Nui/Widgets/NuiSliderFloatTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiSliderTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiSpacerTests.cs | 7 ++-
.../main/API/Nui/Widgets/NuiTextEditTests.cs | 7 ++-
.../src/main/API/Nui/Widgets/NuiTextTests.cs | 5 +-
.../main/API/Nui/Widgets/NuiTogglesTests.cs | 7 ++-
.../src/main/API/Utils/JsonUtilityTests.cs | 9 +--
.../src/main/API/EngineStructures/Json.cs | 25 ++++++++-
.../ModuleEvents/ModuleEvents.OnNuiEvent.cs | 3 +-
.../src/main/API/Nui/Bindings/NuiBind.cs | 8 +--
.../main/API/Nui/Bindings/NuiBindStrRef.cs | 8 +--
NWN.Anvil/src/main/API/Nui/Layout/NuiGroup.cs | 2 +-
NWN.Anvil/src/main/API/Nui/NuiWindowToken.cs | 4 +-
NWN.Anvil/src/main/API/Objects/NwArea.cs | 2 +-
NWN.Anvil/src/main/API/Objects/NwPlayer.cs | 2 +-
NWN.Anvil/src/main/API/Utils/JsonUtility.cs | 55 -------------------
.../Variables/Local/LocalVariableStruct.cs | 4 +-
.../ObjectStorageVariableStruct.cs | 5 +-
37 files changed, 176 insertions(+), 181 deletions(-)
delete mode 100644 NWN.Anvil/src/main/API/Utils/JsonUtility.cs
diff --git a/NWN.Anvil.Tests/src/main/API/ColorTests.cs b/NWN.Anvil.Tests/src/main/API/ColorTests.cs
index 9a5f30024..cb213c6a5 100644
--- a/NWN.Anvil.Tests/src/main/API/ColorTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/ColorTests.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Text.Json;
using Anvil.API;
using NUnit.Framework;
@@ -45,7 +46,7 @@ public void CreateColorTokenContainsNoNullTerminators(Color color)
[TestCase("""{"r":255,"g":100,"b":10,"a":30}""", 255, 100, 10, 30)]
public void DeserializeColorCreatesCorrectColor(string json, byte expectedRed, byte expectedGreen, byte expectedBlue, byte expectedAlpha)
{
- Color color = JsonUtility.FromJson(json);
+ Color color = JsonSerializer.Deserialize(json);
Assert.That(color, Is.EqualTo(new Color(expectedRed, expectedGreen, expectedBlue, expectedAlpha)));
}
@@ -95,8 +96,8 @@ public void ParseRGBAReturnsCorrectColor(uint packedColor, byte expectedRed, byt
[TestCaseSource(nameof(ColorTestCases))]
public void SerializeColorRetainsColorValues(Color color)
{
- string serializedColor = JsonUtility.ToJson(color);
- Color deserializedColor = JsonUtility.FromJson(serializedColor);
+ string serializedColor = JsonSerializer.Serialize(color);
+ Color deserializedColor = JsonSerializer.Deserialize(serializedColor);
Assert.That(deserializedColor, Is.EqualTo(color));
}
diff --git a/NWN.Anvil.Tests/src/main/API/EngineStructures/JsonTests.cs b/NWN.Anvil.Tests/src/main/API/EngineStructures/JsonTests.cs
index 6306dbc29..b45c6a20e 100644
--- a/NWN.Anvil.Tests/src/main/API/EngineStructures/JsonTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/EngineStructures/JsonTests.cs
@@ -10,7 +10,7 @@ public sealed class JsonTests
public void CreateAndDisposeJsonFreesNativeStructure()
{
int[] test = [1, 2];
- Json json = JsonUtility.ToJsonStructure(test);
+ Json json = Json.Serialize(test);
Assert.That(json.IsValid, Is.True, "Json struct was not valid after creation.");
json.Dispose();
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
index 4a0f87741..ebf78c876 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiBindTests.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
using Anvil.API;
using NUnit.Framework;
@@ -10,44 +11,44 @@ public sealed class NuiBindTests
public void SerializeNuiBindStringReturnsValidJson()
{
NuiBind bind = new NuiBind("test");
- Assert.That(JsonUtility.ToJson(bind), Is.EqualTo("""{"bind":"test"}"""));
- Assert.That(JsonUtility.ToJson>(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)bind), Is.EqualTo("""{"bind":"test"}"""));
}
[Test(Description = "Serializing a NuiBind creates a valid JSON structure.")]
public void SerializeNuiBindStrRefReturnsValidJson()
{
NuiBindStrRef bind = new NuiBindStrRef("test");
- Assert.That(JsonUtility.ToJson(bind), Is.EqualTo("""{"bind":"test"}"""));
- Assert.That(JsonUtility.ToJson>(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)bind), Is.EqualTo("""{"bind":"test"}"""));
}
[Test(Description = "Serializing a NuiBind creates a valid JSON structure.")]
public void SerializeNuiBindNuiRectReturnsValidJson()
{
NuiBind bind = new NuiBind("test");
- Assert.That(JsonUtility.ToJson(bind), Is.EqualTo("""{"bind":"test"}"""));
- Assert.That(JsonUtility.ToJson>(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize(bind), Is.EqualTo("""{"bind":"test"}"""));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)bind), Is.EqualTo("""{"bind":"test"}"""));
}
[Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindStringReturnsValidJson()
{
- NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
+ NuiBind? bind = JsonSerializer.Deserialize>("""{"bind":"test"}""");
Assert.That(bind?.Key, Is.EqualTo("test"));
}
[Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindStrRefReturnsValidJson()
{
- NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
+ NuiBind? bind = JsonSerializer.Deserialize>("""{"bind":"test"}""");
Assert.That(bind?.Key, Is.EqualTo("test"));
}
[Test(Description = "Deserializing a NuiBind creates a valid value/object.")]
public void DeserializeNuiBindNuiRectReturnsValidJson()
{
- NuiBind? bind = JsonUtility.FromJson>("""{"bind":"test"}""");
+ NuiBind? bind = JsonSerializer.Deserialize>("""{"bind":"test"}""");
Assert.That(bind?.Key, Is.EqualTo("test"));
}
}
diff --git a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
index 18a4c3b8b..1083b9a6e 100644
--- a/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
+++ b/NWN.Anvil.Tests/src/main/API/Nui/Bindings/NuiValueTests.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Text.Json;
using Anvil.API;
using NUnit.Framework;
@@ -18,8 +19,8 @@ public sealed class NuiValueTests
public void SerializeNuiValueStringReturnsValidJson(string rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
- Assert.That(JsonUtility.ToJson(value), Is.EqualTo(expected));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)value), Is.EqualTo(expected));
}
[Test(Description = "Serializing a NuiValueStrRef creates a valid JSON structure.")]
@@ -29,8 +30,8 @@ public void SerializeNuiValueStringReturnsValidJson(string rawValue, string expe
public void SerializeNuiValueStrRefReturnsValidJson(uint? rawValue, string expected)
{
NuiValueStrRef value = new NuiValueStrRef(rawValue != null ? new StrRef(rawValue.Value) : null);
- Assert.That(JsonUtility.ToJson(value), Is.EqualTo(expected));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)value), Is.EqualTo(expected));
}
[Test(Description = "Serializing a NuiValue creates a valid JSON structure.")]
@@ -43,8 +44,8 @@ public void SerializeNuiValueStrRefReturnsValidJson(uint? rawValue, string expec
public void SerializeNuiValueIntReturnsValidJson(int rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
- Assert.That(JsonUtility.ToJson(value), Is.EqualTo(expected));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)value), Is.EqualTo(expected));
}
[Test(Description = "Serializing a NuiValue creates a valid JSON structure.")]
@@ -58,8 +59,8 @@ public void SerializeNuiValueIntReturnsValidJson(int rawValue, string expected)
public void SerializeNuiValueNullableIntReturnsValidJson(int? rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
- Assert.That(JsonUtility.ToJson(value), Is.EqualTo(expected));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)value), Is.EqualTo(expected));
}
[Test(Description = "Serializing a NuiValue creates a valid JSON structure.")]
@@ -72,8 +73,8 @@ public void SerializeNuiValueNullableIntReturnsValidJson(int? rawValue, string e
public void SerializeNuiValueFloatReturnsValidJson(float rawValue, string expected)
{
NuiValue value = new NuiValue(rawValue);
- Assert.That(JsonUtility.ToJson(value), Is.EqualTo(expected));
- Assert.That(JsonUtility.ToJson>(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize(value), Is.EqualTo(expected));
+ Assert.That(JsonSerializer.Serialize((NuiProperty)value), Is.EqualTo(expected));
}
[Test(Description = "Serializing a NuiValue