-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from flightlex/master
level length
- Loading branch information
Showing
8 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.IO; | ||
using System.Net; | ||
using FluentAssertions; | ||
using GeometryDashAPI.Levels; | ||
using GeometryDashAPI.Server; | ||
using GeometryDashAPI.Server.Responses; | ||
using NUnit.Framework; | ||
|
||
namespace GeometryDashAPI.Tests; | ||
|
||
[TestFixture] | ||
public class LevelLengthTests | ||
{ | ||
[TestCase("12034598_Conclusion", 57)] | ||
[TestCase("28755513_TheFinalLair", 154)] | ||
[TestCase("116631_XmasParty", 87)] | ||
public void Test(string fileName, int expectedSeconds) | ||
{ | ||
var responseBody = File.ReadAllText(Path.Combine("data", "levels", fileName)); | ||
var response = new ServerResponse<LevelResponse>(HttpStatusCode.OK, responseBody); | ||
var level = new Level(response.GetResultOrDefault().Level.LevelString, compressed: true); | ||
level.LevelLength.TotalSeconds.Should().BeApproximately(expectedSeconds, precision: 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Linq; | ||
using GeometryDashAPI.Levels.GameObjects.Specific; | ||
|
||
namespace GeometryDashAPI.Levels | ||
{ | ||
public static class LevelLength | ||
{ | ||
public static TimeSpan Measure(Level level) | ||
{ | ||
var maxX = level.Blocks.Max(x => x.PositionX); | ||
var portals = GetSpeedBlocks(level); | ||
|
||
var seconds = 0d; | ||
var i = 1; | ||
for (; i < portals.Length; i++) | ||
seconds += (portals[i].PositionX - portals[i - 1].PositionX) / portals[i - 1].SpeedType.GetSpeed(); | ||
|
||
var final = Math.Min(i, portals.Length - 1); | ||
var total = seconds + (maxX - portals[final].PositionX) / portals[final].SpeedType.GetSpeed(); | ||
|
||
return TimeSpan.FromSeconds(total); | ||
} | ||
|
||
private static SpeedBlock[] GetSpeedBlocks(Level level) | ||
{ | ||
return new[] { new SpeedBlock(level.Options.PlayerSpeed) } | ||
.Concat(level.Blocks.OfType<SpeedBlock>() | ||
.Where(x => x.Checked) | ||
.OrderBy(x => x.PositionX) | ||
).ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using GeometryDashAPI.Levels.Enums; | ||
|
||
namespace GeometryDashAPI.Levels | ||
{ | ||
public static class LevelSpeed | ||
{ | ||
public const double Half = 251.16; | ||
public const double Default = 311.58; | ||
public const double X2 = 387.42; | ||
public const double X3 = 468; | ||
public const double X4 = 576; | ||
|
||
public static double GetSpeed(this SpeedType speedType) | ||
{ | ||
return speedType switch | ||
{ | ||
SpeedType.Half => Half, | ||
SpeedType.Default => Default, | ||
SpeedType.X2 => X2, | ||
SpeedType.X3 => X3, | ||
SpeedType.X4 => X4 | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using GeometryDashAPI.Attributes; | ||
using GeometryDashAPI.Levels.GameObjects.Default; | ||
|
||
namespace GeometryDashAPI.Levels | ||
{ | ||
public class Portal : Block | ||
{ | ||
[GameProperty("13", true, true)] public bool Checked { get; set; } | ||
|
||
public Portal() | ||
{ | ||
} | ||
|
||
public Portal(int id) : base(id) | ||
{ | ||
} | ||
} | ||
} |