Skip to content

Commit

Permalink
Better Custom Display Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Sep 10, 2021
1 parent 5150890 commit 2053ac2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 10 deletions.
13 changes: 13 additions & 0 deletions BTD Mod Helper Core/Api/Display/ICustomDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
{
internal interface ICustomDisplay
{
/// <summary>
/// The name of the asset bundle file that the model is in, not including the .bundle extension
/// </summary>
string AssetBundleName { get; }


/// <summary>
/// The name of the prefab that the model has within the Asset Bundle
/// </summary>
string PrefabName { get; }


/// <summary>
/// The name of the material that should be applied to the tower from the asset bundle
/// </summary>
string MaterialName { get; }
}
}
15 changes: 15 additions & 0 deletions BTD Mod Helper Core/Api/Display/ModCustomDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@

namespace BTD_Mod_Helper.Api.Display
{
/// <summary>
/// The custom version of a ModDisplay that loads in a model from a unity assetbundle
/// </summary>
public abstract class ModCustomDisplay : ModDisplay, ICustomDisplay
{
/// <inheritdoc />
public abstract string AssetBundleName { get; }

/// <inheritdoc />
public abstract string PrefabName { get; }

/// <inheritdoc />
public abstract string MaterialName { get; }

/// <summary>
/// On a ModCustomDisplay, this property does nothing
/// </summary>
public override string BaseDisplay => null;

/// <summary>
/// Performs alterations to the unity display node when it is created
/// </summary>
/// <param name="node"></param>
public override void ModifyDisplayNode(UnityDisplayNode node)
{

Expand Down
19 changes: 19 additions & 0 deletions BTD Mod Helper Core/Api/Display/ModTowerCustomDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@

namespace BTD_Mod_Helper.Api.Display
{
/// <summary>
/// A ModCustomDisplay that will automatically apply to a ModTower for specific tiers
/// </summary>
public abstract class ModTowerCustomDisplay : ModTowerDisplay, ICustomDisplay
{
/// <inheritdoc />
public abstract string AssetBundleName { get; }

/// <inheritdoc />
public abstract string PrefabName { get; }

/// <inheritdoc />
public abstract string MaterialName { get; }

/// <summary>
/// On a ModCustomDisplay, this property does nothing
/// </summary>
public override string BaseDisplay => null;

/// <summary>
/// Performs alterations to the unity display node when it is created
/// </summary>
/// <param name="node"></param>
public override void ModifyDisplayNode(UnityDisplayNode node)
{

}
}

/// <summary>
/// A convenient generic class for applying a ModTowerCustomDisplay to a ModTower
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class ModTowerCustomDisplay<T> : ModTowerCustomDisplay where T : ModTower
{
/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion BTD Mod Helper Core/Api/Display/ModTowerDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace BTD_Mod_Helper.Api.Display
{
/// <summary>
/// A ModDisplay that will specifically be used as the main display for a ModTower
/// A ModDisplay that will automatically apply to a ModTower for specific tiers
/// </summary>
public abstract class ModTowerDisplay : ModDisplay
{
Expand Down
28 changes: 21 additions & 7 deletions BTD Mod Helper Core/Api/ModContent.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Assets.Scripts.Models;
using Assets.Scripts.Unity;
using BTD_Mod_Helper.Api;
#if BloonsTD6
using Assets.Scripts.Models.Towers;
using Assets.Scripts.Models.Towers.Upgrades;
using BTD_Mod_Helper.Api.Towers;
#elif BloonsAT
#endif
Expand Down Expand Up @@ -274,10 +270,11 @@ public static Texture2D GetTexture<T>(string fileName) where T : BloonsMod
{
return GetTexture(GetInstance<T>(), fileName);
}

/// <summary>
/// Constructs a Sprite for a given texture name within a given mod
/// </summary>
/// <param name="mod"></param>
/// <param name="name">The file name of your texture, without the extension</param>
/// <param name="pixelsPerUnit">The pixels per unit for the Sprite to have</param>
/// <returns>A Sprite</returns>
Expand Down Expand Up @@ -309,6 +306,11 @@ public static Sprite GetSprite<T>(string name, float pixelsPerUnit = 10f) where
}

#if BloonsTD6
/// <summary>
/// Gets the GUID (thing that should be used in the display field for things) for a specific ModDisplay
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static string GetDisplayGUID<T>() where T : ModDisplay
{
return GetInstance<T>().Id;
Expand Down Expand Up @@ -403,7 +405,11 @@ public static object GetInstance(Type type)
return !Instances.ContainsKey(type) ? default : Instances[type];
}


/// <summary>
/// Gets a bundle from a mod with the specified name (no file extension)
/// </summary>
/// <param name="mod"></param>
/// <param name="name"></param>
public static AssetBundle GetBundle(BloonsMod mod, string name)
{
if (ResourceHandler.Bundles.TryGetValue(mod.IDPrefix + name, out var bundle))
Expand All @@ -427,12 +433,20 @@ public static AssetBundle GetBundle(BloonsMod mod, string name)
}
return null;
}


/// <summary>
/// Gets a bundle from the mod T with the specified name (no file extension)
/// </summary>
/// <param name="name"></param>
public static AssetBundle GetBundle<T>(string name) where T : BloonsMod
{
return GetBundle(GetInstance<T>(), name);
}

/// <summary>
/// Gets a bundle from your mod with the specified name (no file extension)
/// </summary>
/// <param name="name"></param>
protected AssetBundle GetBundle(string name)
{
return GetBundle(mod, name);
Expand Down
4 changes: 2 additions & 2 deletions BTD Mod Helper Core/BloonsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public abstract class BloonsMod : MelonMod
public virtual void OnModOptionsOpened()
{
}

/*
/// <summary>
/// Called when the Mod Options Menu gets closed
/// </summary>
/*public virtual void OnModOptionsClosed() // not implemented for now
public virtual void OnModOptionsClosed() // not implemented for now
{
}*/

Expand Down

0 comments on commit 2053ac2

Please sign in to comment.