major refactoring, maybe some bugfixes, idk
This commit is contained in:
43
MareSynchronos/Models/CachedPlayer.cs
Normal file
43
MareSynchronos/Models/CachedPlayer.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using MareSynchronos.API;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public class CachedPlayer
|
||||
{
|
||||
private bool _isVisible = false;
|
||||
|
||||
public CachedPlayer(string nameHash)
|
||||
{
|
||||
PlayerNameHash = nameHash;
|
||||
}
|
||||
|
||||
public Dictionary<int, CharacterCacheDto> CharacterCache { get; set; } = new();
|
||||
public bool IsVisible
|
||||
{
|
||||
get => _isVisible;
|
||||
set
|
||||
{
|
||||
WasVisible = _isVisible;
|
||||
_isVisible = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int? JobId { get; set; }
|
||||
public PlayerCharacter? PlayerCharacter { get; set; }
|
||||
public string? PlayerName { get; set; }
|
||||
public string PlayerNameHash { get; }
|
||||
public bool WasVisible { get; private set; }
|
||||
public void Reset()
|
||||
{
|
||||
PlayerName = string.Empty;
|
||||
JobId = null;
|
||||
PlayerCharacter = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return PlayerNameHash + " : " + PlayerName + " : HasChar " + (PlayerCharacter != null);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,16 @@
|
||||
using Dalamud.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CharacterCache
|
||||
public class CharacterData
|
||||
{
|
||||
public CharacterCacheDto ToCharacterCacheDto()
|
||||
{
|
||||
return new CharacterCacheDto()
|
||||
{
|
||||
FileReplacements = AllReplacements.Select(f => f.ToFileReplacementDto()).ToList(),
|
||||
GlamourerData = GlamourerString,
|
||||
Hash = CacheHash,
|
||||
JobId = (int)JobId,
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public List<FileReplacement> AllReplacements =>
|
||||
FileReplacements.Where(f => f.HasFileReplacement)
|
||||
@@ -32,6 +19,9 @@ namespace MareSynchronos.Models
|
||||
.Distinct().OrderBy(f => f.GamePaths[0])
|
||||
.ToList();
|
||||
|
||||
[JsonProperty]
|
||||
public string CacheHash { get; set; } = string.Empty;
|
||||
|
||||
public List<FileReplacement> FileReplacements { get; set; } = new List<FileReplacement>();
|
||||
|
||||
[JsonProperty]
|
||||
@@ -40,12 +30,10 @@ namespace MareSynchronos.Models
|
||||
public bool IsReady => FileReplacements.All(f => f.Computed);
|
||||
|
||||
[JsonProperty]
|
||||
public string CacheHash { get; set; } = string.Empty;
|
||||
public uint JobId { get; set; } = 0;
|
||||
|
||||
public string ManipulationString { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public uint JobId { get; set; } = 0;
|
||||
public void AddAssociatedResource(FileReplacement resource, FileReplacement? mdlParent, FileReplacement? mtrlParent)
|
||||
{
|
||||
try
|
||||
@@ -71,7 +59,7 @@ namespace MareSynchronos.Models
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Debug(ex.Message);
|
||||
Logger.Debug(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,10 +80,21 @@ namespace MareSynchronos.Models
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Debug(ex.Message);
|
||||
Logger.Debug(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public CharacterCacheDto ToCharacterCacheDto()
|
||||
{
|
||||
return new CharacterCacheDto()
|
||||
{
|
||||
FileReplacements = AllReplacements.Select(f => f.ToFileReplacementDto()).ToList(),
|
||||
GlamourerData = GlamourerString,
|
||||
Hash = CacheHash,
|
||||
JobId = (int)JobId,
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
@@ -15,36 +15,35 @@ namespace MareSynchronos.Models
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class FileReplacement
|
||||
{
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
{
|
||||
return new FileReplacementDto
|
||||
{
|
||||
GamePaths = GamePaths,
|
||||
Hash = Hash,
|
||||
};
|
||||
}
|
||||
|
||||
private readonly string penumbraDirectory;
|
||||
|
||||
[JsonProperty]
|
||||
public string[] GamePaths { get; set; } = Array.Empty<string>();
|
||||
[JsonProperty]
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
[JsonProperty]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
public bool IsInUse { get; set; } = false;
|
||||
public List<FileReplacement> Associated { get; set; } = new List<FileReplacement>();
|
||||
[JsonProperty]
|
||||
public string ImcData { get; set; } = string.Empty;
|
||||
public bool HasFileReplacement => GamePaths.Length >= 1 && GamePaths[0] != ResolvedPath;
|
||||
|
||||
public bool Computed => (computationTask == null || (computationTask?.IsCompleted ?? true)) && Associated.All(f => f.Computed);
|
||||
private Task? computationTask = null;
|
||||
|
||||
public FileReplacement(string penumbraDirectory)
|
||||
{
|
||||
this.penumbraDirectory = penumbraDirectory;
|
||||
}
|
||||
|
||||
public List<FileReplacement> Associated { get; set; } = new List<FileReplacement>();
|
||||
|
||||
public bool Computed => (computationTask == null || (computationTask?.IsCompleted ?? true)) && Associated.All(f => f.Computed);
|
||||
|
||||
[JsonProperty]
|
||||
public string[] GamePaths { get; set; } = Array.Empty<string>();
|
||||
|
||||
public bool HasFileReplacement => GamePaths.Length >= 1 && GamePaths[0] != ResolvedPath;
|
||||
|
||||
[JsonProperty]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string ImcData { get; set; } = string.Empty;
|
||||
|
||||
public bool IsInUse { get; set; } = false;
|
||||
|
||||
[JsonProperty]
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
|
||||
public void AddAssociated(FileReplacement fileReplacement)
|
||||
{
|
||||
fileReplacement.IsInUse = true;
|
||||
@@ -52,6 +51,27 @@ namespace MareSynchronos.Models
|
||||
Associated.Add(fileReplacement);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj == null) return true;
|
||||
if (obj.GetType() == typeof(FileReplacement))
|
||||
{
|
||||
return Hash == ((FileReplacement)obj).Hash;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int result = 13;
|
||||
result *= 397;
|
||||
result += Hash.GetHashCode();
|
||||
result += ResolvedPath.GetHashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetResolvedPath(string path)
|
||||
{
|
||||
ResolvedPath = path.ToLower().Replace('/', '\\').Replace(penumbraDirectory, "").Replace('\\', '/');
|
||||
@@ -89,6 +109,29 @@ namespace MareSynchronos.Models
|
||||
});
|
||||
}
|
||||
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
{
|
||||
return new FileReplacementDto
|
||||
{
|
||||
GamePaths = GamePaths,
|
||||
Hash = Hash,
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {string.Join(",", GamePaths)} => {ResolvedPath}");
|
||||
foreach (var l1 in Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l1.HasFileReplacement} - {string.Join(",", l1.GamePaths)} => {l1.ResolvedPath}");
|
||||
foreach (var l2 in l1.Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l2.HasFileReplacement} - {string.Join(",", l2.GamePaths)} => {l2.ResolvedPath}");
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private string ComputeHash(FileInfo fi)
|
||||
{
|
||||
// compute hash if hash is not present
|
||||
@@ -115,41 +158,5 @@ namespace MareSynchronos.Models
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {string.Join(",", GamePaths)} => {ResolvedPath}");
|
||||
foreach (var l1 in Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l1.HasFileReplacement} - {string.Join(",", l1.GamePaths)} => {l1.ResolvedPath}");
|
||||
foreach (var l2 in l1.Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l2.HasFileReplacement} - {string.Join(",", l2.GamePaths)} => {l2.ResolvedPath}");
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj == null) return true;
|
||||
if (obj.GetType() == typeof(FileReplacement))
|
||||
{
|
||||
return Hash == ((FileReplacement)obj).Hash;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int result = 13;
|
||||
result *= 397;
|
||||
result += Hash.GetHashCode();
|
||||
result += ResolvedPath.GetHashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user