From 900c804c29b6dcedef158d3b36fcebb7846e8a16 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Wed, 2 Mar 2016 12:24:15 -0500 Subject: update for new event and other crap --- StardewModdingAPI/Inheritance/SGame.cs | 39 ++++++++++++ StardewModdingAPI/Inheritance/SGameLocation.cs | 88 +++++++------------------- StardewModdingAPI/Inheritance/SObject.cs | 19 +++++- 3 files changed, 80 insertions(+), 66 deletions(-) (limited to 'StardewModdingAPI/Inheritance') diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index fdc6f3f7..fbea47bd 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -49,6 +49,8 @@ namespace StardewModdingAPI.Inheritance public GameLocation PreviousGameLocation { get; private set; } public IClickableMenu PreviousActiveMenu { get; private set; } + public Farmer PreviousFarmer { get; private set; } + protected override void Initialize() { Program.Log("XNA Initialize"); @@ -104,6 +106,12 @@ namespace StardewModdingAPI.Inheritance PreviousGameLocation = Game1.currentLocation; } + if (Game1.player != null && Game1.player != PreviousFarmer) + { + Events.InvokeFarmerChanged(Game1.player); + PreviousFarmer = Game1.player; + } + if (CurrentLocation != null) CurrentLocation.update(gameTime); @@ -184,5 +192,36 @@ namespace StardewModdingAPI.Inheritance } return null; } + + public static SGameLocation LoadOrCreateSGameLocationFromName(String name) + { + if (GetLocationFromName(name) != null) + return GetLocationFromName(name); + else + { + GameLocation gl = Game1.locations.FirstOrDefault(x => x.name == name); + if (gl != null) + { + Program.LogDebug("A custom location was created for the new name: " + name); + SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); + ModLocations.Add(s); + return s; + } + else + { + if (Game1.currentLocation != null && Game1.currentLocation.name == name) + { + gl = Game1.currentLocation; + Program.LogDebug("A custom location was created from the current location for the new name: " + name); + SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); + ModLocations.Add(s); + return s; + } + + Program.LogDebug("A custom location could not be created for: " + name); + return null; + } + } + } } } \ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGameLocation.cs b/StardewModdingAPI/Inheritance/SGameLocation.cs index 14d9afa6..50058bff 100644 --- a/StardewModdingAPI/Inheritance/SGameLocation.cs +++ b/StardewModdingAPI/Inheritance/SGameLocation.cs @@ -18,85 +18,40 @@ namespace StardewModdingAPI.Inheritance public SerializableDictionary ModObjects { get; set; } - public static SGameLocation ConstructFromBaseClass(GameLocation baseClass) + public static SGameLocation ConstructFromBaseClass(GameLocation baseClass, bool copyAllData = false) { SGameLocation s = new SGameLocation(); s.BaseGameLocation = baseClass; - s.ModObjects = new SerializableDictionary(); + s.name = baseClass.name; + + Program.LogDebug("CONSTRUCTED: " + s.name); - foreach (var v in baseClass.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) + if (copyAllData) { - try + foreach (var v in baseClass.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { - var fi = s.GetType().GetField(v.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - if (fi != null && !fi.IsStatic) + try { - fi.SetValue(s, v.GetValue(baseClass)); - //Console.WriteLine("SET {0} ON {1} TO {2}", fi.Name, s.name, v.GetValue(baseClass)); + var fi = s.GetType().GetField(v.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + if (fi != null && !fi.IsStatic) + { + fi.SetValue(s, v.GetValue(baseClass)); + //Console.WriteLine("SET {0} ON {1} TO {2}", fi.Name, s.name, v.GetValue(baseClass)); + } + } + catch (Exception ex) + { + Program.LogError(ex); } - } - catch (Exception ex) - { - Program.LogError(ex); } } - //s.IsFarm = baseClass.IsFarm; - //s.IsOutdoors = baseClass.IsOutdoors; - //s.LightLevel = baseClass.LightLevel; - //s.Map = baseClass.Map; - //s.objects = baseClass.objects; - //s.temporarySprites = baseClass.temporarySprites; - - /* - s.actionObjectForQuestionDialogue = baseClass.actionObjectForQuestionDialogue; - s.characters = baseClass.characters; - s.critters = (List)typeof(GameLocation).GetField("critters", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(baseClass); - s.currentEvent = baseClass.currentEvent; - s.debris = baseClass.debris; - s.doorSprites = baseClass.doorSprites; - s.doors = baseClass.doors; - s.farmers = baseClass.farmers; - s.fishSplashAnimation = baseClass.fishSplashAnimation; - s.fishSplashPoint = baseClass.fishSplashPoint; - s.forceViewportPlayerFollow = baseClass.forceViewportPlayerFollow; - s.ignoreDebrisWeather = baseClass.ignoreDebrisWeather; - s.ignoreLights = baseClass.ignoreLights; - s.ignoreOutdoorLighting = baseClass.ignoreOutdoorLighting; - s.isFarm = baseClass.isFarm; - s.isOutdoors = baseClass.isOutdoors; - s.isStructure = baseClass.isStructure; - s.largeTerrainFeatures = baseClass.largeTerrainFeatures; - s.lastQuestionKey = baseClass.lastQuestionKey; - s.lastTouchActionLocation = baseClass.lastTouchActionLocation; - s.lightGlows = baseClass.lightGlows; - s.map = baseClass.map; - s.name = baseClass.name; - s.numberOfSpawnedObjectsOnMap = baseClass.numberOfSpawnedObjectsOnMap; - s.objects = baseClass.objects; - s.orePanAnimation = baseClass.orePanAnimation; - s.orePanPoint = baseClass.orePanPoint; - s.projectiles = baseClass.projectiles; - s.temporarySprites = baseClass.temporarySprites; - s.terrainFeatures = baseClass.terrainFeatures; - s.uniqueName = baseClass.uniqueName; - s.warps = baseClass.warps; - s.wasUpdated = (bool)typeof(GameLocation).GetField("wasUpdated", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(baseClass); - s.waterAnimationIndex = baseClass.waterAnimationIndex; - s.waterAnimationTimer = baseClass.waterAnimationTimer; - s.waterColor = baseClass.waterColor; - s.waterTileFlip = baseClass.waterTileFlip; - s.waterTiles = baseClass.waterTiles; - */ - - - return s; } - public static List ConvertGameLocations(List baseGameLocations) + public static List ConstructFromBaseClasses(List baseGameLocations, bool copyAllData = false) { - return baseGameLocations.Select(ConstructFromBaseClass).ToList(); + return baseGameLocations.Select(gl => ConstructFromBaseClass(gl, copyAllData)).ToList(); } public virtual void update(GameTime gameTime) @@ -110,5 +65,10 @@ namespace StardewModdingAPI.Inheritance v.Value.draw(b, (int)v.Key.X, (int)v.Key.Y, 0.999f, 1); } } + + public SGameLocation() + { + ModObjects = new SerializableDictionary(); + } } } diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 97d2fa41..5e36b5b7 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -48,13 +48,23 @@ namespace StardewModdingAPI.Inheritance public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) { - if (Texture != null) - spriteBatch.Draw(Texture, new Vector2(x, y), new Color(255, 255, 255, 255f * alpha)); + { + int targSize = Game1.tileSize; + int midX = (int) ((x) + 32); + int midY = (int) ((y) + 32); + + int targX = midX - targSize / 2; + int targY = midY - targSize / 2; + + Rectangle targ = new Rectangle(targX, targY, targSize, targSize); + spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha), 0, Vector2.Zero, SpriteEffects.None, 0.999f); + } } public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { + Program.LogInfo("DRAW ME2"); return; try { @@ -183,6 +193,11 @@ namespace StardewModdingAPI.Inheritance public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { + Vector2 key = new Vector2(x, y); + if (!location.objects.ContainsKey(key)) + location.objects.Add(key, this); + return false; + SGameLocation s = SGame.GetLocationFromName(location.name); if (s.GetHashCode() != SGame.CurrentLocation.GetHashCode()) -- cgit From 47fecbd81eeecd9244ee2384f99bc224d5475029 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Wed, 2 Mar 2016 22:54:37 -0500 Subject: more events --- Release/Mods/TrainerMod.dll | Bin 23040 -> 23040 bytes Release/SMAPI_0.35.zip | Bin 0 -> 32394 bytes Release/StardewModdingAPI.exe | Bin 59904 -> 64512 bytes StardewModdingAPI/Events.cs | 28 ++++ StardewModdingAPI/Inheritance/SGame.cs | 197 ++++++++++++++----------- StardewModdingAPI/Inheritance/SGameLocation.cs | 1 + StardewModdingAPI/Inheritance/SObject.cs | 103 ++++++++----- StardewModdingAPI/Program.cs | 22 +-- TrainerMod/TrainerMod.cs | 5 + TrainerMod/bin/Debug/TrainerMod.dll | Bin 23040 -> 23040 bytes TrainerMod/obj/Debug/TrainerMod.dll | Bin 23040 -> 23040 bytes 11 files changed, 214 insertions(+), 142 deletions(-) create mode 100644 Release/SMAPI_0.35.zip (limited to 'StardewModdingAPI/Inheritance') diff --git a/Release/Mods/TrainerMod.dll b/Release/Mods/TrainerMod.dll index 4552ec76..2ca9ad54 100644 Binary files a/Release/Mods/TrainerMod.dll and b/Release/Mods/TrainerMod.dll differ diff --git a/Release/SMAPI_0.35.zip b/Release/SMAPI_0.35.zip new file mode 100644 index 00000000..fd587597 Binary files /dev/null and b/Release/SMAPI_0.35.zip differ diff --git a/Release/StardewModdingAPI.exe b/Release/StardewModdingAPI.exe index 3310bfc4..f47bb06e 100644 Binary files a/Release/StardewModdingAPI.exe and b/Release/StardewModdingAPI.exe differ diff --git a/StardewModdingAPI/Events.cs b/StardewModdingAPI/Events.cs index 9a92b705..97e55d8d 100644 --- a/StardewModdingAPI/Events.cs +++ b/StardewModdingAPI/Events.cs @@ -42,6 +42,14 @@ namespace StardewModdingAPI public delegate void FarmerChangedD(Farmer newFarmer); public static event FarmerChangedD FarmerChanged = delegate { }; + public delegate void IntChanged(Int32 newInt); + public static event IntChanged TimeOfDayChanged = delegate { }; + public static event IntChanged DayOfMonthChanged = delegate { }; + public static event IntChanged YearOfGameChanged = delegate { }; + + public delegate void StringChanged(String newString); + public static event StringChanged SeasonOfYearChanged = delegate { }; + public static void InvokeGameLoaded() { GameLoaded.Invoke(); @@ -134,5 +142,25 @@ namespace StardewModdingAPI { FarmerChanged.Invoke(newFarmer); } + + public static void InvokeTimeOfDayChanged(Int32 newInt) + { + TimeOfDayChanged.Invoke(newInt); + } + + public static void InvokeDayOfMonthChanged(Int32 newInt) + { + DayOfMonthChanged.Invoke(newInt); + } + + public static void InvokeYearOfGameChanged(Int32 newInt) + { + YearOfGameChanged.Invoke(newInt); + } + + public static void InvokeSeasonOfYearChanged(String newString) + { + SeasonOfYearChanged.Invoke(newString); + } } } diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index fbea47bd..27eb3c4b 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -1,19 +1,12 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text; -using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using StardewValley; using StardewValley.Menus; -using StardewValley.Minigames; namespace StardewModdingAPI.Inheritance { @@ -49,6 +42,11 @@ namespace StardewModdingAPI.Inheritance public GameLocation PreviousGameLocation { get; private set; } public IClickableMenu PreviousActiveMenu { get; private set; } + public Int32 PreviousTimeOfDay { get; private set; } + public Int32 PreviousDayOfMonth { get; private set; } + public String PreviousSeasonOfYear { get; private set; } + public Int32 PreviousYearOfGame { get; private set; } + public Farmer PreviousFarmer { get; private set; } protected override void Initialize() @@ -69,53 +67,18 @@ namespace StardewModdingAPI.Inheritance protected override void Update(GameTime gameTime) { - KStateNow = Keyboard.GetState(); - CurrentlyPressedKeys = KStateNow.GetPressedKeys(); - MStateNow = Mouse.GetState(); - - foreach (Keys k in FramePressedKeys) - Events.InvokeKeyPressed(k); - - if (KStateNow != KStatePrior) - { - Events.InvokeKeyboardChanged(KStateNow); - KStatePrior = KStateNow; - } - - if (MStateNow != MStatePrior) - { - Events.InvokeMouseChanged(MStateNow); - MStatePrior = MStateNow; - } - - if (Game1.activeClickableMenu != null && Game1.activeClickableMenu != PreviousActiveMenu) - { - Events.InvokeMenuChanged(Game1.activeClickableMenu); - PreviousActiveMenu = Game1.activeClickableMenu; - } - - if (Game1.locations.GetHash() != PreviousGameLocations) - { - Events.InvokeLocationsChanged(Game1.locations); - PreviousGameLocations = Game1.locations.GetHash(); - } + UpdateEventCalls(); - if (Game1.currentLocation != PreviousGameLocation) + try { - Events.InvokeCurrentLocationChanged(Game1.currentLocation); - PreviousGameLocation = Game1.currentLocation; + base.Update(gameTime); } - - if (Game1.player != null && Game1.player != PreviousFarmer) + catch (Exception ex) { - Events.InvokeFarmerChanged(Game1.player); - PreviousFarmer = Game1.player; + Program.LogError("An error occured in the base update loop: " + ex); + Console.ReadKey(); } - if (CurrentLocation != null) - CurrentLocation.update(gameTime); - - base.Update(gameTime); Events.InvokeUpdateTick(); PreviouslyPressedKeys = CurrentlyPressedKeys; @@ -126,15 +89,15 @@ namespace StardewModdingAPI.Inheritance base.Draw(gameTime); Events.InvokeDrawTick(); - if (Program.debug) + if (false) { spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); if (CurrentLocation != null) - CurrentLocation.draw(Game1.spriteBatch); + CurrentLocation.draw(spriteBatch); if (player != null && player.position != null) - spriteBatch.DrawString(Game1.dialogueFont, Game1.player.position.ToString(), new Vector2(0, 180), Color.Orange); + spriteBatch.DrawString(dialogueFont, player.position.ToString(), new Vector2(0, 180), Color.Orange); spriteBatch.End(); } @@ -164,24 +127,15 @@ namespace StardewModdingAPI.Inheritance { return ModItems.ElementAt(id).Value.Clone(); } - else - { - Program.LogError("ModItem Dictionary does not contain index: " + id); - return null; - } + Program.LogError("ModItem Dictionary does not contain index: " + id); + return null; } - else + if (ModItems.ContainsKey(id)) { - if (ModItems.ContainsKey(id)) - { - return ModItems[id].Clone(); - } - else - { - Program.LogError("ModItem Dictionary does not contain ID: " + id); - return null; - } + return ModItems[id].Clone(); } + Program.LogError("ModItem Dictionary does not contain ID: " + id); + return null; } public static SGameLocation GetLocationFromName(String name) @@ -197,30 +151,95 @@ namespace StardewModdingAPI.Inheritance { if (GetLocationFromName(name) != null) return GetLocationFromName(name); - else + GameLocation gl = locations.FirstOrDefault(x => x.name == name); + if (gl != null) { - GameLocation gl = Game1.locations.FirstOrDefault(x => x.name == name); - if (gl != null) - { - Program.LogDebug("A custom location was created for the new name: " + name); - SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); - ModLocations.Add(s); - return s; - } - else - { - if (Game1.currentLocation != null && Game1.currentLocation.name == name) - { - gl = Game1.currentLocation; - Program.LogDebug("A custom location was created from the current location for the new name: " + name); - SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); - ModLocations.Add(s); - return s; - } - - Program.LogDebug("A custom location could not be created for: " + name); - return null; - } + Program.LogDebug("A custom location was created for the new name: " + name); + SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); + ModLocations.Add(s); + return s; + } + if (currentLocation != null && currentLocation.name == name) + { + gl = currentLocation; + Program.LogDebug("A custom location was created from the current location for the new name: " + name); + SGameLocation s = SGameLocation.ConstructFromBaseClass(gl); + ModLocations.Add(s); + return s; + } + + Program.LogDebug("A custom location could not be created for: " + name); + return null; + } + + + public void UpdateEventCalls() + { + KStateNow = Keyboard.GetState(); + CurrentlyPressedKeys = KStateNow.GetPressedKeys(); + MStateNow = Mouse.GetState(); + + foreach (Keys k in FramePressedKeys) + Events.InvokeKeyPressed(k); + + if (KStateNow != KStatePrior) + { + Events.InvokeKeyboardChanged(KStateNow); + KStatePrior = KStateNow; + } + + if (MStateNow != MStatePrior) + { + Events.InvokeMouseChanged(MStateNow); + MStatePrior = MStateNow; + } + + if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu) + { + Events.InvokeMenuChanged(activeClickableMenu); + PreviousActiveMenu = activeClickableMenu; + } + + if (locations.GetHash() != PreviousGameLocations) + { + Events.InvokeLocationsChanged(locations); + PreviousGameLocations = locations.GetHash(); + } + + if (currentLocation != PreviousGameLocation) + { + Events.InvokeCurrentLocationChanged(currentLocation); + PreviousGameLocation = currentLocation; + } + + if (player != null && player != PreviousFarmer) + { + Events.InvokeFarmerChanged(player); + PreviousFarmer = player; + } + + if (timeOfDay != PreviousTimeOfDay) + { + Events.InvokeTimeOfDayChanged(timeOfDay); + PreviousTimeOfDay = timeOfDay; + } + + if (dayOfMonth != PreviousDayOfMonth) + { + Events.InvokeDayOfMonthChanged(dayOfMonth); + PreviousDayOfMonth = dayOfMonth; + } + + if (currentSeason != PreviousSeasonOfYear) + { + Events.InvokeSeasonOfYearChanged(currentSeason); + PreviousSeasonOfYear = currentSeason; + } + + if (year != PreviousYearOfGame) + { + Events.InvokeYearOfGameChanged(year); + PreviousYearOfGame = year; } } } diff --git a/StardewModdingAPI/Inheritance/SGameLocation.cs b/StardewModdingAPI/Inheritance/SGameLocation.cs index 50058bff..0787c0e1 100644 --- a/StardewModdingAPI/Inheritance/SGameLocation.cs +++ b/StardewModdingAPI/Inheritance/SGameLocation.cs @@ -12,6 +12,7 @@ using StardewValley.BellsAndWhistles; namespace StardewModdingAPI.Inheritance { + [Obsolete] public class SGameLocation : GameLocation { public GameLocation BaseGameLocation { get; private set; } diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 5e36b5b7..9d112859 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -12,7 +12,10 @@ namespace StardewModdingAPI.Inheritance { public class SObject : StardewValley.Object { - public override String Name { get; set; } + public override String Name { + get { return name; } + set { name = value; } + } public String Description { get; set; } public Texture2D Texture { get; set; } public String CategoryName { get; set; } @@ -29,9 +32,18 @@ namespace StardewModdingAPI.Inheritance public Boolean FlaggedForPickup { get; set; } + public Vector2 CurrentMouse { get; protected set; } + public Vector2 PlacedAt { get; protected set; } + + public override int Stack + { + get { return stack; } + set { stack = value; } + } + public SObject() { - Name = "Modded Item Name"; + name = "Modded Item Name"; Description = "Modded Item Description"; CategoryName = "Modded Item Category"; Category = 4163; @@ -39,6 +51,9 @@ namespace StardewModdingAPI.Inheritance IsPassable = false; IsPlaceable = false; boundingBox = new Rectangle(0, 0, 64, 64); + MaxStackSize = 999; + + type = "interactive"; } public override string getDescription() @@ -49,22 +64,20 @@ namespace StardewModdingAPI.Inheritance public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) { if (Texture != null) - { - int targSize = Game1.tileSize; - int midX = (int) ((x) + 32); - int midY = (int) ((y) + 32); - - int targX = midX - targSize / 2; - int targY = midY - targSize / 2; + { + int targSize = Game1.tileSize; + int midX = (int) ((x) + 32); + int midY = (int) ((y) + 32); - Rectangle targ = new Rectangle(targX, targY, targSize, targSize); - spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha), 0, Vector2.Zero, SpriteEffects.None, 0.999f); - } + Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2(x,y)); + Rectangle targ = new Rectangle((int)local.X, (int)local.Y, targSize, targSize); + spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha)); + } } public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { - Program.LogInfo("DRAW ME2"); + Program.LogInfo("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED"); return; try { @@ -191,39 +204,51 @@ namespace StardewModdingAPI.Inheritance return this.Clone(); } + public override void actionWhenBeingHeld(Farmer who) + { + Point p = Game1.getMousePosition(); + CurrentMouse = new Vector2(p.X, p.Y); + base.actionWhenBeingHeld(who); + } + + public override bool canBePlacedHere(GameLocation l, Vector2 tile) + { + if (!l.objects.ContainsKey(tile)) + return true; + + return false; + } + public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { + x = (x / Game1.tileSize) * Game1.tileSize; + y = (y / Game1.tileSize) * Game1.tileSize; + Vector2 key = new Vector2(x, y); - if (!location.objects.ContainsKey(key)) - location.objects.Add(key, this); - return false; - SGameLocation s = SGame.GetLocationFromName(location.name); + if (!canBePlacedHere(location, key)) + return false; - if (s.GetHashCode() != SGame.CurrentLocation.GetHashCode()) - { - Program.LogError("HASH DIFFERENCE: " + s.GetHashCode() + " | " + SGame.ModLocations[SGame.ModLocations.IndexOf(SGame.ModLocations.First(z => z.name == location.name))].GetHashCode() + " | " + SGame.CurrentLocation.GetHashCode()); - Console.ReadKey(); - } + SObject s = Clone(); - Console.Title = (this.GetHashCode() + " PLACEMENT"); + s.PlacedAt = key; + s.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); - if (s != null) - { - Vector2 index1 = new Vector2(x - (Game1.tileSize / 2), y - (Game1.tileSize / 2)); - if (!s.ModObjects.ContainsKey(index1)) - { - s.ModObjects.Add(index1, this); - Game1.player.position = index1; - return true; - } - } - else - { - Program.LogError("No SGameLocation could be found for the supplied GameLocation!"); - return false; - } - return false; + location.objects.Add(key, s); + Program.LogInfo("{0} - {1}", this.GetHashCode(), s.GetHashCode()); + + return true; + } + + public override void actionOnPlayerEntry() + { + //base.actionOnPlayerEntry(); + } + + public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) + { + if (canBePlacedHere(location, CurrentMouse)) + base.drawPlacementBounds(spriteBatch, location); } } } \ No newline at end of file diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 53a1a2c7..a58a5f9b 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -49,12 +49,14 @@ namespace StardewModdingAPI public static Thread gameThread; public static Thread consoleInputThread; - public const string Version = "0.34 Alpha"; + public const string Version = "0.35 Alpha"; public const bool debug = false; public static bool disableLogging { get; private set; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + private static void Main(string[] args) { Console.Title = "Stardew Modding API Console"; @@ -62,8 +64,6 @@ namespace StardewModdingAPI Console.Title += " - Version " + Version; if (debug) Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR FORGOT TO INCREMENT VERSION VARS"; - - //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -178,8 +178,8 @@ namespace StardewModdingAPI if (debug) { //Experimental - Events.LocationsChanged += Events_LocationsChanged; - Events.CurrentLocationChanged += Events_CurrentLocationChanged; + //Events.LocationsChanged += Events_LocationsChanged; + //Events.CurrentLocationChanged += Events_CurrentLocationChanged; } //Do tweaks using winforms invoke because I'm lazy @@ -349,6 +349,9 @@ namespace StardewModdingAPI so2.IsPlaceable = true; LogColour(ConsoleColor.Cyan, "REGISTERED WITH ID OF: " + SGame.RegisterModItem(so2)); } + + if (debug) + Command.CallCommand("load"); } static void Events_KeyPressed(Keys key) @@ -404,10 +407,6 @@ namespace StardewModdingAPI File.WriteAllText(Program.LogPath + "\\MODDED_ErrorLog_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - static void help_CommandFired(Command cmd) { if (cmd.CalledArgs.Length > 0) @@ -427,11 +426,6 @@ namespace StardewModdingAPI LogInfo("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - #region Logging public static void Log(object o, params object[] format) diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index 250ccab5..a9896aac 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -46,6 +46,9 @@ namespace TrainerMod static void Events_UpdateTick() { + if (Game1.player == null) + return; + if (infHealth) { Game1.player.health = Game1.player.maxHealth; @@ -756,6 +759,8 @@ namespace TrainerMod static void RegisterNewItem(Command cmd) { + if (!Program.debug) + return; SObject s = SGame.PullModItemFromDict(0, true); s.Stack = 999; Game1.player.addItemToInventory(s); diff --git a/TrainerMod/bin/Debug/TrainerMod.dll b/TrainerMod/bin/Debug/TrainerMod.dll index 4552ec76..2ca9ad54 100644 Binary files a/TrainerMod/bin/Debug/TrainerMod.dll and b/TrainerMod/bin/Debug/TrainerMod.dll differ diff --git a/TrainerMod/obj/Debug/TrainerMod.dll b/TrainerMod/obj/Debug/TrainerMod.dll index 4552ec76..2ca9ad54 100644 Binary files a/TrainerMod/obj/Debug/TrainerMod.dll and b/TrainerMod/obj/Debug/TrainerMod.dll differ -- cgit From 250559d227fa3a8148ad97d75a725ed0a47a0f4f Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Wed, 2 Mar 2016 23:38:51 -0500 Subject: we can have more than 2 args in a command, c'mon brain --- Release/Mods/TrainerMod.dll | Bin 23040 -> 23552 bytes Release/StardewModdingAPI.exe | Bin 64512 -> 66560 bytes StardewModdingAPI/Command.cs | 2 +- StardewModdingAPI/Inheritance/SGame.cs | 8 ++++++++ StardewModdingAPI/Inheritance/SObject.cs | 18 ++++++++++++++---- StardewModdingAPI/Program.cs | 7 ++++--- TrainerMod/TrainerMod.cs | 1 + TrainerMod/bin/Debug/TrainerMod.dll | Bin 23040 -> 23552 bytes TrainerMod/obj/Debug/TrainerMod.dll | Bin 23040 -> 23552 bytes 9 files changed, 28 insertions(+), 8 deletions(-) (limited to 'StardewModdingAPI/Inheritance') diff --git a/Release/Mods/TrainerMod.dll b/Release/Mods/TrainerMod.dll index 2ca9ad54..9fc10782 100644 Binary files a/Release/Mods/TrainerMod.dll and b/Release/Mods/TrainerMod.dll differ diff --git a/Release/StardewModdingAPI.exe b/Release/StardewModdingAPI.exe index f47bb06e..aa593708 100644 Binary files a/Release/StardewModdingAPI.exe and b/Release/StardewModdingAPI.exe differ diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs index 1659b1e9..c65e8122 100644 --- a/StardewModdingAPI/Command.cs +++ b/StardewModdingAPI/Command.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI { args = input.Split(new[] {" "}, 2, StringSplitOptions.RemoveEmptyEntries); fnd = FindCommand(args[0]); - args = args[1].Split(new[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries); + args = args[1].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); } else { diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 27eb3c4b..99db73d9 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -49,6 +49,14 @@ namespace StardewModdingAPI.Inheritance public Farmer PreviousFarmer { get; private set; } + public SGame() + { + if (Program.debug) + { + //SaveGame.serializer. + } + } + protected override void Initialize() { Program.Log("XNA Initialize"); diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 9d112859..5c80cd52 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Serialization; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; @@ -66,8 +67,6 @@ namespace StardewModdingAPI.Inheritance if (Texture != null) { int targSize = Game1.tileSize; - int midX = (int) ((x) + 32); - int midY = (int) ((y) + 32); Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2(x,y)); Rectangle targ = new Rectangle((int)local.X, (int)local.Y, targSize, targSize); @@ -207,12 +206,14 @@ namespace StardewModdingAPI.Inheritance public override void actionWhenBeingHeld(Farmer who) { Point p = Game1.getMousePosition(); - CurrentMouse = new Vector2(p.X, p.Y); + CurrentMouse = new Vector2((p.X / Game1.tileSize), (p.Y / Game1.tileSize)); + Program.LogInfo(canBePlacedHere(Game1.currentLocation, CurrentMouse)); base.actionWhenBeingHeld(who); } public override bool canBePlacedHere(GameLocation l, Vector2 tile) { + Program.LogInfo(CurrentMouse.ToString().Replace("{", "").Replace("}", "")); if (!l.objects.ContainsKey(tile)) return true; @@ -221,6 +222,9 @@ namespace StardewModdingAPI.Inheritance public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { + if (Game1.didPlayerJustRightClick()) + return false; + x = (x / Game1.tileSize) * Game1.tileSize; y = (y / Game1.tileSize) * Game1.tileSize; @@ -248,7 +252,13 @@ namespace StardewModdingAPI.Inheritance public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) { if (canBePlacedHere(location, CurrentMouse)) - base.drawPlacementBounds(spriteBatch, location); + { + int targSize = Game1.tileSize; + + int x = Game1.oldMouseState.X + Game1.viewport.X; + int y = Game1.oldMouseState.Y + Game1.viewport.Y; + spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)(x / Game1.tileSize * Game1.tileSize - Game1.viewport.X), (float)(y / Game1.tileSize * Game1.tileSize - Game1.viewport.Y)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(Utility.playerCanPlaceItemHere(location, (Item)this, x, y, Game1.player) ? 194 : 210, 388, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 0.01f); + } } } } \ No newline at end of file diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index a58a5f9b..313fcbe5 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -49,8 +49,8 @@ namespace StardewModdingAPI public static Thread gameThread; public static Thread consoleInputThread; - public const string Version = "0.35 Alpha"; - public const bool debug = false; + public const string Version = "0.36 Alpha"; + public const bool debug = true; public static bool disableLogging { get; private set; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -63,7 +63,7 @@ namespace StardewModdingAPI Console.Title += " - Version " + Version; if (debug) - Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR FORGOT TO INCREMENT VERSION VARS"; + Console.Title += " - DEBUG IS NOT FALSE, AUTHOUR NEEDS TO REUPLOAD THIS VERSION"; //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -84,6 +84,7 @@ namespace StardewModdingAPI } catch (Exception ex) { + LogError("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); } } diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index a9896aac..86b03673 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -602,6 +602,7 @@ namespace TrainerMod int quality = 0; if (cmd.CalledArgs.Length > 1) { + Console.WriteLine(cmd.CalledArgs[1]); if (cmd.CalledArgs[1].IsInt32()) { count = cmd.CalledArgs[1].AsInt32(); diff --git a/TrainerMod/bin/Debug/TrainerMod.dll b/TrainerMod/bin/Debug/TrainerMod.dll index 2ca9ad54..9fc10782 100644 Binary files a/TrainerMod/bin/Debug/TrainerMod.dll and b/TrainerMod/bin/Debug/TrainerMod.dll differ diff --git a/TrainerMod/obj/Debug/TrainerMod.dll b/TrainerMod/obj/Debug/TrainerMod.dll index 2ca9ad54..9fc10782 100644 Binary files a/TrainerMod/obj/Debug/TrainerMod.dll and b/TrainerMod/obj/Debug/TrainerMod.dll differ -- cgit