This commit is contained in:
rootdarkarchon
2023-10-14 12:13:43 +02:00
parent a46c63c12a
commit a9a57e0a31
6 changed files with 51 additions and 22 deletions

View File

@@ -13,14 +13,15 @@ public class CharacterData
public string HeelsData { get; set; } = string.Empty;
public string HonorificData { get; set; } = string.Empty;
public bool IsReady => FileReplacements.SelectMany(k => k.Value).All(f => f.Computed);
public string ManipulationString { get; set; } = string.Empty;
public string PalettePlusPalette { get; set; } = string.Empty;
public API.Data.CharacterData ToAPI()
{
var fileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap).GroupBy(f => f.Hash, StringComparer.OrdinalIgnoreCase).Select(g =>
Dictionary<ObjectKind, List<FileReplacementData>> fileReplacements =
FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap)
.GroupBy(f => f.Hash, StringComparer.OrdinalIgnoreCase)
.Select(g =>
{
return new FileReplacementData()
{

View File

@@ -1,27 +1,21 @@
using System.Text.RegularExpressions;
using MareSynchronos.FileCache;
using MareSynchronos.API.Data;
namespace MareSynchronos.PlayerData.Data;
public partial class FileReplacement
{
private readonly Lazy<string> _hashLazy;
public FileReplacement(string[] gamePaths, string filePath, FileCacheManager fileDbManager)
public FileReplacement(string[] gamePaths, string filePath)
{
GamePaths = gamePaths.Select(g => g.Replace('\\', '/').ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
ResolvedPath = filePath.Replace('\\', '/');
_hashLazy = new(() => !IsFileSwap ? fileDbManager.GetFileCacheByPath(ResolvedPath)?.Hash ?? string.Empty : string.Empty);
}
public bool Computed => IsFileSwap || !HasFileReplacement || !string.IsNullOrEmpty(Hash);
public HashSet<string> GamePaths { get; init; }
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => !string.Equals(p, ResolvedPath, StringComparison.Ordinal));
public string Hash => _hashLazy.Value;
public string Hash { get; set; } = string.Empty;
public bool IsFileSwap => !LocalPathRegex().IsMatch(ResolvedPath) && GamePaths.All(p => !LocalPathRegex().IsMatch(p));
public string ResolvedPath { get; init; }