Skip to content

Commit

Permalink
Fix auto-imported maps causing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Mar 2, 2024
1 parent 94d6b78 commit 415a2d1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions fluXis.Game/Map/MapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using fluXis.Game.Utils;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Logging;

namespace fluXis.Game.Map;

Expand Down Expand Up @@ -138,20 +137,37 @@ public virtual T GetMapEvents<T>()
return MapEvents.Load<T>(content);
}

public Storyboard GetStoryboard()
public virtual Storyboard GetStoryboard()
{
var path = MapFiles.GetFullPath(Map?.MapSet.GetPathForFile(StoryboardFile));
var file = Map?.MapSet.GetPathForFile(StoryboardFile);

if (string.IsNullOrEmpty(file))
return new Storyboard();

var path = MapFiles.GetFullPath(file);

Logger.Log($"Loading storyboard from {path}");
if (string.IsNullOrEmpty(path) || !File.Exists(path))
return new Storyboard();

var json = File.ReadAllText(path);
Logger.Log($"Loaded storyboard from {path}");
return json.Deserialize<Storyboard>();
}

public DrawableStoryboard CreateDrawableStoryboard() => new(GetStoryboard(), MapFiles.GetFullPath(Map!.MapSet.ID.ToString()));
public virtual DrawableStoryboard CreateDrawableStoryboard()
{
var sb = GetStoryboard();
var folderName = Map?.MapSet.ID.ToString();

if (string.IsNullOrEmpty(folderName))
return new DrawableStoryboard(sb, ".");

var path = MapFiles.GetFullPath(folderName);

if (!Directory.Exists(path))
return new DrawableStoryboard(sb, ".");

return new DrawableStoryboard(sb, MapFiles.GetFullPath(Map!.MapSet.ID.ToString()));
}

public TimingPoint GetTimingPoint(double time)
{
Expand Down

0 comments on commit 415a2d1

Please sign in to comment.