Skip to content

Commit 49e035d

Browse files
committed
0.39.1 inbound!
1 parent eeb9e50 commit 49e035d

File tree

9 files changed

+85
-417
lines changed

9 files changed

+85
-417
lines changed

StardewModdingAPI/Config.cs

Lines changed: 10 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Copyright 2016 Zoey (Zoryn)
1111

1212
namespace StardewModdingAPI
1313
{
14-
public partial class Config
14+
public class Config
1515
{
1616
[JsonIgnore]
1717
public virtual string ConfigLocation { get; protected internal set; }
@@ -47,7 +47,7 @@ public virtual T LoadConfig<T>() where T : Config
4747
if (!File.Exists(ConfigLocation))
4848
{
4949
//no config exists, generate default values
50-
var c = this.GenerateBaseConfig<T>();
50+
var c = this.GenerateDefaultConfig<T>();
5151
c.ConfigLocation = ConfigLocation;
5252
ret = c;
5353
}
@@ -67,8 +67,8 @@ public virtual T LoadConfig<T>() where T : Config
6767
}
6868
catch (Exception ex)
6969
{
70-
Log.Error("Invalid JSON Config: {0} \n{1}", ConfigLocation, ex);
71-
return GenerateBaseConfig<T>();
70+
Log.Error("Invalid JSON ({0}): {1} \n{2}", GetType().Name, ConfigLocation, ex);
71+
return GenerateDefaultConfig<T>();
7272
}
7373
}
7474

@@ -84,15 +84,6 @@ public virtual T GenerateDefaultConfig<T>() where T : Config
8484
return null;
8585
}
8686

87-
/// <summary>
88-
/// Use the public GenerateDefaultConfig insteaad
89-
/// </summary>
90-
[Obsolete]
91-
protected virtual T GenerateBaseConfig<T>() where T : Config
92-
{
93-
return GenerateDefaultConfig<T>();
94-
}
95-
9687
/// <summary>
9788
/// Merges a default-value config with the user-config on disk.
9889
/// </summary>
@@ -103,7 +94,7 @@ public virtual T UpdateConfig<T>() where T : Config
10394
try
10495
{
10596
//default config
106-
var b = JObject.FromObject(Instance<T>().GenerateBaseConfig<T>());
97+
var b = JObject.FromObject(Instance<T>().GenerateDefaultConfig<T>());
10798

10899
//user config
109100
var u = JObject.FromObject(this);
@@ -133,7 +124,12 @@ public static class ConfigExtensions
133124
/// Initializes an instance of any class that inherits from Config.
134125
/// This method performs the loading, saving, and merging of the config on the disk and in memory at a default state.
135126
/// This method should not be used to re-load or to re-save a config.
127+
/// NOTE: You MUST set your config EQUAL to the return of this method!
136128
/// </summary>
129+
/// <typeparam name="T"></typeparam>
130+
/// <param name="baseConfig"></param>
131+
/// <param name="configLocation"></param>
132+
/// <returns></returns>
137133
public static T InitializeConfig<T>(this T baseConfig, string configLocation) where T : Config
138134
{
139135
if (baseConfig == null)
@@ -184,122 +180,5 @@ public static T ReloadConfig<T>(this T baseConfig) where T : Config
184180
{
185181
return baseConfig.UpdateConfig<T>();
186182
}
187-
188-
[Obsolete]
189-
public static void WriteConfig(this Config baseConfig)
190-
{
191-
Log.Error("A config has been written through an obsolete way.\n\tThis method of writing configs will not be supported in future versions.");
192-
WriteConfig<Config>(baseConfig);
193-
}
194-
195-
[Obsolete]
196-
public static Config ReloadConfig(this Config baseConfig)
197-
{
198-
Log.Error("A config has been reloaded through an obsolete way.\n\tThis method of loading configs will not be supported in future versions.");
199-
return baseConfig.ReloadConfig<Config>();
200-
}
201-
}
202-
203-
public partial class Config
204-
{
205-
[Obsolete] public static int invalids = 0;
206-
207-
[JsonIgnore]
208-
[Obsolete]
209-
public virtual JObject JObject { get; protected set; }
210-
211-
[Obsolete]
212-
public static Config InitializeConfig(string configLocation, Config baseConfig)
213-
{
214-
invalids++;
215-
216-
if (string.IsNullOrEmpty(configLocation))
217-
{
218-
Log.Verbose("The location to save the config to must not be empty.");
219-
return null;
220-
}
221-
222-
if (baseConfig == null)
223-
{
224-
Log.Verbose("A config must be instantiated before being passed to Initialize.\n\t" + configLocation);
225-
return null;
226-
}
227-
228-
baseConfig.ConfigLocation = configLocation;
229-
return baseConfig.LoadConfig(baseConfig);
230-
}
231-
232-
[Obsolete]
233-
public virtual Config GenerateBaseConfig(Config baseConfig)
234-
{
235-
//Must be implemented in sub-class
236-
return null;
237-
}
238-
239-
[Obsolete]
240-
public virtual Config LoadConfig(Config baseConfig)
241-
{
242-
if (!File.Exists(baseConfig.ConfigLocation))
243-
{
244-
var v = (Config) baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] {baseConfig});
245-
v.WriteConfig();
246-
}
247-
else
248-
{
249-
var p = baseConfig.ConfigLocation;
250-
251-
try
252-
{
253-
var j = JObject.Parse(File.ReadAllText(baseConfig.ConfigLocation));
254-
baseConfig = (Config) j.ToObject(baseConfig.GetType());
255-
baseConfig.ConfigLocation = p;
256-
baseConfig.JObject = j;
257-
258-
baseConfig = UpdateConfig(baseConfig);
259-
baseConfig.ConfigLocation = p;
260-
baseConfig.JObject = j;
261-
262-
baseConfig.WriteConfig();
263-
}
264-
catch
265-
{
266-
Log.Verbose("Invalid JSON: " + p);
267-
}
268-
}
269-
270-
return baseConfig;
271-
}
272-
273-
[Obsolete]
274-
public virtual Config UpdateConfig(Config baseConfig)
275-
{
276-
try
277-
{
278-
//default config with all standard values
279-
var b = JObject.FromObject(baseConfig.GetType().GetMethod("GenerateBaseConfig", BindingFlags.Public | BindingFlags.Instance).Invoke(baseConfig, new object[] {baseConfig}));
280-
//user config with their values
281-
var u = baseConfig.JObject;
282-
283-
b.Merge(u, new JsonMergeSettings {MergeArrayHandling = MergeArrayHandling.Replace});
284-
285-
return (Config) b.ToObject(baseConfig.GetType());
286-
}
287-
catch (Exception ex)
288-
{
289-
Log.Error(ex.ToString());
290-
}
291-
return baseConfig;
292-
}
293-
294-
/// <summary>
295-
/// NOTICE: THIS IS OBSOLETE AND WILL BE REMOVED IN THE FUTURE. 'BaseConfigPath' IS NOW A PROPERTY IN A MOD
296-
/// </summary>
297-
/// <param name="theMod"></param>
298-
/// <returns></returns>
299-
[Obsolete]
300-
public static string GetBasePath(Mod theMod)
301-
{
302-
return theMod.BaseConfigPath;
303-
}
304183
}
305184
}

StardewModdingAPI/Constants.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,15 @@ public static class Constants
3636
/// <summary>
3737
/// Title for the API console
3838
/// </summary>
39-
public static string ConsoleTitle => string.Format("Stardew Modding API Console - Version {0} - Mods Loaded: {1}", VersionString, ModsLoaded);
39+
public static string ConsoleTitle => $"Stardew Modding API Console - Version {Version.VersionString} - Mods Loaded: {ModsLoaded}";
4040

4141
/// <summary>
4242
/// Path for log files to be output to.
4343
/// %LocalAppData%//StardewValley//ErrorLogs
4444
/// </summary>
4545
public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs");
4646

47-
public const int MajorVersion = 0;
48-
49-
public const int MinorVersion = 38;
50-
51-
public const int PatchVersion = 8;
52-
53-
public const string Build = "Alpha";
54-
55-
public static string VersionString => string.Format("{0}.{1}.{2} {3}", MajorVersion, MinorVersion, PatchVersion, Build);
47+
public static readonly Version Version = new Version(0, 39, 1, "Alpha");
5648

5749
/// <summary>
5850
/// Not quite "constant", but it makes more sense for it to be here, at least for now

StardewModdingAPI/Inheritance/SGameLocation.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

StardewModdingAPI/Manifest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Manifest : Config
1717
/// <summary>
1818
/// The version of the mod.
1919
/// </summary>
20-
public virtual string Version { get; set; }
20+
public virtual Version Version { get; set; }
2121

2222
/// <summary>
2323
/// A description of the mod.
@@ -39,11 +39,11 @@ public class Manifest : Config
3939
/// </summary>
4040
public virtual string EntryDll { get; set; }
4141

42-
protected override T GenerateBaseConfig<T>()
42+
public override T GenerateDefaultConfig<T>()
4343
{
4444
Name = "";
4545
Authour = "";
46-
Version = "";
46+
Version = new Version(0, 0, 0, "");
4747
Description = "";
4848
UniqueID = Guid.NewGuid().ToString();
4949
PerSaveConfigs = false;

StardewModdingAPI/Mod.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@ namespace StardewModdingAPI
55
{
66
public class Mod
77
{
8-
/// <summary>
9-
/// The name of your mod.
10-
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
11-
/// </summary>
12-
[Obsolete]
13-
public virtual string Name { get; set; }
14-
15-
/// <summary>
16-
/// The name of the mod's authour.
17-
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
18-
/// </summary>
19-
[Obsolete]
20-
public virtual string Authour { get; set; }
21-
22-
/// <summary>
23-
/// The version of the mod.
24-
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
25-
/// </summary>
26-
[Obsolete]
27-
public virtual string Version { get; set; }
28-
29-
/// <summary>
30-
/// A description of the mod.
31-
/// NOTE: THIS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION OF SMAPI
32-
/// </summary>
33-
[Obsolete]
34-
public virtual string Description { get; set; }
35-
368
/// <summary>
379
/// The mod's manifest
3810
/// </summary>

0 commit comments

Comments
 (0)