1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:09:34 +08:00
osu-lazer/osu.Game/Rulesets/Mods/ModPreset.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.4 KiB
C#
Raw Normal View History

2022-07-22 02:56:43 +08:00
// 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.
using System;
using System.Collections.Generic;
2022-07-23 23:25:11 +08:00
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Game.Database;
using osu.Game.Online.API;
using Realms;
2022-07-22 02:56:43 +08:00
namespace osu.Game.Rulesets.Mods
{
/// <summary>
/// A mod preset is a named collection of configured mods.
/// Presets are presented to the user in the mod select overlay for convenience.
/// </summary>
2022-07-23 23:25:11 +08:00
public class ModPreset : RealmObject, IHasGuidPrimaryKey, ISoftDelete
2022-07-22 02:56:43 +08:00
{
2022-07-23 23:25:11 +08:00
/// <summary>
/// The internal database ID of the preset.
/// </summary>
[PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid();
2022-07-22 02:56:43 +08:00
/// <summary>
/// The ruleset that the preset is valid for.
/// </summary>
2022-07-23 23:25:11 +08:00
public RulesetInfo Ruleset { get; set; } = null!;
2022-07-22 02:56:43 +08:00
/// <summary>
/// The name of the mod preset.
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// The description of the mod preset.
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// The set of configured mods that are part of the preset.
/// </summary>
2022-07-23 23:25:11 +08:00
[Ignored]
public ICollection<Mod> Mods
{
get
{
if (string.IsNullOrEmpty(ModsJson))
return Array.Empty<Mod>();
var apiMods = JsonConvert.DeserializeObject<IEnumerable<APIMod>>(ModsJson);
var ruleset = Ruleset.CreateInstance();
return apiMods.AsNonNull().Select(mod => mod.ToMod(ruleset)).ToArray();
}
set
{
var apiMods = value.Select(mod => new APIMod(mod)).ToArray();
ModsJson = JsonConvert.SerializeObject(apiMods);
}
}
/// <summary>
/// The set of configured mods that are part of the preset, serialised as a JSON blob.
/// </summary>
[MapTo("Mods")]
public string ModsJson { get; set; } = string.Empty;
/// <summary>
/// Whether the preset has been soft-deleted by the user.
/// </summary>
public bool DeletePending { get; set; }
2022-07-22 02:56:43 +08:00
}
}