1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00
osu-lazer/osu.Game/Rulesets/Mods/Mod.cs

132 lines
4.3 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 17:19:50 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
2018-11-28 12:12:29 +08:00
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
2018-11-28 12:12:29 +08:00
using osu.Game.IO.Serialization;
2020-03-19 11:43:26 +08:00
using osu.Game.Rulesets.UI;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mods
{
/// <summary>
/// The base class for gameplay modifiers.
/// </summary>
public abstract class Mod : IMod, IJsonSerializable
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// The name of this mod.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2018-04-13 17:19:50 +08:00
public abstract string Name { get; }
/// <summary>
/// The shortened name of this mod.
/// </summary>
public abstract string Acronym { get; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// The icon of this mod.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2020-01-14 21:22:00 +08:00
public virtual IconUsage? Icon => null;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The type of this mod.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
public virtual ModType Type => ModType.Fun;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The user readable description of this mod.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2018-04-13 17:19:50 +08:00
public virtual string Description => string.Empty;
2020-03-19 11:43:26 +08:00
/// <summary>
/// The tooltip to display for this mod when used in a <see cref="ModIcon"/>.
/// </summary>
/// <remarks>
/// Differs from <see cref="Name"/>, as the value of attributes (AR, CS, etc) changeable via the mod
/// are displayed in the tooltip.
/// </remarks>
[JsonIgnore]
public string IconTooltip
{
get
{
2020-03-23 10:06:54 +08:00
string settingDescription = string.IsNullOrEmpty(SettingDescription) ? string.Empty : $" ({SettingDescription})";
return $"{Name}{settingDescription}";
}
}
/// <summary>
/// The description of editable settings of a mod to use in the <see cref="IconTooltip"/>.
/// </summary>
/// <remarks>
/// Parentheses are added to the tooltip, surrounding the value of this property. If this property is <c>string.Empty</c>,
/// the tooltip will not have parentheses.
/// </remarks>
public virtual string SettingDescription
{
get
{
var tooltipTexts = new List<string>();
foreach ((SettingSourceAttribute attr, PropertyInfo property) in this.GetOrderedSettingsSourceProperties())
{
object bindableObj = property.GetValue(this);
bool? settingIsDefault = (bindableObj as IHasDefaultValue)?.IsDefault;
2020-03-23 10:51:29 +08:00
string tooltipText = settingIsDefault == true ? string.Empty : attr.Label + " " + bindableObj;
tooltipTexts.Add(tooltipText);
}
string joinedTooltipText = string.Join(", ", tooltipTexts.Where(s => !string.IsNullOrEmpty(s)));
return $"{joinedTooltipText}";
}
}
2020-03-19 11:43:26 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The score multiplier of this mod.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2018-04-13 17:19:50 +08:00
public abstract double ScoreMultiplier { get; }
/// <summary>
/// Returns true if this mod is implemented (and playable).
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2018-04-13 17:19:50 +08:00
public virtual bool HasImplementation => this is IApplicableMod;
/// <summary>
/// Returns if this mod is ranked.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2018-04-13 17:19:50 +08:00
public virtual bool Ranked => false;
/// <summary>
/// Whether this mod requires configuration to apply changes to the game.
/// </summary>
[JsonIgnore]
public virtual bool RequiresConfiguration => false;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The mods this mod cannot be enabled with.
/// </summary>
2018-11-28 12:12:29 +08:00
[JsonIgnore]
2019-11-28 21:41:29 +08:00
public virtual Type[] IncompatibleMods => Array.Empty<Type>();
/// <summary>
/// Creates a copy of this <see cref="Mod"/> initialised to a default state.
/// </summary>
public virtual Mod CreateCopy() => (Mod)MemberwiseClone();
public bool Equals(IMod other) => GetType() == other?.GetType();
2018-04-13 17:19:50 +08:00
}
}