// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using osu.Framework.Extensions.ObjectExtensions; using osu.Game.Database; using osu.Game.Online.API; using Realms; namespace osu.Game.Rulesets.Mods { /// /// A mod preset is a named collection of configured mods. /// Presets are presented to the user in the mod select overlay for convenience. /// public class ModPreset : RealmObject, IHasGuidPrimaryKey, ISoftDelete { /// /// The internal database ID of the preset. /// [PrimaryKey] public Guid ID { get; set; } = Guid.NewGuid(); /// /// The ruleset that the preset is valid for. /// public RulesetInfo Ruleset { get; set; } = null!; /// /// The name of the mod preset. /// public string Name { get; set; } = string.Empty; /// /// The description of the mod preset. /// public string Description { get; set; } = string.Empty; /// /// The set of configured mods that are part of the preset. /// [Ignored] public ICollection Mods { get { if (string.IsNullOrEmpty(ModsJson)) return Array.Empty(); var apiMods = JsonConvert.DeserializeObject>(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); } } /// /// The set of configured mods that are part of the preset, serialised as a JSON blob. /// [MapTo("Mods")] public string ModsJson { get; set; } = string.Empty; /// /// Whether the preset has been soft-deleted by the user. /// public bool DeletePending { get; set; } } }