Skip to content

Commit

Permalink
Merge pull request #185 from ManuelHu/feature/set
Browse files Browse the repository at this point in the history
Settings erweitert
  • Loading branch information
tomwendel authored Nov 24, 2016
2 parents 17b2c1c + 3b8028c commit 811b2d1
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public OptionsOptionControl(ScreenComponent manager, OptionsScreen optionsScreen

Checkbox disablePersistence = new Checkbox(manager)
{
Checked = bool.Parse(settings.Get<string>("DisablePersistence")),
Checked = settings.Get("DisablePersistence", false),
HookBrush = new TextureBrush(manager.Game.Assets.LoadTexture(typeof(ScreenComponent), "iconCheck_brown"), TextureBrushMode.Stretch),
};
disablePersistence.CheckedChanged += (state) => SetPersistence(state);
Expand Down Expand Up @@ -110,7 +110,7 @@ public OptionsOptionControl(ScreenComponent manager, OptionsScreen optionsScreen

Checkbox enableFullscreen = new Checkbox(manager)
{
Checked = bool.Parse(settings.Get<string>("EnableFullscreen")),
Checked = settings.Get<bool>("EnableFullscreen"),
HookBrush = new TextureBrush(manager.Game.Assets.LoadTexture(typeof(ScreenComponent), "iconCheck_brown"), TextureBrushMode.Stretch),
};
enableFullscreen.CheckedChanged += (state) => SetFullscreen(state);
Expand Down
10 changes: 3 additions & 7 deletions OctoAwesome/OctoAwesome.Client/OctoGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ public OctoGame()

//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15);

int width = 1080, height = 720;
if (Settings.KeyExists("Width"))
width = Settings.Get<int>("Width");
if (Settings.KeyExists("Height"))
height = Settings.Get<int>("Height");
int width = Settings.Get("Width", 1080);
int height = Settings.Get("Height", 720);
Window.ClientSize = new Size(width, height);

if (Settings.KeyExists("EnableFullscreen") && Settings.Get<bool>("EnableFullscreen"))
Window.Fullscreen = true;
Window.Fullscreen = Settings.Get("EnableFullscreen", false);

if (Settings.KeyExists("Viewrange"))
{
Expand Down
3 changes: 1 addition & 2 deletions OctoAwesome/OctoAwesome.Client/Screens/LoadScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public LoadScreen(ScreenComponent manager) : base(manager)
if (levelList.Items.Count >= 1)
levelList.SelectedItem = levelList.Items[0];

if (settings.KeyExists("LastUniverse") && settings.Get<string>("LastUniverse") != null
&& settings.Get<string>("LastUniverse") != "")
if (settings.Get<string>("LastUniverse") != null)
{
var lastlevel = levelList.Items.FirstOrDefault(u => u.Id == Guid.Parse(settings.Get<string>("LastUniverse")));
if (lastlevel != null)
Expand Down
2 changes: 1 addition & 1 deletion OctoAwesome/OctoAwesome.Runtime/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private ResourceManager()

planets = new Dictionary<int, IPlanet>();

bool.TryParse(Settings.Get<string>("DisablePersistence"), out disablePersistence);
disablePersistence = Settings.Get("DisablePersistence", false);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OctoAwesome/OctoAwesome.Tests/OctoAwesome.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7E2C82CC-CCC7-4837-9662-9850092BDC3B}</ProjectGuid>
<ProjectGuid>{0468B67C-E076-4B19-833C-382513606A5A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OctoAwesome.Tests</RootNamespace>
Expand Down
164 changes: 90 additions & 74 deletions OctoAwesome/OctoAwesome.Tests/SettingsManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,74 +1,90 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Xunit;

namespace OctoAwesome.Tests
{

public class SettingsManagerTests
{
[Fact]
public void ReadWrite()
{
Settings settings = new Settings(true);

string[] testArray = new string[] {"foo", "bar"};
settings.Set("foo", testArray);

string[] newArray = settings.GetArray<string>("foo");

Assert.True(testArray.SequenceEqual(newArray));


int[] testArrayInt = new int[] { 3,5,333,456,3457};
settings.Set("fooInt", testArrayInt);

int[] newArrayInt = settings.GetArray<int>("fooInt");

Assert.True(testArray.SequenceEqual(newArray));


bool[] testArrayBool = new bool[] { true, false};
settings.Set("fooBool", testArrayBool);

bool[] newArrayBool = settings.GetArray<bool>("fooBool");

Assert.True(testArray.SequenceEqual(newArray));


String inputString = "randomStringWith§$%&/()=Charakters";
settings.Set("inputString", inputString);


Assert.Equal(inputString, settings.Get<string>("inputString"));


int inputInt = new Random().Next();
settings.Set("inputInt", inputInt);

Assert.Equal(inputInt, settings.Get<int>("inputInt"));


bool inputBool = true;
settings.Set("inputBool", inputBool);

Assert.Equal(inputBool, settings.Get<bool>("inputBool"));





}

[Fact]
public void NullTest()
{

Settings settings = new Settings(true);

int test = settings.Get<int>("foobarnotset");
Assert.Equal(0,test);
}
}
}
using System;
using System.Linq;
using System.Linq.Expressions;
using Xunit;

namespace OctoAwesome.Tests
{
public class SettingsManagerTests
{
[Fact]
public void ReadWrite()
{
Settings settings = new Settings(true);

string[] testArray = new string[] { "foo", "bar" };
settings.Set("foo", testArray);

string[] newArray = settings.GetArray<string>("foo");

Assert.True(testArray.SequenceEqual(newArray));


int[] testArrayInt = new int[] { 3, 5, 333, 456, 3457 };
settings.Set("fooInt", testArrayInt);

int[] newArrayInt = settings.GetArray<int>("fooInt");

Assert.True(testArray.SequenceEqual(newArray));


bool[] testArrayBool = new bool[] { true, false };
settings.Set("fooBool", testArrayBool);

bool[] newArrayBool = settings.GetArray<bool>("fooBool");

Assert.True(testArray.SequenceEqual(newArray));


String inputString = "randomStringWith§$%&/()=Charakters";
settings.Set("inputString", inputString);


Assert.Equal(inputString, settings.Get<string>("inputString"));


int inputInt = new Random().Next();
settings.Set("inputInt", inputInt);

Assert.Equal(inputInt, settings.Get<int>("inputInt"));


bool inputBool = true;
settings.Set("inputBool", inputBool);

Assert.Equal(inputBool, settings.Get<bool>("inputBool"));
}

[Fact]
public void UnsetTest()
{
Settings settings = new Settings(true);

int testInt = settings.Get<int>("foobarnotset");
Assert.Equal(0, testInt);

string testString = settings.Get<string>("foobarnotset");
Assert.Equal(null, testString);

int testIntDefault = settings.Get("foobarnotset", 42);
Assert.Equal(42, testIntDefault);

string testStringDefault = settings.Get("foobarnotset", "ABC");
Assert.Equal("ABC", testStringDefault);
}

[Fact]
public void DeleteTest()
{
Settings settings = new Settings(true);

settings.Set("test", 1);
int test1 = settings.Get<int>("test");
Assert.Equal(1, test1);

settings.Delete("test");
int test2 = settings.Get<int>("test");
Assert.Equal(0, test2);
}
}
}
17 changes: 17 additions & 0 deletions OctoAwesome/OctoAwesome/ISettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace OctoAwesome
{
/// <summary>
/// Interface zur Verwaltung der Anwendungseinstellungen
/// </summary>
public interface ISettings
{
/// <summary>
Expand All @@ -9,6 +12,14 @@ public interface ISettings
/// <returns>Der Wert der Einstellung.</returns>
T Get<T>(string key);

/// <summary>
/// Gibt den Wert einer Einstellung zurück.
/// </summary>
/// <param name="key">Der Schlüssel der Einstellung.</param>
/// <param name="defaultValue">Default-Wert, der zurückgegeben wird, wenn der key nicht vorhanden ist.</param>
/// <returns>Der Wert der Einstellung oder der Default-Wert.</returns>
T Get<T>(string key, T defaultValue);

/// <summary>
/// Gibt das Array einer Einstellung zurück
/// </summary>
Expand Down Expand Up @@ -65,5 +76,11 @@ public interface ISettings
/// <param name="key">Der Schlüssel der Einstellung.</param>
/// <param name="values">Der Wert der Einstellung.</param>
void Set(string key, bool[] values);

/// <summary>
/// Löscht eine Eigenschaft aus den Einstellungen
/// </summary>
/// <param name="key">Der Schlüssel der Einstellung</param>
void Delete(string key);
}
}
Loading

0 comments on commit 811b2d1

Please sign in to comment.