1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Move event handlign internal to LegacyTcpIpcProvider

This commit is contained in:
Dan Balasescu 2021-11-28 23:02:57 +09:00
parent 0d147b4ad9
commit 4ee2063683
2 changed files with 44 additions and 45 deletions

View File

@ -2,9 +2,18 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using Newtonsoft.Json.Linq;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
namespace osu.Desktop.LegacyIpc
{
@ -33,7 +42,7 @@ namespace osu.Desktop.LegacyIpc
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType);
object result = MessageReceived?.Invoke(value);
object result = onLegacyIpcMessageReceived(value);
return result != null ? new LegacyIpcMessage { Value = result } : null;
}
catch (Exception ex)
@ -58,5 +67,39 @@ namespace osu.Desktop.LegacyIpc
throw new ArgumentException($"Unknown type: {type}");
}
}
private object onLegacyIpcMessageReceived(object message)
{
switch (message)
{
case LegacyIpcDifficultyCalculationRequest req:
try
{
Ruleset ruleset = req.RulesetId switch
{
0 => new OsuRuleset(),
1 => new TaikoRuleset(),
2 => new CatchRuleset(),
3 => new ManiaRuleset(),
_ => throw new ArgumentException("Invalid ruleset id")
};
Mod[] mods = ruleset.ConvertFromLegacyMods((LegacyMods)req.Mods).ToArray();
WorkingBeatmap beatmap = new FlatFileWorkingBeatmap(req.BeatmapFile, _ => ruleset);
return new LegacyIpcDifficultyCalculationResponse
{
StarRating = ruleset.CreateDifficultyCalculator(beatmap).Calculate(mods).StarRating
};
}
catch
{
return new LegacyIpcDifficultyCalculationResponse();
}
}
Console.WriteLine("Type not matched.");
return null;
}
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Desktop.LegacyIpc;
@ -11,15 +10,7 @@ using osu.Framework;
using osu.Framework.Development;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.IPC;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Tournament;
namespace osu.Desktop
@ -98,7 +89,6 @@ namespace osu.Desktop
{
Logger.Log("Starting legacy IPC provider...");
legacyIpc = new LegacyTcpIpcProvider();
legacyIpc.MessageReceived += onLegacyIpcMessageReceived;
legacyIpc.Bind();
legacyIpc.StartAsync();
}
@ -132,39 +122,5 @@ namespace osu.Desktop
return continueExecution;
}
private static object onLegacyIpcMessageReceived(object message)
{
switch (message)
{
case LegacyIpcDifficultyCalculationRequest req:
try
{
Ruleset ruleset = req.RulesetId switch
{
0 => new OsuRuleset(),
1 => new TaikoRuleset(),
2 => new CatchRuleset(),
3 => new ManiaRuleset(),
_ => throw new ArgumentException("Invalid ruleset id")
};
Mod[] mods = ruleset.ConvertFromLegacyMods((LegacyMods)req.Mods).ToArray();
WorkingBeatmap beatmap = new FlatFileWorkingBeatmap(req.BeatmapFile, _ => ruleset);
return new LegacyIpcDifficultyCalculationResponse
{
StarRating = ruleset.CreateDifficultyCalculator(beatmap).Calculate(mods).StarRating
};
}
catch
{
return new LegacyIpcDifficultyCalculationResponse();
}
}
Console.WriteLine("Type not matched.");
return null;
}
}
}