mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Move event handlign internal to LegacyTcpIpcProvider
This commit is contained in:
@ -2,9 +2,18 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
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
|
namespace osu.Desktop.LegacyIpc
|
||||||
{
|
{
|
||||||
@ -33,7 +42,7 @@ namespace osu.Desktop.LegacyIpc
|
|||||||
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
|
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
|
||||||
object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType);
|
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;
|
return result != null ? new LegacyIpcMessage { Value = result } : null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -58,5 +67,39 @@ namespace osu.Desktop.LegacyIpc
|
|||||||
throw new ArgumentException($"Unknown type: {type}");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Desktop.LegacyIpc;
|
using osu.Desktop.LegacyIpc;
|
||||||
@ -11,15 +10,7 @@ using osu.Framework;
|
|||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Beatmaps.Legacy;
|
|
||||||
using osu.Game.IPC;
|
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;
|
using osu.Game.Tournament;
|
||||||
|
|
||||||
namespace osu.Desktop
|
namespace osu.Desktop
|
||||||
@ -98,7 +89,6 @@ namespace osu.Desktop
|
|||||||
{
|
{
|
||||||
Logger.Log("Starting legacy IPC provider...");
|
Logger.Log("Starting legacy IPC provider...");
|
||||||
legacyIpc = new LegacyTcpIpcProvider();
|
legacyIpc = new LegacyTcpIpcProvider();
|
||||||
legacyIpc.MessageReceived += onLegacyIpcMessageReceived;
|
|
||||||
legacyIpc.Bind();
|
legacyIpc.Bind();
|
||||||
legacyIpc.StartAsync();
|
legacyIpc.StartAsync();
|
||||||
}
|
}
|
||||||
@ -132,39 +122,5 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
return continueExecution;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user