Skip to content

Commit aac1bb1

Browse files
authored
Merge pull request #28 from IRacle1/dev
Some Features/Fixes
2 parents 4e9a2f5 + 33ae468 commit aac1bb1

File tree

14 files changed

+95
-39
lines changed

14 files changed

+95
-39
lines changed

GeometryDashAPI.Tests/TypeDescriptorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,16 @@ public void OverrideVirtualFieldSet_Specific()
140140

141141
block.ZLayer.Should().Be(Layer.B4);
142142
}
143+
144+
[Test]
145+
public void PrivateFieldFromInheritedClass()
146+
{
147+
var input = "1,10,2,20,3,333";
148+
var descriptor = new TypeDescriptor<InheritField>();
149+
150+
var actual = descriptor.Create(input.AsSpan());
151+
152+
actual.X.Should().Be(10);
153+
actual.Y.Should().Be(20);
154+
}
143155
}

GeometryDashAPI/Attributes/GamePropertyAttribute.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ public class GamePropertyAttribute : Attribute
1010
public bool AlwaysSet { get; }
1111
public int KeyOverride { get; set; }
1212
public int Order { get; set; } = int.MaxValue;
13-
public bool IgnoreField = false;
1413

15-
public GamePropertyAttribute(string key, object defaultDefaultValue = null, bool alwaysSet = false)
14+
public GamePropertyAttribute(string key, object defaultValue = null, bool alwaysSet = false)
1615
{
1716
Key = key;
18-
DefaultValue = defaultDefaultValue;
17+
DefaultValue = defaultValue;
1918
AlwaysSet = alwaysSet;
2019
}
2120
}

GeometryDashAPI/Crypt.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public static byte[] GZipCompress(byte[] data)
4848
using var memory = new MemoryStream();
4949
using (var destination = new GZipStream(memory, CompressionMode.Compress))
5050
{
51-
using (var memoryStream2 = new MemoryStream(data))
52-
memoryStream2.CopyTo(destination);
51+
using var memoryStream2 = new MemoryStream(data);
52+
memoryStream2.CopyTo(destination);
5353
}
5454
return memory.ToArray();
5555
}

GeometryDashAPI/Data/LocalLevels.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace GeometryDashAPI.Data
1010
{
11-
public class LocalLevels : GameData, IEnumerable<LevelCreatorModel>
11+
public class LocalLevels : GameData, IReadOnlyCollection<LevelCreatorModel>
1212
{
1313
private List<LevelCreatorModel> levels { get; set; }
1414
private Dictionary<string, Dictionary<int, int>> index;
@@ -19,6 +19,7 @@ public int BinaryVersion
1919
set => DataPlist["LLM_02"] = value;
2020
}
2121

22+
[Obsolete("Use Count instead", true)]
2223
public int LevelCount => levels.Count;
2324

2425
protected LocalLevels() : base(GameDataType.LocalLevels)
@@ -104,6 +105,8 @@ public bool Remove(LevelCreatorModel levelInfo)
104105
return true;
105106
}
106107

108+
public int Count => levels.Count;
109+
107110
public IEnumerator<LevelCreatorModel> GetEnumerator()
108111
{
109112
foreach (var level in levels)
@@ -152,7 +155,7 @@ public static LocalLevels CreateNew()
152155
public void AddLevel(LevelCreatorModel levelInfo)
153156
{
154157
var all = DataPlist["LLM_01"];
155-
for (var i = LevelCount - 1; i >= 0; i--)
158+
for (var i = Count - 1; i >= 0; i--)
156159
all[$"k_{i + 1}"] = all[$"k_{i}"];
157160
all["k_0"] = levelInfo.DataLevel;
158161
LoadLevels();

GeometryDashAPI/Levels/GameObjects/Default/Block.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public class Block : GameObject, IBlock
1919
[GameProperty("36", false, Order = Trigger.OrderTriggerBase)] public bool IsTrigger { get; set; }
2020

2121
[GameProperty("6", 0)] public int Rotation { get; set; }
22+
2223
public bool Glow
2324
{
2425
get => !glow;
2526
set => glow = !value;
2627
}
28+
2729
[GameProperty("96", true)] private bool glow = true;
2830
[GameProperty("108", 0)] public int LinkControl { get; set; }
2931
[GameProperty("20", (short)0)] public short EditorL { get; set; }
@@ -32,11 +34,13 @@ public bool Glow
3234
[GameProperty("57")] [ArraySeparator(".")] public int[] Groups { get; set; }
3335
[GameProperty("67", false)] public bool DontEnter { get; set; }
3436
[GameProperty("25", 2)] public virtual int ZOrder { get; set; } = 2;
37+
3538
public Layer ZLayer
3639
{
3740
get => (Layer)zLayer;
3841
set => zLayer = (short)value;
3942
}
43+
4044
[GameProperty("24", (short)Layer.T1)] protected virtual short zLayer { get; set; } = (int)Layer.T1;
4145
[GameProperty("32", 1f)] public float Scale { get; set; } = 1f;
4246
[GameProperty("34", false)] public bool GroupParent { get; set; }

GeometryDashAPI/Levels/GameObjects/Default/Trigger.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ public abstract class Trigger : Block, ITrigger
88

99
[GameProperty("11", false, Order = 100)] public bool TouchTrigger { get; set; } = false;
1010
[GameProperty("62", false, Order = 101)] public bool SpawnTrigger { get; set; } = false;
11-
[GameProperty("87", false, Order = 102)] public virtual bool MultiTrigger { get; set; } = false;
11+
[GameProperty("87", false, Order = 102)] protected bool multiTrigger;
12+
13+
public virtual bool MultiTrigger
14+
{
15+
get => multiTrigger;
16+
set => multiTrigger = value;
17+
}
1218

1319
public Trigger()
1420
{

GeometryDashAPI/Levels/GameObjects/Triggers/ShakeTrigger.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ public class ShakeTrigger : Trigger
1010
[GameProperty("75", 0f, false, Order = OrderTriggerBase + 2)] public float Strength { get; set; }
1111
[GameProperty("84", 0f, false, Order = OrderTriggerBase + 3)] public float Interval { get; set; }
1212

13-
// robtop 300iq coder
14-
[GameProperty("87", false, Order = 102)]
15-
private bool multiTrigger;
16-
17-
[GameProperty("87", false, Order = 102, IgnoreField = true)]
1813
public override bool MultiTrigger
1914
{
2015
get => !multiTrigger;

GeometryDashAPI/Levels/GameObjects/Triggers/TouchTrigger.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ public class TouchTrigger : Trigger
1212
[GameProperty("82", ToggleMode.None, false, Order = OrderTriggerBase + 3)] public ToggleMode ToggleMode { get; set; } = ToggleMode.None;
1313
[GameProperty("89", false, false, Order = OrderTriggerBase + 4)] public bool DualMode { get; set; } = false;
1414

15-
// robtop 300iq coder
16-
[GameProperty("87", false, Order = 102)]
17-
private bool multiTrigger;
18-
19-
[GameProperty("87", false, Order = 102, IgnoreField = true)]
2015
public override bool MultiTrigger
2116
{
2217
get => !multiTrigger;

GeometryDashAPI/Serialization/TypeDescriptor.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
1212
{
1313
private readonly SetterInfo<T>[] setters;
1414
private readonly PrinterInfo<T>[] printers;
15-
private readonly Dictionary<string, int> mappings;
15+
private readonly Dictionary<string, int>? mappings;
1616
private readonly string sense;
1717
private readonly Func<T> create;
1818
private readonly bool isStruct;
@@ -21,7 +21,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
2121
public TypeDescriptor()
2222
{
2323
var type = typeof(T);
24-
create = CreateInstanceExpression<T>(type).Compile();
24+
create = CreateInstanceExpression<T>().Compile();
2525

2626
var senseAttribute = type.GetCustomAttribute<SenseAttribute>();
2727
if (senseAttribute == null)
@@ -33,7 +33,6 @@ public TypeDescriptor()
3333
var members = GetPropertiesAndFields(type)
3434
.Select(member => (member, attribute: member.GetCustomAttribute<GamePropertyAttribute>()))
3535
.Where(x => x.attribute != null)
36-
.Where(x => !x.attribute.IgnoreField)
3736
.ToArray();
3837
var createSetter = typeof(TypeDescriptorHelper)
3938
.GetMethod(nameof(TypeDescriptorHelper.CreateSetter), BindingFlags.Static | BindingFlags.NonPublic);
@@ -91,14 +90,13 @@ public T Create(ReadOnlySpan<char> raw)
9190
if (!int.TryParse(key.ToString(), out var index))
9291
#endif
9392
{
94-
var keyString = key.ToString();
95-
if (!mappings.TryGetValue(keyString, out var mapped))
93+
if (mappings == null || !mappings.TryGetValue(key.ToString(), out var mapped))
9694
{
9795
instance.WithoutLoaded.Add($"{key.ToString()}{sense}{value.ToString()}");
9896
continue;
9997
}
10098
if (!TrySet(instance, mapped, value))
101-
instance.WithoutLoaded.Add($"{keyString}{sense}{value.ToString()}");
99+
instance.WithoutLoaded.Add($"{key.ToString()}{sense}{value.ToString()}");
102100
continue;
103101
}
104102
if (!TrySet(instance, baseIndex + index, value))
@@ -187,19 +185,19 @@ private PrinterInfo<T>[] InitPrinters(IEnumerable<(MemberInfo member, GameProper
187185
.ToArray();
188186
}
189187

190-
private static Expression<Func<TB>> CreateInstanceExpression<TB>(Type type)
188+
private static Expression<Func<TB>> CreateInstanceExpression<TB>()
191189
{
192-
var ctor = Expression.New(type);
190+
var ctor = Expression.New(typeof(TB));
193191
var memberInit = Expression.MemberInit(ctor);
194192

195193
return Expression.Lambda<Func<TB>>(memberInit);
196194
}
197195

198-
private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int> mappings) InitSetters(Type type, IEnumerable<(MemberInfo member, GamePropertyAttribute attribute)> members)
196+
private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int>? mappings) InitSetters(Type type, IEnumerable<(MemberInfo member, GamePropertyAttribute attribute)> members)
199197
{
200198
var keys = new HashSet<string>();
201199
var maxKeyValue = 0;
202-
Dictionary<string, int> mappings = null;
200+
Dictionary<string, int>? mappings = null;
203201
foreach (var (member, attribute) in members)
204202
{
205203
if (int.TryParse(attribute.Key, out var key))
@@ -212,9 +210,9 @@ private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int> mappings
212210
continue;
213211
}
214212

215-
mappings ??= new Dictionary<string, int>();
216213
if (attribute.KeyOverride == -1)
217214
throw new InvalidOperationException($"Key override for member '{attribute.Key}' in {type.Name} is not set");
215+
mappings ??= new Dictionary<string, int>();
218216
mappings.Add(attribute.Key, attribute.KeyOverride);
219217
}
220218

@@ -239,7 +237,7 @@ private static IEnumerable<MemberInfo> GetPropertiesAndFields(Type type)
239237
var current = type;
240238
while (current != null && current != typeof(object))
241239
{
242-
foreach (var field in current.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
240+
foreach (var field in current.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
243241
yield return field;
244242
current = current.BaseType;
245243
}
@@ -519,12 +517,12 @@ private static Expression<Setter<TInstance>> CreateEnumSetter<TProp, TInstance>(
519517
);
520518
}
521519

522-
private static MethodInfo GetParserMethod<TProp>(out Expression instanceExpression)
520+
private static MethodInfo GetParserMethod<TProp>(out Expression? instanceExpression)
523521
{
524522
return GetParserMethod(typeof(TProp), out instanceExpression);
525523
}
526524

527-
private static MethodInfo GetParserMethod(Type propType, out Expression serializerExp)
525+
private static MethodInfo GetParserMethod(Type propType, out Expression? serializerExp)
528526
{
529527
if (typeof(IGameObject).IsAssignableFrom(propType))
530528
{

GeometryDashAPI/Server/Dtos/Account.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using GeometryDashAPI.Attributes;
1+
using System;
2+
3+
using GeometryDashAPI.Attributes;
24
using GeometryDashAPI.Server.Enums;
35

46
namespace GeometryDashAPI.Server.Dtos
@@ -45,7 +47,15 @@ public class Account : GameObject
4547
[GameProperty("45")] public string TwitchId { get; set; }
4648
[GameProperty("46")] public int Diamonds { get; set; }
4749
[GameProperty("48")] public int ExplosionId { get; set; }
48-
[GameProperty("49")] public int Moderator { get; set; }
50+
[GameProperty("49")] public GameModeratorType ModeratorType { get; set; }
51+
52+
[Obsolete("Use ModeratorType instead.")]
53+
public int Moderator
54+
{
55+
get => (int)ModeratorType;
56+
set => ModeratorType = (GameModeratorType)value;
57+
}
58+
4959
[GameProperty("50")] public int CommentHistoryState { get; set; }
5060
}
5161
}

0 commit comments

Comments
 (0)