From 96351ff17a7ebbc49368c247c66485589bd676bb Mon Sep 17 00:00:00 2001 From: ontrigger Date: Sun, 23 Aug 2020 16:34:44 +0300 Subject: [PATCH] small refactor --- ItemStats/ItemStats.csproj | 5 ++--- ItemStats/src/Api/ProvidesItemStats.cs | 11 ---------- ItemStats/src/ItemStatDef.cs | 17 --------------- ItemStats/src/ItemStatsMod.cs | 1 + ItemStats/src/Stat/ItemStatDef.cs | 21 +++++++++++++++++++ ItemStats/src/{ => Stat}/StatContext.cs | 0 .../DefaultStatCalculationStrategy.cs | 10 ++++++++- .../IStatCalculationStrategy.cs | 2 +- 8 files changed, 34 insertions(+), 33 deletions(-) delete mode 100644 ItemStats/src/Api/ProvidesItemStats.cs delete mode 100644 ItemStats/src/ItemStatDef.cs create mode 100644 ItemStats/src/Stat/ItemStatDef.cs rename ItemStats/src/{ => Stat}/StatContext.cs (100%) diff --git a/ItemStats/ItemStats.csproj b/ItemStats/ItemStats.csproj index 3c0c7d2..72e33fe 100644 --- a/ItemStats/ItemStats.csproj +++ b/ItemStats/ItemStats.csproj @@ -69,18 +69,17 @@ - - - + + diff --git a/ItemStats/src/Api/ProvidesItemStats.cs b/ItemStats/src/Api/ProvidesItemStats.cs deleted file mode 100644 index 9eb5b75..0000000 --- a/ItemStats/src/Api/ProvidesItemStats.cs +++ /dev/null @@ -1,11 +0,0 @@ -using RoR2; - -namespace ItemStats.Api -{ - public interface IProvidesItemStats - { - ItemStatDef StatDef { get; } - - ItemDef ItemDef { get; } - } -} \ No newline at end of file diff --git a/ItemStats/src/ItemStatDef.cs b/ItemStats/src/ItemStatDef.cs deleted file mode 100644 index b9c0621..0000000 --- a/ItemStats/src/ItemStatDef.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using ItemStats.Stat; -using ItemStats.StatCalculation; - -namespace ItemStats -{ - public class ItemStatDef - { - private readonly IStatCalculationStrategy _strategy = new DefaultStatCalculationStrategy(); - public List Stats; - - public string ProcessItem(int count, StatContext context) - { - return _strategy.ProcessItem(Stats, count, context); - } - } -} \ No newline at end of file diff --git a/ItemStats/src/ItemStatsMod.cs b/ItemStats/src/ItemStatsMod.cs index 5d2bc9c..3fd7472 100644 --- a/ItemStats/src/ItemStatsMod.cs +++ b/ItemStats/src/ItemStatsMod.cs @@ -11,6 +11,7 @@ namespace ItemStats { [BepInDependency("com.bepis.r2api")] [BepInPlugin("dev.ontrigger.itemstats", "ItemStats", "1.5.0")] + [NetworkCompatibility(CompatibilityLevel.NoNeedForSync, VersionStrictness.DifferentModVersionsAreOk)] public class ItemStatsMod : BaseUnityPlugin { private readonly Dictionary _displayToMasterRef = diff --git a/ItemStats/src/Stat/ItemStatDef.cs b/ItemStats/src/Stat/ItemStatDef.cs new file mode 100644 index 0000000..dce452f --- /dev/null +++ b/ItemStats/src/Stat/ItemStatDef.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using ItemStats.Stat; +using ItemStats.StatCalculation; + +namespace ItemStats +{ + public class ItemStatDef + { + public IStatCalculationStrategy StatCalculationStrategy = new DefaultStatCalculationStrategy(); + + public List Stats; + + // additional text that only appears on stat tooltip and not the logbook + public string AdditionalText; + + public string ProcessItem(int count, StatContext context) + { + return StatCalculationStrategy.ProcessItem(Stats, count, context, AdditionalText); + } + } +} \ No newline at end of file diff --git a/ItemStats/src/StatContext.cs b/ItemStats/src/Stat/StatContext.cs similarity index 100% rename from ItemStats/src/StatContext.cs rename to ItemStats/src/Stat/StatContext.cs diff --git a/ItemStats/src/StatCalculation/DefaultStatCalculationStrategy.cs b/ItemStats/src/StatCalculation/DefaultStatCalculationStrategy.cs index 9f42ca9..3d170c4 100644 --- a/ItemStats/src/StatCalculation/DefaultStatCalculationStrategy.cs +++ b/ItemStats/src/StatCalculation/DefaultStatCalculationStrategy.cs @@ -2,16 +2,24 @@ using System.Collections.Generic; using System.Text; using ItemStats.Stat; +using JetBrains.Annotations; namespace ItemStats.StatCalculation { public class DefaultStatCalculationStrategy : IStatCalculationStrategy { - public string ProcessItem(List stats, int count, StatContext context) + public string ProcessItem(List stats, int count, StatContext context, + [CanBeNull] string additionalText) { var fullStatText = new StringBuilder(); fullStatText.Append("\n\n"); + if (additionalText != null) + { + fullStatText.Append(additionalText); + fullStatText.Append("\n\n"); + } + foreach (var stat in stats) { var m = stat.GetInitialStat(count, context); diff --git a/ItemStats/src/StatCalculation/IStatCalculationStrategy.cs b/ItemStats/src/StatCalculation/IStatCalculationStrategy.cs index 4399281..b725f84 100644 --- a/ItemStats/src/StatCalculation/IStatCalculationStrategy.cs +++ b/ItemStats/src/StatCalculation/IStatCalculationStrategy.cs @@ -5,6 +5,6 @@ namespace ItemStats.StatCalculation { public interface IStatCalculationStrategy { - string ProcessItem(List stats, int count, StatContext context); + string ProcessItem(List stats, int count, StatContext context, string additionalText); } } \ No newline at end of file