Skip to content

Commit

Permalink
NotSalvagable fix, coloring fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Denadan committed Jul 24, 2018
1 parent fc8240f commit 3388dbb
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 38 deletions.
34 changes: 17 additions & 17 deletions source/CCLight/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ internal static IEnumerable<T> GetCustomComponents<T>(MechComponentDef def)
internal static T GetCustomComponent<T>(MechComponentRef cref)
{

//if (cref.Def == null)
//{
// if (cref.DataManager == null)
// {
// if (game.DataManager != null)
// {
// cref.DataManager = game.DataManager;
// cref.RefreshComponentDef();
// }
// else
// {
// Control.Logger.Log("No datamanager found!");
// }
// }
// else
// cref.RefreshComponentDef();
//}
if (cref.Def == null)
{
if (cref.DataManager == null)
{
if (DataManager != null)
{
cref.DataManager = DataManager;
cref.RefreshComponentDef();
}
else
{
Control.Logger.LogError("No datamanager found!");
}
}
else
cref.RefreshComponentDef();
}

return GetCustomComponent<T>(Key(cref));

Expand Down
6 changes: 3 additions & 3 deletions source/CCLight/Factories/SimpleCustomComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class SimpleCustomComponent : ICustomComponent
private string id;

[JsonIgnore]
public MechComponentDef Def
public MechComponentDef Def// { get; internal set; }
{
get
{
if (_def == null)
return null;
if(!_def.IsAlive)
if (!_def.IsAlive)
{
var def = Database.RefreshDef(id, type);
if (def == null)
Expand All @@ -37,7 +37,7 @@ internal set
_def = null;
id = "";
type = ComponentType.NotSet;
}
}
else
{
_def = new WeakReference(value);
Expand Down
2 changes: 1 addition & 1 deletion source/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void Init(string directory, string settingsJSON)
Validator.RegisterMechValidator(CategoryController.ValidateMech, CategoryController.ValidateMechCanBeFielded);


Logger.Log("Loaded CustomComponents v0.5.5.4.3");
Logger.Log("Loaded CustomComponents v0.6.0.0.4");
Logger.Log($"DataManager is null: {Database.DataManager == null}");
#if CCDEBUG
Logger.LogDebug("Loading Categories");
Expand Down
1 change: 0 additions & 1 deletion source/Helpers/DefaultHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public static void AddInventory(string defaultID, MechDef mech, ChassisLocations
public static MechLabItemSlotElement CreateSlot(string id, ComponentType type, MechLabPanel mechLab)
{
var component_ref = new MechComponentRef(id, string.Empty, type, ChassisLocations.None);
component_ref.DataManager = mechLab.dataManager;

if (!component_ref.IsDefault())
{
Expand Down
15 changes: 7 additions & 8 deletions source/Patches/Contract_AddToFilnaSalvagePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ public static bool Prefix(SalvageDef def)
if (def.ComponentType == ComponentType.MechPart)
return true;

if (def.MechComponentDef == null)
{
Control.Logger.Log($"AddToFinalSalvage: Def is null {def}");
return true;
}
var flags = Database.GetCustomComponent<Flags>(def.Description.Id);

//Control.Logger.LogDebug($"AddToFinalSalvage: {def.Description.Id}, Salvagable:{flags == null || !flags.NotSalvagable}");

return !(def.MechComponentDef.Is<Flags>(out var f) && f.NotSalvagable);
return flags == null || !flags.NotSalvagable;
}
}

Expand All @@ -28,8 +26,9 @@ internal static class Contract_AddMechComponentToSalvage
{
public static bool Prefix(MechComponentDef def)
{
Control.Logger.LogDebug(def.Description.Id);
return !(def.Is<Flags>(out var f) && f.NotSalvagable);
var flags = def.GetComponent<Flags>();
//Control.Logger.LogDebug($"salvage: {def.Description.Id} Flags null:{flags == null} Default:{flags!= null && flags.Default} Salvagabe:{flags != null && flags.NotSalvagable}");
return !(flags!= null && flags.NotSalvagable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public static class ListElementController_SalvageGear_NotListView_RefreshItemCol
{
public static bool Prefix(InventoryItemElement theWidget, ListElementController_SalvageGear_NotListView __instance)
{
if (__instance.salvageDef.MechComponentDef == null)
if (__instance.salvageDef.MechComponentDef == null || __instance.salvageDef.Description == null)
return true;
try
{
if (__instance.salvageDef.MechComponentDef.Is<ColorComponent>(out var color))
var color = Database.GetCustomComponent<ColorComponent>(__instance.salvageDef.Description.Id);

if (color != null)
{
var uicolor = color.UIColor;
foreach (UIColorRefTracker uicolorRefTracker in theWidget.iconBGColors)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BattleTech.UI;
using System;
using BattleTech.UI;
using Harmony;

namespace CustomComponents
Expand All @@ -8,16 +9,60 @@ public static class ListElementController_SalvageGear_RefreshItemColor_Patch
{
public static bool Prefix(InventoryItemElement theWidget, ListElementController_SalvageGear __instance)
{
if (__instance.salvageDef.MechComponentDef.Is<ColorComponent>(out var color))
if (__instance.salvageDef.MechComponentDef == null || __instance.salvageDef.Description == null)
return true;
try
{
var uicolor = color.UIColor;
foreach (UIColorRefTracker uicolorRefTracker in theWidget.iconBGColors)
var color = Database.GetCustomComponent<ColorComponent>(__instance.salvageDef.Description.Id);

if (color != null)
{
uicolorRefTracker.SetUIColor(uicolor);
var uicolor = color.UIColor;
foreach (UIColorRefTracker uicolorRefTracker in theWidget.iconBGColors)
{
uicolorRefTracker.SetUIColor(uicolor);
}

return false;
}
}
catch (Exception e)
{
Control.Logger.LogError("Salvage coloring problem!", e);
}

return true;
}
}


return false;
[HarmonyPatch(typeof(ListElementController_ShopGear), "RefreshItemColor")]
public static class ListElementController_ShopGear_RefreshItemColor_Patch
{
public static bool Prefix(InventoryItemElement theWidget, ListElementController_ShopGear __instance)
{
if (__instance.componentDef == null )
return true;
try
{
var color = Database.GetCustomComponent<ColorComponent>(__instance.componentDef.Description.Id);

if (color != null)
{
var uicolor = color.UIColor;
foreach (UIColorRefTracker uicolorRefTracker in theWidget.iconBGColors)
{
uicolorRefTracker.SetUIColor(uicolor);
}

return false;
}
}
catch (Exception e)
{
Control.Logger.LogError("Salvage coloring problem!", e);
}

return true;
}
}
Expand Down

0 comments on commit 3388dbb

Please sign in to comment.