mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Add automatic scoring
This commit is contained in:
parent
713038bff8
commit
629657044d
@ -6,6 +6,7 @@ using System.IO;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform.Windows;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
@ -15,6 +16,15 @@ using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Tournament.IPC
|
||||
{
|
||||
public enum TourneyState
|
||||
{
|
||||
Initialising,
|
||||
Idle,
|
||||
WaitingForClients,
|
||||
Playing,
|
||||
Ranking
|
||||
}
|
||||
|
||||
public class FileBasedIPC : Component
|
||||
{
|
||||
[Resolved]
|
||||
@ -27,7 +37,11 @@ namespace osu.Game.Tournament.IPC
|
||||
|
||||
public readonly Bindable<LegacyMods> Mods = new Bindable<LegacyMods>();
|
||||
|
||||
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
|
||||
|
||||
private int lastBeatmapId;
|
||||
public int Score1;
|
||||
public int Score2;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -35,6 +49,8 @@ namespace osu.Game.Tournament.IPC
|
||||
var stable = new StableStorage();
|
||||
|
||||
const string file_ipc_filename = "ipc.txt";
|
||||
const string file_ipc_state_filename = "ipc-state.txt";
|
||||
const string file_ipc_scores_filename = "ipc-scores.txt";
|
||||
|
||||
if (stable.Exists(file_ipc_filename))
|
||||
Scheduler.AddDelayed(delegate
|
||||
@ -62,6 +78,35 @@ namespace osu.Game.Tournament.IPC
|
||||
{
|
||||
// file might be in use.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = stable.GetStream(file_ipc_state_filename))
|
||||
using (var sr = new StreamReader(stream))
|
||||
{
|
||||
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e.ToString(), LoggingTarget.Runtime);
|
||||
// file might be in use.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = stable.GetStream(file_ipc_scores_filename))
|
||||
using (var sr = new StreamReader(stream))
|
||||
{
|
||||
Score1 = int.Parse(sr.ReadLine());
|
||||
Score2 = int.Parse(sr.ReadLine());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e.ToString(), LoggingTarget.Runtime);
|
||||
// file might be in use.
|
||||
}
|
||||
}, 250, true);
|
||||
}
|
||||
|
||||
@ -72,33 +117,46 @@ namespace osu.Game.Tournament.IPC
|
||||
{
|
||||
protected override string LocateBasePath()
|
||||
{
|
||||
|
||||
bool checkExists(string p)
|
||||
{
|
||||
return Directory.Exists(Path.Combine(p, "Songs"));
|
||||
return File.Exists(Path.Combine(p, "ipc.txt"));
|
||||
}
|
||||
|
||||
string stableInstallPath;
|
||||
string stableInstallPath = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
stableInstallPath = "E:\\osu!mappool";
|
||||
try
|
||||
{
|
||||
stableInstallPath = "E:\\osu!tourney";
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = "E:\\osu!mappool";
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
finally
|
||||
{
|
||||
Logger.Log($"Stable path for tourney usage: {stableInstallPath}");
|
||||
}
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StableStorage()
|
||||
|
@ -4,9 +4,13 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Gameplay
|
||||
{
|
||||
@ -14,9 +18,16 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
{
|
||||
private readonly BindableBool warmup = new BindableBool();
|
||||
|
||||
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
||||
|
||||
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
|
||||
private TriangleButton warmupButton;
|
||||
private FileBasedIPC ipc;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder, TextureStore textures)
|
||||
private void load(LadderInfo ladder, TextureStore textures, FileBasedIPC ipc)
|
||||
{
|
||||
this.ipc = ipc;
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new MatchHeader(),
|
||||
@ -26,12 +37,21 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
// Origin = Anchor.BottomCentre,
|
||||
// Size = new Vector2(0.4f, 1)
|
||||
// },
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 720 / 1080f,
|
||||
Colour = new Color4(0, 255, 0, 255),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin= Anchor.Centre,
|
||||
},
|
||||
new ControlPanel
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TriangleButton
|
||||
warmupButton = new TriangleButton
|
||||
{
|
||||
Colour = Color4.Gray,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = "Toggle warmup",
|
||||
Action = toggleWarmup
|
||||
@ -39,11 +59,33 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
State.BindValueChanged(stateChanged);
|
||||
State.BindTo(ipc.State);
|
||||
|
||||
currentMatch.BindTo(ladder.CurrentMatch);
|
||||
}
|
||||
|
||||
private void stateChanged(TourneyState state)
|
||||
{
|
||||
if (state == TourneyState.Ranking)
|
||||
{
|
||||
if (warmup.Value) return;
|
||||
|
||||
if (ipc.Score1 > ipc.Score2)
|
||||
currentMatch.Value.Team1Score.Value++;
|
||||
else
|
||||
currentMatch.Value.Team2Score.Value++;
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleWarmup()
|
||||
{
|
||||
warmup.Toggle();
|
||||
if (warmup.Value)
|
||||
warmupButton.Colour = Color4.White;
|
||||
else
|
||||
warmupButton.Colour = Color4.Gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user