Added in a feature where crops can be planted on hoeAble dirt outside the farm. Also updated the feature to water those tiles when it is raining.

This commit is contained in:
Joshua Navarro 2017-01-06 23:21:34 -08:00
parent 57b70e53fe
commit 3a012cae5e
10 changed files with 431 additions and 191 deletions

View File

@ -47,7 +47,7 @@ namespace Revitalize
bool gametick; bool gametick;
bool mapWipe; bool mapWipe;
public static bool hasLoadedTerrainList;
List<GameLoc> newLoc; List<GameLoc> newLoc;
public override void Entry(IModHelper helper) public override void Entry(IModHelper helper)
@ -58,12 +58,36 @@ namespace Revitalize
StardewModdingAPI.Events.GameEvents.UpdateTick += BedCleanUpCheck; StardewModdingAPI.Events.GameEvents.UpdateTick += BedCleanUpCheck;
StardewModdingAPI.Events.GameEvents.GameLoaded += GameEvents_GameLoaded; StardewModdingAPI.Events.GameEvents.GameLoaded += GameEvents_GameLoaded;
StardewModdingAPI.Events.GameEvents.OneSecondTick += MapWipe; StardewModdingAPI.Events.GameEvents.OneSecondTick += MapWipe;
StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += Util.ResetAllDailyBooleans;
StardewModdingAPI.Events.PlayerEvents.LoadedGame += PlayerEvents_LoadedGame;
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
//StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += Util.WaterAllCropsInAllLocations;
hasCleanedUp = true; hasCleanedUp = true;
hasLoadedTerrainList = false;
path = Helper.DirectoryPath; path = Helper.DirectoryPath;
newLoc = new List<GameLoc>(); newLoc = new List<GameLoc>();
} }
private void GameEvents_UpdateTick(object sender, EventArgs e)
{
if (Game1.player.isMoving() == true && hasLoadedTerrainList == false)
{
Lists.loadAllLists();
Log.AsyncC("CHEEZNIPS!");
Util.WaterAllCropsInAllLocations();
}
}
private void PlayerEvents_LoadedGame(object sender, EventArgsLoadedGameChanged e)
{
}
private void ControlEvents_MouseChanged(object sender, EventArgsMouseStateChanged e) private void ControlEvents_MouseChanged(object sender, EventArgsMouseStateChanged e)
{ {
@ -78,16 +102,19 @@ namespace Revitalize
if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed || mState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed || mState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
{ {
Log.AsyncG("LAME");
// Game1.showRedMessage("YOOO");
//do some stuff when the right button is down
// rotate();
if (Game1.player.ActiveObject != null) if (Game1.player.ActiveObject != null)
{ {
mouseAction = true; mouseAction = true;
if (Game1.player.ActiveObject as GiftPackage != null) (Game1.player.ActiveObject as GiftPackage).getContents();
string s = Game1.player.ActiveObject.getCategoryName();
if (Dictionaries.interactionTypes.ContainsKey(s))
{
Dictionaries.interactFunction f;
Dictionaries.interactionTypes.TryGetValue(s,out f);
f.Invoke();
}
} }
else { else {
@ -106,7 +133,7 @@ namespace Revitalize
private void GameEvents_GameLoaded(object sender, EventArgs e) private void GameEvents_GameLoaded(object sender, EventArgs e)
{ {
Dictionaries.initializeDictionaries(); Dictionaries.initializeDictionaries();
Lists.initializeAllLists();
mapWipe = false; mapWipe = false;
@ -174,13 +201,13 @@ namespace Revitalize
if (hasCleanedUp == false) if (hasCleanedUp == false)
{ {
Log.AsyncC("CleanUp!"); Log.AsyncC("CleanUp!");
CleanUp.cleanUpInventory(); Serialize.cleanUpInventory();
hasCleanedUp = true; hasCleanedUp = true;
} }
} }
else else
{ {
CleanUp.restoreInventory(); Serialize.restoreInventory();
hasCleanedUp = false; hasCleanedUp = false;
} }
} }
@ -206,7 +233,7 @@ namespace Revitalize
private void ShopCall(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) private void ShopCall(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
{ {
Game1.player.money = 9999; Game1.player.money = 9999;
Log.AsyncG(Game1.tileSize); // Log.AsyncG(Game1.tileSize);
//Game1.timeOfDay = 2500; //Game1.timeOfDay = 2500;
if (Game1.activeClickableMenu != null) return; if (Game1.activeClickableMenu != null) return;
@ -222,11 +249,15 @@ namespace Revitalize
objShopList.Add(new Light(3, Vector2.Zero, LightColors.Aquamarine)); objShopList.Add(new Light(3, Vector2.Zero, LightColors.Aquamarine));
objShopList.Add(new Quarry(3, Vector2.Zero,9,"copper")); objShopList.Add(new Quarry(3, Vector2.Zero,9,"copper"));
objShopList.Add(new Decoration(3, Vector2.Zero)); objShopList.Add(new Decoration(3, Vector2.Zero));
objShopList.Add(new StardewValley.Object(495, 1));
foreach(var v in objShopList) objShopList.Add(new StardewValley.Object(496, 1));
objShopList.Add(new StardewValley.Object(497, 1));
objShopList.Add(new StardewValley.Object(498, 1));
objShopList.Add(new StardewValley.Object(770, 1));
foreach (var v in objShopList)
{ {
newInventory.Add(v); newInventory.Add(v);
Log.AsyncG("GRRR"); // Log.AsyncG("GRRR");
} }
objShopList.Add(new GiftPackage(1120, Vector2.Zero,newInventory)); objShopList.Add(new GiftPackage(1120, Vector2.Zero,newInventory));

View File

@ -1,160 +0,0 @@
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using Revitalize;
using Revitalize.Objects;
using Revitalize.Resources;
using Revitalize.Resources.DataNodes;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Revitalize
{
public class CleanUp
{
public static string InvPath;
public static string PlayerDataPath;
public static string DataDirectoryPath;
public static void createDirectories()
{
DataDirectoryPath = Path.Combine(Class1.path, "PlayerData");
PlayerDataPath = Path.Combine(DataDirectoryPath, Game1.player.name);
InvPath = Path.Combine(PlayerDataPath, "Inventory");
if (!Directory.Exists(DataDirectoryPath))
{
Directory.CreateDirectory(DataDirectoryPath);
}
if (!Directory.Exists(PlayerDataPath))
{
Directory.CreateDirectory(PlayerDataPath);
}
if (!Directory.Exists(InvPath))
{
Directory.CreateDirectory(InvPath);
}
}
public static void cleanUpInventory()
{
createDirectories();
List<Item> removalList = new List<Item>();
foreach(Item d in Game1.player.items)
{
try {
if (d == null) {
//Log.AsyncG("WTF");
continue;
}
// Log.AsyncC(d.GetType());
}
catch(Exception e)
{
}
string s = Convert.ToString((d.GetType()));
if (Dictionaries.acceptedTypes.ContainsKey(s))
{
SerializerDataNode t;
bool works= Dictionaries.acceptedTypes.TryGetValue(s, out t);
if (works == true)
{
t.serialize.Invoke(d);
removalList.Add(d);
}
}
}
foreach(var i in removalList)
{
Game1.player.removeItemFromInventory(i);
}
removalList.Clear();
Log.AsyncM("Done cleaning inventory!");
}
public static void restoreInventory()
{
createDirectories();
// Log.AsyncG(InvPath);
ProcessDirectory(InvPath);
}
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
{
ProcessFile(fileName);
File.Delete(fileName);
}
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
string[] ehh = File.ReadAllLines(path);
string data = ehh[0];
Log.AsyncC(data);
dynamic obj = JObject.Parse(data);
// Log.AsyncC(obj.thisType);
string a = obj.thisType;
string[] b = a.Split(',');
string s = b.ElementAt(0);
// Log.AsyncC(s);
if (Dictionaries.acceptedTypes.ContainsKey(s))
{
// Log.AsyncC("FUUUUU");
foreach (KeyValuePair<string, SerializerDataNode> pair in Dictionaries.acceptedTypes)
{
if (pair.Key == s)
{
var cObj = pair.Value.parse.Invoke(data);
Log.AsyncC("NEED TO HANDLE PUTTING OBJECTS BACK INTO A LOCATION!!!!");
if (cObj.thisLocation == null)
{
Game1.player.addItemToInventory(cObj);
return;
}
}
}
}
}
}
}

View File

@ -1015,12 +1015,14 @@ namespace Revitalize.Objects
return Util.invertColor(LightColors.Magenta); return Util.invertColor(LightColors.Magenta);
} }
public virtual void getContents() public virtual void getContents()
{ {
List<Item> removalList = new List<Item>(); List<Item> removalList = new List<Item>();
// Log.AsyncC("step 1"); // Log.AsyncC("step 1");
foreach(var v in this.inventory) foreach (var v in this.inventory)
{ {
if (Game1.player.isInventoryFull() == true) break; if (Game1.player.isInventoryFull() == true) break;
// Log.AsyncC("ok"); // Log.AsyncC("ok");
@ -1030,7 +1032,7 @@ namespace Revitalize.Objects
} }
foreach(var v in removalList) foreach (var v in removalList)
{ {
this.inventory.Remove(v); this.inventory.Remove(v);
} }

View File

@ -0,0 +1,27 @@
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.TerrainFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Revitalize.Resources.DataNodes
{
class TrackedTerrainDataNode
{
public HoeDirt terrainFeature;
public Vector2 position;
public GameLocation location;
public TrackedTerrainDataNode(GameLocation loc, HoeDirt terrain, Vector2 tile)
{
location = loc;
terrainFeature = terrain;
position = tile;
}
}
}

View File

@ -0,0 +1,26 @@
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.TerrainFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Revitalize.Resources.DataNodes
{
class TrackedTerrainDummyDataNode
{
public Vector2 position;
public string location;
public TrackedTerrainDummyDataNode(string loc, Vector2 tile)
{
location = loc;
position = tile;
}
}
}

View File

@ -14,7 +14,10 @@ namespace Revitalize.Resources
public delegate CoreObject par(string data); public delegate CoreObject par(string data);
public delegate void ser(Item item); public delegate void ser(Item item);
public delegate void interactFunction();
public static Dictionary<string, SerializerDataNode> acceptedTypes; public static Dictionary<string, SerializerDataNode> acceptedTypes;
public static Dictionary<string, interactFunction> interactionTypes;
public static Dictionary<string, QuarryDataNode> quarryList; public static Dictionary<string, QuarryDataNode> quarryList;
@ -23,13 +26,14 @@ namespace Revitalize.Resources
{ {
acceptedTypes = new Dictionary<string, SerializerDataNode>(); acceptedTypes = new Dictionary<string, SerializerDataNode>();
quarryList = new Dictionary<string, QuarryDataNode>(); quarryList = new Dictionary<string, QuarryDataNode>();
interactionTypes = new Dictionary<string, interactFunction>();
fillAllDictionaries(); fillAllDictionaries();
} }
public static void fillAllDictionaries() public static void fillAllDictionaries()
{ {
addAllAcceptedTypes(); addAllAcceptedTypes();
addAllInteractionTypes();
fillQuaryList(); fillQuaryList();
} }
@ -44,6 +48,13 @@ namespace Revitalize.Resources
acceptedTypes.Add("Revitalize.Objects.GiftPackage", new SerializerDataNode(new ser(Serialize.serializeGiftPackage), new par(Serialize.parseGiftPackage))); acceptedTypes.Add("Revitalize.Objects.GiftPackage", new SerializerDataNode(new ser(Serialize.serializeGiftPackage), new par(Serialize.parseGiftPackage)));
} }
public static void addAllInteractionTypes()
{
interactionTypes.Add("Seed", Util.plantCropHere);
interactionTypes.Add("Gift Package", Util.getGiftPackageContents);
}
public static void fillQuaryList() public static void fillQuaryList()
{ {

View File

@ -0,0 +1,31 @@
using StardewModdingAPI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Revitalize.Resources
{
class Lists
{
public static List<Revitalize.Resources.DataNodes.TrackedTerrainDataNode> trackedTerrainFeatures;
public static List<Revitalize.Resources.DataNodes.TrackedTerrainDummyDataNode> trackedTerrainFeaturesDummyList;
public static void initializeAllLists()
{
trackedTerrainFeatures = new List<DataNodes.TrackedTerrainDataNode>();
trackedTerrainFeaturesDummyList = new List<DataNodes.TrackedTerrainDummyDataNode>();
}
public static void loadAllLists()
{
Serialize.parseTrackedTerrainDataNodeList(Path.Combine( Serialize.PlayerDataPath ,"TrackedTerrainFeaturesList.json"));
Class1.hasLoadedTerrainList = true;
// Log.AsyncC(Path.Combine(Serialize.PlayerDataPath, "TrackedTerrainFeaturesList.json"));
}
}
}

View File

@ -48,7 +48,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Class1.cs" /> <Compile Include="Class1.cs" />
<Compile Include="CleanUp.cs" />
<Compile Include="CoreObject.cs" /> <Compile Include="CoreObject.cs" />
<Compile Include="GameLoc.cs" /> <Compile Include="GameLoc.cs" />
<Compile Include="Locations\ModTown.cs" /> <Compile Include="Locations\ModTown.cs" />
@ -65,9 +64,12 @@
<Compile Include="Objects\shopObject.cs" /> <Compile Include="Objects\shopObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\DataNodes\SerializerDataNode.cs" /> <Compile Include="Resources\DataNodes\SerializerDataNode.cs" />
<Compile Include="Resources\DataNodes\TrackedTerrainDataNode.cs" />
<Compile Include="Resources\DataNodes\TrackedTerrainDummyDataNode.cs" />
<Compile Include="Resources\Dictionaries.cs" /> <Compile Include="Resources\Dictionaries.cs" />
<Compile Include="Resources\LightColors.cs" /> <Compile Include="Resources\LightColors.cs" />
<Compile Include="Resources\DataNodes\QuarryDataNode.cs" /> <Compile Include="Resources\DataNodes\QuarryDataNode.cs" />
<Compile Include="Resources\Lists.cs" />
<Compile Include="Serialize.cs" /> <Compile Include="Serialize.cs" />
<Compile Include="Util.cs" /> <Compile Include="Util.cs" />
</ItemGroup> </ItemGroup>

View File

@ -8,6 +8,7 @@ using Revitalize.Resources;
using Revitalize.Resources.DataNodes; using Revitalize.Resources.DataNodes;
using StardewModdingAPI; using StardewModdingAPI;
using StardewValley; using StardewValley;
using StardewValley.TerrainFeatures;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -19,6 +20,150 @@ namespace Revitalize
{ {
class Serialize class Serialize
{ {
public static string InvPath;
public static string PlayerDataPath;
public static string DataDirectoryPath;
public static string TrackedTerrainDataPath;
public static void createDirectories()
{
DataDirectoryPath = Path.Combine(Class1.path, "PlayerData");
PlayerDataPath = Path.Combine(DataDirectoryPath, Game1.player.name);
InvPath = Path.Combine(PlayerDataPath, "Inventory");
Log.AsyncC(TrackedTerrainDataPath);
if (!Directory.Exists(DataDirectoryPath))
{
Directory.CreateDirectory(DataDirectoryPath);
}
if (!Directory.Exists(PlayerDataPath))
{
Directory.CreateDirectory(PlayerDataPath);
}
if (!Directory.Exists(InvPath))
{
Directory.CreateDirectory(InvPath);
}
}
public static void cleanUpInventory()
{
List<Item> removalList = new List<Item>();
foreach (Item d in Game1.player.items)
{
try
{
if (d == null)
{
//Log.AsyncG("WTF");
continue;
}
// Log.AsyncC(d.GetType());
}
catch (Exception e)
{
}
string s = Convert.ToString((d.GetType()));
if (Dictionaries.acceptedTypes.ContainsKey(s))
{
SerializerDataNode t;
bool works = Dictionaries.acceptedTypes.TryGetValue(s, out t);
if (works == true)
{
t.serialize.Invoke(d);
removalList.Add(d);
}
}
}
foreach (var i in removalList)
{
Game1.player.removeItemFromInventory(i);
}
removalList.Clear();
Log.AsyncM("Done cleaning inventory!");
}
public static void restoreInventory()
{
// Log.AsyncG(InvPath);
ProcessDirectoryForCleanUp(InvPath);
}
public static void ProcessDirectoryForCleanUp(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
{
ProcessFileForCleanUp(fileName);
File.Delete(fileName);
}
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectoryForCleanUp(subdirectory);
}
// Insert logic for processing found files here.
public static void ProcessFileForCleanUp(string path)
{
string[] ehh = File.ReadAllLines(path);
string data = ehh[0];
Log.AsyncC(data);
dynamic obj = JObject.Parse(data);
// Log.AsyncC(obj.thisType);
string a = obj.thisType;
string[] b = a.Split(',');
string s = b.ElementAt(0);
// Log.AsyncC(s);
if (Dictionaries.acceptedTypes.ContainsKey(s))
{
// Log.AsyncC("FUUUUU");
foreach (KeyValuePair<string, SerializerDataNode> pair in Dictionaries.acceptedTypes)
{
if (pair.Key == s)
{
var cObj = pair.Value.parse.Invoke(data);
Log.AsyncC("NEED TO HANDLE PUTTING OBJECTS BACK INTO A LOCATION!!!!");
if (cObj.thisLocation == null)
{
Game1.player.addItemToInventory(cObj);
return;
}
}
}
}
}
public static void WriteToJsonFile<T>(string filePath, T objectToWrite, bool append = false) where T : new() public static void WriteToJsonFile<T>(string filePath, T objectToWrite, bool append = false) where T : new()
@ -195,7 +340,7 @@ namespace Revitalize
} }
public static void serializeDecoration(Item d) public static void serializeDecoration(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Decoration)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (Decoration)d);
} }
@ -291,7 +436,7 @@ namespace Revitalize
} }
public static void serializeSpawner(Item d) public static void serializeSpawner(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Spawner)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (Spawner)d);
} }
@ -387,7 +532,7 @@ namespace Revitalize
} }
public static void serializeGiftPackage(Item d) public static void serializeGiftPackage(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (GiftPackage)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (GiftPackage)d);
} }
@ -483,7 +628,7 @@ namespace Revitalize
} }
public static void serializeLight(Item d) public static void serializeLight(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Light)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (Light)d);
} }
public static Quarry parseQuarry(string data) public static Quarry parseQuarry(string data)
@ -579,7 +724,7 @@ namespace Revitalize
} }
public static void serializeQuarry(Item d) public static void serializeQuarry(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Quarry)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (Quarry)d);
} }
public static shopObject parseShopObject(string data) public static shopObject parseShopObject(string data)
@ -675,9 +820,57 @@ namespace Revitalize
} }
public static void serializeShopObject(Item d) public static void serializeShopObject(Item d)
{ {
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (shopObject)d); Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (shopObject)d);
} }
public static void parseTrackedTerrainDataNodeList(string data)
{
if (File.Exists(data))
{
Lists.trackedTerrainFeaturesDummyList = ReadFromJsonFile<List<TrackedTerrainDummyDataNode>>(data);
foreach(var v in Lists.trackedTerrainFeaturesDummyList)
{
GameLocation location = Game1.getLocationFromName(v.location);
Vector2 position = v.position;
TerrainFeature t;
bool ehh = location.terrainFeatures.TryGetValue(position, out t);
if (t == null)
{
Log.AsyncC("BOOOOO");
}
Lists.trackedTerrainFeatures.Add(new TrackedTerrainDataNode(location, (HoeDirt)t, position));
// Log.AsyncG("YAY");
}
Lists.trackedTerrainFeaturesDummyList.Clear();
}
}
public static void serializeTrackedTerrainDataNodeList(List<TrackedTerrainDataNode> list)
{
Lists.trackedTerrainFeaturesDummyList.Clear();
foreach(var v in list)
{
Lists.trackedTerrainFeaturesDummyList.Add(new TrackedTerrainDummyDataNode(v.location.name, v.position));
}
if (File.Exists(Path.Combine(PlayerDataPath, "TrackedTerrainFeaturesList.json")))
{
File.Delete(Path.Combine(PlayerDataPath, "TrackedTerrainFeaturesList.json"));
}
if (Lists.trackedTerrainFeaturesDummyList.Count == 0)
{
File.Delete(Path.Combine(PlayerDataPath, "TrackedTerrainFeaturesList.json"));
return;
}
WriteToJsonFile<List<TrackedTerrainDummyDataNode>>(Path.Combine(PlayerDataPath, "TrackedTerrainFeaturesList.json"), Lists.trackedTerrainFeaturesDummyList);
}
public static List<Item> parseInventoryList(JArray array) public static List<Item> parseInventoryList(JArray array)
{ {

View File

@ -1,6 +1,8 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Revitalize.Objects; using Revitalize.Objects;
using Revitalize.Resources;
using StardewModdingAPI; using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley; using StardewValley;
using StardewValley.Locations; using StardewValley.Locations;
using StardewValley.Objects; using StardewValley.Objects;
@ -16,9 +18,19 @@ namespace Revitalize
{ {
class Util class Util
{ {
public static bool hasWateredAllCropsToday;
public static void ResetAllDailyBooleans(object sender, EventArgsIntChanged e)
{
Serialize.createDirectories();
hasWateredAllCropsToday = false;
if (Lists.trackedTerrainFeatures != null)
{
if(Class1.hasLoadedTerrainList== true) Serialize.serializeTrackedTerrainDataNodeList(Lists.trackedTerrainFeatures);
}
Util.WaterAllCropsInAllLocations();
}
public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s){ public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s){
@ -660,5 +672,70 @@ namespace Revitalize
} }
public static void plantCropHere()
{
HoeDirt t;
TerrainFeature r;
bool plant = Game1.player.currentLocation.terrainFeatures.TryGetValue(Game1.currentCursorTile, out r);
t = (r as HoeDirt);
if (t is HoeDirt)
{
if ((t as HoeDirt).crop == null)
{
(t as HoeDirt).crop = new Crop(Game1.player.ActiveObject.parentSheetIndex, (int)Game1.currentCursorTile.X, (int)Game1.currentCursorTile.Y);
Game1.player.reduceActiveItemByOne();
Game1.playSound("dirtyHit");
Revitalize.Resources.Lists.trackedTerrainFeatures.Add(new Resources.DataNodes.TrackedTerrainDataNode(Game1.player.currentLocation,t,new Vector2((int)Game1.currentCursorTile.X,(int)Game1.currentCursorTile.Y)));
}
}
}
/// <summary>
/// Static wrapper;
/// </summary>
public static void getGiftPackageContents()
{
if (Game1.player.ActiveObject as GiftPackage != null)
{
(Game1.player.ActiveObject as GiftPackage).getContents();
}
}
public static void WaterAllCropsInAllLocations()
{
Game1.weatherForTomorrow = Game1.weather_rain;
List<Revitalize.Resources.DataNodes.TrackedTerrainDataNode> removalList = new List<Resources.DataNodes.TrackedTerrainDataNode>();
if (Game1.isRaining)
{
// Log.AsyncC("WHY");
foreach (var v in Lists.trackedTerrainFeatures)
{
if ((v.terrainFeature as HoeDirt).crop==null)
{
removalList.Add(v);
Log.AsyncR("WHY REMOVE???");
continue;
}
if ((v.terrainFeature as HoeDirt).state == 0) (v.terrainFeature as HoeDirt).state = 1;
hasWateredAllCropsToday = true;
}
foreach (var v in removalList)
{
Lists.trackedTerrainFeatures.Remove(v);
}
removalList.Clear();
}
}
} }
} }