Skip to content

Commit 3c4516b

Browse files
committed
Update version and refactor constants to ModConstants
- Bumped version in `CarryChests.csproj` to `1.2.2-beta.1`. - Renamed `Constants` class to `ModConstants` and updated all references. - Modified slowness effect application in `ModEntry.cs` to use `ModConstants`. - Adjusted inventory checks and item handling in `ModEntry.cs` for clarity. - Updated Harmony initialization in `ModPatches.cs` to use `ModConstants.ModId`. - Refined positioning logic for UI elements in `ModPatches.cs`. - Ensured consistent handling of placed objects in `ModPatches.cs` with `ModConstants`. - Changed global inventory ID reference in `ModState.cs` to `ModConstants`. - Updated item addition and backup handling in `ModExtensions.cs` to use `ModConstants`. - Updated subproject commit reference in `FauxCore`.
1 parent 45c08cd commit 3c4516b

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

CarryChests/CarryChests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PropertyGroup>
77
<Name>Carry Chests</Name>
88
<Description>Allows you to pick up placed chests with items.</Description>
9-
<Version>1.2.1</Version>
9+
<Version>1.2.2-beta.1</Version>
1010
<EnableHarmony>true</EnableHarmony>
1111
<RootNamespace>LeFauxMods.CarryChest</RootNamespace>
1212
<UniqueId>furyx639.CarryChest</UniqueId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace LeFauxMods.CarryChest;
22

3-
internal static class Constants
3+
internal static class ModConstants
44
{
55
public const string BetterChestsColorKey = BetterChestsPrefix + "PlayerChoiceColor";
66

CarryChests/ModEntry.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void OnOneSecondUpdateTicked(object? sender, OneSecondUpdateTicke
4949
{
5050
Game1.player.applyBuff(
5151
new Buff(
52-
Constants.SlowEffectKey,
52+
ModConstants.SlowEffectKey,
5353
duration: 60_000,
5454
iconTexture: Game1.buffsIcons,
5555
iconSheetIndex: 13,
@@ -60,13 +60,13 @@ private static void OnOneSecondUpdateTicked(object? sender, OneSecondUpdateTicke
6060
return;
6161
}
6262

63-
if (!Game1.player.hasBuff(Constants.SlowEffectKey))
63+
if (!Game1.player.hasBuff(ModConstants.SlowEffectKey))
6464
{
6565
return;
6666
}
6767

6868
// Remove status effect from the player
69-
Game1.player.buffs.Remove(Constants.SlowEffectKey);
69+
Game1.player.buffs.Remove(ModConstants.SlowEffectKey);
7070
Log.Trace("Removing the slowness effect");
7171
}
7272

@@ -149,7 +149,7 @@ private void OnButtonPressed(object? sender, ButtonPressedEventArgs e)
149149
ItemGrabMenu { inventory: { } inventory } when inventory.isWithinBounds(mouseX, mouseY) =>
150150
inventory,
151151
GameMenu gameMenu when gameMenu.GetCurrentPage() is InventoryPage { inventory: { } inventory } &&
152-
inventory.isWithinBounds(mouseX, mouseY) => inventory,
152+
inventory.isWithinBounds(mouseX, mouseY) => inventory,
153153
_ => null
154154
};
155155

@@ -200,15 +200,15 @@ private void OnSaveLoaded(object? sender, SaveLoadedEventArgs e)
200200
if (item is not Chest chest)
201201
{
202202
if (item is null ||
203-
!item.modData.TryGetValue(Constants.BetterChestsGlobalInventoryKey, out var id) ||
203+
!item.modData.TryGetValue(ModConstants.BetterChestsGlobalInventoryKey, out var id) ||
204204
!Game1.player.team.globalInventories.ContainsKey(id))
205205
{
206206
continue;
207207
}
208208

209209
// Attempt to restore a Better Chest proxy
210210
var color = Color.Black;
211-
if (item.modData.TryGetValue(Constants.BetterChestsColorKey, out var colorString) &&
211+
if (item.modData.TryGetValue(ModConstants.BetterChestsColorKey, out var colorString) &&
212212
int.TryParse(colorString, out var colorValue))
213213
{
214214
var r = (byte)(colorValue & 0xFF);
@@ -220,26 +220,26 @@ private void OnSaveLoaded(object? sender, SaveLoadedEventArgs e)
220220
chest = new Chest(true, item.ItemId)
221221
{
222222
GlobalInventoryId = id,
223-
fridge = { Value = item.modData.ContainsKey(Constants.BetterChestsFridgeKey) },
223+
fridge = { Value = item.modData.ContainsKey(ModConstants.BetterChestsFridgeKey) },
224224
playerChoiceColor = { Value = color }
225225
};
226226

227227
chest.CopyFieldsFrom(item);
228-
_ = chest.modData.Remove(Constants.BetterChestsFridgeKey);
229-
_ = chest.modData.Remove(Constants.BetterChestsColorKey);
230-
_ = chest.modData.Remove(Constants.BetterChestsGlobalInventoryKey);
228+
_ = chest.modData.Remove(ModConstants.BetterChestsFridgeKey);
229+
_ = chest.modData.Remove(ModConstants.BetterChestsColorKey);
230+
_ = chest.modData.Remove(ModConstants.BetterChestsGlobalInventoryKey);
231231
Game1.player.Items[i] = chest;
232232
}
233233

234-
_ = ModState.Backups.TryAddBackup(chest, Constants.Prefix);
234+
_ = ModState.Backups.TryAddBackup(chest, ModConstants.Prefix);
235235
}
236236

237237
// Create generic backups for any missing
238238
foreach (var (id, _) in Game1.player.team.globalInventories.Pairs)
239239
{
240240
// Only create backups for known ids
241-
if (!id.StartsWith(Constants.Prefix, StringComparison.OrdinalIgnoreCase) &&
242-
!id.StartsWith(Constants.BetterChestsPrefix, StringComparison.OrdinalIgnoreCase))
241+
if (!id.StartsWith(ModConstants.Prefix, StringComparison.OrdinalIgnoreCase) &&
242+
!id.StartsWith(ModConstants.BetterChestsPrefix, StringComparison.OrdinalIgnoreCase))
243243
{
244244
continue;
245245
}

CarryChests/Services/ModPatches.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace LeFauxMods.CarryChest.Services;
1010
/// <summary>Encapsulates mod patches.</summary>
1111
internal static class ModPatches
1212
{
13-
private static readonly Harmony Harmony = new(Constants.ModId);
13+
private static readonly Harmony Harmony = new(ModConstants.ModId);
1414

1515
public static void Apply()
1616
{
@@ -125,9 +125,9 @@ private static void Object_drawInMenu_postfix(
125125
}
126126

127127
var position = location
128-
+ new Vector2(
129-
Game1.tileSize - Utility.getWidthOfTinyDigitString(items, 3f * scaleSize) - (3f * scaleSize),
130-
2f * scaleSize);
128+
+ new Vector2(
129+
Game1.tileSize - Utility.getWidthOfTinyDigitString(items, 3f * scaleSize) - (3f * scaleSize),
130+
2f * scaleSize);
131131

132132
Utility.drawTinyDigits(items, spriteBatch, position, 3f * scaleSize, 1f, color);
133133
}
@@ -166,18 +166,18 @@ private static void Object_placementAction_postfix(
166166
}
167167

168168
var placementTile = new Vector2((int)(x / (float)Game1.tileSize), (int)(y / (float)Game1.tileSize));
169-
if (!location.Objects.TryGetValue(
170-
new Vector2((int)(x / (float)Game1.tileSize), (int)(y / (float)Game1.tileSize)),
171-
out var placedObject)
172-
|| placedObject is not Chest)
169+
if (!location.Objects.TryGetValue(placementTile, out var placedObject)
170+
|| placedObject is not Chest placedChest)
173171
{
174172
return;
175173
}
176174

177-
location.Objects[placementTile] = chest;
178-
chest.localKickStartTile = null;
179-
chest.kickProgress = -1f;
180-
chest.shakeTimer = 50;
175+
placedChest.CopyFieldsFrom(chest);
176+
placedChest.fridge.Value = chest.fridge.Value;
177+
placedChest.playerChoiceColor.Value = chest.playerChoiceColor.Value;
178+
placedChest.SpecialChestType = chest.SpecialChestType;
179+
placedChest.Tint = chest.Tint;
180+
placedChest.GlobalInventoryId = chest.GlobalInventoryId;
181181
who.removeItemFromInventory(who.CurrentItem);
182182
who.showNotCarrying();
183183

@@ -188,10 +188,10 @@ private static void Object_placementAction_postfix(
188188
}
189189

190190
// Move items from temporary global inventory back to chest
191-
if (!string.IsNullOrWhiteSpace(chest.GlobalInventoryId) &&
192-
chest.GlobalInventoryId.StartsWith(Constants.Prefix, StringComparison.OrdinalIgnoreCase))
191+
if (!string.IsNullOrWhiteSpace(placedChest.GlobalInventoryId) &&
192+
placedChest.GlobalInventoryId.StartsWith(ModConstants.Prefix, StringComparison.OrdinalIgnoreCase))
193193
{
194-
chest.ToLocalInventory();
194+
placedChest.ToLocalInventory();
195195
}
196196
}
197197

CarryChests/Services/ModState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private ModState(IModHelper helper)
2323
}
2424

2525
public static Inventory Backups => Instance!.backups ??=
26-
Game1.player.team.GetOrCreateGlobalInventory(Constants.GlobalInventoryId);
26+
Game1.player.team.GetOrCreateGlobalInventory(ModConstants.GlobalInventoryId);
2727

2828
public static ModConfig Config => Instance!.configHelper.Config;
2929

CarryChests/Utilities/ModExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public static bool TryCarry(this Chest chest)
2424
}
2525

2626
// Grab as chest
27-
if ((ModState.Config.TotalLimit > 0
28-
&& Game1.player.Items.OfType<Chest>().Count() >= ModState.Config.TotalLimit)
29-
|| !Game1.player.addItemToInventoryBool(chest, true))
27+
if ((ModState.Config.TotalLimit <= 0
28+
|| Game1.player.Items.OfType<Chest>().Count() < ModState.Config.TotalLimit)
29+
&& !Game1.player.addItemToInventoryBool(chest, true))
3030
{
3131
return false;
3232
}
@@ -38,7 +38,7 @@ public static bool TryCarry(this Chest chest)
3838
chest.TileLocation.Y);
3939

4040
// Copy a backup for safety
41-
_ = ModState.Backups.TryAddBackup(chest, Constants.Prefix);
41+
_ = ModState.Backups.TryAddBackup(chest, ModConstants.Prefix);
4242
return true;
4343
}
4444

0 commit comments

Comments
 (0)