From b707e2c47a466f8371f383493b67739bc575bb70 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 4 Nov 2024 22:50:58 -0500 Subject: [PATCH] add rewriters for location tile method changes --- .../StardewValley_1_6/GameLocationFacade.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/GameLocationFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/GameLocationFacade.cs index 40351718c..f7545f981 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/GameLocationFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/GameLocationFacade.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Microsoft.Xna.Framework; using Netcode; using StardewModdingAPI.Framework.ModLoading.Framework; @@ -7,6 +8,7 @@ using StardewValley.Buildings; using StardewValley.Extensions; using StardewValley.Objects; +using xTile; using xTile.Dimensions; namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6; @@ -80,6 +82,24 @@ public string GetSeasonForLocation() return base.GetSeasonKey(); } + /// Changed in Stardew Valley 1.6.9. + public int getTileIndexAt(Location p, string layer) + { + return base.getTileIndexAt(p, layer); + } + + /// Changed in Stardew Valley 1.6.9. + public int getTileIndexAt(Point p, string layer) + { + return base.getTileIndexAt(p.X, p.Y, layer); + } + + /// Changed in Stardew Valley 1.6.9. + public int getTileIndexAt(int x, int y, string layer) + { + return base.getTileIndexAt(x, y, layer); + } + /// Changed in Stardew Valley 1.6.9. public bool hasLightSource(int identifier) { @@ -183,6 +203,30 @@ public void removeLightSource(int identifier) base.removeLightSource(identifier.ToString()); } + /// Changed in Stardew Valley 1.6.9. + public void setAnimatedMapTile(int tileX, int tileY, int[] animationTileIndexes, long interval, string layer, string action, int whichTileSheet = 0) + { + if (GameLocationFacade.TryGetTileSheetId(this, whichTileSheet, out string? tilesheetId)) + base.setAnimatedMapTile(tileX, tileY, animationTileIndexes, interval, layer, tilesheetId, action); + } + + /// Changed in Stardew Valley 1.6.9. + public void setMapTile(int tileX, int tileY, int index, string layer, string action, int whichTileSheet = 0) + { + if (GameLocationFacade.TryGetTileSheetId(this, whichTileSheet, out string? tilesheetId)) + base.setMapTile(tileX, tileY, index, layer, tilesheetId, action); + } + + /// Changed in Stardew Valley 1.6.9. + public void setMapTileIndex(int tileX, int tileY, int index, string layer, int whichTileSheet = 0) + { + if (index == -1) + base.removeMapTile(tileX, tileY, layer); + + else if (GameLocationFacade.TryGetTileSheetId(this, whichTileSheet, out string? tilesheetId)) + base.setMapTile(tileX, tileY, index, layer, tilesheetId); + } + /********* ** Private methods @@ -191,4 +235,23 @@ private GameLocationFacade() { RewriteHelper.ThrowFakeConstructorCalled(); } + + /// Get the ID for the tilesheet at the given index in this location's . + /// The location whose tilesheets to search. + /// The index to check. + /// The ID of the tilesheet, if found. + /// Returns whether the index was within the bounds of the tilesheet list. + private static bool TryGetTileSheetId(GameLocation location, int index, [NotNullWhen(true)] out string? id) + { + var tilesheets = location.map?.TileSheets; + + if (tilesheets is not null && index >= 0 && index < tilesheets.Count) + { + id = tilesheets[index].Id; + return true; + } + + id = null; + return false; + } }