mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 00:42:55 +08:00
Cleanup room definition
This commit is contained in:
parent
cc68cf2f95
commit
7c4fd8ca60
12
osu.Game/Online/API/Requests/Responses/APIMod.cs
Normal file
12
osu.Game/Online/API/Requests/Responses/APIMod.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
|
{
|
||||||
|
public class APIMod : IMod
|
||||||
|
{
|
||||||
|
public string Acronym { get; set; }
|
||||||
|
}
|
||||||
|
}
|
93
osu.Game/Online/Multiplayer/PlaylistItem.cs
Normal file
93
osu.Game/Online/Multiplayer/PlaylistItem.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Multiplayer
|
||||||
|
{
|
||||||
|
public class PlaylistItem
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int ID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("beatmap_id")]
|
||||||
|
public int BeatmapID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("ruleset_id")]
|
||||||
|
public int RulesetID { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public BeatmapInfo Beatmap
|
||||||
|
{
|
||||||
|
get => beatmap;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
beatmap = value;
|
||||||
|
BeatmapID = value?.OnlineBeatmapID ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public RulesetInfo Ruleset { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public readonly BindableCollection<Mod> AllowedMods = new BindableCollection<Mod>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public readonly BindableCollection<Mod> RequiredMods = new BindableCollection<Mod>();
|
||||||
|
|
||||||
|
[JsonProperty("beatmap")]
|
||||||
|
private APIBeatmap apiBeatmap { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("allowed_mods")]
|
||||||
|
private APIMod[] allowedMods
|
||||||
|
{
|
||||||
|
get => AllowedMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
||||||
|
set => _allowedMods = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonProperty("required_mods")]
|
||||||
|
private APIMod[] requiredMods
|
||||||
|
{
|
||||||
|
get => RequiredMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
||||||
|
set => _requiredMods = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeatmapInfo beatmap;
|
||||||
|
private APIMod[] _allowedMods;
|
||||||
|
private APIMod[] _requiredMods;
|
||||||
|
|
||||||
|
public void MapObjects(BeatmapManager beatmaps, RulesetStore rulesets)
|
||||||
|
{
|
||||||
|
// If we don't have an api beatmap, the request occurred as a result of room creation, so we can query the local beatmap instead
|
||||||
|
// Todo: Is this a bug?
|
||||||
|
Beatmap = apiBeatmap == null ? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == BeatmapID) : apiBeatmap.ToBeatmap(rulesets);
|
||||||
|
Ruleset = rulesets.GetRuleset(RulesetID);
|
||||||
|
|
||||||
|
if (_allowedMods != null)
|
||||||
|
{
|
||||||
|
AllowedMods.Clear();
|
||||||
|
AllowedMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _allowedMods.Any(m => m.Acronym == mod.Acronym)));
|
||||||
|
|
||||||
|
_allowedMods = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_requiredMods != null)
|
||||||
|
{
|
||||||
|
RequiredMods.Clear();
|
||||||
|
RequiredMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _requiredMods.Any(m => m.Acronym == mod.Acronym)));
|
||||||
|
|
||||||
|
_requiredMods = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldSerializeID() => false;
|
||||||
|
public bool ShouldSerializeapiBeatmap() => false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,11 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
@ -16,15 +13,13 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
public class Room
|
public class Room
|
||||||
{
|
{
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
public Bindable<int?> RoomID { get; } = new Bindable<int?>();
|
public Bindable<int?> RoomID { get; private set; } = new Bindable<int?>();
|
||||||
|
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public readonly Bindable<string> Name = new Bindable<string>("My awesome room!");
|
public Bindable<string> Name { get; private set; } = new Bindable<string>("My awesome room!");
|
||||||
|
|
||||||
[JsonProperty("host")]
|
[JsonProperty("host")]
|
||||||
public readonly Bindable<User> Host = new Bindable<User>();
|
public Bindable<User> Host { get; private set; } = new Bindable<User>();
|
||||||
|
|
||||||
public bool ShouldSerializeHost() => false;
|
|
||||||
|
|
||||||
[JsonProperty("playlist")]
|
[JsonProperty("playlist")]
|
||||||
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
||||||
@ -35,12 +30,28 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>(new RoomStatusOpen());
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Bindable<GameType> Type = new Bindable<GameType>(new GameTypeTimeshift());
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Bindable<int?> MaxParticipants = new Bindable<int?>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
|
||||||
|
|
||||||
[JsonProperty("duration")]
|
[JsonProperty("duration")]
|
||||||
private int duration
|
private int duration
|
||||||
{
|
{
|
||||||
get => (int)Duration.Value.TotalMinutes;
|
get => (int)Duration.Value.TotalMinutes;
|
||||||
set => Duration.Value = TimeSpan.FromMinutes(value);
|
set => Duration.Value = TimeSpan.FromMinutes(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
||||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
private int? maxAttempts
|
private int? maxAttempts
|
||||||
@ -49,12 +60,6 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
set => MaxAttempts.Value = value;
|
set => MaxAttempts.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>(new RoomStatusOpen());
|
|
||||||
public Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
|
||||||
public Bindable<GameType> Type = new Bindable<GameType>(new GameTypeTimeshift());
|
|
||||||
public Bindable<int?> MaxParticipants = new Bindable<int?>();
|
|
||||||
public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
|
|
||||||
|
|
||||||
public void CopyFrom(Room other)
|
public void CopyFrom(Room other)
|
||||||
{
|
{
|
||||||
RoomID.Value = other.RoomID;
|
RoomID.Value = other.RoomID;
|
||||||
@ -69,92 +74,8 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
Playlist.Clear();
|
Playlist.Clear();
|
||||||
Playlist.AddRange(other.Playlist);
|
Playlist.AddRange(other.Playlist);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class PlaylistItem
|
public bool ShouldSerializeRoomID() => false;
|
||||||
{
|
public bool ShouldSerializeHost() => false;
|
||||||
[JsonProperty("id")]
|
|
||||||
public int ID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("beatmap")]
|
|
||||||
private APIBeatmap apiBeatmap { get; set; }
|
|
||||||
|
|
||||||
public bool ShouldSerializeapiBeatmap() => false;
|
|
||||||
|
|
||||||
private BeatmapInfo beatmap;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public BeatmapInfo Beatmap
|
|
||||||
{
|
|
||||||
get => beatmap;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
beatmap = value;
|
|
||||||
BeatmapID = value?.OnlineBeatmapID ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty("beatmap_id")]
|
|
||||||
public int BeatmapID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("ruleset_id")]
|
|
||||||
public int RulesetID { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public readonly BindableCollection<Mod> AllowedMods = new BindableCollection<Mod>();
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public readonly BindableCollection<Mod> RequiredMods = new BindableCollection<Mod>();
|
|
||||||
|
|
||||||
private APIMod[] _allowedMods;
|
|
||||||
|
|
||||||
[JsonProperty("allowed_mods")]
|
|
||||||
private APIMod[] allowedMods
|
|
||||||
{
|
|
||||||
get => AllowedMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
|
||||||
set => _allowedMods = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private APIMod[] _requiredMods;
|
|
||||||
|
|
||||||
[JsonProperty("required_mods")]
|
|
||||||
private APIMod[] requiredMods
|
|
||||||
{
|
|
||||||
get => RequiredMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
|
||||||
set => _requiredMods = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public RulesetInfo Ruleset { get; set; }
|
|
||||||
|
|
||||||
public void MapObjects(BeatmapManager beatmaps, RulesetStore rulesets)
|
|
||||||
{
|
|
||||||
// If we don't have an api beatmap, the request occurred as a result of room creation, so we can query the local beatmap instead
|
|
||||||
// Todo: Is this a bug?
|
|
||||||
Beatmap = apiBeatmap == null ? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == BeatmapID) : apiBeatmap.ToBeatmap(rulesets);
|
|
||||||
Ruleset = rulesets.GetRuleset(RulesetID);
|
|
||||||
|
|
||||||
if (_allowedMods != null)
|
|
||||||
{
|
|
||||||
AllowedMods.Clear();
|
|
||||||
AllowedMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _allowedMods.Any(m => m.Acronym == mod.Acronym)));
|
|
||||||
|
|
||||||
_allowedMods = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_requiredMods != null)
|
|
||||||
{
|
|
||||||
RequiredMods.Clear();
|
|
||||||
RequiredMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _requiredMods.Any(m => m.Acronym == mod.Acronym)));
|
|
||||||
|
|
||||||
_requiredMods = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Todo: Move this elsewhere for reusability
|
|
||||||
private class APIMod : IMod
|
|
||||||
{
|
|
||||||
public string Acronym { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user