Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Framework/Model/PlayerData.cs
#	Framework/NewSaveGameMenuV2.cs
#	Framework/SaveManager.cs
#	manifest.json
  • Loading branch information
RealSweetPanda committed Jan 20, 2023
2 parents 5fad0e5 + 9fdacf5 commit bd6f6a1
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 84 deletions.
146 changes: 80 additions & 66 deletions Framework/NPCExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,94 @@
namespace SaveAnywhere.Framework {
public static class NPCExtensions {
public static void fillInSchedule(this NPC npc) {
if (npc.Schedule == null)
return;
var rawSchedule = GetRawSchedule(npc.Name);
if (rawSchedule == null)
return;
var scheduleKey = GetScheduleKey(npc);
string str;
rawSchedule.TryGetValue(scheduleKey, out str);
if (string.IsNullOrEmpty(str))
return;
var strArray1 = str.Split('/');
var source = new SortedDictionary<int, SchedulePathInfo>();
for (var index = 0; index < strArray1.Length; ++index) {
var strArray2 = strArray1[index].Split(' ');
if (strArray2[0].Equals("GOTO")) {
rawSchedule.TryGetValue(strArray2[1], out str);
strArray1 = str.Split('/');
index = -1;
}

var schedulePathInfo = new SchedulePathInfo(strArray1[index]);
if (schedulePathInfo.timeToGoTo != 0)
source.Add(schedulePathInfo.timeToGoTo, schedulePathInfo);
}
try
{
if (npc.Schedule == null)
return;
var rawSchedule = GetRawSchedule(npc.Name);
if (rawSchedule == null)
return;
var scheduleKey = GetScheduleKey(npc);
string str;
rawSchedule.TryGetValue(scheduleKey, out str);
if (string.IsNullOrEmpty(str))
return;
var strArray1 = str.Split('/');
var source = new SortedDictionary<int, SchedulePathInfo>();
for (var index = 0; index < strArray1.Length; ++index)
{
var strArray2 = strArray1[index].Split(' ');
if (strArray2[0].Equals("GOTO"))
{
rawSchedule.TryGetValue(strArray2[1], out str);
strArray1 = str.Split('/');
continue;
}

var index1 = 0;
var list = source.ToList();
list.OrderBy((Func<KeyValuePair<int, SchedulePathInfo>, int>) (i => i.Key));
KeyValuePair<int, SchedulePathInfo> keyValuePair;
for (var key1 = 600; key1 <= 2600; key1 += 10)
if (index1 >= list.Count && !source.ContainsKey(key1)) {
var sortedDictionary = source;
var key2 = key1;
keyValuePair = list[list.Count - 1];
var schedulePathInfo = keyValuePair.Value;
sortedDictionary.Add(key2, schedulePathInfo);
var schedulePathInfo = new SchedulePathInfo(strArray1[index]);
if (schedulePathInfo.timeToGoTo != 0)
source.Add(schedulePathInfo.timeToGoTo, schedulePathInfo);
}
else if (index1 == list.Count - 1) {
if (!source.ContainsKey(key1)) {

var index1 = 0;
var list = source.ToList();
list.OrderBy((Func<KeyValuePair<int, SchedulePathInfo>, int>)(i => i.Key));
KeyValuePair<int, SchedulePathInfo> keyValuePair;
for (var key1 = 600; key1 <= 2600; key1 += 10)
if (index1 >= list.Count && !source.ContainsKey(key1))
{
var sortedDictionary = source;
var key3 = key1;
keyValuePair = list[index1];
var key2 = key1;
// fix ArgumentOutOfRangeException that happens below
if (list.Count != 0) keyValuePair = list[list.Count - 1];
else keyValuePair = new KeyValuePair<int, SchedulePathInfo>();
var schedulePathInfo = keyValuePair.Value;
sortedDictionary.Add(key3, schedulePathInfo);
sortedDictionary.Add(key2, schedulePathInfo);
}
}
else {
var num = key1;
keyValuePair = list[index1 + 1];
var key4 = keyValuePair.Key;
if (num == key4) {
++index1;
else if (index1 == list.Count - 1)
{
if (!source.ContainsKey(key1))
{
var sortedDictionary = source;
var key3 = key1;
keyValuePair = list[index1];
var schedulePathInfo = keyValuePair.Value;
sortedDictionary.Add(key3, schedulePathInfo);
}
}
else if (!source.ContainsKey(key1)) {
var sortedDictionary = source;
var key5 = key1;
keyValuePair = list[index1];
var schedulePathInfo = keyValuePair.Value;
sortedDictionary.Add(key5, schedulePathInfo);
else
{
var num = key1;
keyValuePair = list[index1 + 1];
var key4 = keyValuePair.Key;
if (num == key4)
{
++index1;
}
else if (!source.ContainsKey(key1))
{
var sortedDictionary = source;
var key5 = key1;
keyValuePair = list[index1];
var schedulePathInfo = keyValuePair.Value;
sortedDictionary.Add(key5, schedulePathInfo);
}
}
}

var schedulePathInfo1 = source[Game1.timeOfDay];
var schedulePathDescription = SaveAnywhere.ModHelper.Reflection
.GetMethod(npc, "pathfindToNextScheduleLocation").Invoke<SchedulePathDescription>(
npc.currentLocation.Name, npc.getTileX(), npc.getTileY(), schedulePathInfo1.endMap,
schedulePathInfo1.endX, schedulePathInfo1.endY, schedulePathInfo1.endDirection,
schedulePathInfo1.endBehavior, schedulePathInfo1.endMessage);
npc.DirectionsToNewLocation = schedulePathDescription;
npc.controller = new PathFindController(npc.DirectionsToNewLocation.route, npc,
Utility.getGameLocationOfCharacter(npc)) {
finalFacingDirection = npc.DirectionsToNewLocation.facingDirection,
endBehaviorFunction = null
};
var schedulePathInfo1 = source[Game1.timeOfDay];
var schedulePathDescription = SaveAnywhere.ModHelper.Reflection
.GetMethod(npc, "pathfindToNextScheduleLocation").Invoke<SchedulePathDescription>(
npc.currentLocation.Name, npc.getTileX(), npc.getTileY(), schedulePathInfo1.endMap,
schedulePathInfo1.endX, schedulePathInfo1.endY, schedulePathInfo1.endDirection,
schedulePathInfo1.endBehavior, schedulePathInfo1.endMessage);
npc.DirectionsToNewLocation = schedulePathDescription;
npc.controller = new PathFindController(npc.DirectionsToNewLocation.route, npc,
Utility.getGameLocationOfCharacter(npc))
{
finalFacingDirection = npc.DirectionsToNewLocation.facingDirection,
endBehaviorFunction = null
};
} catch{}
}

private static IDictionary<string, string> GetRawSchedule(string npcName) {
Expand Down
5 changes: 4 additions & 1 deletion Framework/NewShippingMenuV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class NewShippingMenuV2 : IClickableMenu {
private int timesPokedMoon;
private readonly int totalWidth;
private float weatherX;



public NewShippingMenuV2(IList<Item> items) : base(0, 0, Game1.viewport.Width, Game1.viewport.Height) {
Game1.player.team.endOfNightStatus.UpdateState("shipment");
Expand All @@ -70,6 +72,7 @@ public NewShippingMenuV2(IList<Item> items) : base(0, 0, Game1.viewport.Width, G
centerX = Game1.viewport.Width / 2;
centerY = Game1.viewport.Height / 2;
_hasFinished = false;
outro = true;
var num = -1;
for (var index = 0; index < 6; ++index) {
var categories = this.categories;
Expand Down Expand Up @@ -527,6 +530,7 @@ private void okClicked() {
outroFadeTimer = 800;
Game1.playSound("bigDeSelect");
Game1.changeMusicTrack("none");
Game1.currentLoader = SaveGame.Save();
}

public override void receiveLeftClick(int x, int y, bool playSound = true) {
Expand Down Expand Up @@ -607,7 +611,6 @@ public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBou

public override void draw(SpriteBatch b)
{
SaveAnywhere.ModMonitor.Log("Test",LogLevel.Debug);
if (Game1.wasRainingYesterday) {
b.Draw(Game1.mouseCursors, new Rectangle(0, 0, Game1.viewport.Width, Game1.viewport.Height),
new Rectangle(639, 858, 1, 184),
Expand Down
1 change: 1 addition & 0 deletions Framework/SaveAnywhereAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SaveAnywhere.Framework {
public class SaveAnywhereAPI {

public event EventHandler BeforeSave {
add => SaveAnywhere.Instance.SaveManager.beforeSave += value;
remove => SaveAnywhere.Instance.SaveManager.beforeSave -= value;
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# SaveAnywhere 1.5

#### Updated for SDV 1.5!

Compatible with Stardew Valley 1.5+ on Linux, Mac, and Windows. Requires SMAPI 3.0 or later.

### Install

[Install the latest version of SMAPI.](https://smapi.io/)

Download this mod and unzip it into Stardew Valley/Mods.

Run the game using SMAPI.

### How To Use
Press K to save anywhere. Edit the `config.json` file in a text editor to change the key (it will appear after you run the game once).

Press K to save anywhere. Edit the `config.json` file in a text editor to change the key (it will appear after you run
the game once).

#### Created by Omegasis, Aredjay, CMiSSioN and Sweet Panda

### Notes
*This mod does not work when using mods that add locations due to the map usually. It also does not usually log NPC's that are added to the game via mods. A fix may come in the future to solve this, but not likely for map extensions.*

*This mod is also **semi-experimental meaning that it can crash and cause issues. This is hit or miss. PLEASE BACKUP BEFORE USING** If you have a problem it is probably because of a mod conflict. The best experience will be with no other big mods, Again, this doesn't always happen it's just a thing to take note of.*
*This mod is
also **semi-experimental meaning that it can crash and cause issues. This is hit or miss. PLEASE BACKUP BEFORE USING**
If you have a problem it is probably because of a mod conflict. The best experience will be with no other big mods,
Again, this doesn't always happen it's just a thing to take note of.*
14 changes: 0 additions & 14 deletions SaveAnywhere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e) {
return;
SaveManager.Update();
}

if (Game1.activeClickableMenu == null && Context.IsWorldReady)
IsCustomSaving = false;
if (Game1.activeClickableMenu == null && !customMenuOpen)
return;
if (Game1.activeClickableMenu == null && customMenuOpen) {
customMenuOpen = false;
}
else {
if (Game1.activeClickableMenu == null ||
!(Game1.activeClickableMenu.GetType() == typeof(NewSaveGameMenuV2)))
return;
customMenuOpen = true;
}
}

public void cleanMonsters() {
Expand Down

0 comments on commit bd6f6a1

Please sign in to comment.