Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
csinkers committed Sep 30, 2024
1 parent 13fc13a commit 764a5c8
Show file tree
Hide file tree
Showing 64 changed files with 337 additions and 277 deletions.
2 changes: 2 additions & 0 deletions src/Api/Eventing/DiagEditAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public sealed class DiagEditAttribute : Attribute
public int MaxLength { get; set; } = int.MaxValue; // For strings
public int Min { get; set; } = int.MaxValue; // For sliders
public int Max { get; set; } = int.MinValue; // For sliders
public string MinProperty { get; set; } // For sliders
public string MaxProperty { get; set; } // For sliders
}
9 changes: 9 additions & 0 deletions src/Api/Eventing/DiagEditStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ public enum DiagEditStyle
Dropdown, // For enum
Checkboxes, // For flags enum
Text, // For strings

Size2D,

Size3D,
Position3D,
TilePosition3D,
CharacterAttribute,
IdPicker,
InvSlot
}
2 changes: 2 additions & 0 deletions src/Api/Eventing/EventNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,7 @@ public override bool Equals(object obj)
return Equals((EventNode)obj);
}

// ReSharper disable NonReadonlyMemberInGetHashCode
public override int GetHashCode() => HashCode.Combine(Id, Event.GetHashCode(), Next?.Id);
// ReSharper restore NonReadonlyMemberInGetHashCode
}
7 changes: 4 additions & 3 deletions src/Core.Veldrid/ImGuiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void InitialiseLayout()
var config = ImGuiConfig.Load(layout);
var newConfig = new ImGuiConfig();

var oldIni = ImGui.SaveIniSettingsToMemory();
// var oldIni = ImGui.SaveIniSettingsToMemory();

// Create windows
var menus = Resolve<IImGuiMenuManager>();
Expand Down Expand Up @@ -122,8 +122,9 @@ void InitialiseLayout()

var newConfigText = newConfig.ToString();
ImGui.LoadIniSettingsFromMemory(newConfigText);
var roundTrip = ImGui.SaveIniSettingsToMemory();
int diff = roundTrip.Length - newConfigText.Length;

// var roundTrip = ImGui.SaveIniSettingsToMemory();
// int diff = roundTrip.Length - newConfigText.Length;
}

public int GetNextWindowId() => Interlocked.Increment(ref _nextWindowId);
Expand Down
3 changes: 3 additions & 0 deletions src/Core.Veldrid/Reflection/AuxiliaryReflectorStateCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace UAlbion.Core.Veldrid.Reflection;

public class AuxiliaryReflectorStateCache
{
// ReSharper disable NotAccessedPositionalProperty.Local
record struct Key(object Parent, ReflectorMetadata Meta, int Index, string Type);
// ReSharper restore NotAccessedPositionalProperty.Local

readonly Dictionary<Key, object> _cache1 = new();
readonly Dictionary<Key, object> _cache2 = new();
bool _cache1Active = true;
Expand Down
28 changes: 28 additions & 0 deletions src/Core.Veldrid/Reflection/BoolReflector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ImGuiNET;

namespace UAlbion.Core.Veldrid.Reflection;

sealed class BoolReflector : IReflector
{
BoolReflector() { }
public static BoolReflector Instance { get; } = new();

public void Reflect(in ReflectorState state)
{
var value = (bool)state.Target;
var description = ReflectorUtil.NameText(state);
ImGui.Indent();
ImGui.TextWrapped(description);
ImGui.SameLine();

if (state.Meta.Options != null)
{
if (ImGui.Checkbox("##" + description, ref value))
state.Meta.Setter(state, value);
}
else
ImGui.TextWrapped(value.ToString());

ImGui.Unindent();
}
}
17 changes: 17 additions & 0 deletions src/Core.Veldrid/Reflection/NullReflector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ImGuiNET;

namespace UAlbion.Core.Veldrid.Reflection;

sealed class NullReflector : IReflector
{
NullReflector() { }
public static NullReflector Instance { get; } = new();

public void Reflect(in ReflectorState state)
{
var description = ReflectorUtil.Describe(state, "null", "null");
ImGui.Indent();
ImGui.TextUnformatted(description);
ImGui.Unindent();
}
}
2 changes: 1 addition & 1 deletion src/Core.Veldrid/Reflection/ReflectorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static T GetAuxiliaryState<T>(in ReflectorState state, string type, Func<
{
ArgumentNullException.ThrowIfNull(auxStateBuilder);

lock (AuxState)
lock (SyncRoot)
{
var result = AuxState.Get(state, type);
if (result == null)
Expand Down
41 changes: 2 additions & 39 deletions src/Core.Veldrid/Reflection/StringReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Reflect(in ReflectorState state)
}
);

if (ImGui.InputText(name, buf, (uint)buf.Length))
if (ImGui.InputText("##" + name, buf, (uint)buf.Length))
{
var str = ImGuiUtil.GetString(buf);
state.Meta.Setter(state, str);
Expand All @@ -51,41 +51,4 @@ public void Reflect(in ReflectorState state)
ImGui.Unindent();

}
}
sealed class BoolReflector : IReflector
{
BoolReflector() { }
public static BoolReflector Instance { get; } = new();

public void Reflect(in ReflectorState state)
{
var value = (bool)state.Target;
var description = ReflectorUtil.NameText(state);
ImGui.Indent();
ImGui.TextWrapped(description);
ImGui.SameLine();

if (state.Meta?.Options != null)
{
if (ImGui.Checkbox("##" + description, ref value))
state.Meta.Setter(state, value);
}
else
ImGui.TextWrapped(value.ToString());

ImGui.Unindent();
}
}
sealed class NullReflector : IReflector
{
NullReflector() { }
public static NullReflector Instance { get; } = new();

public void Reflect(in ReflectorState state)
{
var description = ReflectorUtil.Describe(state, "null", "null");
ImGui.Indent();
ImGui.TextUnformatted(description);
ImGui.Unindent();
}
}
}
11 changes: 6 additions & 5 deletions src/Core/LogExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ public void Receive(IEvent e, object sender)
static void PrintHelp(StringBuilder sb, string pattern)
{
sb.AppendLine();
var metadata = EventSerializer.Instance.GetEventMetadata()
.FirstOrDefault(x => x.Name.Equals(pattern, StringComparison.OrdinalIgnoreCase)
|| x.Aliases != null &&
x.Aliases.Any(y => y.Equals(pattern, StringComparison.OrdinalIgnoreCase)));
var metadata =
EventSerializer.Instance.GetEventMetadata()
.FirstOrDefault(x =>
x.Name.Equals(pattern, StringComparison.OrdinalIgnoreCase)
|| x.Aliases != null && x.Aliases.Any(y => y.Equals(pattern, StringComparison.OrdinalIgnoreCase)));

if (metadata != null)
{
Expand All @@ -197,7 +198,7 @@ static void PrintHelp(StringBuilder sb, string pattern)
.Distinct()
.ToList();

if (matchingEvents.Count == 0)
if (matchingEvents.Count != 0)
PrintHelpSummary(sb, matchingEvents);
else
sb.AppendFormat("The command \"{0}\" is not recognised." + Environment.NewLine, pattern);
Expand Down
1 change: 1 addition & 0 deletions src/Core/VarRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace UAlbion.Core;

public class VarRegistry : ServiceComponent<IVarRegistry>, IVarRegistry
{
// ReSharper disable once NotAccessedPositionalProperty.Local
sealed record VarInfo(IVar Var, Type ValueType, Type OwningType);
readonly Dictionary<string, VarInfo> _vars = new();

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Visual/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Sprite(
_textureLoaderFunc = textureLoaderFunc ?? DefaultLoader;
}

[DiagEdit]
public IAssetId Id
{
get => _id;
Expand All @@ -71,6 +72,7 @@ public IAssetId Id
public Func<object> SelectionCallback { get; init; }
static Vector3 Normal => Vector3.UnitZ; // TODO

[DiagEdit(Style = DiagEditStyle.Position3D)]
public Vector3 Position
{
get => _position;
Expand All @@ -84,9 +86,11 @@ public Vector3 Position
Raise(_moveEvent);
}
}

public Vector3 Dimensions => new(Size.X, Size.Y, Size.X);
public int DebugZ => DepthUtil.DepthToLayer(Position.Z);

[DiagEdit(Style = DiagEditStyle.Size2D)]
public Vector2 Size
{
get => _size ?? Vector2.One;
Expand All @@ -101,6 +105,7 @@ public Vector2 Size
}
}

[DiagEdit(Style = DiagEditStyle.NumericSlider, Min = 0, MaxProperty = nameof(FrameCount))]
public int Frame
{
get => _frame % FrameCount;
Expand Down
8 changes: 2 additions & 6 deletions src/Editor/EditorAddInstanceEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

namespace UAlbion.Editor;

public class EditorAddInstanceEvent : Event, IEditorEvent
{
public int Id { get; }
public string CollectionName { get; }
public int Index { get; }
}
// ReSharper disable once ClassNeverInstantiated.Global
public record EditorAddInstanceEvent(int Id, string CollectionName, int Index) : EventRecord, IEditorEvent;
2 changes: 1 addition & 1 deletion src/Editor/EditorAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void MoveInCollection(string collectionName, int fromIndex, int toIndex)

public bool Apply(IEditorEvent editorEvent)
{
if (editorEvent == null) throw new ArgumentNullException(nameof(editorEvent));
ArgumentNullException.ThrowIfNull(editorEvent);
switch (editorEvent)
{
case EditorSetPropertyEvent setProperty:
Expand Down
2 changes: 1 addition & 1 deletion src/Editor/EditorAssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool InnerApply(IEditorEvent e)
return false;
}

void Undo(IEditorEvent e)
void Undo(IEditorEvent _)
{
// Verify id is valid
// Perform inverse of change
Expand Down
11 changes: 4 additions & 7 deletions src/Editor/EditorMoveInstanceEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace UAlbion.Editor;

public class EditorMoveInstanceEvent : Event, IEditorEvent
{
public int Id { get; }
public string CollectionName { get; }
public int FromIndex { get; }
public int ToIndex { get; }
}
// ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable once ClassNeverInstantiated.Global
public record EditorMoveInstanceEvent(int Id, string CollectionName, int FromIndex, int ToIndex) : EventRecord, IEditorEvent;
// ReSharper restore NotAccessedPositionalProperty.Global
12 changes: 5 additions & 7 deletions src/Editor/EditorRemoveInstanceEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace UAlbion.Editor;

public class EditorRemoveInstanceEvent : Event, IEditorEvent
{
public int Id { get; }
public string CollectionName { get; }
public int Index { get; }
public EditorAsset Asset { get; }
}
// ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable once ClassNeverInstantiated.Global
public record EditorRemoveInstanceEvent(int Id, string CollectionName, int Index, EditorAsset Asset)
// ReSharper restore NotAccessedPositionalProperty.Global
: EventRecord, IEditorEvent;
7 changes: 3 additions & 4 deletions src/Editor/MapEditor.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using System;
using ImGuiNET;
using ImGuiNET;
using UAlbion.Formats.Assets.Maps;

namespace UAlbion.Editor;

public class FlatMapEditor : AssetEditor
{
readonly string _name;
readonly MapData2D _map;
// readonly MapData2D _map;

public FlatMapEditor(string name, MapData2D map): base(map)
{
_name = name;
_map = map ?? throw new ArgumentNullException(nameof(map));
// _map = map ?? throw new ArgumentNullException(nameof(map));
}

public override void Render()
Expand Down
18 changes: 10 additions & 8 deletions src/Formats/Assets/CharacterAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using UAlbion.Api.Eventing;

namespace UAlbion.Formats.Assets;

Expand Down Expand Up @@ -27,14 +28,15 @@ public IEnumerable<CharacterAttribute> Enumerate()
ICharacterAttribute ICharacterAttributes.Luck => Luck;
ICharacterAttribute ICharacterAttributes.MagicResistance => MagicResistance;
ICharacterAttribute ICharacterAttributes.MagicTalent => MagicTalent;
public CharacterAttribute Strength { get; set; }
public CharacterAttribute Intelligence { get; set; }
public CharacterAttribute Dexterity { get; set; }
public CharacterAttribute Speed { get; set; }
public CharacterAttribute Stamina { get; set; }
public CharacterAttribute Luck { get; set; }
public CharacterAttribute MagicResistance { get; set; }
public CharacterAttribute MagicTalent { get; set; }

[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Strength { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Intelligence { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Dexterity { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Speed { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Stamina { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute Luck { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute MagicResistance { get; set; }
[DiagEdit(Style = DiagEditStyle.CharacterAttribute)] public CharacterAttribute MagicTalent { get; set; }

public CharacterAttributes DeepClone() => new CharacterAttributes().CopyFrom(this);
public CharacterAttributes CopyFrom(CharacterAttributes other)
Expand Down
Loading

0 comments on commit 764a5c8

Please sign in to comment.