some fixes for models sharing materials and code cleanup
This commit is contained in:
@@ -146,7 +146,6 @@ public class CachedPlayer
|
||||
Logger.Debug(
|
||||
$"Request Redraw for {PlayerName}");
|
||||
_ipcManager.PenumbraSetTemporaryMods(tempCollection, moddedPaths, cache.ManipulationData);
|
||||
_ipcManager.GlamourerRevertCharacterCustomization(PlayerName!);
|
||||
_ipcManager.GlamourerApplyAll(cache.GlamourerData, PlayerName!);
|
||||
}
|
||||
|
||||
@@ -164,7 +163,6 @@ public class CachedPlayer
|
||||
_ipcManager.PenumbraRemoveTemporaryCollection(PlayerName);
|
||||
if (IsVisible)
|
||||
{
|
||||
_ipcManager.GlamourerRevertCharacterCustomization(PlayerName);
|
||||
_ipcManager.GlamourerApplyOnlyCustomization(_originalGlamourerData, PlayerName);
|
||||
_ipcManager.GlamourerApplyOnlyEquipment(_lastGlamourerData, PlayerName);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -12,12 +10,7 @@ namespace MareSynchronos.Models
|
||||
public class CharacterData
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<FileReplacement> AllReplacements =>
|
||||
FileReplacements.Where(f => f.HasFileReplacement)
|
||||
.Concat(FileReplacements.SelectMany(f => f.Associated)).Where(f => f.HasFileReplacement)
|
||||
.Concat(FileReplacements.SelectMany(f => f.Associated).SelectMany(f => f.Associated)).Where(f => f.HasFileReplacement)
|
||||
.Distinct().OrderBy(f => f.GamePaths[0])
|
||||
.ToList();
|
||||
public List<FileReplacement> AllReplacements => FileReplacements.Where(f => f.HasFileReplacement).GroupBy(f => f.Hash).Select(g => g.First()).ToList();
|
||||
|
||||
[JsonProperty]
|
||||
public string CacheHash { get; set; } = string.Empty;
|
||||
@@ -34,53 +27,18 @@ namespace MareSynchronos.Models
|
||||
|
||||
public string ManipulationString { get; set; } = string.Empty;
|
||||
|
||||
public void AddAssociatedResource(FileReplacement resource, FileReplacement? mdlParent, FileReplacement? mtrlParent)
|
||||
public void AddFileReplacement(FileReplacement fileReplacement)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mdlParent == null)
|
||||
{
|
||||
resource.IsInUse = true;
|
||||
FileReplacements.Add(resource);
|
||||
return;
|
||||
}
|
||||
if (!fileReplacement.HasFileReplacement) return;
|
||||
|
||||
var mdlReplacements = FileReplacements.Where(f => f == mdlParent && mtrlParent == null);
|
||||
foreach (var mdlReplacement in mdlReplacements)
|
||||
{
|
||||
mdlReplacement.AddAssociated(resource);
|
||||
}
|
||||
|
||||
var mtrlReplacements = FileReplacements.Where(f => f == mdlParent).SelectMany(a => a.Associated).Where(f => f == mtrlParent);
|
||||
foreach (var mtrlReplacement in mtrlReplacements)
|
||||
{
|
||||
mtrlReplacement.AddAssociated(resource);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
var existingReplacement = FileReplacements.SingleOrDefault(f => f.ResolvedPath == fileReplacement.ResolvedPath);
|
||||
if (existingReplacement != null)
|
||||
{
|
||||
Logger.Debug(ex.Message);
|
||||
existingReplacement.GamePaths.AddRange(fileReplacement.GamePaths.Where(e => !existingReplacement.GamePaths.Contains(e)));
|
||||
}
|
||||
}
|
||||
|
||||
public void Invalidate(List<FileReplacement>? fileReplacements = null)
|
||||
{
|
||||
try
|
||||
else
|
||||
{
|
||||
var fileReplacement = fileReplacements ?? FileReplacements.ToList();
|
||||
foreach (var item in fileReplacement)
|
||||
{
|
||||
item.IsInUse = false;
|
||||
Invalidate(item.Associated);
|
||||
if (FileReplacements.Contains(item))
|
||||
{
|
||||
FileReplacements.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Debug(ex.Message);
|
||||
FileReplacements.Add(fileReplacement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +53,7 @@ namespace MareSynchronos.Models
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
|
||||
@@ -24,14 +24,12 @@ namespace MareSynchronos.Models
|
||||
this._penumbraDirectory = penumbraDirectory;
|
||||
}
|
||||
|
||||
public List<FileReplacement> Associated { get; set; } = new();
|
||||
|
||||
public bool Computed => (_computationTask == null || (_computationTask?.IsCompleted ?? true)) && Associated.All(f => f.Computed);
|
||||
public bool Computed => (_computationTask == null || (_computationTask?.IsCompleted ?? true));
|
||||
|
||||
[JsonProperty]
|
||||
public string[] GamePaths { get; set; } = Array.Empty<string>();
|
||||
public List<string> GamePaths { get; set; } = new();
|
||||
|
||||
public bool HasFileReplacement => GamePaths.Length >= 1 && GamePaths[0] != ResolvedPath;
|
||||
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => p != ResolvedPath);
|
||||
|
||||
[JsonProperty]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
@@ -43,35 +41,7 @@ namespace MareSynchronos.Models
|
||||
|
||||
[JsonProperty]
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
|
||||
public void AddAssociated(FileReplacement fileReplacement)
|
||||
{
|
||||
fileReplacement.IsInUse = true;
|
||||
|
||||
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('\\', '/');
|
||||
@@ -113,7 +83,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
return new FileReplacementDto
|
||||
{
|
||||
GamePaths = GamePaths,
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
};
|
||||
}
|
||||
@@ -121,14 +91,6 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user