aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-04-29 08:43:00 -0400
committerMichael <[email protected]>2017-04-29 08:43:00 -0400
commitfc815c48696e5f3193411ad5decfd1324f06572f (patch)
tree9f2810c4a7dfd332842eb1ede0b1c81329cce3e4
parentf762756dbc62a3eecf09cfa227732441a5c105be (diff)
downloadshiftos_thereturn-fc815c48696e5f3193411ad5decfd1324f06572f.tar.gz
shiftos_thereturn-fc815c48696e5f3193411ad5decfd1324f06572f.tar.bz2
shiftos_thereturn-fc815c48696e5f3193411ad5decfd1324f06572f.zip
Custom Upgrade Providers
-rw-r--r--ShiftOS.WinForms/Program.cs2
-rw-r--r--ShiftOS_TheReturn/AudioManager.cs3
-rw-r--r--ShiftOS_TheReturn/Shiftorium.cs44
3 files changed, 30 insertions, 19 deletions
diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs
index a8f5693..b2f064d 100644
--- a/ShiftOS.WinForms/Program.cs
+++ b/ShiftOS.WinForms/Program.cs
@@ -53,7 +53,6 @@ namespace ShiftOS.WinForms
SkinEngine.SetIconProber(new ShiftOSIconProvider());
ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider());
Localization.RegisterProvider(new WFLanguageProvider());
- Shiftorium.RegisterProvider(new WinformsShiftoriumProvider());
AppearanceManager.OnExit += () =>
{
Environment.Exit(0);
@@ -95,6 +94,7 @@ namespace ShiftOS.WinForms
}
}
+ [ShiftoriumProvider]
internal class WinformsShiftoriumProvider : IShiftoriumProvider
{
public List<ShiftoriumUpgrade> GetDefaults()
diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs
index 82b7000..d689cad 100644
--- a/ShiftOS_TheReturn/AudioManager.cs
+++ b/ShiftOS_TheReturn/AudioManager.cs
@@ -41,8 +41,7 @@ namespace ShiftOS.Engine
private static WaveOut _out = null;
private static AudioFileReader _reader = null;
private static IAudioProvider _provider = null;
- private static bool _running = true;
-
+
/// <summary>
/// Stops the current sound if one is playing and disposes of the sound.
/// </summary>
diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs
index 007877c..2637f1b 100644
--- a/ShiftOS_TheReturn/Shiftorium.cs
+++ b/ShiftOS_TheReturn/Shiftorium.cs
@@ -280,6 +280,7 @@ namespace ShiftOS.Engine
private static IShiftoriumProvider _provider = null;
+ [Obsolete("Please annotate your provider with a [ShiftoriumProvider] attribute instead. This function doesn't do anything.")]
public static void RegisterProvider(IShiftoriumProvider p)
{
_provider = p;
@@ -289,18 +290,6 @@ namespace ShiftOS.Engine
public static List<ShiftoriumUpgrade> GetDefaults()
{
List<ShiftoriumUpgrade> list = new List<ShiftoriumUpgrade>();
- try
- {
- list = _provider.GetDefaults();
- }
- catch (Exception ex)
- {
- Console.WriteLine("Couldn't get the upgrade definition list from the provider.");
- Console.WriteLine("This might be able to help:");
- Console.WriteLine(ex);
- list = JsonConvert.DeserializeObject<List<ShiftoriumUpgrade>>(Properties.Resources.Shiftorium);
- }
-
//Now we probe for ShiftoriumUpgradeAttributes for mods.
foreach(var file in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
{
@@ -311,10 +300,20 @@ namespace ShiftOS.Engine
var asm = Assembly.LoadFile(file);
foreach (var type in asm.GetTypes())
{
+ if (type.GetInterfaces().Contains(typeof(IShiftoriumProvider)))
+ {
+ if(type.GetCustomAttributes().FirstOrDefault(x=> x is ShiftoriumProviderAttribute) != null)
+ {
+ var _p = Activator.CreateInstance(type, null) as IShiftoriumProvider;
+ list.AddRange(_p.GetDefaults());
+ }
+ }
+
+
ShiftoriumUpgradeAttribute attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute;
if (attrib != null)
{
- if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null)
+ if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null)
throw new ShiftoriumConflictException(attrib.Upgrade);
list.Add(new ShiftoriumUpgrade
{
@@ -332,7 +331,7 @@ namespace ShiftOS.Engine
attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute;
if (attrib != null)
{
- if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null)
+ if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null)
throw new ShiftoriumConflictException(attrib.Upgrade);
list.Add(new ShiftoriumUpgrade
{
@@ -352,7 +351,7 @@ namespace ShiftOS.Engine
attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute;
if (attrib != null)
{
- if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null)
+ if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null)
throw new ShiftoriumConflictException(attrib.Upgrade);
list.Add(new ShiftoriumUpgrade
{
@@ -372,7 +371,7 @@ namespace ShiftOS.Engine
attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute;
if (attrib != null)
{
- if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null)
+ if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null)
throw new ShiftoriumConflictException(attrib.Upgrade);
list.Add(new ShiftoriumUpgrade
{
@@ -392,6 +391,14 @@ namespace ShiftOS.Engine
catch { }
}
}
+
+
+
+ foreach(var item in list)
+ {
+ if (list.Where(x => x.ID == item.ID).Count() > 1)
+ throw new ShiftoriumConflictException(item.Id);
+ }
return list;
}
}
@@ -460,4 +467,9 @@ namespace ShiftOS.Engine
}
}
+
+ public class ShiftoriumProviderAttribute : Attribute
+ {
+
+ }
}