diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-10-31 12:05:02 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-10-31 12:05:02 -0400 |
commit | d9adaf73869ce768686301ef30687a5fc18048a0 (patch) | |
tree | f9c53227a6682388f40ad5b1307bcdd12ad6ba29 /src | |
parent | 1c15738233453edee36e964f099694ced64cb1b8 (diff) | |
download | SMAPI-d9adaf73869ce768686301ef30687a5fc18048a0.tar.gz SMAPI-d9adaf73869ce768686301ef30687a5fc18048a0.tar.bz2 SMAPI-d9adaf73869ce768686301ef30687a5fc18048a0.zip |
split combined class files per .NET conventions
Diffstat (limited to 'src')
36 files changed, 1195 insertions, 1065 deletions
diff --git a/src/StardewModdingAPI/Events/Controls.cs b/src/StardewModdingAPI/Events/ControlEvents.cs index 6415561a..cb597cf1 100644 --- a/src/StardewModdingAPI/Events/Controls.cs +++ b/src/StardewModdingAPI/Events/ControlEvents.cs @@ -1,58 +1,58 @@ -using System;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Input;
-
-namespace StardewModdingAPI.Events
-{
- public static class ControlEvents
- {
- public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged = delegate { };
- public static event EventHandler<EventArgsKeyPressed> KeyPressed = delegate { };
- public static event EventHandler<EventArgsKeyPressed> KeyReleased = delegate { };
- public static event EventHandler<EventArgsMouseStateChanged> MouseChanged = delegate { };
- public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed = delegate { };
- public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased = delegate { };
- public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed = delegate { };
- public static event EventHandler<EventArgsControllerTriggerReleased> 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));
- }
- }
+using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + public static class ControlEvents + { + public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged = delegate { }; + public static event EventHandler<EventArgsKeyPressed> KeyPressed = delegate { }; + public static event EventHandler<EventArgsKeyPressed> KeyReleased = delegate { }; + public static event EventHandler<EventArgsMouseStateChanged> MouseChanged = delegate { }; + public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed = delegate { }; + public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased = delegate { }; + public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed = delegate { }; + public static event EventHandler<EventArgsControllerTriggerReleased> 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<GameLocation> newLocations)
- {
- NewLocations = newLocations;
- }
-
- public List<GameLocation> 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<Vector2, Object> newObjects)
- {
- NewObjects = newObjects;
- }
-
- public SerializableDictionary<Vector2, Object> 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<Item> inventory, List<ItemStackChange> 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<Item> Inventory { get; private set; }
- public List<ItemStackChange> Added { get; private set; }
- public List<ItemStackChange> Removed { get; private set; }
- public List<ItemStackChange> 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<GameLocation> newLocations) + { + NewLocations = newLocations; + } + + public List<GameLocation> 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<Item> inventory, List<ItemStackChange> 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<Item> Inventory { get; private set; } + public List<ItemStackChange> Added { get; private set; } + public List<ItemStackChange> Removed { get; private set; } + public List<ItemStackChange> 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<Vector2, Object> newObjects) + { + NewObjects = newObjects; + } + + public SerializableDictionary<Vector2, Object> 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/GameEvents.cs index 8b8042ed..1a366011 100644 --- a/src/StardewModdingAPI/Events/Game.cs +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -1,123 +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 { };
-
- /// <summary>
- /// Fires every update (1/60 of a second)
- /// </summary>
- public static event EventHandler UpdateTick = delegate { };
-
- /// <summary>
- /// Fires every other update (1/30 of a second)
- /// </summary>
- public static event EventHandler SecondUpdateTick = delegate { };
-
- /// <summary>
- /// Fires every fourth update (1/15 of a second)
- /// </summary>
- public static event EventHandler FourthUpdateTick = delegate { };
-
- /// <summary>
- /// Fires every eighth update (roughly 1/8 of a second)
- /// </summary>
- public static event EventHandler EighthUpdateTick = delegate { };
-
- /// <summary>
- /// Fires every fifthteenth update (1/4 of a second)
- /// </summary>
- public static event EventHandler QuarterSecondTick = delegate { };
-
- /// <summary>
- /// Fires every thirtieth update (1/2 of a second)
- /// </summary>
- public static event EventHandler HalfSecondTick = delegate { };
-
- /// <summary>
- /// Fires every sixtieth update (a second)
- /// </summary>
- 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);
- }
- }
+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 { }; + + /// <summary> + /// Fires every update (1/60 of a second) + /// </summary> + public static event EventHandler UpdateTick = delegate { }; + + /// <summary> + /// Fires every other update (1/30 of a second) + /// </summary> + public static event EventHandler SecondUpdateTick = delegate { }; + + /// <summary> + /// Fires every fourth update (1/15 of a second) + /// </summary> + public static event EventHandler FourthUpdateTick = delegate { }; + + /// <summary> + /// Fires every eighth update (roughly 1/8 of a second) + /// </summary> + public static event EventHandler EighthUpdateTick = delegate { }; + + /// <summary> + /// Fires every fifthteenth update (1/4 of a second) + /// </summary> + public static event EventHandler QuarterSecondTick = delegate { }; + + /// <summary> + /// Fires every thirtieth update (1/2 of a second) + /// </summary> + public static event EventHandler HalfSecondTick = delegate { }; + + /// <summary> + /// Fires every sixtieth update (a second) + /// </summary> + 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/GraphicsEvents.cs index 331d3e3a..1435bc37 100644 --- a/src/StardewModdingAPI/Events/Graphics.cs +++ b/src/StardewModdingAPI/Events/GraphicsEvents.cs @@ -1,162 +1,162 @@ -using System;
-
-namespace StardewModdingAPI.Events
-{
- /// <summary>
- ///
- /// </summary>
- public static class GraphicsEvents
- {
- /// <summary>
- /// Occurs when the form (game) is resized.
- /// </summary>
- public static event EventHandler Resize = delegate { };
-
- /// <summary>
- /// Occurs before anything is drawn.
- /// </summary>
- public static event EventHandler OnPreRenderEvent = delegate { };
-
- /// <summary>
- /// Occurs before the GUI is drawn.
- /// </summary>
- public static event EventHandler OnPreRenderGuiEvent = delegate { };
-
- /// <summary>
- /// Occurs after the GUI is drawn.
- /// </summary>
- public static event EventHandler OnPostRenderGuiEvent = delegate { };
-
- /// <summary>
- /// Occurs before the HUD is drawn.
- /// </summary>
- public static event EventHandler OnPreRenderHudEvent = delegate { };
-
- /// <summary>
- /// Occurs after the HUD is drawn.
- /// </summary>
- public static event EventHandler OnPostRenderHudEvent = delegate { };
-
- /// <summary>
- /// Occurs after everything is drawn.
- /// </summary>
- public static event EventHandler OnPostRenderEvent = delegate { };
-
- /// <summary>
- /// Occurs before the GUI is drawn. Does not check for conditional statements.
- /// </summary>
- public static event EventHandler OnPreRenderGuiEventNoCheck = delegate { };
-
- /// <summary>
- /// Occurs after the GUI is drawn. Does not check for conditional statements.
- /// </summary>
- public static event EventHandler OnPostRenderGuiEventNoCheck = delegate { };
-
- /// <summary>
- /// Occurs before the HUD is drawn. Does not check for conditional statements.
- /// </summary>
- public static event EventHandler OnPreRenderHudEventNoCheck = delegate { };
-
- /// <summary>
- /// Occurs after the HUD is drawn. Does not check for conditional statements.
- /// </summary>
- public static event EventHandler OnPostRenderHudEventNoCheck = delegate { };
-
- /// <summary>
- /// 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.
- /// </summary>
- 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
- }
+using System; + +namespace StardewModdingAPI.Events +{ + /// <summary> + /// + /// </summary> + public static class GraphicsEvents + { + /// <summary> + /// Occurs when the form (game) is resized. + /// </summary> + public static event EventHandler Resize = delegate { }; + + /// <summary> + /// Occurs before anything is drawn. + /// </summary> + public static event EventHandler OnPreRenderEvent = delegate { }; + + /// <summary> + /// Occurs before the GUI is drawn. + /// </summary> + public static event EventHandler OnPreRenderGuiEvent = delegate { }; + + /// <summary> + /// Occurs after the GUI is drawn. + /// </summary> + public static event EventHandler OnPostRenderGuiEvent = delegate { }; + + /// <summary> + /// Occurs before the HUD is drawn. + /// </summary> + public static event EventHandler OnPreRenderHudEvent = delegate { }; + + /// <summary> + /// Occurs after the HUD is drawn. + /// </summary> + public static event EventHandler OnPostRenderHudEvent = delegate { }; + + /// <summary> + /// Occurs after everything is drawn. + /// </summary> + public static event EventHandler OnPostRenderEvent = delegate { }; + + /// <summary> + /// Occurs before the GUI is drawn. Does not check for conditional statements. + /// </summary> + public static event EventHandler OnPreRenderGuiEventNoCheck = delegate { }; + + /// <summary> + /// Occurs after the GUI is drawn. Does not check for conditional statements. + /// </summary> + public static event EventHandler OnPostRenderGuiEventNoCheck = delegate { }; + + /// <summary> + /// Occurs before the HUD is drawn. Does not check for conditional statements. + /// </summary> + public static event EventHandler OnPreRenderHudEventNoCheck = delegate { }; + + /// <summary> + /// Occurs after the HUD is drawn. Does not check for conditional statements. + /// </summary> + public static event EventHandler OnPostRenderHudEventNoCheck = delegate { }; + + /// <summary> + /// 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. + /// </summary> + 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/LocationEvents.cs index f951ab95..b4b4ac33 100644 --- a/src/StardewModdingAPI/Events/Location.cs +++ b/src/StardewModdingAPI/Events/LocationEvents.cs @@ -1,30 +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<EventArgsGameLocationsChanged> LocationsChanged = delegate { };
- public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged = delegate { };
- public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged = delegate { };
-
- internal static void InvokeLocationsChanged(List<GameLocation> 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<Vector2, Object> newObjects)
- {
- LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects));
- }
- }
+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<EventArgsGameLocationsChanged> LocationsChanged = delegate { }; + public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged = delegate { }; + public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged = delegate { }; + + internal static void InvokeLocationsChanged(List<GameLocation> 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<Vector2, Object> 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/MenuEvents.cs index 0e043780..fdd96f00 100644 --- a/src/StardewModdingAPI/Events/Menu.cs +++ b/src/StardewModdingAPI/Events/MenuEvents.cs @@ -1,21 +1,21 @@ -using System;
-using StardewValley.Menus;
-
-namespace StardewModdingAPI.Events
-{
- public static class MenuEvents
- {
- public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged = delegate { };
- public static event EventHandler<EventArgsClickableMenuClosed> 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));
- }
- }
+using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + public static class MenuEvents + { + public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged = delegate { }; + public static event EventHandler<EventArgsClickableMenuClosed> 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/MineEvents.cs index 55514d42..b9c3070c 100644 --- a/src/StardewModdingAPI/Events/Mine.cs +++ b/src/StardewModdingAPI/Events/MineEvents.cs @@ -1,14 +1,14 @@ -using System;
-
-namespace StardewModdingAPI.Events
-{
- public static class MineEvents
- {
- public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged = delegate { };
-
- internal static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel)
- {
- MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMinelevel, currentMineLevel));
- }
- }
+using System; + +namespace StardewModdingAPI.Events +{ + public static class MineEvents + { + public static event EventHandler<EventArgsMineLevelChanged> 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/PlayerEvents.cs index 22f572b7..910f3c96 100644 --- a/src/StardewModdingAPI/Events/Player.cs +++ b/src/StardewModdingAPI/Events/PlayerEvents.cs @@ -1,35 +1,35 @@ -using System;
-using System.Collections.Generic;
-using StardewModdingAPI.Inheritance;
-using StardewValley;
-
-namespace StardewModdingAPI.Events
-{
- public static class PlayerEvents
- {
- public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { };
- public static event EventHandler<EventArgsInventoryChanged> InventoryChanged = delegate { };
- public static event EventHandler<EventArgsLevelUp> LeveledUp = delegate { };
- public static event EventHandler<EventArgsLoadedGameChanged> LoadedGame = delegate { };
-
- internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer)
- {
- FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer));
- }
-
- internal static void InvokeInventoryChanged(List<Item> inventory, List<ItemStackChange> 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);
- }
- }
+using System; +using System.Collections.Generic; +using StardewModdingAPI.Inheritance; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + public static class PlayerEvents + { + public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { }; + public static event EventHandler<EventArgsInventoryChanged> InventoryChanged = delegate { }; + public static event EventHandler<EventArgsLevelUp> LeveledUp = delegate { }; + public static event EventHandler<EventArgsLoadedGameChanged> LoadedGame = delegate { }; + + internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + } + + internal static void InvokeInventoryChanged(List<Item> inventory, List<ItemStackChange> 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/TimeEvents.cs index 39ca642a..42fa6ce2 100644 --- a/src/StardewModdingAPI/Events/Time.cs +++ b/src/StardewModdingAPI/Events/TimeEvents.cs @@ -1,42 +1,42 @@ -using System;
-
-namespace StardewModdingAPI.Events
-{
- public static class TimeEvents
- {
- public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged = delegate { };
- public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged = delegate { };
- public static event EventHandler<EventArgsIntChanged> YearOfGameChanged = delegate { };
- public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged = delegate { };
-
- /// <summary>
- /// Occurs when Game1.newDay changes. True directly before saving, and False directly after.
- /// </summary>
- public static event EventHandler<EventArgsNewDay> 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));
- }
- }
+using System; + +namespace StardewModdingAPI.Events +{ + public static class TimeEvents + { + public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged = delegate { }; + public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged = delegate { }; + public static event EventHandler<EventArgsIntChanged> YearOfGameChanged = delegate { }; + public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged = delegate { }; + + /// <summary> + /// Occurs when Game1.newDay changes. True directly before saving, and False directly after. + /// </summary> + public static event EventHandler<EventArgsNewDay> 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 + + /// <summary> + /// Catch unhandled exception from the application + /// </summary> + /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> + 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()); + } + + /// <summary> + /// Catch thread exception from the application + /// </summary> + /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> + 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 + + /// <summary> + /// NOTICE: Sync logging is discouraged. Please use Async instead. + /// </summary> + /// <param name="message">Message to log</param> + /// <param name="colour">Colour of message</param> + 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("<value> must be specified"); + } + + public static void LogObjectValueNotSpecified() + { + AsyncR("<object> and <value> must be specified"); + } + + public static void LogValueInvalid() + { + AsyncR("<value> is invalid"); + } + + public static void LogObjectInvalid() + { + AsyncR("<object> is invalid"); + } + + public static void LogValueNotInt32() + { + AsyncR("<value> 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 +{ + /// <summary> + /// A Logging class implementing the Singleton pattern and an internal Queue to be flushed perdiodically + /// </summary> + public class LogWriter + { + private static LogWriter _instance; + private static ConcurrentQueue<LogInfo> _logQueue; + private static StreamWriter _stream; + + /// <summary> + /// Private to prevent creation of other instances + /// </summary> + private LogWriter() + { + } + + /// <summary> + /// Exposes _instace and creates a new one if it is null + /// </summary> + 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<LogInfo>(); + 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; + } + } + + /// <summary> + /// Writes into the ConcurrentQueue the Message specified + /// </summary> + /// <param name="message">The message to write to the log</param> + public void WriteToLog(string message) + { + lock (_logQueue) + { + var logEntry = new LogInfo(message); + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// <summary> + /// Writes into the ConcurrentQueue the Entry specified + /// </summary> + /// <param name="logEntry">The logEntry to write to the log</param> + public void WriteToLog(LogInfo logEntry) + { + lock (_logQueue) + { + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// <summary> + /// Flushes the ConcurrentQueue to the log file specified in Constants + /// </summary> + 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 - - /// <summary> - /// Catch unhandled exception from the application - /// </summary> - /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> - 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()); - } - - /// <summary> - /// Catch thread exception from the application - /// </summary> - /// <remarks>Should be moved out of here if we do more than just log the exception.</remarks> - 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 - - /// <summary> - /// NOTICE: Sync logging is discouraged. Please use Async instead. - /// </summary> - /// <param name="message">Message to log</param> - /// <param name="colour">Colour of message</param> - 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("<value> must be specified"); - } - - public static void LogObjectValueNotSpecified() - { - AsyncR("<object> and <value> must be specified"); - } - - public static void LogValueInvalid() - { - AsyncR("<value> is invalid"); - } - - public static void LogObjectInvalid() - { - AsyncR("<object> is invalid"); - } - - public static void LogValueNotInt32() - { - AsyncR("<value> 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 - } - - /// <summary> - /// A Logging class implementing the Singleton pattern and an internal Queue to be flushed perdiodically - /// </summary> - public class LogWriter - { - private static LogWriter _instance; - private static ConcurrentQueue<LogInfo> _logQueue; - private static StreamWriter _stream; - - /// <summary> - /// Private to prevent creation of other instances - /// </summary> - private LogWriter() - { - } - - /// <summary> - /// Exposes _instace and creates a new one if it is null - /// </summary> - 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<LogInfo>(); - 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; - } - } - - /// <summary> - /// Writes into the ConcurrentQueue the Message specified - /// </summary> - /// <param name="message">The message to write to the log</param> - public void WriteToLog(string message) - { - lock (_logQueue) - { - var logEntry = new LogInfo(message); - _logQueue.Enqueue(logEntry); - - if (_logQueue.Any()) - { - FlushLog(); - } - } - } - - /// <summary> - /// Writes into the ConcurrentQueue the Entry specified - /// </summary> - /// <param name="logEntry">The logEntry to write to the log</param> - public void WriteToLog(LogInfo logEntry) - { - lock (_logQueue) - { - _logQueue.Enqueue(logEntry); - - if (_logQueue.Any()) - { - FlushLog(); - } - } - } - - /// <summary> - /// Flushes the ConcurrentQueue to the log file specified in Constants - /// </summary> - 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(); - } - } - } - /// <summary> /// A struct to store the message and the Date and Time the log entry was created /// </summary> 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 @@ <Compile Include="Config.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Entities\SPlayer.cs" />
- <Compile Include="Events\Controls.cs" />
- <Compile Include="Events\EventArgs.cs" />
- <Compile Include="Events\Game.cs" />
- <Compile Include="Events\Graphics.cs" />
- <Compile Include="Events\Location.cs" />
- <Compile Include="Events\Menu.cs" />
- <Compile Include="Events\Mine.cs" />
- <Compile Include="Events\Player.cs" />
- <Compile Include="Events\Time.cs" />
+ <Compile Include="Events\ControlEvents.cs" />
+ <Compile Include="Events\EventArgsCommand.cs" />
+ <Compile Include="Events\EventArgsClickableMenuChanged.cs" />
+ <Compile Include="Events\EventArgsClickableMenuClosed.cs" />
+ <Compile Include="Events\EventArgsControllerButtonPressed.cs" />
+ <Compile Include="Events\EventArgsControllerButtonReleased.cs" />
+ <Compile Include="Events\EventArgsControllerTriggerPressed.cs" />
+ <Compile Include="Events\EventArgsControllerTriggerReleased.cs" />
+ <Compile Include="Events\EventArgsCurrentLocationChanged.cs" />
+ <Compile Include="Events\EventArgsFarmerChanged.cs" />
+ <Compile Include="Events\EventArgsGameLocationsChanged.cs" />
+ <Compile Include="Events\EventArgsIntChanged.cs" />
+ <Compile Include="Events\EventArgsInventoryChanged.cs" />
+ <Compile Include="Events\EventArgsKeyboardStateChanged.cs" />
+ <Compile Include="Events\EventArgsKeyPressed.cs" />
+ <Compile Include="Events\EventArgsLevelUp.cs" />
+ <Compile Include="Events\EventArgsLoadedGameChanged.cs" />
+ <Compile Include="Events\EventArgsLocationObjectsChanged.cs" />
+ <Compile Include="Events\EventArgsMineLevelChanged.cs" />
+ <Compile Include="Events\EventArgsMouseStateChanged.cs" />
+ <Compile Include="Events\EventArgsNewDay.cs" />
+ <Compile Include="Events\EventArgsStringChanged.cs" />
+ <Compile Include="Events\GameEvents.cs" />
+ <Compile Include="Events\GraphicsEvents.cs" />
+ <Compile Include="Events\LocationEvents.cs" />
+ <Compile Include="Events\MenuEvents.cs" />
+ <Compile Include="Events\MineEvents.cs" />
+ <Compile Include="Events\PlayerEvents.cs" />
+ <Compile Include="Events\TimeEvents.cs" />
<Compile Include="Extensions.cs" />
+ <Compile Include="Inheritance\ChangeType.cs" />
<Compile Include="Inheritance\ItemStackChange.cs" />
<Compile Include="Inheritance\Menus\SBobberBar.cs" />
<Compile Include="Inheritance\Menus\SGameMenu.cs" />
<Compile Include="Inheritance\Menus\SInventoryPage.cs" />
<Compile Include="Inheritance\SBareObject.cs" />
<Compile Include="JsonResolver.cs" />
+ <Compile Include="Log.cs" />
<Compile Include="Logger.cs" />
+ <Compile Include="LogWriter.cs" />
<Compile Include="Manifest.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Program.cs" />
|