New actor assignment ui experiments

This commit is contained in:
RisaDev
2024-10-05 22:17:47 +03:00
parent 9cb105bf36
commit a7da74bb80
7 changed files with 335 additions and 122 deletions

View File

@@ -21,13 +21,19 @@ namespace CustomizePlus.Profiles.Data;
/// </summary>
public sealed class Profile : ISavable
{
public const int Version = 4;
private static int _nextGlobalId;
private readonly int _localId;
public List<Armature> Armatures = new();
[Obsolete("To be removed")]
public LowerString CharacterName { get; set; } = LowerString.Empty;
public ActorIdentifier Character { get; set; } = ActorIdentifier.Invalid;
public LowerString Name { get; set; } = LowerString.Empty;
/// <summary>
@@ -35,8 +41,6 @@ public sealed class Profile : ISavable
/// </summary>
public bool LimitLookupToOwnedObjects { get; set; } = false;
public int Version { get; set; } = Constants.ConfigurationVersion;
public bool Enabled { get; set; }
public DateTimeOffset CreationDate { get; set; } = DateTime.UtcNow;
public DateTimeOffset ModifiedDate { get; set; } = DateTime.UtcNow;
@@ -99,6 +103,7 @@ public sealed class Profile : ISavable
["CreationDate"] = CreationDate,
["ModifiedDate"] = ModifiedDate,
["CharacterName"] = CharacterName.Text,
//["Character"] = Character.ToJson(),
["Name"] = Name.Text,
["LimitLookupToOwnedObjects"] = LimitLookupToOwnedObjects,
["Enabled"] = Enabled,
@@ -124,62 +129,7 @@ public sealed class Profile : ISavable
#endregion
#region Deserialization
public static Profile Load(TemplateManager templateManager, JObject obj)
{
var version = obj["Version"]?.ToObject<int>() ?? 0;
return version switch
{
//Ignore everything below v4 for now
4 => LoadV4(templateManager, obj),
_ => throw new Exception("The design to be loaded has no valid Version."),
};
}
private static Profile LoadV4(TemplateManager templateManager, JObject obj)
{
var creationDate = obj["CreationDate"]?.ToObject<DateTimeOffset>() ?? throw new ArgumentNullException("CreationDate");
var profile = new Profile()
{
CreationDate = creationDate,
UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"),
Name = new LowerString(obj["Name"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("Name")),
CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")),
LimitLookupToOwnedObjects = obj["LimitLookupToOwnedObjects"]?.ToObject<bool>() ?? throw new ArgumentNullException("LimitLookupToOwnedObjects"),
Enabled = obj["Enabled"]?.ToObject<bool>() ?? throw new ArgumentNullException("Enabled"),
ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate,
IsWriteProtected = obj["IsWriteProtected"]?.ToObject<bool>() ?? false,
Templates = new List<Template>()
};
if (profile.ModifiedDate < creationDate)
profile.ModifiedDate = creationDate;
if (obj["Templates"] is not JArray templateArray)
return profile;
foreach (var templateObj in templateArray)
{
if (templateObj is not JObject templateObjCast)
{
//todo: warning
continue;
}
var templateId = templateObjCast["TemplateId"]?.ToObject<Guid>();
if (templateId == null)
continue; //todo: error
var template = templateManager.GetTemplate((Guid)templateId);
if (template != null)
profile.Templates.Add(template);
}
return profile;
}
#endregion
//Loading is in ProfileManager
#region ISavable