Skip to content

Commit

Permalink
Add feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizeta committed Jun 5, 2017
1 parent 22ae493 commit b938cca
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Observer/Observer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void LateUpdate()
{
battleManager.Loop();
replayManager.Loop();
CardAllListEnhancer.SetUp();

if (Settings.ShowSummonCard)
CardAllListEnhancer.SetUp();
}
catch (Exception e)
{
Expand All @@ -50,6 +52,9 @@ private void Receiver_OnReceived(string action, string data)
case "ReplayRequest":
replayManager.InjectReplay(data);
break;
case "Setting":
Settings.Parse(data);
break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Observer/Observer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Compile Include="Helper\ReflectHelper.cs" />
<Compile Include="Replay\ReplayHelper.cs" />
<Compile Include="Replay\ReplayManager.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Socket\Receiver.cs" />
<Compile Include="Socket\Sender.cs" />
</ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions Observer/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ShadowWatcher
{
public static class Settings
{
public const int SHOW_SUMMON_CARD = 1;

public static bool ShowSummonCard { get; set; } = false;

public static void Parse(string data)
{
int flag = int.Parse(data);
ShowSummonCard = (flag & SHOW_SUMMON_CARD) > 0;
}

public static new string ToString()
{
int flag = 0;
flag |= ShowSummonCard ? SHOW_SUMMON_CARD : 0;
return flag.ToString();
}
}
}
5 changes: 5 additions & 0 deletions ShadowWatcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Feature">
<StackPanel x:Name="SettingPanel" Margin="10">
<CheckBox Content="显示召唤卡" IsChecked="{Binding ShowSummonCard}" />
</StackPanel>
</TabItem>
<TabItem Header="Log">
<TextBox x:Name="LogText"/>
</TabItem>
Expand Down
2 changes: 2 additions & 0 deletions ShadowWatcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public MainWindow()
MainTab.IsEnabled = false;

DataContext = this;
SettingPanel.DataContext = new SettingModel();
}

private void attachObserver()
Expand Down Expand Up @@ -66,6 +67,7 @@ private void Receiver_OnReceived(string action, string data)
break;
case "Load":
Sender.Initialize(int.Parse(data));
Sender.Send($"Setting:{Settings.ToString()}");
break;
case "EnemyPlay":
case "EnemyAdd":
Expand Down
55 changes: 55 additions & 0 deletions ShadowWatcher/SettingModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using ShadowWatcher.Socket;
using System.ComponentModel;
using System.IO;
using System.IO.IsolatedStorage;

namespace ShadowWatcher
{
public class SettingModel : INotifyPropertyChanged
{
private IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly();

public SettingModel()
{
if (!storage.FileExists("setting"))
{
Save();
}
else
{
var reader = new StreamReader(new IsolatedStorageFileStream("setting", FileMode.Open, storage));
Settings.Parse(reader.ReadLine());
}
}

public bool ShowSummonCard
{
get => Settings.ShowSummonCard;
set
{
if (Settings.ShowSummonCard != value)
{
Settings.ShowSummonCard = value;
Save();
NotifyPropertyChanged("ShowSummonCard");
}
}
}

public void Save()
{
var writer = new StreamWriter(new IsolatedStorageFileStream("setting", FileMode.Create, storage));
writer.Write(Settings.ToString());
writer.Close();

Sender.Send($"Setting:{Settings.ToString()}");
}

public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
1 change: 1 addition & 0 deletions ShadowWatcher/ShadowWatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</ApplicationDefinition>
<Compile Include="AmountToColorConverter.cs" />
<Compile Include="CardList.cs" />
<Compile Include="SettingModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down

0 comments on commit b938cca

Please sign in to comment.