-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added toggle to plant grower classes (such as Hydroponics basin)
- Loading branch information
Showing
27 changed files
with
354 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.* | ||
_* | ||
/* | ||
*.user | ||
*.pdb | ||
!/.gitignore | ||
!/README.md | ||
!/source/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
Source/Patch/RimWorld_WorkGiver_GrowerHarvest_HasJobOnCell.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
Source/Patch/Verse_Profile_MemoryUtility_ClearAllMapsAndWorld.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
1 change: 0 additions & 1 deletion
1
Languages/English/Keyed/ToggleHarvest.xml → ...Languages/English/Keyed/ToggleHarvest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
source/Patch/RimWorld_WorkGiver_GrowerHarvest_HasJobOnCell.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.