Skip to content

Commit b04b30c

Browse files
authored
API and Variable Descriptor cleanup (#2480)
* chore: remove unused usings * fix: add missing route attributes to AvatarController * chore: relocate controllers * chore: move everything out of the Net7/RestApi folders, adjust namespaces and cleanup uses as needed * chore: delete old dead code * fix: rename conflicting Type property and clean up the location of the variable descriptor types fix: update Editor to refer to VariableDescriptor.DataType, fix straggler references to the old name (I should have done a rename refactor, instead I got to use a temporary fake incorrectly typed `new Point Type` to find all of the missing updates in the server) fix: make FixVariables Sqlite migration have the same name as the MySql migration * chore: rename variable descriptor types chore: generate no-op migrations for renaming the descriptor types
1 parent 55e18df commit b04b30c

File tree

139 files changed

+8082
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+8082
-1040
lines changed

Framework/Intersect.Framework.Core/Descriptors/GameObjectType.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Intersect.Extensions;
2+
using Intersect.Framework.Core.GameObjects.Variables;
23
using Intersect.GameObjects;
34
using Intersect.GameObjects.Crafting;
45
using Intersect.GameObjects.Events;
@@ -47,10 +48,10 @@ public enum GameObjectType
4748
[GameObjectInfo(typeof(EventBase), "events")]
4849
Event,
4950

50-
[GameObjectInfo(typeof(PlayerVariableBase), "player_variables")]
51+
[GameObjectInfo(typeof(PlayerVariableDescriptor), "player_variables")]
5152
PlayerVariable,
5253

53-
[GameObjectInfo(typeof(ServerVariableBase), "server_variables")]
54+
[GameObjectInfo(typeof(ServerVariableDescriptor), "server_variables")]
5455
ServerVariable,
5556

5657
[GameObjectInfo(typeof(TilesetBase), "tilesets")]
@@ -59,9 +60,9 @@ public enum GameObjectType
5960
[GameObjectInfo(typeof(TimeBase), "")]
6061
Time,
6162

62-
[GameObjectInfo(typeof(GuildVariableBase), "guild_variables")]
63+
[GameObjectInfo(typeof(GuildVariableDescriptor), "guild_variables")]
6364
GuildVariable,
6465

65-
[GameObjectInfo(typeof(UserVariableBase), "user_variables")]
66+
[GameObjectInfo(typeof(UserVariableDescriptor), "user_variables")]
6667
UserVariable,
6768
}

Framework/Intersect.Framework.Core/Descriptors/GameObjectTypeExtensions.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Diagnostics.CodeAnalysis;
22
using Intersect.Collections;
33
using Intersect.Extensions;
4+
using Intersect.Framework.Core.GameObjects.Variables;
45
using Intersect.GameObjects;
5-
using Intersect.GameObjects.Switches_and_Variables;
66
using Intersect.Models;
77

88
namespace Intersect.Enums;
@@ -70,7 +70,7 @@ public static IDatabaseObject CreateNew(this GameObjectType gameObjectType)
7070
return instance as IDatabaseObject;
7171
}
7272

73-
public static int ListIndex(this GameObjectType gameObjectType, Guid id, VariableDataType dataTypeFilter = 0)
73+
public static int ListIndex(this GameObjectType gameObjectType, Guid id, VariableDataType dataTypeFilter = default)
7474
{
7575
var lookup = gameObjectType.GetLookup();
7676

@@ -82,9 +82,9 @@ public static int ListIndex(this GameObjectType gameObjectType, Guid id, Variabl
8282
return lookup
8383
.OrderBy(kv => kv.Value?.Name)
8484
.Select(kv => kv.Value)
85-
.OfType<IVariableBase>()
86-
.Where(desc => desc.Type == dataTypeFilter)
87-
.Select(desc => desc.Id)
85+
.OfType<IVariableDescriptor>()
86+
.Where(descriptor => dataTypeFilter == default || descriptor.DataType == dataTypeFilter)
87+
.Select(descriptor => descriptor.Id)
8888
.ToList()
8989
.IndexOf(id);
9090
}
@@ -94,11 +94,11 @@ public static VariableDataType GetVariableType(this GameObjectType gameObjectTyp
9494
var lookup = gameObjectType.GetLookup();
9595

9696
return lookup.ValueList
97-
.OfType<IVariableBase>()
98-
.FirstOrDefault(var => var.Id == variableDescriptorId)?.Type ?? 0;
97+
.OfType<IVariableDescriptor>()
98+
.FirstOrDefault(descriptor => descriptor.Id == variableDescriptorId)?.DataType ?? default;
9999
}
100100

101-
public static Guid IdFromList(this GameObjectType gameObjectType, int listIndex, VariableDataType dataTypeFilter = 0)
101+
public static Guid IdFromList(this GameObjectType gameObjectType, int listIndex, VariableDataType dataTypeFilter = default)
102102
{
103103
var lookup = gameObjectType.GetLookup();
104104

@@ -115,31 +115,31 @@ public static Guid IdFromList(this GameObjectType gameObjectType, int listIndex,
115115
return lookup
116116
.OrderBy(kv => kv.Value?.Name)
117117
.Select(kv => kv.Value)
118-
.OfType<IVariableBase>()
119-
.Where(desc => desc.Type == dataTypeFilter)
120-
.Select(desc => desc.Id)
118+
.OfType<IVariableDescriptor>()
119+
.Where(descriptor => dataTypeFilter == default || descriptor.DataType == dataTypeFilter)
120+
.Select(descriptor => descriptor.Id)
121121
.Skip(listIndex)
122122
.FirstOrDefault();
123123
}
124124

125-
public static string[] Names(this GameObjectType gameObjectType, VariableDataType dataTypeFilter = 0)
125+
public static string[] Names(this GameObjectType gameObjectType, VariableDataType dataTypeFilter = default)
126126
{
127127
if (dataTypeFilter == 0)
128128
{
129129
return gameObjectType
130130
.GetLookup()
131131
.OrderBy(p => p.Value?.Name)
132-
.Select(pair => pair.Value?.Name ?? PlayerVariableBase.Deleted)
132+
.Select(pair => pair.Value?.Name ?? PlayerVariableDescriptor.Deleted)
133133
.ToArray();
134134
}
135135

136136
return gameObjectType
137137
.GetLookup()
138138
.Select(kv => kv.Value)
139-
.OfType<IVariableBase>()
140-
.Where(desc => desc.Type == dataTypeFilter)
141-
.OrderBy(p => p?.Name)
142-
.Select(pair => pair?.Name ?? PlayerVariableBase.Deleted)
139+
.OfType<IVariableDescriptor>()
140+
.Where(descriptor => dataTypeFilter == default || descriptor.DataType == dataTypeFilter)
141+
.OrderBy(descriptor => descriptor.Name)
142+
.Select(descriptor => descriptor.Name ?? PlayerVariableDescriptor.Deleted)
143143
.ToArray();
144144
}
145145
}

Framework/Intersect.Framework.Core/GameObjects/GuildVariableBase.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

Framework/Intersect.Framework.Core/GameObjects/Switches and Variables/IVariableBase.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

Framework/Intersect.Framework.Core/GameObjects/Switches and Variables/PlayerVariableBase.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

Framework/Intersect.Framework.Core/GameObjects/UserVariableBase.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Intersect.Framework.Core.GameObjects.Variables;
4+
5+
public partial class GuildVariableDescriptor : VariableDescriptor<GuildVariableDescriptor>, IVariableDescriptor
6+
{
7+
[JsonConstructor]
8+
public GuildVariableDescriptor(Guid id) : base(id)
9+
{
10+
Name = "New Guild Variable";
11+
}
12+
13+
public GuildVariableDescriptor()
14+
{
15+
Name = "New Guild Variable";
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Intersect.Enums;
2+
using Intersect.Models;
3+
4+
namespace Intersect.Framework.Core.GameObjects.Variables;
5+
6+
public interface IVariableDescriptor : IDatabaseObject, IFolderable
7+
{
8+
/// <summary>
9+
/// The data type of the variable.
10+
/// </summary>
11+
VariableDataType DataType { get; set; }
12+
13+
/// <summary>
14+
/// Identifier used for event chat variables to display the value of this variable/switch.
15+
/// </summary>
16+
/// <seealso href="https://www.ascensiongamedev.com/topic/749-event-text-variables/" />
17+
string TextId { get; set; }
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Intersect.Framework.Core.GameObjects.Variables;
4+
5+
public partial class PlayerVariableDescriptor : VariableDescriptor<PlayerVariableDescriptor>, IVariableDescriptor
6+
{
7+
[JsonConstructor]
8+
public PlayerVariableDescriptor(Guid id) : base(id)
9+
{
10+
Name = "New Player Variable";
11+
}
12+
13+
public PlayerVariableDescriptor()
14+
{
15+
Name = "New Player Variable";
16+
}
17+
}

Framework/Intersect.Framework.Core/GameObjects/Switches and Variables/ServerVariableBase.cs renamed to Framework/Intersect.Framework.Core/GameObjects/Variables/ServerVariableDescriptor.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
using System.ComponentModel.DataAnnotations.Schema;
2-
3-
using Intersect.Enums;
4-
using Intersect.GameObjects.Switches_and_Variables;
5-
62
using Newtonsoft.Json;
73

8-
namespace Intersect.GameObjects;
4+
namespace Intersect.Framework.Core.GameObjects.Variables;
95

10-
public partial class ServerVariableBase : VariableDescriptor<ServerVariableBase>, IVariableBase
6+
public partial class ServerVariableDescriptor : VariableDescriptor<ServerVariableDescriptor>, IVariableDescriptor
117
{
128
[JsonConstructor]
13-
public ServerVariableBase(Guid id) : base(id)
9+
public ServerVariableDescriptor(Guid id) : base(id)
1410
{
1511
Name = "New Global Variable";
1612
}
1713

18-
public ServerVariableBase()
14+
public ServerVariableDescriptor()
1915
{
2016
Name = "New Global Variable";
2117
}
2218

23-
//Identifier used for event chat variables to display the value of this variable/switch.
24-
//See https://www.ascensiongamedev.com/topic/749-event-text-variables/ for usage info.
25-
public string TextId { get; set; }
26-
27-
// TODO(0.8): Rename this to DataType
28-
public new VariableDataType Type { get; set; } = VariableDataType.Boolean;
29-
3019
[NotMapped]
3120
[JsonIgnore]
3221
public VariableValue Value { get; set; } = new();
@@ -52,7 +41,4 @@ private set
5241
}
5342
}
5443
}
55-
56-
/// <inheritdoc />
57-
public string Folder { get; set; } = string.Empty;
5844
}

0 commit comments

Comments
 (0)