1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 18:27:18 +08:00

113 lines
4.1 KiB
C#
Raw Normal View History

2018-04-13 18:19:50 +09:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-12-17 14:45:06 +09:00
using System;
using System.Collections.Generic;
2018-12-03 20:50:40 +09:00
using System.Linq;
using Newtonsoft.Json;
2018-04-13 18:19:50 +09:00
using osu.Framework.Configuration;
2018-12-26 16:46:50 +09:00
using osu.Game.Online.Multiplayer.GameTypes;
2018-12-27 13:30:36 +09:00
using osu.Game.Online.Multiplayer.RoomStatuses;
2018-04-13 18:19:50 +09:00
using osu.Game.Users;
namespace osu.Game.Online.Multiplayer
{
public class Room
{
2018-12-12 19:04:11 +09:00
[JsonProperty("id")]
2018-12-17 14:45:06 +09:00
public Bindable<int?> RoomID { get; private set; } = new Bindable<int?>();
[JsonProperty("name")]
public Bindable<string> Name { get; private set; } = new Bindable<string>();
[JsonProperty("host")]
2018-12-17 14:45:06 +09:00
public Bindable<User> Host { get; private set; } = new Bindable<User>();
2018-12-12 19:04:11 +09:00
[JsonProperty("playlist")]
2018-12-21 13:06:11 +09:00
public BindableCollection<PlaylistItem> Playlist { get; set; } = new BindableCollection<PlaylistItem>();
2018-12-21 14:01:06 +09:00
[JsonProperty("channel_id")]
public Bindable<int> ChannelId { get; private set; } = new Bindable<int>();
2018-12-17 14:44:54 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<TimeSpan> Duration { get; private set; } = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
2018-12-12 19:04:11 +09:00
2018-12-13 16:06:30 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<int?> MaxAttempts { get; private set; } = new Bindable<int?>();
2018-12-13 16:06:30 +09:00
2018-12-17 14:45:06 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<RoomStatus> Status { get; private set; } = new Bindable<RoomStatus>(new RoomStatusOpen());
2018-12-17 14:45:06 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<RoomAvailability> Availability { get; private set; } = new Bindable<RoomAvailability>();
2018-12-17 14:45:06 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<GameType> Type { get; private set; } = new Bindable<GameType>(new GameTypeTimeshift());
2018-12-17 14:45:06 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<int?> MaxParticipants { get; private set; } = new Bindable<int?>();
2018-12-17 14:45:06 +09:00
[JsonIgnore]
2018-12-21 13:06:11 +09:00
public Bindable<IEnumerable<User>> Participants { get; private set; } = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
2018-12-17 14:45:06 +09:00
2018-12-26 21:58:14 +09:00
public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>();
// todo: TEMPORARY
[JsonProperty("participant_count")]
private int? participantCount
{
get => ParticipantCount;
set => ParticipantCount.Value = value ?? 0;
}
2018-12-17 14:44:54 +09:00
[JsonProperty("duration")]
private int duration
{
get => (int)Duration.Value.TotalMinutes;
set => Duration.Value = TimeSpan.FromMinutes(value);
}
2018-12-17 14:45:06 +09:00
// Only supports retrieval for now
[JsonProperty("ends_at")]
2018-12-21 13:06:11 +09:00
public Bindable<DateTimeOffset> EndDate { get; private set; } = new Bindable<DateTimeOffset>();
2018-12-13 16:06:30 +09:00
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
private int? maxAttempts
{
get => MaxAttempts;
set => MaxAttempts.Value = value;
}
2018-12-12 19:04:11 +09:00
public void CopyFrom(Room other)
{
2018-12-12 16:20:11 +09:00
RoomID.Value = other.RoomID;
Name.Value = other.Name;
2018-12-25 18:07:50 +09:00
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
Host.Value = other.Host;
Status.Value = other.Status;
Availability.Value = other.Availability;
Type.Value = other.Type;
MaxParticipants.Value = other.MaxParticipants;
2018-12-26 21:58:14 +09:00
ParticipantCount.Value = other.ParticipantCount.Value;
Participants.Value = other.Participants.Value.ToArray();
2018-12-19 13:07:56 +09:00
EndDate.Value = other.EndDate;
2018-12-27 13:30:36 +09:00
if (DateTimeOffset.Now >= EndDate.Value)
Status.Value = new RoomStatusEnded();
2018-12-25 18:07:50 +09:00
// Todo: Temporary, should only remove/add new items (requires framework changes)
if (Playlist.Count == 0)
Playlist.AddRange(other.Playlist);
2018-12-26 22:14:49 +09:00
else if (other.Playlist.Count > 0)
Playlist.First().ID = other.Playlist.First().ID;
}
2018-12-17 14:45:06 +09:00
public bool ShouldSerializeRoomID() => false;
public bool ShouldSerializeHost() => false;
public bool ShouldSerializeEndDate() => false;
}
2018-04-13 18:19:50 +09:00
}