osu/osu.Game/Users/User.cs

295 lines
7.6 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using JetBrains.Annotations;
2018-04-13 09:19:50 +00:00
using Newtonsoft.Json;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
using osu.Game.Online.API.Requests;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Users
{
2020-02-27 10:21:59 +00:00
public class User : IEquatable<User>
2018-04-13 09:19:50 +00:00
{
[JsonProperty(@"id")]
public int Id = 1;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"join_date")]
public DateTimeOffset JoinDate;
[JsonProperty(@"username")]
public string Username;
[JsonProperty(@"previous_usernames")]
public string[] PreviousUsernames;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"country")]
public Country Country;
2019-12-18 05:07:12 +00:00
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
2018-04-13 09:19:50 +00:00
2019-12-18 05:07:12 +00:00
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();
2018-04-13 09:19:50 +00:00
//public Team Team;
[JsonProperty(@"profile_colour")]
public string Colour;
[JsonProperty(@"avatar_url")]
public string AvatarUrl;
[JsonProperty(@"cover_url")]
public string CoverUrl
{
get => Cover?.Url;
set => Cover = new UserCover { Url = value };
2018-04-13 09:19:50 +00:00
}
[JsonProperty(@"cover")]
public UserCover Cover;
public class UserCover
{
[JsonProperty(@"custom_url")]
public string CustomUrl;
[JsonProperty(@"url")]
public string Url;
[JsonProperty(@"id")]
public int? Id;
}
[JsonProperty(@"is_admin")]
public bool IsAdmin;
[JsonProperty(@"is_supporter")]
public bool IsSupporter;
2018-12-22 15:51:24 +00:00
[JsonProperty(@"support_level")]
public int SupportLevel;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"is_gmt")]
public bool IsGMT;
[JsonProperty(@"is_qat")]
public bool IsQAT;
[JsonProperty(@"is_bng")]
public bool IsBNG;
[JsonProperty(@"is_bot")]
public bool IsBot;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"is_active")]
public bool Active;
2019-06-18 16:13:21 +00:00
[JsonProperty(@"is_online")]
public bool IsOnline;
2018-12-22 15:51:24 +00:00
[JsonProperty(@"pm_friends_only")]
public bool PMFriendsOnly;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"interests")]
public string Interests;
[JsonProperty(@"occupation")]
public string Occupation;
[JsonProperty(@"title")]
public string Title;
[JsonProperty(@"location")]
public string Location;
2018-08-26 03:31:33 +00:00
[JsonProperty(@"last_visit")]
public DateTimeOffset? LastVisit;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"twitter")]
public string Twitter;
[JsonProperty(@"discord")]
public string Discord;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"website")]
public string Website;
[JsonProperty(@"post_count")]
public int PostCount;
[JsonProperty(@"comments_count")]
public int CommentsCount;
2018-12-22 15:51:24 +00:00
[JsonProperty(@"follower_count")]
2019-07-18 05:05:57 +00:00
public int FollowerCount;
2018-12-22 15:51:24 +00:00
2021-01-21 19:02:19 +00:00
[JsonProperty(@"mapping_follower_count")]
public int MappingFollowerCount;
2019-12-17 09:36:44 +00:00
[JsonProperty(@"favourite_beatmapset_count")]
public int FavouriteBeatmapsetCount;
[JsonProperty(@"graveyard_beatmapset_count")]
public int GraveyardBeatmapsetCount;
[JsonProperty(@"loved_beatmapset_count")]
public int LovedBeatmapsetCount;
[JsonProperty(@"ranked_beatmapset_count")]
public int RankedBeatmapsetCount;
2019-12-17 09:36:44 +00:00
[JsonProperty(@"pending_beatmapset_count")]
public int PendingBeatmapsetCount;
2019-12-17 09:36:44 +00:00
2021-04-24 16:27:32 +00:00
[JsonProperty(@"scores_best_count")]
public int ScoresBestCount;
2019-12-17 09:36:44 +00:00
[JsonProperty(@"scores_first_count")]
public int ScoresFirstCount;
2021-04-24 16:26:43 +00:00
[JsonProperty(@"scores_recent_count")]
public int ScoresRecentCount;
[JsonProperty(@"beatmap_playcounts_count")]
public int BeatmapPlaycountsCount;
[JsonProperty]
private string[] playstyle
{
set => PlayStyles = value?.Select(str => Enum.Parse(typeof(PlayStyle), str, true)).Cast<PlayStyle>().ToArray();
}
public PlayStyle[] PlayStyles;
2018-04-13 09:19:50 +00:00
[JsonProperty(@"playmode")]
public string PlayMode;
[JsonProperty(@"profile_order")]
public string[] ProfileOrder;
[JsonProperty(@"kudosu")]
public KudosuCount Kudosu;
public class KudosuCount
{
[JsonProperty(@"total")]
public int Total;
[JsonProperty(@"available")]
public int Available;
}
private UserStatistics statistics;
/// <summary>
/// User statistics for the requested ruleset (in the case of a <see cref="GetUserRequest"/> or <see cref="GetFriendsRequest"/> response).
2021-02-09 05:55:50 +00:00
/// Otherwise empty.
/// </summary>
2018-04-13 09:19:50 +00:00
[JsonProperty(@"statistics")]
public UserStatistics Statistics
{
get => statistics ??= new UserStatistics();
set
{
if (statistics != null)
// we may already have rank history populated
value.RankHistory = statistics.RankHistory;
statistics = value;
}
}
[JsonProperty(@"rank_history")]
private RankHistoryData rankHistory
{
set => statistics.RankHistory = value;
}
2018-04-13 09:19:50 +00:00
public class RankHistoryData
{
[JsonProperty(@"mode")]
public string Mode;
[JsonProperty(@"data")]
public int[] Data;
}
2018-04-15 21:44:59 +00:00
[JsonProperty("badges")]
public Badge[] Badges;
2018-12-22 15:51:24 +00:00
[JsonProperty("user_achievements")]
public UserAchievement[] Achievements;
public class UserAchievement
{
[JsonProperty("achieved_at")]
public DateTimeOffset AchievedAt;
[JsonProperty("achievement_id")]
public int ID;
}
2020-02-07 13:21:47 +00:00
[JsonProperty("monthly_playcounts")]
public UserHistoryCount[] MonthlyPlaycounts;
[JsonProperty("replays_watched_counts")]
public UserHistoryCount[] ReplaysWatchedCounts;
/// <summary>
/// All user statistics per ruleset's short name (in the case of a <see cref="GetUsersRequest"/> response).
/// Otherwise empty. Can be altered for testing purposes.
/// </summary>
// todo: this should likely be moved to a separate UserCompact class at some point.
[JsonProperty("statistics_rulesets")]
[CanBeNull]
public Dictionary<string, UserStatistics> RulesetsStatistics { get; set; }
2020-02-07 13:21:47 +00:00
2018-04-13 09:19:50 +00:00
public override string ToString() => Username;
/// <summary>
/// A user instance for displaying locally created system messages.
/// </summary>
2018-09-13 05:03:21 +00:00
public static readonly User SYSTEM_USER = new User
{
Username = "system",
Colour = @"9c0101",
Id = 0
};
public bool Equals(User other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id == other.Id;
}
public enum PlayStyle
{
[Description("Keyboard")]
Keyboard,
2019-03-06 07:30:56 +00:00
[Description("Mouse")]
Mouse,
2019-03-06 07:30:56 +00:00
[Description("Tablet")]
Tablet,
2019-03-06 07:30:56 +00:00
[Description("Touch Screen")]
Touch,
}
2020-02-27 10:21:59 +00:00
public class UserHistoryCount
2020-02-27 10:21:59 +00:00
{
[JsonProperty("start_date")]
public DateTime Date;
2020-02-27 10:21:59 +00:00
[JsonProperty("count")]
public long Count;
2020-02-27 10:21:59 +00:00
}
2018-04-13 09:19:50 +00:00
}
}