mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 19:42:55 +08:00
Use realm support for Guid
This commit is contained in:
parent
15db0e97d7
commit
68f2e7f61a
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
@ -11,16 +10,7 @@ namespace osu.Game.Database
|
|||||||
public interface IHasGuidPrimaryKey
|
public interface IHasGuidPrimaryKey
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[Ignored]
|
|
||||||
public Guid Guid
|
|
||||||
{
|
|
||||||
get => new Guid(ID);
|
|
||||||
set => ID = value.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
string ID { get; set; }
|
public Guid ID { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Statistics;
|
using osu.Framework.Statistics;
|
||||||
|
using osu.Game.Input.Bindings;
|
||||||
using Realms;
|
using Realms;
|
||||||
|
using Realms.Schema;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -17,7 +19,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private const string database_name = @"client";
|
private const string database_name = @"client";
|
||||||
|
|
||||||
private const int schema_version = 5;
|
private const int schema_version = 6;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock object which is held for the duration of a write operation (via <see cref="GetForWrite"/>).
|
/// Lock object which is held for the duration of a write operation (via <see cref="GetForWrite"/>).
|
||||||
@ -93,6 +95,13 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
||||||
{
|
{
|
||||||
|
switch (lastSchemaVersion)
|
||||||
|
{
|
||||||
|
case 5:
|
||||||
|
// let's keep things simple. changing the type of the primary key is a bit involved.
|
||||||
|
migration.NewRealm.RemoveAll<RealmKeyBinding>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using Realms;
|
using Realms;
|
||||||
@ -11,7 +12,7 @@ namespace osu.Game.Input.Bindings
|
|||||||
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
||||||
{
|
{
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public string ID { get; set; }
|
public Guid ID { get; set; }
|
||||||
|
|
||||||
public int? RulesetID { get; set; }
|
public int? RulesetID { get; set; }
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace osu.Game.Input
|
|||||||
// insert any defaults which are missing.
|
// insert any defaults which are missing.
|
||||||
usage.Realm.Add(new RealmKeyBinding
|
usage.Realm.Add(new RealmKeyBinding
|
||||||
{
|
{
|
||||||
ID = Guid.NewGuid().ToString(),
|
ID = Guid.NewGuid(),
|
||||||
KeyCombinationString = k.KeyCombination.ToString(),
|
KeyCombinationString = k.KeyCombination.ToString(),
|
||||||
ActionInt = (int)k.Action,
|
ActionInt = (int)k.Action,
|
||||||
RulesetID = rulesetId,
|
RulesetID = rulesetId,
|
||||||
|
@ -341,7 +341,7 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
usage.Realm.Add(new RealmKeyBinding
|
usage.Realm.Add(new RealmKeyBinding
|
||||||
{
|
{
|
||||||
ID = Guid.NewGuid().ToString(),
|
ID = Guid.NewGuid(),
|
||||||
KeyCombinationString = dkb.KeyCombination.ToString(),
|
KeyCombinationString = dkb.KeyCombination.ToString(),
|
||||||
ActionInt = (int)dkb.Action,
|
ActionInt = (int)dkb.Action,
|
||||||
RulesetID = dkb.RulesetID,
|
RulesetID = dkb.RulesetID,
|
||||||
|
Loading…
Reference in New Issue
Block a user