mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-14 12:44:19 +01:00
Add some refactoring of data, Stains and STM files.
This commit is contained in:
parent
7e167cf0cf
commit
8d11e1075d
11 changed files with 580 additions and 227 deletions
56
Penumbra.GameData/Data/DataSharer.cs
Normal file
56
Penumbra.GameData/Data/DataSharer.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using Dalamud;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
|
||||
namespace Penumbra.GameData.Data;
|
||||
|
||||
public abstract class DataSharer : IDisposable
|
||||
{
|
||||
private readonly DalamudPluginInterface _pluginInterface;
|
||||
private readonly int _version;
|
||||
protected readonly ClientLanguage Language;
|
||||
private bool _disposed;
|
||||
|
||||
protected DataSharer(DalamudPluginInterface pluginInterface, ClientLanguage language, int version)
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
Language = language;
|
||||
_version = version;
|
||||
}
|
||||
|
||||
protected virtual void DisposeInternal()
|
||||
{ }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
DisposeInternal();
|
||||
GC.SuppressFinalize(this);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
~DataSharer()
|
||||
=> Dispose();
|
||||
|
||||
protected void DisposeTag(string tag)
|
||||
=> _pluginInterface.RelinquishData(GetVersionedTag(tag));
|
||||
|
||||
private string GetVersionedTag(string tag)
|
||||
=> $"Penumbra.GameData.{tag}.{Language}.V{_version}";
|
||||
|
||||
protected T TryCatchData<T>(string tag, Func<T> func) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pluginInterface.GetOrCreateData(GetVersionedTag(tag), func);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Error($"Error creating shared actor data for {tag}:\n{ex}");
|
||||
return func();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue