mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Introduce concept of HitObjectParsers, fix tests and stop using reflection (unreliable due to lazy loading).
This commit is contained in:
@ -48,6 +48,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
new Color4(121,9,13, 255),
|
||||
};
|
||||
|
||||
if (colours.Count == 0) return;
|
||||
|
||||
int i = -1;
|
||||
|
||||
foreach (HitObject h in b.HitObjects)
|
||||
|
@ -221,7 +221,9 @@ namespace osu.Game.Beatmaps.Formats
|
||||
BaseDifficulty = new BaseDifficulty(),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
HitObjectParser parser = null;
|
||||
|
||||
var section = Section.None;
|
||||
string line;
|
||||
while (true)
|
||||
@ -233,14 +235,14 @@ namespace osu.Game.Beatmaps.Formats
|
||||
continue;
|
||||
if (line.StartsWith(@"osu file format v"))
|
||||
continue;
|
||||
|
||||
|
||||
if (line.StartsWith(@"[") && line.EndsWith(@"]"))
|
||||
{
|
||||
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
||||
throw new InvalidDataException($@"Unknown osu section {line}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
string val = line, key = null;
|
||||
if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects)
|
||||
{
|
||||
@ -251,6 +253,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
case Section.General:
|
||||
handleGeneral(beatmap, key, val);
|
||||
parser = Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).CreateHitObjectParser();
|
||||
break;
|
||||
case Section.Editor:
|
||||
handleEditor(beatmap, key, val);
|
||||
@ -271,13 +274,13 @@ namespace osu.Game.Beatmaps.Formats
|
||||
handleColours(beatmap, key, val);
|
||||
break;
|
||||
case Section.HitObjects:
|
||||
var h = HitObject.Parse(beatmap.BeatmapInfo.Mode, val);
|
||||
if (h != null)
|
||||
beatmap.HitObjects.Add(h);
|
||||
var obj = parser?.Parse(val);
|
||||
if (obj != null)
|
||||
beatmap.HitObjects.Add(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return beatmap;
|
||||
}
|
||||
}
|
||||
|
@ -21,17 +21,5 @@ namespace osu.Game.Modes.Objects
|
||||
public double Duration => EndTime - StartTime;
|
||||
|
||||
public HitSampleInfo Sample;
|
||||
|
||||
public static HitObject Parse(PlayMode mode, string val)
|
||||
{
|
||||
//TODO: move to modular HitObjectParser system rather than static parsing. (https://github.com/ppy/osu/pull/60/files#r83135780)
|
||||
switch (mode)
|
||||
{
|
||||
case PlayMode.Osu:
|
||||
return null; //return OsuBaseHit.Parse(val);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
osu.Game/Modes/Objects/HitObjectParser.cs
Normal file
16
osu.Game/Modes/Objects/HitObjectParser.cs
Normal file
@ -0,0 +1,16 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Modes.Objects
|
||||
{
|
||||
public abstract class HitObjectParser
|
||||
{
|
||||
public abstract HitObject Parse(string text);
|
||||
}
|
||||
}
|
@ -13,17 +13,19 @@ namespace osu.Game.Modes
|
||||
{
|
||||
public abstract class Ruleset
|
||||
{
|
||||
private static List<Type> availableRulesets = new List<Type>();
|
||||
|
||||
public abstract ScoreOverlay CreateScoreOverlay();
|
||||
|
||||
public abstract HitRenderer CreateHitRendererWith(List<HitObject> objects);
|
||||
|
||||
public abstract HitObjectParser CreateHitObjectParser();
|
||||
|
||||
public static void Register(Ruleset ruleset) => availableRulesets.Add(ruleset.GetType());
|
||||
|
||||
public static Ruleset GetRuleset(PlayMode mode)
|
||||
{
|
||||
Type type = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.Where(a => a.FullName.Contains($@"osu.Game.Modes.{mode}"))
|
||||
.SelectMany(a => a.GetTypes())
|
||||
.FirstOrDefault(t => t.Name == $@"{mode}Ruleset");
|
||||
Type type = availableRulesets.FirstOrDefault(t => t.Name == $@"{mode}Ruleset");
|
||||
|
||||
if (type == null)
|
||||
return null;
|
||||
|
@ -63,6 +63,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Modes\Objects\HitObjectParser.cs" />
|
||||
<Compile Include="Overlays\DragBar.cs" />
|
||||
<Compile Include="Overlays\MusicController.cs" />
|
||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||
|
Reference in New Issue
Block a user