Skip to content

Commit

Permalink
Document and clean up DGA integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tqdv committed Dec 26, 2022
1 parent ccad62f commit 9494be4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
7 changes: 5 additions & 2 deletions UIInfoSuite2/Compatibility/DynamicGameAssetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public DynamicGameAssetsHelper(IDynamicGameAssetsApi api, IModHelper helper, IMo
this.ModEvents.GameLoop.DayEnding += OnDayEnding;
}

/// Supply an object of any DGA type to enable access to classes inside DGA
public void SupplyDga(object dga)
/// <summary>Inject an object of any DGA type to get a reference to the DGA Assembly</summary>
public void InjectDga(object dga)
{
if (_dgaAssembly == null)
{
Expand Down Expand Up @@ -159,6 +159,7 @@ private int GetDeterministicHashCode(string str)
}
}

/// <summary>Mod.Find()</summary>
public object? FindPackData(string fullId)
{
var modFind = GetModFindMethod();
Expand All @@ -174,11 +175,13 @@ public int GetDgaObjectFakeId(SObject dgaItem)
}

#region DGA instance fields, methods and properties
/// <summary>CustomCrop.Data</summary>
private object? GetCropData(object customCrop)
{
return Reflector.GetPropertyGetter<object?>(customCrop, "Data").GetValue();
}

/// <summary>IDGAItem.FullId</summary>
public string? GetFullId(object dgaItem)
{
return Reflection.GetProperty<string?>(dgaItem, "FullId").GetValue();
Expand Down
36 changes: 20 additions & 16 deletions UIInfoSuite2/Compatibility/DynamicGameAssetsEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UIInfoSuite2.Compatibility
{
/// Entrypoint for all things DGA
/// <summary>Entrypoint for all things DGA</summary>
public class DynamicGameAssetsEntry
{
private IModHelper Helper { get; init; }
Expand All @@ -18,36 +18,40 @@ public DynamicGameAssetsEntry(IModHelper helper, IMonitor monitor)
this.Monitor = monitor;
}

public void SetApi(IDynamicGameAssetsApi api)
/// <summary>Inject the DGA API which allows DGAHelper to be inialized</summary>
public void InjectApi(IDynamicGameAssetsApi api)
{
this.Api = api;
this._dgaHelper = new DynamicGameAssetsHelper(Api, Helper, Monitor);
if (this.Api == null)
{
this.Api = api;
this._dgaHelper = new DynamicGameAssetsHelper(Api, Helper, Monitor);
}
}

/// <summary>Check if <paramref name="obj"/> is a DGA CustomCrop and provide a <see cref="DynamicGameAssetsHelper"/></summary>
public bool IsCustomCrop(object obj, out DynamicGameAssetsHelper? dgaHelper)
{
dgaHelper = null;
if (obj.GetType().FullName == "DynamicGameAssets.Game.CustomCrop")
return GetDgaHelper(obj, out dgaHelper);
return false;
dgaHelper = GetDgaHelper(obj);
return dgaHelper != null;
}



/// <summary>Check if <paramref name="obj"/> is a DGA CustomObject and provide a <see cref="DynamicGameAssetsHelper"/></summary>
public bool IsCustomObject(object obj, out DynamicGameAssetsHelper? dgaHelper)
{
dgaHelper = null;
if (obj.GetType().FullName == "DynamicGameAssets.Game.CustomObject")
return GetDgaHelper(obj, out dgaHelper);
return false;
dgaHelper = GetDgaHelper(obj);
return dgaHelper != null;
}

private bool GetDgaHelper(object obj, out DynamicGameAssetsHelper? dgaHelper)
/// <returns>null if <see cref="_dgaHelper"/> is null</returns>
private DynamicGameAssetsHelper? GetDgaHelper(object obj)
{
dgaHelper = _dgaHelper;
if (_dgaHelper == null)
return false;

_dgaHelper.SupplyDga(obj);
return true;
_dgaHelper?.InjectDga(obj);
return _dgaHelper;
}
}
}
2 changes: 1 addition & 1 deletion UIInfoSuite2/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
// get DGA's API
var dgaApi = Helper.ModRegistry.GetApi<IDynamicGameAssetsApi>("spacechase0.DynamicGameAssets");
if (dgaApi != null)
DGA.SetApi(dgaApi);
DGA.InjectApi(dgaApi);

// get Generic Mod Config Menu's API (if it's installed)
var modVersion = Helper.ModRegistry.Get("spacechase0.GenericModConfigMenu")?.Manifest?.Version;
Expand Down

0 comments on commit 9494be4

Please sign in to comment.