From d9adaf73869ce768686301ef30687a5fc18048a0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 31 Oct 2016 12:05:02 -0400 Subject: split combined class files per .NET conventions --- src/StardewModdingAPI/Events/ControlEvents.cs | 58 ++++ src/StardewModdingAPI/Events/Controls.cs | 58 ---- src/StardewModdingAPI/Events/EventArgs.cs | 272 ------------------- .../Events/EventArgsClickableMenuChanged.cs | 17 ++ .../Events/EventArgsClickableMenuClosed.cs | 15 ++ src/StardewModdingAPI/Events/EventArgsCommand.cs | 14 + .../Events/EventArgsControllerButtonPressed.cs | 18 ++ .../Events/EventArgsControllerButtonReleased.cs | 18 ++ .../Events/EventArgsControllerTriggerPressed.cs | 20 ++ .../Events/EventArgsControllerTriggerReleased.cs | 20 ++ .../Events/EventArgsCurrentLocationChanged.cs | 17 ++ .../Events/EventArgsFarmerChanged.cs | 17 ++ .../Events/EventArgsGameLocationsChanged.cs | 16 ++ .../Events/EventArgsIntChanged.cs | 16 ++ .../Events/EventArgsInventoryChanged.cs | 24 ++ .../Events/EventArgsKeyPressed.cs | 15 ++ .../Events/EventArgsKeyboardStateChanged.cs | 17 ++ src/StardewModdingAPI/Events/EventArgsLevelUp.cs | 26 ++ .../Events/EventArgsLoadedGameChanged.cs | 14 + .../Events/EventArgsLocationObjectsChanged.cs | 17 ++ .../Events/EventArgsMineLevelChanged.cs | 16 ++ .../Events/EventArgsMouseStateChanged.cs | 17 ++ src/StardewModdingAPI/Events/EventArgsNewDay.cs | 18 ++ .../Events/EventArgsStringChanged.cs | 16 ++ src/StardewModdingAPI/Events/Game.cs | 123 --------- src/StardewModdingAPI/Events/GameEvents.cs | 123 +++++++++ src/StardewModdingAPI/Events/Graphics.cs | 162 ----------- src/StardewModdingAPI/Events/GraphicsEvents.cs | 162 +++++++++++ src/StardewModdingAPI/Events/Location.cs | 30 --- src/StardewModdingAPI/Events/LocationEvents.cs | 30 +++ src/StardewModdingAPI/Events/Menu.cs | 21 -- src/StardewModdingAPI/Events/MenuEvents.cs | 21 ++ src/StardewModdingAPI/Events/Mine.cs | 14 - src/StardewModdingAPI/Events/MineEvents.cs | 14 + src/StardewModdingAPI/Events/Player.cs | 35 --- src/StardewModdingAPI/Events/PlayerEvents.cs | 35 +++ src/StardewModdingAPI/Events/Time.cs | 42 --- src/StardewModdingAPI/Events/TimeEvents.cs | 42 +++ src/StardewModdingAPI/Inheritance/ChangeType.cs | 9 + .../Inheritance/ItemStackChange.cs | 7 - src/StardewModdingAPI/Log.cs | 200 ++++++++++++++ src/StardewModdingAPI/LogWriter.cs | 109 ++++++++ src/StardewModdingAPI/Logger.cs | 300 --------------------- src/StardewModdingAPI/StardewModdingAPI.csproj | 41 ++- 44 files changed, 1203 insertions(+), 1073 deletions(-) create mode 100644 src/StardewModdingAPI/Events/ControlEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Controls.cs delete mode 100644 src/StardewModdingAPI/Events/EventArgs.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsClickableMenuChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsClickableMenuClosed.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsCommand.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsControllerButtonPressed.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsControllerButtonReleased.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsControllerTriggerPressed.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsControllerTriggerReleased.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsCurrentLocationChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsGameLocationsChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsIntChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsInventoryChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsKeyPressed.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsKeyboardStateChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsLevelUp.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsLocationObjectsChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsMineLevelChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsMouseStateChanged.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsNewDay.cs create mode 100644 src/StardewModdingAPI/Events/EventArgsStringChanged.cs delete mode 100644 src/StardewModdingAPI/Events/Game.cs create mode 100644 src/StardewModdingAPI/Events/GameEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Graphics.cs create mode 100644 src/StardewModdingAPI/Events/GraphicsEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Location.cs create mode 100644 src/StardewModdingAPI/Events/LocationEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Menu.cs create mode 100644 src/StardewModdingAPI/Events/MenuEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Mine.cs create mode 100644 src/StardewModdingAPI/Events/MineEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Player.cs create mode 100644 src/StardewModdingAPI/Events/PlayerEvents.cs delete mode 100644 src/StardewModdingAPI/Events/Time.cs create mode 100644 src/StardewModdingAPI/Events/TimeEvents.cs create mode 100644 src/StardewModdingAPI/Inheritance/ChangeType.cs create mode 100644 src/StardewModdingAPI/Log.cs create mode 100644 src/StardewModdingAPI/LogWriter.cs (limited to 'src') diff --git a/src/StardewModdingAPI/Events/ControlEvents.cs b/src/StardewModdingAPI/Events/ControlEvents.cs new file mode 100644 index 00000000..cb597cf1 --- /dev/null +++ b/src/StardewModdingAPI/Events/ControlEvents.cs @@ -0,0 +1,58 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public static class ControlEvents + { + public static event EventHandler KeyboardChanged = delegate { }; + public static event EventHandler KeyPressed = delegate { }; + public static event EventHandler KeyReleased = delegate { }; + public static event EventHandler MouseChanged = delegate { }; + public static event EventHandler ControllerButtonPressed = delegate { }; + public static event EventHandler ControllerButtonReleased = delegate { }; + public static event EventHandler ControllerTriggerPressed = delegate { }; + public static event EventHandler ControllerTriggerReleased = delegate { }; + + internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) + { + KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + } + + internal static void InvokeMouseChanged(MouseState priorState, MouseState newState) + { + MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState)); + } + + internal static void InvokeKeyPressed(Keys key) + { + KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); + } + + internal static void InvokeKeyReleased(Keys key) + { + KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); + } + + internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons) + { + ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, buttons)); + } + + internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons) + { + ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons)); + } + + internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons buttons, float value) + { + ControllerTriggerPressed.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, buttons, value)); + } + + internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons buttons, float value) + { + ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, buttons, value)); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Controls.cs b/src/StardewModdingAPI/Events/Controls.cs deleted file mode 100644 index 6415561a..00000000 --- a/src/StardewModdingAPI/Events/Controls.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; - -namespace StardewModdingAPI.Events -{ - public static class ControlEvents - { - public static event EventHandler KeyboardChanged = delegate { }; - public static event EventHandler KeyPressed = delegate { }; - public static event EventHandler KeyReleased = delegate { }; - public static event EventHandler MouseChanged = delegate { }; - public static event EventHandler ControllerButtonPressed = delegate { }; - public static event EventHandler ControllerButtonReleased = delegate { }; - public static event EventHandler ControllerTriggerPressed = delegate { }; - public static event EventHandler ControllerTriggerReleased = delegate { }; - - internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) - { - KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); - } - - internal static void InvokeMouseChanged(MouseState priorState, MouseState newState) - { - MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState)); - } - - internal static void InvokeKeyPressed(Keys key) - { - KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); - } - - internal static void InvokeKeyReleased(Keys key) - { - KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); - } - - internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons) - { - ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, buttons)); - } - - internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons) - { - ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons)); - } - - internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons buttons, float value) - { - ControllerTriggerPressed.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, buttons, value)); - } - - internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons buttons, float value) - { - ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, buttons, value)); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgs.cs b/src/StardewModdingAPI/Events/EventArgs.cs deleted file mode 100644 index 2bce964e..00000000 --- a/src/StardewModdingAPI/Events/EventArgs.cs +++ /dev/null @@ -1,272 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; -using StardewModdingAPI.Inheritance; -using StardewValley; -using StardewValley.Menus; -using Object = StardewValley.Object; - -namespace StardewModdingAPI.Events -{ - public class EventArgsKeyboardStateChanged : EventArgs - { - public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) - { - NewState = newState; - NewState = newState; - } - - public KeyboardState NewState { get; private set; } - public KeyboardState PriorState { get; private set; } - } - - public class EventArgsKeyPressed : EventArgs - { - public EventArgsKeyPressed(Keys keyPressed) - { - KeyPressed = keyPressed; - } - - public Keys KeyPressed { get; private set; } - } - - public class EventArgsControllerButtonPressed : EventArgs - { - public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons buttonPressed) - { - PlayerIndex = playerIndex; - ButtonPressed = buttonPressed; - } - - public PlayerIndex PlayerIndex { get; private set; } - public Buttons ButtonPressed { get; private set; } - } - - public class EventArgsControllerButtonReleased : EventArgs - { - public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons buttonReleased) - { - PlayerIndex = playerIndex; - ButtonReleased = buttonReleased; - } - - public PlayerIndex PlayerIndex { get; private set; } - public Buttons ButtonReleased { get; private set; } - } - - public class EventArgsControllerTriggerPressed : EventArgs - { - public EventArgsControllerTriggerPressed(PlayerIndex playerIndex, Buttons buttonPressed, float value) - { - PlayerIndex = playerIndex; - ButtonPressed = buttonPressed; - Value = value; - } - - public PlayerIndex PlayerIndex { get; private set; } - public Buttons ButtonPressed { get; private set; } - public float Value { get; private set; } - } - - public class EventArgsControllerTriggerReleased : EventArgs - { - public EventArgsControllerTriggerReleased(PlayerIndex playerIndex, Buttons buttonReleased, float value) - { - PlayerIndex = playerIndex; - ButtonReleased = buttonReleased; - Value = value; - } - - public PlayerIndex PlayerIndex { get; private set; } - public Buttons ButtonReleased { get; private set; } - public float Value { get; private set; } - } - - public class EventArgsMouseStateChanged : EventArgs - { - public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) - { - NewState = newState; - NewState = newState; - } - - public MouseState NewState { get; private set; } - public MouseState PriorState { get; private set; } - } - - public class EventArgsClickableMenuChanged : EventArgs - { - public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) - { - NewMenu = newMenu; - PriorMenu = priorMenu; - } - - public IClickableMenu NewMenu { get; private set; } - public IClickableMenu PriorMenu { get; private set; } - } - - public class EventArgsClickableMenuClosed : EventArgs - { - public EventArgsClickableMenuClosed(IClickableMenu priorMenu) - { - PriorMenu = priorMenu; - } - - public IClickableMenu PriorMenu { get; private set; } - } - - public class EventArgsGameLocationsChanged : EventArgs - { - public EventArgsGameLocationsChanged(List newLocations) - { - NewLocations = newLocations; - } - - public List NewLocations { get; private set; } - } - - public class EventArgsMineLevelChanged : EventArgs - { - public EventArgsMineLevelChanged(int previousMineLevel, int currentMineLevel) - { - PreviousMineLevel = previousMineLevel; - CurrentMineLevel = currentMineLevel; - } - - public int PreviousMineLevel { get; private set; } - public int CurrentMineLevel { get; private set; } - } - - public class EventArgsLocationObjectsChanged : EventArgs - { - public EventArgsLocationObjectsChanged(SerializableDictionary newObjects) - { - NewObjects = newObjects; - } - - public SerializableDictionary NewObjects { get; private set; } - } - - public class EventArgsCurrentLocationChanged : EventArgs - { - public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) - { - NewLocation = newLocation; - PriorLocation = priorLocation; - } - - public GameLocation NewLocation { get; private set; } - public GameLocation PriorLocation { get; private set; } - } - - public class EventArgsFarmerChanged : EventArgs - { - public EventArgsFarmerChanged(Farmer priorFarmer, Farmer newFarmer) - { - NewFarmer = NewFarmer; - PriorFarmer = PriorFarmer; - } - - public Farmer NewFarmer { get; } - public Farmer PriorFarmer { get; } - } - - public class EventArgsInventoryChanged : EventArgs - { - public EventArgsInventoryChanged(List inventory, List changedItems) - { - Inventory = inventory; - Added = changedItems.Where(n => n.ChangeType == ChangeType.Added).ToList(); - Removed = changedItems.Where(n => n.ChangeType == ChangeType.Removed).ToList(); - QuantityChanged = changedItems.Where(n => n.ChangeType == ChangeType.StackChange).ToList(); - } - - public List Inventory { get; private set; } - public List Added { get; private set; } - public List Removed { get; private set; } - public List QuantityChanged { get; private set; } - } - - public class EventArgsLevelUp : EventArgs - { - public enum LevelType - { - Combat, - Farming, - Fishing, - Foraging, - Mining, - Luck - } - - public EventArgsLevelUp(LevelType type, int newLevel) - { - Type = type; - NewLevel = newLevel; - } - - public LevelType Type { get; private set; } - public int NewLevel { get; private set; } - } - - public class EventArgsIntChanged : EventArgs - { - public EventArgsIntChanged(int priorInt, int newInt) - { - NewInt = NewInt; - PriorInt = PriorInt; - } - - public int NewInt { get; } - public int PriorInt { get; } - } - - public class EventArgsStringChanged : EventArgs - { - public EventArgsStringChanged(string priorString, string newString) - { - NewString = newString; - PriorString = priorString; - } - - public string NewString { get; private set; } - public string PriorString { get; private set; } - } - - public class EventArgsLoadedGameChanged : EventArgs - { - public EventArgsLoadedGameChanged(bool loadedGame) - { - LoadedGame = loadedGame; - } - - public bool LoadedGame { get; private set; } - } - - public class EventArgsNewDay : EventArgs - { - public EventArgsNewDay(int prevDay, int curDay, bool newDay) - { - PreviousDay = prevDay; - CurrentDay = curDay; - IsNewDay = newDay; - } - - public int PreviousDay { get; private set; } - public int CurrentDay { get; private set; } - public bool IsNewDay { get; private set; } - } - - public class EventArgsCommand : EventArgs - { - public EventArgsCommand(Command command) - { - Command = command; - } - - public Command Command { get; private set; } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsClickableMenuChanged.cs b/src/StardewModdingAPI/Events/EventArgsClickableMenuChanged.cs new file mode 100644 index 00000000..6765c8da --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsClickableMenuChanged.cs @@ -0,0 +1,17 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + public class EventArgsClickableMenuChanged : EventArgs + { + public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + NewMenu = newMenu; + PriorMenu = priorMenu; + } + + public IClickableMenu NewMenu { get; private set; } + public IClickableMenu PriorMenu { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsClickableMenuClosed.cs b/src/StardewModdingAPI/Events/EventArgsClickableMenuClosed.cs new file mode 100644 index 00000000..bdf44285 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsClickableMenuClosed.cs @@ -0,0 +1,15 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + public class EventArgsClickableMenuClosed : EventArgs + { + public EventArgsClickableMenuClosed(IClickableMenu priorMenu) + { + PriorMenu = priorMenu; + } + + public IClickableMenu PriorMenu { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsCommand.cs b/src/StardewModdingAPI/Events/EventArgsCommand.cs new file mode 100644 index 00000000..fd2d4a51 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsCommand.cs @@ -0,0 +1,14 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsCommand : EventArgs + { + public EventArgsCommand(Command command) + { + Command = command; + } + + public Command Command { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsControllerButtonPressed.cs b/src/StardewModdingAPI/Events/EventArgsControllerButtonPressed.cs new file mode 100644 index 00000000..b51a8a5b --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsControllerButtonPressed.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsControllerButtonPressed : EventArgs + { + public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons buttonPressed) + { + PlayerIndex = playerIndex; + ButtonPressed = buttonPressed; + } + + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonPressed { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsControllerButtonReleased.cs b/src/StardewModdingAPI/Events/EventArgsControllerButtonReleased.cs new file mode 100644 index 00000000..0164b8d6 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsControllerButtonReleased.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsControllerButtonReleased : EventArgs + { + public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons buttonReleased) + { + PlayerIndex = playerIndex; + ButtonReleased = buttonReleased; + } + + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonReleased { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsControllerTriggerPressed.cs b/src/StardewModdingAPI/Events/EventArgsControllerTriggerPressed.cs new file mode 100644 index 00000000..1bf4fa46 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsControllerTriggerPressed.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsControllerTriggerPressed : EventArgs + { + public EventArgsControllerTriggerPressed(PlayerIndex playerIndex, Buttons buttonPressed, float value) + { + PlayerIndex = playerIndex; + ButtonPressed = buttonPressed; + Value = value; + } + + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonPressed { get; private set; } + public float Value { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsControllerTriggerReleased.cs b/src/StardewModdingAPI/Events/EventArgsControllerTriggerReleased.cs new file mode 100644 index 00000000..07a4bcb1 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsControllerTriggerReleased.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsControllerTriggerReleased : EventArgs + { + public EventArgsControllerTriggerReleased(PlayerIndex playerIndex, Buttons buttonReleased, float value) + { + PlayerIndex = playerIndex; + ButtonReleased = buttonReleased; + Value = value; + } + + public PlayerIndex PlayerIndex { get; private set; } + public Buttons ButtonReleased { get; private set; } + public float Value { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsCurrentLocationChanged.cs b/src/StardewModdingAPI/Events/EventArgsCurrentLocationChanged.cs new file mode 100644 index 00000000..53ed1551 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsCurrentLocationChanged.cs @@ -0,0 +1,17 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public class EventArgsCurrentLocationChanged : EventArgs + { + public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + NewLocation = newLocation; + PriorLocation = priorLocation; + } + + public GameLocation NewLocation { get; private set; } + public GameLocation PriorLocation { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs b/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs new file mode 100644 index 00000000..468d18ee --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs @@ -0,0 +1,17 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public class EventArgsFarmerChanged : EventArgs + { + public EventArgsFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + NewFarmer = NewFarmer; + PriorFarmer = PriorFarmer; + } + + public Farmer NewFarmer { get; } + public Farmer PriorFarmer { get; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsGameLocationsChanged.cs b/src/StardewModdingAPI/Events/EventArgsGameLocationsChanged.cs new file mode 100644 index 00000000..6a55c87a --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsGameLocationsChanged.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public class EventArgsGameLocationsChanged : EventArgs + { + public EventArgsGameLocationsChanged(List newLocations) + { + NewLocations = newLocations; + } + + public List NewLocations { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsIntChanged.cs b/src/StardewModdingAPI/Events/EventArgsIntChanged.cs new file mode 100644 index 00000000..c8a6e86d --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsIntChanged.cs @@ -0,0 +1,16 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsIntChanged : EventArgs + { + public EventArgsIntChanged(int priorInt, int newInt) + { + NewInt = NewInt; + PriorInt = PriorInt; + } + + public int NewInt { get; } + public int PriorInt { get; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsInventoryChanged.cs b/src/StardewModdingAPI/Events/EventArgsInventoryChanged.cs new file mode 100644 index 00000000..fa929ab5 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsInventoryChanged.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewModdingAPI.Inheritance; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public class EventArgsInventoryChanged : EventArgs + { + public EventArgsInventoryChanged(List inventory, List changedItems) + { + Inventory = inventory; + Added = changedItems.Where(n => n.ChangeType == ChangeType.Added).ToList(); + Removed = changedItems.Where(n => n.ChangeType == ChangeType.Removed).ToList(); + QuantityChanged = changedItems.Where(n => n.ChangeType == ChangeType.StackChange).ToList(); + } + + public List Inventory { get; private set; } + public List Added { get; private set; } + public List Removed { get; private set; } + public List QuantityChanged { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsKeyPressed.cs b/src/StardewModdingAPI/Events/EventArgsKeyPressed.cs new file mode 100644 index 00000000..df45e111 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsKeyPressed.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsKeyPressed : EventArgs + { + public EventArgsKeyPressed(Keys keyPressed) + { + KeyPressed = keyPressed; + } + + public Keys KeyPressed { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsKeyboardStateChanged.cs b/src/StardewModdingAPI/Events/EventArgsKeyboardStateChanged.cs new file mode 100644 index 00000000..784cd197 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsKeyboardStateChanged.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsKeyboardStateChanged : EventArgs + { + public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) + { + NewState = newState; + NewState = newState; + } + + public KeyboardState NewState { get; private set; } + public KeyboardState PriorState { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsLevelUp.cs b/src/StardewModdingAPI/Events/EventArgsLevelUp.cs new file mode 100644 index 00000000..762422c2 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsLevelUp.cs @@ -0,0 +1,26 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsLevelUp : EventArgs + { + public enum LevelType + { + Combat, + Farming, + Fishing, + Foraging, + Mining, + Luck + } + + public EventArgsLevelUp(LevelType type, int newLevel) + { + Type = type; + NewLevel = newLevel; + } + + public LevelType Type { get; private set; } + public int NewLevel { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs b/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs new file mode 100644 index 00000000..1b6e21e2 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs @@ -0,0 +1,14 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsLoadedGameChanged : EventArgs + { + public EventArgsLoadedGameChanged(bool loadedGame) + { + LoadedGame = loadedGame; + } + + public bool LoadedGame { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsLocationObjectsChanged.cs b/src/StardewModdingAPI/Events/EventArgsLocationObjectsChanged.cs new file mode 100644 index 00000000..70309192 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsLocationObjectsChanged.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Xna.Framework; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Events +{ + public class EventArgsLocationObjectsChanged : EventArgs + { + public EventArgsLocationObjectsChanged(SerializableDictionary newObjects) + { + NewObjects = newObjects; + } + + public SerializableDictionary NewObjects { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsMineLevelChanged.cs b/src/StardewModdingAPI/Events/EventArgsMineLevelChanged.cs new file mode 100644 index 00000000..f95e0ac2 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsMineLevelChanged.cs @@ -0,0 +1,16 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsMineLevelChanged : EventArgs + { + public EventArgsMineLevelChanged(int previousMineLevel, int currentMineLevel) + { + PreviousMineLevel = previousMineLevel; + CurrentMineLevel = currentMineLevel; + } + + public int PreviousMineLevel { get; private set; } + public int CurrentMineLevel { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsMouseStateChanged.cs b/src/StardewModdingAPI/Events/EventArgsMouseStateChanged.cs new file mode 100644 index 00000000..145a4445 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsMouseStateChanged.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public class EventArgsMouseStateChanged : EventArgs + { + public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) + { + PriorState = priorState; + NewState = newState; + } + + public MouseState NewState { get; private set; } + public MouseState PriorState { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsNewDay.cs b/src/StardewModdingAPI/Events/EventArgsNewDay.cs new file mode 100644 index 00000000..04d0e389 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsNewDay.cs @@ -0,0 +1,18 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsNewDay : EventArgs + { + public EventArgsNewDay(int prevDay, int curDay, bool newDay) + { + PreviousDay = prevDay; + CurrentDay = curDay; + IsNewDay = newDay; + } + + public int PreviousDay { get; private set; } + public int CurrentDay { get; private set; } + public bool IsNewDay { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsStringChanged.cs b/src/StardewModdingAPI/Events/EventArgsStringChanged.cs new file mode 100644 index 00000000..626d77b7 --- /dev/null +++ b/src/StardewModdingAPI/Events/EventArgsStringChanged.cs @@ -0,0 +1,16 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public class EventArgsStringChanged : EventArgs + { + public EventArgsStringChanged(string priorString, string newString) + { + NewString = newString; + PriorString = priorString; + } + + public string NewString { get; private set; } + public string PriorString { get; private set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Game.cs b/src/StardewModdingAPI/Events/Game.cs deleted file mode 100644 index 8b8042ed..00000000 --- a/src/StardewModdingAPI/Events/Game.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; - -namespace StardewModdingAPI.Events -{ - public static class GameEvents - { - public static event EventHandler GameLoaded = delegate { }; - public static event EventHandler Initialize = delegate { }; - public static event EventHandler LoadContent = delegate { }; - public static event EventHandler FirstUpdateTick = delegate { }; - - /// - /// Fires every update (1/60 of a second) - /// - public static event EventHandler UpdateTick = delegate { }; - - /// - /// Fires every other update (1/30 of a second) - /// - public static event EventHandler SecondUpdateTick = delegate { }; - - /// - /// Fires every fourth update (1/15 of a second) - /// - public static event EventHandler FourthUpdateTick = delegate { }; - - /// - /// Fires every eighth update (roughly 1/8 of a second) - /// - public static event EventHandler EighthUpdateTick = delegate { }; - - /// - /// Fires every fifthteenth update (1/4 of a second) - /// - public static event EventHandler QuarterSecondTick = delegate { }; - - /// - /// Fires every thirtieth update (1/2 of a second) - /// - public static event EventHandler HalfSecondTick = delegate { }; - - /// - /// Fires every sixtieth update (a second) - /// - public static event EventHandler OneSecondTick = delegate { }; - - internal static void InvokeGameLoaded() - { - GameLoaded.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeInitialize() - { - try - { - Initialize.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - Log.AsyncR("An exception occured in XNA Initialize: " + ex); - } - } - - internal static void InvokeLoadContent() - { - try - { - LoadContent.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - Log.AsyncR("An exception occured in XNA LoadContent: " + ex); - } - } - - internal static void InvokeUpdateTick() - { - try - { - UpdateTick.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - Log.AsyncR("An exception occured in XNA UpdateTick: " + ex); - } - } - - internal static void InvokeSecondUpdateTick() - { - SecondUpdateTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeFourthUpdateTick() - { - FourthUpdateTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeEighthUpdateTick() - { - EighthUpdateTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeQuarterSecondTick() - { - QuarterSecondTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeHalfSecondTick() - { - HalfSecondTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeOneSecondTick() - { - OneSecondTick.Invoke(null, EventArgs.Empty); - } - - internal static void InvokeFirstUpdateTick() - { - FirstUpdateTick.Invoke(null, EventArgs.Empty); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs new file mode 100644 index 00000000..1a366011 --- /dev/null +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -0,0 +1,123 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public static class GameEvents + { + public static event EventHandler GameLoaded = delegate { }; + public static event EventHandler Initialize = delegate { }; + public static event EventHandler LoadContent = delegate { }; + public static event EventHandler FirstUpdateTick = delegate { }; + + /// + /// Fires every update (1/60 of a second) + /// + public static event EventHandler UpdateTick = delegate { }; + + /// + /// Fires every other update (1/30 of a second) + /// + public static event EventHandler SecondUpdateTick = delegate { }; + + /// + /// Fires every fourth update (1/15 of a second) + /// + public static event EventHandler FourthUpdateTick = delegate { }; + + /// + /// Fires every eighth update (roughly 1/8 of a second) + /// + public static event EventHandler EighthUpdateTick = delegate { }; + + /// + /// Fires every fifthteenth update (1/4 of a second) + /// + public static event EventHandler QuarterSecondTick = delegate { }; + + /// + /// Fires every thirtieth update (1/2 of a second) + /// + public static event EventHandler HalfSecondTick = delegate { }; + + /// + /// Fires every sixtieth update (a second) + /// + public static event EventHandler OneSecondTick = delegate { }; + + internal static void InvokeGameLoaded() + { + GameLoaded.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeInitialize() + { + try + { + Initialize.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Log.AsyncR("An exception occured in XNA Initialize: " + ex); + } + } + + internal static void InvokeLoadContent() + { + try + { + LoadContent.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Log.AsyncR("An exception occured in XNA LoadContent: " + ex); + } + } + + internal static void InvokeUpdateTick() + { + try + { + UpdateTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Log.AsyncR("An exception occured in XNA UpdateTick: " + ex); + } + } + + internal static void InvokeSecondUpdateTick() + { + SecondUpdateTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeFourthUpdateTick() + { + FourthUpdateTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeEighthUpdateTick() + { + EighthUpdateTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeQuarterSecondTick() + { + QuarterSecondTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeHalfSecondTick() + { + HalfSecondTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeOneSecondTick() + { + OneSecondTick.Invoke(null, EventArgs.Empty); + } + + internal static void InvokeFirstUpdateTick() + { + FirstUpdateTick.Invoke(null, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Graphics.cs b/src/StardewModdingAPI/Events/Graphics.cs deleted file mode 100644 index 331d3e3a..00000000 --- a/src/StardewModdingAPI/Events/Graphics.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; - -namespace StardewModdingAPI.Events -{ - /// - /// - /// - public static class GraphicsEvents - { - /// - /// Occurs when the form (game) is resized. - /// - public static event EventHandler Resize = delegate { }; - - /// - /// Occurs before anything is drawn. - /// - public static event EventHandler OnPreRenderEvent = delegate { }; - - /// - /// Occurs before the GUI is drawn. - /// - public static event EventHandler OnPreRenderGuiEvent = delegate { }; - - /// - /// Occurs after the GUI is drawn. - /// - public static event EventHandler OnPostRenderGuiEvent = delegate { }; - - /// - /// Occurs before the HUD is drawn. - /// - public static event EventHandler OnPreRenderHudEvent = delegate { }; - - /// - /// Occurs after the HUD is drawn. - /// - public static event EventHandler OnPostRenderHudEvent = delegate { }; - - /// - /// Occurs after everything is drawn. - /// - public static event EventHandler OnPostRenderEvent = delegate { }; - - /// - /// Occurs before the GUI is drawn. Does not check for conditional statements. - /// - public static event EventHandler OnPreRenderGuiEventNoCheck = delegate { }; - - /// - /// Occurs after the GUI is drawn. Does not check for conditional statements. - /// - public static event EventHandler OnPostRenderGuiEventNoCheck = delegate { }; - - /// - /// Occurs before the HUD is drawn. Does not check for conditional statements. - /// - public static event EventHandler OnPreRenderHudEventNoCheck = delegate { }; - - /// - /// Occurs after the HUD is drawn. Does not check for conditional statements. - /// - public static event EventHandler OnPostRenderHudEventNoCheck = delegate { }; - - /// - /// Draws when SGame.Debug is true. F3 toggles this. - /// Game1.spriteBatch.Begin() is pre-called. - /// Do not make end or begin calls to the spritebatch. - /// If you are only trying to add debug information, use SGame.DebugMessageQueue in your Update loop. - /// - public static event EventHandler DrawDebug = delegate { }; - - internal static void InvokeDrawDebug(object sender, EventArgs e) - { - DrawDebug.Invoke(sender, e); - } - - internal static void InvokeOnPreRenderEvent(object sender, EventArgs e) - { - OnPreRenderEvent.Invoke(sender, e); - } - - internal static void InvokeOnPreRenderGuiEvent(object sender, EventArgs e) - { - OnPreRenderGuiEvent.Invoke(sender, e); - } - - internal static void InvokeOnPostRenderGuiEvent(object sender, EventArgs e) - { - OnPostRenderGuiEvent.Invoke(sender, e); - } - - internal static void InvokeOnPreRenderHudEvent(object sender, EventArgs e) - { - OnPreRenderHudEvent.Invoke(sender, e); - } - - internal static void InvokeOnPostRenderHudEvent(object sender, EventArgs e) - { - OnPostRenderHudEvent.Invoke(sender, e); - } - - internal static void InvokeOnPostRenderEvent(object sender, EventArgs e) - { - OnPostRenderEvent.Invoke(sender, e); - } - - internal static void InvokeOnPreRenderGuiEventNoCheck(object sender, EventArgs e) - { - OnPreRenderGuiEventNoCheck.Invoke(sender, e); - } - - internal static void InvokeOnPostRenderGuiEventNoCheck(object sender, EventArgs e) - { - OnPostRenderGuiEventNoCheck.Invoke(sender, e); - } - - internal static void InvokeOnPreRenderHudEventNoCheck(object sender, EventArgs e) - { - OnPreRenderHudEventNoCheck.Invoke(sender, e); - } - - internal static void InvokeOnPostRenderHudEventNoCheck(object sender, EventArgs e) - { - OnPostRenderHudEventNoCheck.Invoke(sender, e); - } - - internal static void InvokeResize(object sender, EventArgs e) - { - Resize.Invoke(sender, e); - } - - #region To Remove - - [Obsolete("Use the other Pre/Post render events instead.")] - public static event EventHandler DrawTick = delegate { }; - - [Obsolete("Use the other Pre/Post render events instead. All of them will automatically be drawn into the render target if needed.")] - public static event EventHandler DrawInRenderTargetTick = delegate { }; - - [Obsolete("Should not be used.")] - public static void InvokeDrawTick() - { - try - { - DrawTick.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - Log.AsyncR("An exception occured in a Mod's DrawTick: " + ex); - } - } - - [Obsolete("Should not be used.")] - public static void InvokeDrawInRenderTargetTick() - { - DrawInRenderTargetTick.Invoke(null, EventArgs.Empty); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/GraphicsEvents.cs b/src/StardewModdingAPI/Events/GraphicsEvents.cs new file mode 100644 index 00000000..1435bc37 --- /dev/null +++ b/src/StardewModdingAPI/Events/GraphicsEvents.cs @@ -0,0 +1,162 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// + /// + /// + public static class GraphicsEvents + { + /// + /// Occurs when the form (game) is resized. + /// + public static event EventHandler Resize = delegate { }; + + /// + /// Occurs before anything is drawn. + /// + public static event EventHandler OnPreRenderEvent = delegate { }; + + /// + /// Occurs before the GUI is drawn. + /// + public static event EventHandler OnPreRenderGuiEvent = delegate { }; + + /// + /// Occurs after the GUI is drawn. + /// + public static event EventHandler OnPostRenderGuiEvent = delegate { }; + + /// + /// Occurs before the HUD is drawn. + /// + public static event EventHandler OnPreRenderHudEvent = delegate { }; + + /// + /// Occurs after the HUD is drawn. + /// + public static event EventHandler OnPostRenderHudEvent = delegate { }; + + /// + /// Occurs after everything is drawn. + /// + public static event EventHandler OnPostRenderEvent = delegate { }; + + /// + /// Occurs before the GUI is drawn. Does not check for conditional statements. + /// + public static event EventHandler OnPreRenderGuiEventNoCheck = delegate { }; + + /// + /// Occurs after the GUI is drawn. Does not check for conditional statements. + /// + public static event EventHandler OnPostRenderGuiEventNoCheck = delegate { }; + + /// + /// Occurs before the HUD is drawn. Does not check for conditional statements. + /// + public static event EventHandler OnPreRenderHudEventNoCheck = delegate { }; + + /// + /// Occurs after the HUD is drawn. Does not check for conditional statements. + /// + public static event EventHandler OnPostRenderHudEventNoCheck = delegate { }; + + /// + /// Draws when SGame.Debug is true. F3 toggles this. + /// Game1.spriteBatch.Begin() is pre-called. + /// Do not make end or begin calls to the spritebatch. + /// If you are only trying to add debug information, use SGame.DebugMessageQueue in your Update loop. + /// + public static event EventHandler DrawDebug = delegate { }; + + internal static void InvokeDrawDebug(object sender, EventArgs e) + { + DrawDebug.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderEvent(object sender, EventArgs e) + { + OnPreRenderEvent.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderGuiEvent(object sender, EventArgs e) + { + OnPreRenderGuiEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderGuiEvent(object sender, EventArgs e) + { + OnPostRenderGuiEvent.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderHudEvent(object sender, EventArgs e) + { + OnPreRenderHudEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderHudEvent(object sender, EventArgs e) + { + OnPostRenderHudEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderEvent(object sender, EventArgs e) + { + OnPostRenderEvent.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderGuiEventNoCheck(object sender, EventArgs e) + { + OnPreRenderGuiEventNoCheck.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderGuiEventNoCheck(object sender, EventArgs e) + { + OnPostRenderGuiEventNoCheck.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderHudEventNoCheck(object sender, EventArgs e) + { + OnPreRenderHudEventNoCheck.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderHudEventNoCheck(object sender, EventArgs e) + { + OnPostRenderHudEventNoCheck.Invoke(sender, e); + } + + internal static void InvokeResize(object sender, EventArgs e) + { + Resize.Invoke(sender, e); + } + + #region To Remove + + [Obsolete("Use the other Pre/Post render events instead.")] + public static event EventHandler DrawTick = delegate { }; + + [Obsolete("Use the other Pre/Post render events instead. All of them will automatically be drawn into the render target if needed.")] + public static event EventHandler DrawInRenderTargetTick = delegate { }; + + [Obsolete("Should not be used.")] + public static void InvokeDrawTick() + { + try + { + DrawTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Log.AsyncR("An exception occured in a Mod's DrawTick: " + ex); + } + } + + [Obsolete("Should not be used.")] + public static void InvokeDrawInRenderTargetTick() + { + DrawInRenderTargetTick.Invoke(null, EventArgs.Empty); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Location.cs b/src/StardewModdingAPI/Events/Location.cs deleted file mode 100644 index f951ab95..00000000 --- a/src/StardewModdingAPI/Events/Location.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using StardewValley; -using Object = StardewValley.Object; - -namespace StardewModdingAPI.Events -{ - public static class LocationEvents - { - public static event EventHandler LocationsChanged = delegate { }; - public static event EventHandler LocationObjectsChanged = delegate { }; - public static event EventHandler CurrentLocationChanged = delegate { }; - - internal static void InvokeLocationsChanged(List newLocations) - { - LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); - } - - internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) - { - CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); - } - - internal static void InvokeOnNewLocationObject(SerializableDictionary newObjects) - { - LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/LocationEvents.cs b/src/StardewModdingAPI/Events/LocationEvents.cs new file mode 100644 index 00000000..b4b4ac33 --- /dev/null +++ b/src/StardewModdingAPI/Events/LocationEvents.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Events +{ + public static class LocationEvents + { + public static event EventHandler LocationsChanged = delegate { }; + public static event EventHandler LocationObjectsChanged = delegate { }; + public static event EventHandler CurrentLocationChanged = delegate { }; + + internal static void InvokeLocationsChanged(List newLocations) + { + LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); + } + + internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + } + + internal static void InvokeOnNewLocationObject(SerializableDictionary newObjects) + { + LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Menu.cs b/src/StardewModdingAPI/Events/Menu.cs deleted file mode 100644 index 0e043780..00000000 --- a/src/StardewModdingAPI/Events/Menu.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using StardewValley.Menus; - -namespace StardewModdingAPI.Events -{ - public static class MenuEvents - { - public static event EventHandler MenuChanged = delegate { }; - public static event EventHandler MenuClosed = delegate { }; - - internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) - { - MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); - } - - internal static void InvokeMenuClosed(IClickableMenu priorMenu) - { - MenuClosed.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/MenuEvents.cs b/src/StardewModdingAPI/Events/MenuEvents.cs new file mode 100644 index 00000000..fdd96f00 --- /dev/null +++ b/src/StardewModdingAPI/Events/MenuEvents.cs @@ -0,0 +1,21 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + public static class MenuEvents + { + public static event EventHandler MenuChanged = delegate { }; + public static event EventHandler MenuClosed = delegate { }; + + internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); + } + + internal static void InvokeMenuClosed(IClickableMenu priorMenu) + { + MenuClosed.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Mine.cs b/src/StardewModdingAPI/Events/Mine.cs deleted file mode 100644 index 55514d42..00000000 --- a/src/StardewModdingAPI/Events/Mine.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace StardewModdingAPI.Events -{ - public static class MineEvents - { - public static event EventHandler MineLevelChanged = delegate { }; - - internal static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel) - { - MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMinelevel, currentMineLevel)); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/MineEvents.cs b/src/StardewModdingAPI/Events/MineEvents.cs new file mode 100644 index 00000000..b9c3070c --- /dev/null +++ b/src/StardewModdingAPI/Events/MineEvents.cs @@ -0,0 +1,14 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public static class MineEvents + { + public static event EventHandler MineLevelChanged = delegate { }; + + internal static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel) + { + MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMinelevel, currentMineLevel)); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Player.cs b/src/StardewModdingAPI/Events/Player.cs deleted file mode 100644 index 22f572b7..00000000 --- a/src/StardewModdingAPI/Events/Player.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using StardewModdingAPI.Inheritance; -using StardewValley; - -namespace StardewModdingAPI.Events -{ - public static class PlayerEvents - { - public static event EventHandler FarmerChanged = delegate { }; - public static event EventHandler InventoryChanged = delegate { }; - public static event EventHandler LeveledUp = delegate { }; - public static event EventHandler LoadedGame = delegate { }; - - internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) - { - FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); - } - - internal static void InvokeInventoryChanged(List inventory, List changedItems) - { - InventoryChanged.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems)); - } - - internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) - { - LeveledUp.Invoke(null, new EventArgsLevelUp(type, newLevel)); - } - - internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) - { - LoadedGame.Invoke(null, loaded); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/PlayerEvents.cs b/src/StardewModdingAPI/Events/PlayerEvents.cs new file mode 100644 index 00000000..910f3c96 --- /dev/null +++ b/src/StardewModdingAPI/Events/PlayerEvents.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using StardewModdingAPI.Inheritance; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public static class PlayerEvents + { + public static event EventHandler FarmerChanged = delegate { }; + public static event EventHandler InventoryChanged = delegate { }; + public static event EventHandler LeveledUp = delegate { }; + public static event EventHandler LoadedGame = delegate { }; + + internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + } + + internal static void InvokeInventoryChanged(List inventory, List changedItems) + { + InventoryChanged.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems)); + } + + internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) + { + LeveledUp.Invoke(null, new EventArgsLevelUp(type, newLevel)); + } + + internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) + { + LoadedGame.Invoke(null, loaded); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/Time.cs b/src/StardewModdingAPI/Events/Time.cs deleted file mode 100644 index 39ca642a..00000000 --- a/src/StardewModdingAPI/Events/Time.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -namespace StardewModdingAPI.Events -{ - public static class TimeEvents - { - public static event EventHandler TimeOfDayChanged = delegate { }; - public static event EventHandler DayOfMonthChanged = delegate { }; - public static event EventHandler YearOfGameChanged = delegate { }; - public static event EventHandler SeasonOfYearChanged = delegate { }; - - /// - /// Occurs when Game1.newDay changes. True directly before saving, and False directly after. - /// - public static event EventHandler OnNewDay = delegate { }; - - internal static void InvokeTimeOfDayChanged(int priorInt, int newInt) - { - TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); - } - - internal static void InvokeDayOfMonthChanged(int priorInt, int newInt) - { - DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); - } - - internal static void InvokeYearOfGameChanged(int priorInt, int newInt) - { - YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); - } - - internal static void InvokeSeasonOfYearChanged(string priorString, string newString) - { - SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); - } - - internal static void InvokeOnNewDay(int priorInt, int newInt, bool newDay) - { - OnNewDay.Invoke(null, new EventArgsNewDay(priorInt, newInt, newDay)); - } - } -} \ No newline at end of file diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs new file mode 100644 index 00000000..42fa6ce2 --- /dev/null +++ b/src/StardewModdingAPI/Events/TimeEvents.cs @@ -0,0 +1,42 @@ +using System; + +namespace StardewModdingAPI.Events +{ + public static class TimeEvents + { + public static event EventHandler TimeOfDayChanged = delegate { }; + public static event EventHandler DayOfMonthChanged = delegate { }; + public static event EventHandler YearOfGameChanged = delegate { }; + public static event EventHandler SeasonOfYearChanged = delegate { }; + + /// + /// Occurs when Game1.newDay changes. True directly before saving, and False directly after. + /// + public static event EventHandler OnNewDay = delegate { }; + + internal static void InvokeTimeOfDayChanged(int priorInt, int newInt) + { + TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + internal static void InvokeDayOfMonthChanged(int priorInt, int newInt) + { + DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + internal static void InvokeYearOfGameChanged(int priorInt, int newInt) + { + YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + internal static void InvokeSeasonOfYearChanged(string priorString, string newString) + { + SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); + } + + internal static void InvokeOnNewDay(int priorInt, int newInt, bool newDay) + { + OnNewDay.Invoke(null, new EventArgsNewDay(priorInt, newInt, newDay)); + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Inheritance/ChangeType.cs b/src/StardewModdingAPI/Inheritance/ChangeType.cs new file mode 100644 index 00000000..4eaa02af --- /dev/null +++ b/src/StardewModdingAPI/Inheritance/ChangeType.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Inheritance +{ + public enum ChangeType + { + Removed, + Added, + StackChange + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Inheritance/ItemStackChange.cs b/src/StardewModdingAPI/Inheritance/ItemStackChange.cs index 88fc002e..78775094 100644 --- a/src/StardewModdingAPI/Inheritance/ItemStackChange.cs +++ b/src/StardewModdingAPI/Inheritance/ItemStackChange.cs @@ -2,13 +2,6 @@ namespace StardewModdingAPI.Inheritance { - public enum ChangeType - { - Removed, - Added, - StackChange - } - public class ItemStackChange { public Item Item { get; set; } diff --git a/src/StardewModdingAPI/Log.cs b/src/StardewModdingAPI/Log.cs new file mode 100644 index 00000000..15c4ce55 --- /dev/null +++ b/src/StardewModdingAPI/Log.cs @@ -0,0 +1,200 @@ +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace StardewModdingAPI +{ + public static class Log + { + private static readonly LogWriter _writer; + + static Log() + { + _writer = LogWriter.Instance; + } + + private static void PrintLog(LogInfo li) + { + _writer.WriteToLog(li); + } + + #region Exception Logging + + /// + /// Catch unhandled exception from the application + /// + /// Should be moved out of here if we do more than just log the exception. + public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Console.WriteLine("An exception has been caught"); + File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{DateTime.UtcNow.Ticks}.txt"), e.ExceptionObject.ToString()); + } + + /// + /// Catch thread exception from the application + /// + /// Should be moved out of here if we do more than just log the exception. + public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + { + Console.WriteLine("A thread exception has been caught"); + File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{Extensions.Random.Next(100000000, 999999999)}.txt"), e.Exception.ToString()); + } + + #endregion + + #region Sync Logging + + /// + /// NOTICE: Sync logging is discouraged. Please use Async instead. + /// + /// Message to log + /// Colour of message + public static void SyncColour(object message, ConsoleColor colour) + { + PrintLog(new LogInfo(message?.ToString(), colour)); + } + + #endregion + + #region Async Logging + + public static void AsyncColour(object message, ConsoleColor colour) + { + Task.Run(() => { PrintLog(new LogInfo(message?.ToString(), colour)); }); + } + + public static void Async(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Gray); + } + + public static void AsyncR(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Red); + } + + public static void AsyncO(object message) + { + AsyncColour(message.ToString(), ConsoleColor.DarkYellow); + } + + public static void AsyncY(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Yellow); + } + + public static void AsyncG(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Green); + } + + public static void AsyncC(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Cyan); + } + + public static void AsyncM(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Magenta); + } + + public static void Error(object message) + { + AsyncR("[ERROR] " + message); + } + + public static void Success(object message) + { + AsyncG("[SUCCESS] " + message); + } + + public static void Info(object message) + { + AsyncY("[INFO] " + message); + } + + public static void Out(object message) + { + Async("[OUT] " + message); + } + + public static void Debug(object message) + { + AsyncO("[DEBUG] " + message); + } + + #endregion + + #region ToRemove + + public static void LogValueNotSpecified() + { + AsyncR(" must be specified"); + } + + public static void LogObjectValueNotSpecified() + { + AsyncR(" and must be specified"); + } + + public static void LogValueInvalid() + { + AsyncR(" is invalid"); + } + + public static void LogObjectInvalid() + { + AsyncR(" is invalid"); + } + + public static void LogValueNotInt32() + { + AsyncR(" must be a whole number (Int32)"); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + private static void PrintLog(object message, bool disableLogging, params object[] values) + { + PrintLog(new LogInfo(message?.ToString())); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Success(object message, params object[] values) + { + Success(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Verbose(object message, params object[] values) + { + Out(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Comment(object message, params object[] values) + { + AsyncC(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Info(object message, params object[] values) + { + Info(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Error(object message, params object[] values) + { + Error(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Debug(object message, params object[] values) + { + Debug(message); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/LogWriter.cs b/src/StardewModdingAPI/LogWriter.cs new file mode 100644 index 00000000..18c940c8 --- /dev/null +++ b/src/StardewModdingAPI/LogWriter.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Linq; + +namespace StardewModdingAPI +{ + /// + /// A Logging class implementing the Singleton pattern and an internal Queue to be flushed perdiodically + /// + public class LogWriter + { + private static LogWriter _instance; + private static ConcurrentQueue _logQueue; + private static StreamWriter _stream; + + /// + /// Private to prevent creation of other instances + /// + private LogWriter() + { + } + + /// + /// Exposes _instace and creates a new one if it is null + /// + internal static LogWriter Instance + { + get + { + if (_instance == null) + { + _instance = new LogWriter(); + // Field cannot be used by anything else regardless, do not surround with lock { } + // ReSharper disable once InconsistentlySynchronizedField + _logQueue = new ConcurrentQueue(); + Console.WriteLine(Constants.LogPath); + + // If the ErrorLogs dir doesn't exist StreamWriter will throw an exception. + if (!Directory.Exists(Constants.LogDir)) + { + Directory.CreateDirectory(Constants.LogDir); + } + + _stream = new StreamWriter(Constants.LogPath, false); + Console.WriteLine("Created log instance"); + } + return _instance; + } + } + + /// + /// Writes into the ConcurrentQueue the Message specified + /// + /// The message to write to the log + public void WriteToLog(string message) + { + lock (_logQueue) + { + var logEntry = new LogInfo(message); + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// + /// Writes into the ConcurrentQueue the Entry specified + /// + /// The logEntry to write to the log + public void WriteToLog(LogInfo logEntry) + { + lock (_logQueue) + { + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// + /// Flushes the ConcurrentQueue to the log file specified in Constants + /// + private void FlushLog() + { + lock (_stream) + { + LogInfo entry; + while (_logQueue.TryDequeue(out entry)) + { + string m = $"[{entry.LogTime}] {entry.Message}"; + + Console.ForegroundColor = entry.Colour; + Console.WriteLine(m); + Console.ForegroundColor = ConsoleColor.Gray; + + _stream.WriteLine(m); + } + _stream.Flush(); + } + } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Logger.cs b/src/StardewModdingAPI/Logger.cs index 5fda6568..0f40cd25 100644 --- a/src/StardewModdingAPI/Logger.cs +++ b/src/StardewModdingAPI/Logger.cs @@ -1,307 +1,7 @@ using System; -using System.Collections.Concurrent; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; namespace StardewModdingAPI { - public static class Log - { - private static readonly LogWriter _writer; - - static Log() - { - _writer = LogWriter.Instance; - } - - private static void PrintLog(LogInfo li) - { - _writer.WriteToLog(li); - } - - #region Exception Logging - - /// - /// Catch unhandled exception from the application - /// - /// Should be moved out of here if we do more than just log the exception. - public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) - { - Console.WriteLine("An exception has been caught"); - File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{DateTime.UtcNow.Ticks}.txt"), e.ExceptionObject.ToString()); - } - - /// - /// Catch thread exception from the application - /// - /// Should be moved out of here if we do more than just log the exception. - public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) - { - Console.WriteLine("A thread exception has been caught"); - File.WriteAllText(Path.Combine(Constants.LogDir, $"MODDED_ErrorLog.Log_{Extensions.Random.Next(100000000, 999999999)}.txt"), e.Exception.ToString()); - } - - #endregion - - #region Sync Logging - - /// - /// NOTICE: Sync logging is discouraged. Please use Async instead. - /// - /// Message to log - /// Colour of message - public static void SyncColour(object message, ConsoleColor colour) - { - PrintLog(new LogInfo(message?.ToString(), colour)); - } - - #endregion - - #region Async Logging - - public static void AsyncColour(object message, ConsoleColor colour) - { - Task.Run(() => { PrintLog(new LogInfo(message?.ToString(), colour)); }); - } - - public static void Async(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Gray); - } - - public static void AsyncR(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Red); - } - - public static void AsyncO(object message) - { - AsyncColour(message.ToString(), ConsoleColor.DarkYellow); - } - - public static void AsyncY(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Yellow); - } - - public static void AsyncG(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Green); - } - - public static void AsyncC(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Cyan); - } - - public static void AsyncM(object message) - { - AsyncColour(message?.ToString(), ConsoleColor.Magenta); - } - - public static void Error(object message) - { - AsyncR("[ERROR] " + message); - } - - public static void Success(object message) - { - AsyncG("[SUCCESS] " + message); - } - - public static void Info(object message) - { - AsyncY("[INFO] " + message); - } - - public static void Out(object message) - { - Async("[OUT] " + message); - } - - public static void Debug(object message) - { - AsyncO("[DEBUG] " + message); - } - - #endregion - - #region ToRemove - - public static void LogValueNotSpecified() - { - AsyncR(" must be specified"); - } - - public static void LogObjectValueNotSpecified() - { - AsyncR(" and must be specified"); - } - - public static void LogValueInvalid() - { - AsyncR(" is invalid"); - } - - public static void LogObjectInvalid() - { - AsyncR(" is invalid"); - } - - public static void LogValueNotInt32() - { - AsyncR(" must be a whole number (Int32)"); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - private static void PrintLog(object message, bool disableLogging, params object[] values) - { - PrintLog(new LogInfo(message?.ToString())); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Success(object message, params object[] values) - { - Success(message); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Verbose(object message, params object[] values) - { - Out(message); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Comment(object message, params object[] values) - { - AsyncC(message); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Info(object message, params object[] values) - { - Info(message); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Error(object message, params object[] values) - { - Error(message); - } - - [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] - public static void Debug(object message, params object[] values) - { - Debug(message); - } - - #endregion - } - - /// - /// A Logging class implementing the Singleton pattern and an internal Queue to be flushed perdiodically - /// - public class LogWriter - { - private static LogWriter _instance; - private static ConcurrentQueue _logQueue; - private static StreamWriter _stream; - - /// - /// Private to prevent creation of other instances - /// - private LogWriter() - { - } - - /// - /// Exposes _instace and creates a new one if it is null - /// - internal static LogWriter Instance - { - get - { - if (_instance == null) - { - _instance = new LogWriter(); - // Field cannot be used by anything else regardless, do not surround with lock { } - // ReSharper disable once InconsistentlySynchronizedField - _logQueue = new ConcurrentQueue(); - Console.WriteLine(Constants.LogPath); - - // If the ErrorLogs dir doesn't exist StreamWriter will throw an exception. - if (!Directory.Exists(Constants.LogDir)) - { - Directory.CreateDirectory(Constants.LogDir); - } - - _stream = new StreamWriter(Constants.LogPath, false); - Console.WriteLine("Created log instance"); - } - return _instance; - } - } - - /// - /// Writes into the ConcurrentQueue the Message specified - /// - /// The message to write to the log - public void WriteToLog(string message) - { - lock (_logQueue) - { - var logEntry = new LogInfo(message); - _logQueue.Enqueue(logEntry); - - if (_logQueue.Any()) - { - FlushLog(); - } - } - } - - /// - /// Writes into the ConcurrentQueue the Entry specified - /// - /// The logEntry to write to the log - public void WriteToLog(LogInfo logEntry) - { - lock (_logQueue) - { - _logQueue.Enqueue(logEntry); - - if (_logQueue.Any()) - { - FlushLog(); - } - } - } - - /// - /// Flushes the ConcurrentQueue to the log file specified in Constants - /// - private void FlushLog() - { - lock (_stream) - { - LogInfo entry; - while (_logQueue.TryDequeue(out entry)) - { - string m = $"[{entry.LogTime}] {entry.Message}"; - - Console.ForegroundColor = entry.Colour; - Console.WriteLine(m); - Console.ForegroundColor = ConsoleColor.Gray; - - _stream.WriteLine(m); - } - _stream.Flush(); - } - } - } - /// /// A struct to store the message and the Date and Time the log entry was created /// diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index cd2c2a6d..90c4dc68 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -163,23 +163,46 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit