Skip to content

Commit 080917b

Browse files
committed
fix resources
1 parent e005116 commit 080917b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

GeometryDashAPI.Tests/GameResourcesTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using FluentAssertions;
34
using GeometryDashAPI.Data;
45
using GeometryDashAPI.Levels;
@@ -46,9 +47,10 @@ public void SetUp()
4647

4748
[TestCase(OfficialLevel.TheChallenge)]
4849

49-
[TestCase(OfficialLevel.TheSevenSeas)]
50-
[TestCase(OfficialLevel.VikingArena)]
51-
[TestCase(OfficialLevel.AirborneRobots)]
50+
// meltdown levels is not supported, we have problems with unzipping
51+
// [TestCase(OfficialLevel.TheSevenSeas)]
52+
// [TestCase(OfficialLevel.VikingArena)]
53+
// [TestCase(OfficialLevel.AirborneRobots)]
5254

5355
[TestCase(OfficialLevel.Payload)]
5456
[TestCase(OfficialLevel.BeastMode)]
@@ -60,12 +62,12 @@ public void SetUp()
6062
[TestCase(OfficialLevel.Embers)]
6163
[TestCase(OfficialLevel.Round1)]
6264
[TestCase(OfficialLevel.MonsterDanceOff)]
63-
public void GetLevel_ShouldParseCorrect(OfficialLevel officialLevel)
65+
public async Task GetLevel_ShouldParseCorrect(OfficialLevel officialLevel)
6466
{
6567
var resources = new GameResources(path);
6668

6769
Level level = null;
68-
Assert.DoesNotThrow(() => level = resources.GetLevel(officialLevel));
70+
Assert.DoesNotThrow(() => level = resources.GetLevelAsync(officialLevel).GetAwaiter().GetResult());
6971

7072
level.Should().NotBeNull();
7173
level.Blocks.Should().HaveCountGreaterThan(0);

GeometryDashAPI/Data/GameResources.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.IO;
5+
using System.Threading.Tasks;
46
using GeometryDashAPI.Levels;
57
using GeometryDashAPI.Serialization;
68

@@ -16,12 +18,16 @@ public GameResources(string path)
1618
this.path = path;
1719
}
1820

19-
public Level GetLevel(OfficialLevel officialLevel)
21+
public async Task<Level> GetLevelAsync(OfficialLevel officialLevel)
2022
{
2123
var gameType = officialLevel.GetGameType();
22-
var plist = levels.GetOrCreate(
23-
gameType,
24-
version => new Plist(File.ReadAllBytes(Path.Combine(path, GetLevelDataPath(version)))));
24+
if (gameType == GameType.Meltdown)
25+
throw new InvalidEnumArgumentException("meltdown levels is not supported");
26+
if (!levels.TryGetValue(gameType, out var plist))
27+
{
28+
var bytes = await File.ReadAllBytesAsync(Path.Combine(path, GetLevelDataPath(gameType)));
29+
levels.TryAdd(gameType, plist = new Plist(bytes));
30+
}
2531

2632
var content = plist[((int)officialLevel).ToString()].ToString();
2733
if (gameType == GameType.Default)

GeometryDashAPI/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GeometryDashAPI
66
{
77
public static class Extensions
88
{
9-
public static T GetAttributeOfSelected<T>(this Enum value) where T : Attribute
9+
public static T? GetAttributeOfSelected<T>(this Enum value) where T : Attribute
1010
{
1111
var info = value.GetType().GetMember(value.ToString())[0];
1212
var attributes = info.GetCustomAttributes(typeof(T), false);

0 commit comments

Comments
 (0)