diff options
| author | Zoryn <Zoryn4163@users.noreply.github.com> | 2016-03-27 01:10:18 -0400 |
|---|---|---|
| committer | Zoryn <Zoryn4163@users.noreply.github.com> | 2016-03-27 01:10:18 -0400 |
| commit | 976bc6e2a96aba761c0feff414dd5f95dd4cd991 (patch) | |
| tree | 9dd87794562d797ec8291fd00af0409b406467df /StardewModdingAPI | |
| parent | 112305161688eb4d88ccfc79b5636eca6e0ab1d9 (diff) | |
| parent | 12bf4fd843be26f89b5fe3415aeec3055c54d786 (diff) | |
| download | SMAPI-976bc6e2a96aba761c0feff414dd5f95dd4cd991.tar.gz SMAPI-976bc6e2a96aba761c0feff414dd5f95dd4cd991.tar.bz2 SMAPI-976bc6e2a96aba761c0feff414dd5f95dd4cd991.zip | |
Merge pull request #67 from Zoryn4163/master
logging things. not sure if ready for release build, testing for a bit.
Diffstat (limited to 'StardewModdingAPI')
38 files changed, 1505 insertions, 857 deletions
diff --git a/StardewModdingAPI/App.config b/StardewModdingAPI/App.config index 697c237b..dc6eaae3 100644 --- a/StardewModdingAPI/App.config +++ b/StardewModdingAPI/App.config @@ -1,9 +1,10 @@ -<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
+
<configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
- </startup>
- <runtime>
- <loadFromRemoteSources enabled="true"/>
- </runtime>
-</configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+ <runtime>
+ <loadFromRemoteSources enabled="true" />
+ </runtime>
+</configuration>
\ No newline at end of file diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs index 7cf2b67b..8bc2c0c3 100644 --- a/StardewModdingAPI/Command.cs +++ b/StardewModdingAPI/Command.cs @@ -7,27 +7,43 @@ namespace StardewModdingAPI public class Command
{
internal static List<Command> RegisteredCommands = new List<Command>();
+ public string[] CalledArgs;
+ public string[] CommandArgs;
+ public string CommandDesc;
+
+ public string CommandName;
+
+ /// <summary>
+ /// Creates a Command from a Name, Description, and Arguments
+ /// </summary>
+ /// <param name="cname">Name</param>
+ /// <param name="cdesc">Description</param>
+ /// <param name="args">Arguments</param>
+ public Command(string cname, string cdesc, string[] args = null)
+ {
+ CommandName = cname;
+ CommandDesc = cdesc;
+ if (args == null)
+ args = new string[0];
+ CommandArgs = args;
+ }
- public String CommandName;
- public String CommandDesc;
- public String[] CommandArgs;
- public String[] CalledArgs;
public event EventHandler<EventArgsCommand> CommandFired;
/// <summary>
- /// Calls the specified command. (It runs the command)
+ /// Calls the specified command. (It runs the command)
/// </summary>
/// <param name="input">The command to run</param>
public static void CallCommand(string input)
{
input = input.TrimEnd(' ');
- string[] args = new string[0];
+ var args = new string[0];
Command fnd;
if (input.Contains(" "))
{
args = input.Split(new[] {" "}, 2, StringSplitOptions.RemoveEmptyEntries);
fnd = FindCommand(args[0]);
- args = args[1].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ args = args[1].Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
}
else
{
@@ -41,12 +57,12 @@ namespace StardewModdingAPI }
else
{
- Log.Error("Unknown Command");
+ Log.AsyncR("Unknown Command");
}
}
/// <summary>
- /// Registers a command to the list of commands properly
+ /// Registers a command to the list of commands properly
/// </summary>
/// <param name="command">Name of the command to register</param>
/// <param name="cdesc">Description</param>
@@ -54,21 +70,21 @@ namespace StardewModdingAPI /// <returns></returns>
public static Command RegisterCommand(string command, string cdesc, string[] args = null)
{
- Command c = new Command(command, cdesc, args);
+ var c = new Command(command, cdesc, args);
if (RegisteredCommands.Contains(c))
{
- Log.Error("Command already registered! [{0}]", c.CommandName);
+ Log.AsyncR($"Command already registered! [{c.CommandName}]");
return RegisteredCommands.Find(x => x.Equals(c));
}
RegisteredCommands.Add(c);
- Log.Verbose("Registered command: " + command);
+ Log.AsyncY("Registered command: " + command);
return c;
}
/// <summary>
- /// Looks up a command in the list of registered commands. Returns null if it doesn't exist (I think)
+ /// Looks up a command in the list of registered commands. Returns null if it doesn't exist (I think)
/// </summary>
/// <param name="name">Name of command to find</param>
/// <returns></returns>
@@ -78,31 +94,16 @@ namespace StardewModdingAPI }
/// <summary>
- /// Creates a Command from a Name, Description, and Arguments
- /// </summary>
- /// <param name="cname">Name</param>
- /// <param name="cdesc">Description</param>
- /// <param name="args">Arguments</param>
- public Command(String cname, String cdesc, String[] args = null)
- {
- CommandName = cname;
- CommandDesc = cdesc;
- if (args == null)
- args = new string[0];
- CommandArgs = args;
- }
-
- /// <summary>
- /// Runs a command. Fires it. Calls it. Any of those.
+ /// Runs a command. Fires it. Calls it. Any of those.
/// </summary>
public void Fire()
{
if (CommandFired == null)
{
- Log.Error("Command failed to fire because it's fire event is null: " + CommandName);
+ Log.AsyncR("Command failed to fire because it's fire event is null: " + CommandName);
return;
}
CommandFired.Invoke(this, new EventArgsCommand(this));
}
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Config.cs b/StardewModdingAPI/Config.cs index 8e6a590c..035d28d7 100644 --- a/StardewModdingAPI/Config.cs +++ b/StardewModdingAPI/Config.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -22,15 +21,7 @@ namespace StardewModdingAPI public virtual Config Instance<T>() where T : Config => Activator.CreateInstance<T>(); /// <summary> - /// Should never be used for anything. - /// </summary> - public Config() - { - - } - - /// <summary> - /// Loads the config from the json blob on disk, updating and re-writing to the disk if needed. + /// Loads the config from the json blob on disk, updating and re-writing to the disk if needed. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> @@ -38,7 +29,7 @@ namespace StardewModdingAPI { if (string.IsNullOrEmpty(ConfigLocation)) { - Log.Error("A config tried to load without specifying a location on the disk."); + Log.AsyncR("A config tried to load without specifying a location on the disk."); return null; } @@ -47,7 +38,7 @@ namespace StardewModdingAPI if (!File.Exists(ConfigLocation)) { //no config exists, generate default values - var c = this.GenerateDefaultConfig<T>(); + var c = GenerateDefaultConfig<T>(); c.ConfigLocation = ConfigLocation; ret = c; } @@ -56,7 +47,7 @@ namespace StardewModdingAPI try { //try to load the config from a json blob on disk - T c = JsonConvert.DeserializeObject<T>(File.ReadAllText(ConfigLocation)); + var c = JsonConvert.DeserializeObject<T>(File.ReadAllText(ConfigLocation), new JsonSerializerSettings {ContractResolver = new JsonResolver()}); c.ConfigLocation = ConfigLocation; @@ -67,7 +58,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Invalid JSON ({0}): {1} \n{2}", GetType().Name, ConfigLocation, ex); + Log.AsyncR($"Invalid JSON ({GetType().Name}): {ConfigLocation} \n{ex}"); return GenerateDefaultConfig<T>(); } } @@ -77,7 +68,7 @@ namespace StardewModdingAPI } /// <summary> - /// MUST be implemented in inheriting class! + /// MUST be implemented in inheriting class! /// </summary> public virtual T GenerateDefaultConfig<T>() where T : Config { @@ -85,7 +76,7 @@ namespace StardewModdingAPI } /// <summary> - /// Merges a default-value config with the user-config on disk. + /// Merges a default-value config with the user-config on disk. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> @@ -94,16 +85,16 @@ namespace StardewModdingAPI try { //default config - var b = JObject.FromObject(Instance<T>().GenerateDefaultConfig<T>()); + var b = JObject.FromObject(Instance<T>().GenerateDefaultConfig<T>(), new JsonSerializer {ContractResolver = new JsonResolver()}); //user config - var u = JObject.FromObject(this); + var u = JObject.FromObject(this, new JsonSerializer {ContractResolver = new JsonResolver()}); //overwrite default values with user values b.Merge(u, new JsonMergeSettings {MergeArrayHandling = MergeArrayHandling.Replace}); //cast json object to config - T c = b.ToObject<T>(); + var c = b.ToObject<T>(); //re-write the location on disk to the object c.ConfigLocation = ConfigLocation; @@ -112,7 +103,7 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("An error occured when updating a config: " + ex); + Log.AsyncR("An error occured when updating a config: " + ex); return this as T; } } @@ -121,10 +112,10 @@ namespace StardewModdingAPI public static class ConfigExtensions { /// <summary> - /// Initializes an instance of any class that inherits from Config. - /// This method performs the loading, saving, and merging of the config on the disk and in memory at a default state. - /// This method should not be used to re-load or to re-save a config. - /// NOTE: You MUST set your config EQUAL to the return of this method! + /// Initializes an instance of any class that inherits from Config. + /// This method performs the loading, saving, and merging of the config on the disk and in memory at a default state. + /// This method should not be used to re-load or to re-save a config. + /// NOTE: You MUST set your config EQUAL to the return of this method! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="baseConfig"></param> @@ -136,35 +127,35 @@ namespace StardewModdingAPI { baseConfig = Activator.CreateInstance<T>(); /* - Log.Error("A config tried to initialize whilst being null."); + Log.AsyncR("A config tried to initialize whilst being null."); return null; */ } if (string.IsNullOrEmpty(configLocation)) { - Log.Error("A config tried to initialize without specifying a location on the disk."); + Log.AsyncR("A config tried to initialize without specifying a location on the disk."); return null; } baseConfig.ConfigLocation = configLocation; - T c = baseConfig.LoadConfig<T>(); + var c = baseConfig.LoadConfig<T>(); return c; } /// <summary> - /// Writes a config to a json blob on the disk specified in the config's properties. + /// Writes a config to a json blob on the disk specified in the config's properties. /// </summary> public static void WriteConfig<T>(this T baseConfig) where T : Config { if (string.IsNullOrEmpty(baseConfig?.ConfigLocation) || string.IsNullOrEmpty(baseConfig.ConfigDir)) { - Log.Error("A config attempted to save when it itself or it's location were null."); + Log.AsyncR("A config attempted to save when it itself or it's location were null."); return; } - string s = JsonConvert.SerializeObject(baseConfig, typeof (T), Formatting.Indented, new JsonSerializerSettings()); + var s = JsonConvert.SerializeObject(baseConfig, typeof (T), Formatting.Indented, new JsonSerializerSettings {ContractResolver = new JsonResolver()}); if (!Directory.Exists(baseConfig.ConfigDir)) Directory.CreateDirectory(baseConfig.ConfigDir); @@ -174,7 +165,8 @@ namespace StardewModdingAPI } /// <summary> - /// Re-reads the json blob on the disk and merges its values with a default config + /// Re-reads the json blob on the disk and merges its values with a default config + /// NOTE: You MUST set your config EQUAL to the return of this method! /// </summary> public static T ReloadConfig<T>(this T baseConfig) where T : Config { diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index a29e5fa8..ddd46115 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -6,13 +6,20 @@ using StardewValley; namespace StardewModdingAPI { /// <summary> - /// Static class containing readonly values. + /// Static class containing readonly values. /// </summary> public static class Constants { + public static readonly Version Version = new Version(0, 39, 3, "Alpha"); + + /// <summary> + /// Not quite "constant", but it makes more sense for it to be here, at least for now + /// </summary> + public static int ModsLoaded = 0; + /// <summary> - /// Stardew Valley's roaming app data location. - /// %AppData%//StardewValley + /// Stardew Valley's roaming app data location. + /// %AppData%//StardewValley /// </summary> public static string DataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"); @@ -29,26 +36,27 @@ namespace StardewModdingAPI public static bool PlayerNull => !Game1.hasLoadedGame || Game1.player == null || string.IsNullOrEmpty(Game1.player.name); /// <summary> - /// Execution path to execute the code. + /// Execution path to execute the code. /// </summary> public static string ExecutionPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); /// <summary> - /// Title for the API console + /// Title for the API console /// </summary> public static string ConsoleTitle => $"Stardew Modding API Console - Version {Version.VersionString} - Mods Loaded: {ModsLoaded}"; /// <summary> - /// Path for log files to be output to. - /// %LocalAppData%//StardewValley//ErrorLogs + /// Path for log files to be output to. + /// %LocalAppData%//StardewValley//ErrorLogs /// </summary> - public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); + public static string LogDir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); - public static readonly Version Version = new Version(0, 39, 2, "Alpha"); + public static string LogPath => Path.Combine(LogDir, "MODDED_ProgramLog.Log_LATEST.txt"); /// <summary> - /// Not quite "constant", but it makes more sense for it to be here, at least for now + /// Whether or not to enable the Render Target drawing code offered by ClxS + /// Do not mark as 'const' or else 'if' checks will complain that the expression is always true in ReSharper /// </summary> - public static int ModsLoaded = 0; + public static bool EnableDrawingIntoRenderTarget => true; } -} +}
\ No newline at end of file diff --git a/StardewModdingAPI/Entities/SCharacter.cs b/StardewModdingAPI/Entities/SCharacter.cs index 39e4f9c8..2d941d55 100644 --- a/StardewModdingAPI/Entities/SCharacter.cs +++ b/StardewModdingAPI/Entities/SCharacter.cs @@ -1,6 +1,6 @@ namespace StardewModdingAPI.Entities
{
- class SCharacter
+ internal class SCharacter
{
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Entities/SFarm.cs b/StardewModdingAPI/Entities/SFarm.cs index 4895df7e..c6c64681 100644 --- a/StardewModdingAPI/Entities/SFarm.cs +++ b/StardewModdingAPI/Entities/SFarm.cs @@ -1,6 +1,6 @@ namespace StardewModdingAPI.Entities
{
- class SFarm
+ internal class SFarm
{
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Entities/SFarmAnimal.cs b/StardewModdingAPI/Entities/SFarmAnimal.cs index 8bd99e1c..fb8ee267 100644 --- a/StardewModdingAPI/Entities/SFarmAnimal.cs +++ b/StardewModdingAPI/Entities/SFarmAnimal.cs @@ -1,6 +1,6 @@ namespace StardewModdingAPI.Entities
{
- class SFarmAnimal
+ internal class SFarmAnimal
{
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Entities/SNpc.cs b/StardewModdingAPI/Entities/SNpc.cs index 612c9c89..727dcff7 100644 --- a/StardewModdingAPI/Entities/SNpc.cs +++ b/StardewModdingAPI/Entities/SNpc.cs @@ -1,6 +1,6 @@ namespace StardewModdingAPI.Entities
{
- class SNpc
+ internal class SNpc
{
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Entities/SPlayer.cs b/StardewModdingAPI/Entities/SPlayer.cs index c74ba461..d464cded 100644 --- a/StardewModdingAPI/Entities/SPlayer.cs +++ b/StardewModdingAPI/Entities/SPlayer.cs @@ -1,33 +1,33 @@ -using System.Collections.Generic;
-using StardewModdingAPI.Inheritance;
+using System;
+using System.Collections.Generic;
using StardewValley;
namespace StardewModdingAPI.Entities
{
- public static class SPlayer
+ /// <summary>
+ /// Static class for intergrating with the player
+ /// </summary>
+ public class SPlayer
{
- public static List<Farmer> AllFarmers
- {
- get
- {
- return SGame.getAllFarmers();
- }
- }
+ /// <summary>
+ /// Calls 'getAllFarmers' in Game1
+ /// </summary>
+ public static List<Farmer> AllFarmers => Game1.getAllFarmers();
- public static Farmer CurrentFarmer
- {
- get
- {
- return SGame.player;
- }
- }
+ /// <summary>
+ /// Do not use.
+ /// </summary>
+ [Obsolete("Use 'Player' instead.")]
+ public static Farmer CurrentFarmer => Game1.player;
- public static GameLocation CurrentFarmerLocation
- {
- get
- {
- return SGame.player.currentLocation;
- }
- }
+ /// <summary>
+ /// Gets the current player from Game1
+ /// </summary>
+ public static Farmer Player => Game1.player;
+
+ /// <summary>
+ /// Gets the player's current location from Game1
+ /// </summary>
+ public static GameLocation CurrentFarmerLocation => Player.currentLocation;
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index 5c604492..87319f37 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -55,4 +55,4 @@ namespace StardewModdingAPI.Events ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, buttons, value));
}
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index a6de3597..91151e86 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -17,6 +17,7 @@ namespace StardewModdingAPI.Events NewState = newState;
NewState = newState;
}
+
public KeyboardState NewState { get; private set; }
public KeyboardState PriorState { get; private set; }
}
@@ -27,6 +28,7 @@ namespace StardewModdingAPI.Events {
KeyPressed = keyPressed;
}
+
public Keys KeyPressed { get; private set; }
}
@@ -37,6 +39,7 @@ namespace StardewModdingAPI.Events PlayerIndex = playerIndex;
ButtonPressed = buttonPressed;
}
+
public PlayerIndex PlayerIndex { get; private set; }
public Buttons ButtonPressed { get; private set; }
}
@@ -48,6 +51,7 @@ namespace StardewModdingAPI.Events PlayerIndex = playerIndex;
ButtonReleased = buttonReleased;
}
+
public PlayerIndex PlayerIndex { get; private set; }
public Buttons ButtonReleased { get; private set; }
}
@@ -60,6 +64,7 @@ namespace StardewModdingAPI.Events ButtonPressed = buttonPressed;
Value = value;
}
+
public PlayerIndex PlayerIndex { get; private set; }
public Buttons ButtonPressed { get; private set; }
public float Value { get; private set; }
@@ -73,18 +78,20 @@ namespace StardewModdingAPI.Events 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; }
}
@@ -96,6 +103,7 @@ namespace StardewModdingAPI.Events NewMenu = newMenu;
PriorMenu = priorMenu;
}
+
public IClickableMenu NewMenu { get; private set; }
public IClickableMenu PriorMenu { get; private set; }
}
@@ -106,15 +114,29 @@ namespace StardewModdingAPI.Events {
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; }
}
@@ -125,6 +147,7 @@ namespace StardewModdingAPI.Events NewLocation = newLocation;
PriorLocation = priorLocation;
}
+
public GameLocation NewLocation { get; private set; }
public GameLocation PriorLocation { get; private set; }
}
@@ -136,8 +159,9 @@ namespace StardewModdingAPI.Events NewFarmer = NewFarmer;
PriorFarmer = PriorFarmer;
}
- public Farmer NewFarmer { get; private set; }
- public Farmer PriorFarmer { get; private set; }
+
+ public Farmer NewFarmer { get; }
+ public Farmer PriorFarmer { get; }
}
public class EventArgsInventoryChanged : Event |
