Skip to content

Commit

Permalink
log usage of GetSupportedMinions API
Browse files Browse the repository at this point in the history
  • Loading branch information
direwolf420 committed Aug 31, 2021
1 parent feaedcc commit 550b0ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 4 additions & 3 deletions SummonersAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class SummonersAssociation : Mod
//(Main purpose is for 1.4 where this was backported from, but it can be used for mods to blacklist minions in 1.3 too, why not)
internal static Dictionary<int, Func<Projectile, bool>> TeleportConditionMinions;

private bool SupportedMinionsFinalized = false;
internal bool SupportedMinionsFinalized = false;

internal static UserInterface HistoryBookUIInterface;
internal static HistoryBookUI HistoryBookUI;

public static SummonersAssociation Instance;
public static SummonersAssociation Instance { get; private set; }

private static bool ProjectileFalse(Projectile p) => false;

Expand Down Expand Up @@ -130,6 +130,7 @@ public override void AddRecipeGroups() {
}
}
}

SupportedMinionsFinalized = true;

var group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Magic Mirror", new int[]
Expand Down Expand Up @@ -502,7 +503,7 @@ public override object Call(params object[] args) {
}
var apiVersion = args[2] is string ? new Version(args[2] as string) : Version; // Future-proofing. Allowing new info to be returned while maintaining backwards compat if necessary.

Logger.Info($"{(mod.DisplayName ?? "A mod")} has registered for {message}");
Logger.Info($"{(mod.DisplayName ?? "A mod")} has registered for {message} via Call");

if (!SupportedMinionsFinalized) {
Logger.Warn($"Call Warning: The attempted message, \"{message}\", was sent too early. Expect the Call message to return incomplete data. For best results, call in PostAddRecipes.");
Expand Down
24 changes: 21 additions & 3 deletions SummonersAssociationAPI.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SummonersAssociation.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;

namespace SummonersAssociation
{
Expand All @@ -12,11 +14,27 @@ namespace SummonersAssociation
public static class SummonersAssociationAPI
{
/// <summary>
/// Returns an List[MinionModel] that is a copy of this mod's data. Cache the result.
/// Returns an List[MinionModel] that is a copy of this mod's data.
/// For best results, call it once in Mod.PostAddRecipes and cache the result
/// </summary>
/// <param name="mod">Your mod</param>
/// <returns>Data of all supported minions by this mod</returns>
public static List<MinionModel> GetSupportedMinions() =>
SummonersAssociation.SupportedMinions.Select(model => new MinionModel(model)).ToList();
public static List<MinionModel> GetSupportedMinions(Mod mod) {
const string method = nameof(GetSupportedMinions);
if (mod == null) {
throw new Exception($"Call Error: The Mod argument for {method} is null.");
}

var saMod = SummonersAssociation.Instance;
var logger = saMod.Logger;
logger.Info($"{(mod.DisplayName ?? "A mod")} has registered for {method} via API");

if (!saMod.SupportedMinionsFinalized) {
logger.Warn($"Call Warning: The attempted method \"{method}\" is called early. Expect the method to return incomplete data. For best results, call in PostAddRecipes.");
}

return SummonersAssociation.SupportedMinions.Select(model => new MinionModel(model)).ToList();
}

/// <summary>
/// Returns the number of "minion" buffs currently active on the player.
Expand Down

0 comments on commit 550b0ac

Please sign in to comment.