Skip to content

Commit

Permalink
Finished with documentation and prepped for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirdoombox committed Apr 7, 2020
1 parent a5c3040 commit 5d1f2f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .tools/BannerLib.ReleasePackager/ReleasePackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class ReleasePackager
// Run this project.

private const string c_MODULE_NAME = "BannerLib";
private const string c_RELEASE_VER = "v0.0.5"; // v is required, major.minor.revision format.
private const string c_RELEASE_VER = "v0.0.6"; // v is required, major.minor.revision format.
private const bool c_IS_SINGLEPLAYER_ONLY = true; // if this is false, the module can also be used in multiplayer, leave it false for now.

private const string c_BIN_DIR = "bin/Release";
Expand Down
14 changes: 13 additions & 1 deletion BannerLib.Gameplay/Models/GameModelLedgerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

namespace BannerLib.Gameplay.Models
{
/// <summary>
/// Describes a replacement, addition or decoration operation that took place via BannerLib.
/// </summary>
public class GameModelLedgerEntry
{
/// <summary>
/// The base type of the replacement in question.
/// </summary>
public Type BaseType { get; }
/// <summary>
/// The original type that was replaced.
/// </summary>
public Type Original { get; }
/// <summary>
/// The replacement type.
/// </summary>
public Type Replacement { get; }

public GameModelLedgerEntry(Type original, Type replacement)
internal GameModelLedgerEntry(Type original, Type replacement)
{
Original = original;
Replacement = replacement;
Expand Down
21 changes: 12 additions & 9 deletions BannerLib.Gameplay/Models/GameModels.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.SandBox.GameComponents;
using TaleWorlds.Core;

namespace BannerLib.Gameplay.Models
Expand Down Expand Up @@ -30,8 +32,8 @@ public static GameModelLedgerEntry IsModelReplaced<TModelBase>() where TModelBas
/// Check if a model implementation exists for a given base type.
/// </summary>
/// <param name="starter"><see cref="IGameStarter"/> Object.</param>
/// <typeparam name="TModelBase"></typeparam>
/// <returns></returns>
/// <typeparam name="TModelBase"><see cref="GameModel"/> Derived base class to check for.</typeparam>
/// <returns>True if a model that derives from the given type exists in the current models.</returns>
public static bool ModelExistsFor<TModelBase>(this IGameStarter starter) where TModelBase : GameModel
{
return starter.Models.Any(x => x is TModelBase);
Expand All @@ -41,8 +43,8 @@ public static bool ModelExistsFor<TModelBase>(this IGameStarter starter) where T
/// Replace a specific GameModel implementation with another.
/// </summary>
/// <param name="starter"><see cref="IGameStarter"/> Object.</param>
/// <param name="replacement"></param>
/// <typeparam name="TReplace"></typeparam>
/// <param name="replacement">Specific instance of a <see cref="GameModel"/> derived type to use as the replacement.</param>
/// <typeparam name="TReplace"><see cref="GameModel"/> derived type to use as the replace.</typeparam>
/// <typeparam name="TReplacement"><see cref="GameModel"/> derived type to use as the replacement.</typeparam>
public static void Replace<TReplace,TReplacement>(this IGameStarter starter, TReplacement replacement)
where TReplace : GameModel where TReplacement : GameModel
Expand All @@ -66,7 +68,7 @@ public static void Replace<TReplace,TReplacement>(this IGameStarter starter, TRe
/// Replace a specific GameModel implementation with another.
/// </summary>
/// <param name="starter"><see cref="IGameStarter"/> Object.</param>
/// <typeparam name="TReplace"></typeparam>
/// <typeparam name="TReplace"><see cref="GameModel"/> Derived base class to replace E.G.: <seealso cref="DefaultGenericXpModel"/></typeparam>
/// <typeparam name="TReplacement"><see cref="GameModel"/> derived type to use as the replacement.</typeparam>
public static void Replace<TReplace, TReplacement>(this IGameStarter starter)
where TReplace : GameModel where TReplacement : GameModel, new() =>
Expand All @@ -77,7 +79,7 @@ public static void Replace<TReplace, TReplacement>(this IGameStarter starter)
/// </summary>
/// <param name="starter"><see cref="IGameStarter"/> Object.</param>
/// <param name="replacement">Instance of a <see cref="GameModel"/> derived type to use as the replacement.</param>
/// <typeparam name="TBaseReplace"></typeparam>
/// <typeparam name="TBaseReplace"><see cref="GameModel"/> Derived base class to replace E.G.: <seealso cref="GenericXpModel"/></typeparam>
/// <typeparam name="TReplacement"><see cref="GameModel"/> derived type to use as the replacement.</typeparam>
public static void ReplaceAll<TBaseReplace, TReplacement>(this IGameStarter starter, TReplacement replacement)
where TBaseReplace : GameModel where TReplacement : GameModel
Expand Down Expand Up @@ -106,9 +108,9 @@ public static void ReplaceAll<TBaseReplace, TReplacement>(this IGameStarter star
/// <summary>
/// Decorates an existing model with a given decorator that is produced by the given function
/// </summary>
/// <typeparam name="TDecoratee"></typeparam>
/// <typeparam name="TDecorater"></typeparam>
/// <param name="starter"></param>
/// <typeparam name="TDecoratee"><see cref="GameModel"/> derived type to decorate.</typeparam>
/// <typeparam name="TDecorater"><see cref="GameModel"/> derived type that will decorate it.</typeparam>
/// <param name="starter"><see cref="IGameStarter"/> Object.</param>
/// <param name="decoraterCtor">Functions which creates the decorator from the given model</param>
public static void Decorate<TDecoratee, TDecorater>(this IGameStarter starter, Func<TDecoratee, TDecorater> decoraterCtor)
where TDecoratee : GameModel where TDecorater : TDecoratee
Expand All @@ -121,6 +123,7 @@ public static void Decorate<TDecoratee, TDecorater>(this IGameStarter starter, F
throw new ArgumentException($"No model or multiple models registered with type '{baseType.Name}'. It must be exactly ONE model with this type to decorate it!");
var decorater = decoraterCtor(model);
starter.Replace<TDecoratee, TDecorater>(decorater);
m_ledger.Add(new GameModelLedgerEntry(typeof(TDecoratee), typeof(TDecorater)));
}

/// <summary>
Expand Down

0 comments on commit 5d1f2f9

Please sign in to comment.