Skip to content

Commit

Permalink
add: #17 AppInfo, AcceptableTextBox, FormattedSlider, pixel perfect
Browse files Browse the repository at this point in the history
  • Loading branch information
Art-Stea1th committed Apr 29, 2017
1 parent 362787b commit af7a2a7
Show file tree
Hide file tree
Showing 31 changed files with 506 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@
<Compile Include="Algorithms\RandomMixer.cs" />
<Compile Include="Algorithms\TheGameOfLife.cs" />
<Compile Include="Controllers\ApplicationStateMachine.cs" />
<Compile Include="Extensions\SettingsExtension.cs" />
<Compile Include="BindingExtensions\SettingsExtension.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="Interfaces\IFrameSequenceGenerator.cs" />
<Compile Include="Interfaces\IGenerationAlgorithm.cs" />
<Compile Include="Interfaces\IMatrix.cs" />
<Compile Include="Interfaces\IMatrixMutator.cs" />
<Compile Include="Interfaces\IMainController.cs" />
<Compile Include="Interfaces\ISeedGenerator.cs" />
<Compile Include="Interfaces\IMatrixGenerator.cs" />
<Compile Include="MVVM\RelayCommand.cs" />
<Compile Include="MVVM\BindableBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
Expand All @@ -94,14 +96,9 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Services\CryptoRandomService.cs" />
<Compile Include="Services\FrameGenerationService.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Resources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms {
using Interfaces;
using MVVM;

public class RandomMixer : BindableBase, IGenerationAlgorithm {
public class RandomMixer : BindableBase, IMatrixMutator {

public string Name => "Random Mixer";

Expand All @@ -16,7 +16,7 @@ public class RandomMixer : BindableBase, IGenerationAlgorithm {
private Random random;
public RandomMixer() => random = new Random();

public byte[,] GenerateNextBy(byte[,] prev) {
public byte[,] Mutate(byte[,] prev) {

var next = new byte[prev.GetLength(0), prev.GetLength(1)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms {
using Interfaces;
using MVVM;

public sealed class TheGameOfLife : BindableBase, IGenerationAlgorithm {
public sealed class TheGameOfLife : BindableBase, IMatrixMutator {

public string Name => "The Game Of Life";

public override string ToString() => Name;

public byte[,] GenerateNextBy(byte[,] prev) {
public byte[,] Mutate(byte[,] prev) {
return NextGeneration(prev);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Windows.Data;

namespace ASD.CellUniverse.Infrastructure.Extensions {

namespace ASD.CellUniverse.Infrastructure.BindingExtensions {

using Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ namespace ASD.CellUniverse.Infrastructure.Controllers {
using MVVM;
using Interfaces;

public sealed class ApplicationStateMachine : BindableBase, IMainController {
public sealed class ApplicationStateMachine : BindableBase, IMainController {

private enum State { Started, Paused, Stopped }
private object shared = new object();

private State state;
public State State { get; private set; }

private StateMachineCommand playCommand, pauseCommand, resumeCommand, stopCommand, resetCommand, dummyCommand;
private StateMachineCommand playPauseResumeCommand, stopResetCommand;

public event Action Started, Paused, Resumed, Stopped, Reseted;
public event Action<State> StateChanged;

public ICommand PlayPauseResume {
public ICommand Start {
get => playPauseResumeCommand;
private set => SetProperty(ref playPauseResumeCommand, value as StateMachineCommand);
}

public ICommand StopReset {
public ICommand Stop {
get => stopResetCommand;
private set => SetProperty(ref stopResetCommand, value as StateMachineCommand);
}
Expand All @@ -35,28 +35,28 @@ private void InitializeCommands() {
playCommand = new StateMachineCommand(
"PLAY",
(o) => ChangeState(State.Started, pauseCommand, stopCommand, Started),
(o) => state == State.Stopped);
(o) => State == State.Stopped);

pauseCommand = new StateMachineCommand(
"PAUSE",
(o) => ChangeState(State.Paused, resumeCommand, resetCommand, Paused),
(o) => state == State.Started);
(o) => State == State.Started);

resumeCommand = new StateMachineCommand(
"RESUME",
(o) => ChangeState(State.Started, pauseCommand, stopCommand, Resumed),
(o) => state == State.Paused);
(o) => State == State.Paused);


stopCommand = new StateMachineCommand(
"STOP",
(o) => ChangeState(State.Stopped, playCommand, dummyCommand, Stopped),
(o) => state == State.Started);
(o) => State == State.Started);

resetCommand = new StateMachineCommand(
"RESET",
(o) => ChangeState(State.Stopped, playCommand, dummyCommand, Reseted),
(o) => state == State.Paused);
(o) => State == State.Paused);

dummyCommand = new StateMachineCommand(
"...",
Expand All @@ -70,24 +70,25 @@ private void ChangeState(
State newState, StateMachineCommand newPlayCommand, StateMachineCommand newStopCommand, Action onNewState) {

lock (shared) {
state = newState;
State = newState;

PlayPauseResume = newPlayCommand;
StopReset = newStopCommand;
Start = newPlayCommand;
Stop = newStopCommand;

onNewState?.Invoke();
StateChanged?.Invoke(State);
}
}

private class StateMachineCommand : RelayCommand {

internal string Name { get; }

public StateMachineCommand(string name, Action<object> execute, Predicate<object> canExecute)
: base(execute, canExecute) {
Name = name;
}
public override string ToString() => Name;

internal string Name { get; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASD.CellUniverse.Infrastructure.Extensions {

public static partial class Extensions {



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IFrameSequenceGenerator : INotifyPropertyChanged {
double FPS { get; set; }
DoubleCollection FPSCollection { get; }

IGenerationAlgorithm GenerationAlgorithm { get; set; }
IMatrixMutator GenerationAlgorithm { get; set; }

byte[,] GeneratedData { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace ASD.CellUniverse.Infrastructure.Interfaces {

public enum State { Started, Paused, Stopped }

public interface IMainController : INotifyPropertyChanged {

event Action Started, Paused, Resumed, Stopped, Reseted;

ICommand PlayPauseResume { get; }
ICommand StopReset { get; }
event Action<State> StateChanged;

State State { get; }

ICommand Start { get; }
ICommand Stop { get; }
}
}
15 changes: 15 additions & 0 deletions Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASD.CellUniverse.Infrastructure.Interfaces {

interface IMatrix {

int Width { get; }
int Height { get; }

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ASD.CellUniverse.Infrastructure.Interfaces {

public interface IGenerationAlgorithm {
public interface IMatrixMutator {

string Name { get; }

byte[,] GenerateNextBy(byte[,] prev);
byte[,] Mutate(byte[,] prev);

}
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ASD.CellUniverse.Infrastructure.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ShellTitle" Type="System.String" Scope="Application">
<Value Profile="(Default)">CellUniverse: Space of the Cellular Machines</Value>
</Setting>
<Setting Name="ShellState" Type="System.Windows.WindowState" Scope="User">
<Value Profile="(Default)">Normal</Value>
</Setting>
<Setting Name="ShellWidth" Type="System.Double" Scope="User">
<Value Profile="(Default)">960</Value>
<Value Profile="(Default)">970</Value>
</Setting>
<Setting Name="ShellHeight" Type="System.Double" Scope="User">
<Value Profile="(Default)">540</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class FrameGenerationService : BindableBase, IFrameSequenceGenerator {

private DispatcherTimer timer;

private double fps = 120.0;
private double fps;
private DoubleCollection fpsCollection;

private IGenerationAlgorithm algorithm;
private IMatrixMutator algorithm;
private byte[,] generatedData;

public double MinFPS => 1.0;
public double MinFPS => fpsCollection.First();
public double MaxFPS => fpsCollection.Last();
public double FPS {
get => fps;
Expand All @@ -29,7 +29,7 @@ public double FPS {
}
public DoubleCollection FPSCollection => fpsCollection;

public IGenerationAlgorithm GenerationAlgorithm {
public IMatrixMutator GenerationAlgorithm {
get => algorithm;
set => SetProperty(ref algorithm, value);
}
Expand All @@ -51,20 +51,22 @@ public IGenerationAlgorithm GenerationAlgorithm {
public void Stop() { timer.Stop(); Reset(); }
public void Reset() => GeneratedData = new byte[GeneratedData.GetLength(0), GeneratedData.GetLength(1)];

public FrameGenerationService(IGenerationAlgorithm algorithm) {
public FrameGenerationService(IMatrixMutator algorithm) {
fpsCollection = new DoubleCollection { 1.0, 2.0, 3.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 50.0, 60.0, 120.0 };
this.algorithm = algorithm;
InitializeTimer();
FPS = fpsCollection.Last();
}

private void InitializeTimer() {
timer = new DispatcherTimer();
timer.Tick += GenerateNext;
UpdateTimerInterval();
}

private void GenerateNext(object sender, EventArgs e) => GeneratedData = algorithm?.GenerateNextBy(generatedData);
private void GenerateNext(object sender, EventArgs e) => GeneratedData = algorithm?.Mutate(generatedData);
private double ValidFps(double fps) => fps < MinFPS ? MinFPS : fps > MaxFPS ? MaxFPS : fps;
private void UpdateTimerInterval() => timer.Interval = TimeSpan.FromMilliseconds(1000.0 / fps);
private void UpdateTimerInterval() => timer.Interval = fps == fpsCollection.Last()
? TimeSpan.FromTicks(1)
: TimeSpan.FromMilliseconds(1000.0 / ValidFps(fps));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\AcceptableTextBox.cs" />
<Compile Include="Controls\FormattedSlider.cs" />
<Compile Include="Controls\MatrixLED.cs" />
<Compile Include="Converters\ShellTitleConverter.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="Helpers\BitmapHelper.cs" />
<Compile Include="Helpers\MeasureArrangeHelper.cs" />
Expand All @@ -55,10 +58,22 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="Converters.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resources.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Styles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit af7a2a7

Please sign in to comment.