Skip to content

Commit

Permalink
v1.6
Browse files Browse the repository at this point in the history
- Added toggle to plant grower classes (such as Hydroponics basin)
  • Loading branch information
Jaxe-Dev committed May 19, 2022
1 parent b84e1bf commit 8d408d2
Show file tree
Hide file tree
Showing 27 changed files with 354 additions and 165 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.*
_*
/*
*.user
*.pdb
!/.gitignore
!/README.md
!/source/
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Toggle Harvest
![Mod Version](https://img.shields.io/badge/Mod_Version-1.5-blue.svg)
![Mod Version](https://img.shields.io/badge/Mod_Version-1.6-blue.svg)
![RimWorld Version](https://img.shields.io/badge/Built_for_RimWorld-1.3-blue.svg)
![Harmony Version](https://img.shields.io/badge/Powered_by_Harmony-2.x-blue.svg)\
![Harmony Version](https://img.shields.io/badge/Powered_by_Harmony-2.2-blue.svg)\
![Steam Subscribers](https://img.shields.io/badge/dynamic/xml.svg?label=Steam+Subscribers&query=//table/tr[2]/td[1]&colorB=blue&url=https://steamcommunity.com/sharedfiles/filedetails/%3Fid=1499848654&suffix=+total)
![GitHub Downloads](https://img.shields.io/github/downloads/Jaxe-Dev/ToggleHarvest/total.svg?colorB=blue&label=GitHub+Downloads)

Expand All @@ -26,6 +26,8 @@ Adds an *Allow Harvest* button to Growing Zones alongside the already existing *

The following base methods are patched with Harmony:
```
Postfix : RimWorld.Building_PlantGrower.ExposeData
Postfix : RimWorld.Building_PlantGrower.GetGizmos
Postfix : RimWorld.WorkGiver_GrowerHarvest.HasJobOnCell
Postfix : RimWorld.Zone_Growing.ExposeData
Postfix : RimWorld.Zone_Growing.GetGizmos
Expand Down
29 changes: 0 additions & 29 deletions Source/Mod.cs

This file was deleted.

18 changes: 0 additions & 18 deletions Source/Patch/RimWorld_WorkGiver_GrowerHarvest_HasJobOnCell.cs

This file was deleted.

17 changes: 0 additions & 17 deletions Source/Patch/RimWorld_Zone_Growing_ExposeData.cs

This file was deleted.

25 changes: 0 additions & 25 deletions Source/Patch/RimWorld_Zone_Growing_GetGizmos.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Source/Patch/Verse_Profile_MemoryUtility_ClearAllMapsAndWorld.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Source/ToggleHarvest.csproj.DotSettings

This file was deleted.

21 changes: 0 additions & 21 deletions Source/ToggleHarvest.sln

This file was deleted.

2 changes: 1 addition & 1 deletion About/About.xml → source/Assets/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<packageId>Jaxe.ToggleHarvest</packageId>
<name>Toggle Harvest</name>
<author>Jaxe</author>
<description>Mod Version: 1.5\n\n\nAdds an &lt;i&gt;Allow Harvest&lt;/i&gt; toggle to Growing Zones alongside the already existing &lt;i&gt;Allow Sowing&lt;/i&gt; button.</description>
<description>Mod Version: {ReleaseVersion}\n\n\nAdds an &lt;i&gt;Allow Harvest&lt;/i&gt; toggle to Growing Zones alongside the already existing &lt;i&gt;Allow Sowing&lt;/i&gt; button.</description>
<supportedVersions>
<li>1.1</li>
<li>1.2</li>
Expand Down
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<LanguageData>
<ToggleHarvest.CommandAllowHarvest>Allow harvest</ToggleHarvest.CommandAllowHarvest>
<ToggleHarvest.CommandAllowHarvestDesc>When disabled, colonists will never harvest plants in this zone.</ToggleHarvest.CommandAllowHarvestDesc>
Expand Down
35 changes: 35 additions & 0 deletions source/Assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Toggle Harvest
![Mod Version](https://img.shields.io/badge/Mod_Version-{ReleaseVersion}-blue.svg)
![RimWorld Version](https://img.shields.io/badge/Built_for_RimWorld-{GameVersion}-blue.svg)
![Harmony Version](https://img.shields.io/badge/Powered_by_Harmony-{HarmonyVersion}-blue.svg)\
![Steam Subscribers](https://img.shields.io/badge/dynamic/xml.svg?label=Steam+Subscribers&query=//table/tr[2]/td[1]&colorB=blue&url=https://steamcommunity.com/sharedfiles/filedetails/%3Fid=1499848654&suffix=+total)
![GitHub Downloads](https://img.shields.io/github/downloads/Jaxe-Dev/ToggleHarvest/total.svg?colorB=blue&label=GitHub+Downloads)

[Link to Steam Workshop page](https://steamcommunity.com/sharedfiles/filedetails/?id=1499848654)\
[Link to Ludeon Forum Post](https://ludeon.com/forums/index.php?topic=43552.0)

---

Adds an *Allow Harvest* button to Growing Zones alongside the already existing *Allow Sowing* button.

---

##### STEAM INSTALLATION
- **[Go to the Steam Workshop page](https://steamcommunity.com/sharedfiles/filedetails/?id=1499848654) and subscribe to the mod.**

---

##### NON-STEAM INSTALLATION
- **[Download the latest release](https://github.com/Jaxe-Dev/ToggleHarvest/releases/latest) and unzip it into your *RimWorld/Mods* folder.**

---

The following base methods are patched with Harmony:
```
Postfix : RimWorld.Building_PlantGrower.ExposeData
Postfix : RimWorld.Building_PlantGrower.GetGizmos
Postfix : RimWorld.WorkGiver_GrowerHarvest.HasJobOnCell
Postfix : RimWorld.Zone_Growing.ExposeData
Postfix : RimWorld.Zone_Growing.GetGizmos
Prefix : Verse.Profile.MemoryUtility.ClearAllMapsAndWorld
```
21 changes: 21 additions & 0 deletions source/Helpers/Building_PlantGrower_Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using RimWorld;

namespace ToggleHarvest.Helpers
{
public static class Building_PlantGrower_Helper
{
private static readonly HashSet<Building_PlantGrower> Disallowed = new HashSet<Building_PlantGrower>();

public static void Reset() => Disallowed.Clear();

public static bool IsAllowed(Building_PlantGrower building) => !Disallowed.Contains(building);

public static void SetAllowed(Building_PlantGrower building, bool allowed)
{
var isDisallowed = Disallowed.Contains(building);
if (allowed && isDisallowed) { Disallowed.Remove(building); }
else if (!allowed && !isDisallowed) { Disallowed.Add(building); }
}
}
}
21 changes: 21 additions & 0 deletions source/Helpers/Zone_Growing_Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using RimWorld;

namespace ToggleHarvest.Helpers
{
public static class Zone_Growing_Helper
{
private static readonly HashSet<Zone_Growing> Disallowed = new HashSet<Zone_Growing>();

public static void Reset() => Disallowed.Clear();

public static bool IsAllowed(Zone_Growing zone) => !Disallowed.Contains(zone);

public static void SetAllowed(Zone_Growing zone, bool allowed)
{
var isDisallowed = Disallowed.Contains(zone);
if (allowed && isDisallowed) { Disallowed.Remove(zone); }
else if (!allowed && !isDisallowed) { Disallowed.Add(zone); }
}
}
}
17 changes: 17 additions & 0 deletions source/Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using HarmonyLib;
using RimWorld;
using Verse;

namespace ToggleHarvest
{
[StaticConstructorOnStartup]
internal static class Mod
{
public const string Id = "ToggleHarvest";
public const string Name = "Toggle Harvest";
public const string Version = "1.6";

static Mod() => new Harmony(Id).PatchAll();
}
}
18 changes: 18 additions & 0 deletions source/Patch/RimWorld_Building_PlantGrower_ExposeData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using HarmonyLib;
using RimWorld;
using ToggleHarvest.Helpers;
using Verse;

namespace ToggleHarvest.Patch
{
[HarmonyPatch(typeof(Building_PlantGrower), nameof(Building_PlantGrower.ExposeData))]
internal static class RimWorld_Building_PlantGrower_ExposeData
{
private static void Postfix(ref Building_PlantGrower __instance)
{
var allowHarvest = Building_PlantGrower_Helper.IsAllowed(__instance);
Scribe_Values.Look(ref allowHarvest, "allowHarvest", true);
Building_PlantGrower_Helper.SetAllowed(__instance, allowHarvest);
}
}
}
26 changes: 26 additions & 0 deletions source/Patch/RimWorld_Building_PlantGrower_GetGizmos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using HarmonyLib;
using RimWorld;
using ToggleHarvest.Helpers;
using Verse;

namespace ToggleHarvest.Patch
{
[HarmonyPatch(typeof(Building_PlantGrower), nameof(Building_PlantGrower.GetGizmos))]
internal static class RimWorld_Building_PlantGrower_GetGizmos
{
private static void Postfix(Building_PlantGrower __instance, ref IEnumerable<Gizmo> __result)
{
var allowHarvestCommand = new Command_Toggle
{
defaultLabel = "ToggleHarvest.CommandAllowHarvest".Translate(),
defaultDesc = "ToggleHarvest.CommandAllowHarvestDesc".Translate(),
icon = TexCommand.ForbidOff,
isActive = () => Building_PlantGrower_Helper.IsAllowed(__instance),
toggleAction = () => Building_PlantGrower_Helper.SetAllowed(__instance, !Building_PlantGrower_Helper.IsAllowed(__instance))
};

__result = new List<Gizmo>(__result) { allowHarvestCommand };
}
}
}
19 changes: 19 additions & 0 deletions source/Patch/RimWorld_WorkGiver_GrowerHarvest_HasJobOnCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HarmonyLib;
using RimWorld;
using ToggleHarvest.Helpers;
using Verse;

namespace ToggleHarvest.Patch
{
[HarmonyPatch(typeof(WorkGiver_GrowerHarvest), nameof(WorkGiver_GrowerHarvest.HasJobOnCell))]
internal static class RimWorld_WorkGiver_GrowerHarvest_HasJobOnCell
{
private static void Postfix(ref bool __result, Pawn pawn, IntVec3 c)
{
if (!__result) { return; }

if (c.GetZone(pawn.Map) is Zone_Growing zone && !Zone_Growing_Helper.IsAllowed(zone)) { __result = false; }
else if (c.GetFirstBuilding(pawn.Map) is Building_PlantGrower building && !Building_PlantGrower_Helper.IsAllowed(building)) { __result = false; }
}
}
}
18 changes: 18 additions & 0 deletions source/Patch/RimWorld_Zone_Growing_ExposeData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using HarmonyLib;
using RimWorld;
using ToggleHarvest.Helpers;
using Verse;

namespace ToggleHarvest.Patch
{
[HarmonyPatch(typeof(Zone_Growing), nameof(Zone_Growing.ExposeData))]
internal static class RimWorld_Zone_Growing_ExposeData
{
private static void Postfix(ref Zone_Growing __instance)
{
var allowHarvest = Zone_Growing_Helper.IsAllowed(__instance);
Scribe_Values.Look(ref allowHarvest, "allowHarvest", true);
Zone_Growing_Helper.SetAllowed(__instance, allowHarvest);
}
}
}
33 changes: 33 additions & 0 deletions source/Patch/RimWorld_Zone_Growing_GetGizmos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using RimWorld;
using ToggleHarvest.Helpers;
using Verse;

namespace ToggleHarvest.Patch
{
[HarmonyPatch(typeof(Zone_Growing), nameof(Zone_Growing.GetGizmos))]
internal static class RimWorld_Zone_Growing_GetGizmos
{
private static void Postfix(Zone_Growing __instance, ref IEnumerable<Gizmo> __result)
{
var allowHarvestCommand = new Command_Toggle
{
defaultLabel = "ToggleHarvest.CommandAllowHarvest".Translate(),
defaultDesc = "ToggleHarvest.CommandAllowHarvestDesc".Translate(),
icon = TexCommand.ForbidOff,
isActive = () => Zone_Growing_Helper.IsAllowed(__instance),
toggleAction = () => Zone_Growing_Helper.SetAllowed(__instance, !Zone_Growing_Helper.IsAllowed(__instance))
};

var list = __result.ToList();
var index = list.FirstIndexOf(gizmo => (gizmo as Command_Toggle)?.Label == "CommandAllowSow".Translate());

if (index <= 0) { list.Add(allowHarvestCommand); }
else { list.Insert(index + 1, allowHarvestCommand); }

__result = list;
}
}
}
Loading

0 comments on commit 8d408d2

Please sign in to comment.