Skip to content

Commit fd2964d

Browse files
codebreaker viewmodels library
1 parent 016f230 commit fd2964d

11 files changed

Lines changed: 478 additions & 0 deletions

src/CodeBreaker.ViewModels.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clients", "clients", "{83BDF6AE-872A-49C8-9463-E9EDA945A2F0}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xaml", "xaml", "{7365E9B0-9655-4D92-9550-2944510D7BA1}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBreaker.ViewModels", "clients\xaml\CodeBreaker.ViewModels\CodeBreaker.ViewModels.csproj", "{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(NestedProjects) = preSolution
27+
{7365E9B0-9655-4D92-9550-2944510D7BA1} = {83BDF6AE-872A-49C8-9463-E9EDA945A2F0}
28+
{7A610AEE-AF04-4A08-8B92-A2C9FD8C74EC} = {7365E9B0-9655-4D92-9550-2944510D7BA1}
29+
EndGlobalSection
30+
EndGlobal
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<PackageId>BastaSpring2023.Codebreaker.ViewModels</PackageId>
11+
<Authors>CN innovation</Authors>
12+
<Company>CN innovation</Company>
13+
<PackageDescription>
14+
Codebreaker shared view-model types for XAML-based applications with WinUI, WPF, .NET MAUI, Platform Uno
15+
</PackageDescription>
16+
<RepositoryUrl>https://github.com/CNILearn/codebreakermini</RepositoryUrl>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="BastaSpring2023.Codebreaker.ClientServices" Version="1.0.0-preview.1.4" />
21+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
22+
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.ObjectModel;
2+
using CodeBreaker.Shared.Api;
3+
4+
namespace CodeBreaker.ViewModels.Components;
5+
6+
public class GameViewModel
7+
{
8+
private readonly GameDto _game;
9+
10+
public GameViewModel(GameDto game)
11+
{
12+
_game = game;
13+
}
14+
15+
public Guid GameId => _game.GameId;
16+
17+
public string Name => _game.Username;
18+
19+
public IReadOnlyList<string> Code => _game.Code;
20+
21+
public IReadOnlyList<string> ColorList => _game.Colors;
22+
23+
public int Holes => _game.Holes;
24+
25+
public int MaxMoves => _game.MaxMoves;
26+
27+
public DateTime StartTime => _game.Start;
28+
29+
public ObservableCollection<MoveViewModel> Moves { get; init; } = new();
30+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System.Windows.Input;
2+
using CommunityToolkit.Mvvm.ComponentModel;
3+
using CommunityToolkit.Mvvm.Input;
4+
5+
namespace CodeBreaker.ViewModels;
6+
7+
public enum InfoMessageSeverity
8+
{
9+
Info,
10+
Success,
11+
Warning,
12+
Error
13+
}
14+
15+
public partial class InfoMessageViewModel : ObservableObject
16+
{
17+
public static InfoMessageViewModel Error(string content)
18+
{
19+
InfoMessageViewModel message = new()
20+
{
21+
Title = "Error",
22+
Message = content,
23+
Severity = InfoMessageSeverity.Error,
24+
ActionTitle = "OK"
25+
};
26+
message.ActionCommand = new RelayCommand(() => message.Close());
27+
return message;
28+
}
29+
30+
public static InfoMessageViewModel Warning(string content)
31+
{
32+
InfoMessageViewModel message = new()
33+
{
34+
Title = "Warning",
35+
Message = content,
36+
Severity = InfoMessageSeverity.Warning,
37+
ActionTitle = "OK"
38+
};
39+
message.ActionCommand = new RelayCommand(() => message.Close());
40+
return message;
41+
}
42+
43+
public static InfoMessageViewModel Information(string content)
44+
{
45+
InfoMessageViewModel message = new()
46+
{
47+
Title = "Information",
48+
Message = content,
49+
Severity = InfoMessageSeverity.Info,
50+
ActionTitle = "OK"
51+
};
52+
message.ActionCommand = new RelayCommand(() => message.Close());
53+
return message;
54+
}
55+
56+
public static InfoMessageViewModel Success(string content)
57+
{
58+
InfoMessageViewModel message = new()
59+
{
60+
Title = "Success",
61+
Message = content,
62+
Severity = InfoMessageSeverity.Success,
63+
ActionTitle = "OK"
64+
};
65+
message.ActionCommand = new RelayCommand(() => message.Close());
66+
return message;
67+
}
68+
69+
internal ICollection<InfoMessageViewModel>? ContainingCollection { get; set; }
70+
71+
[ObservableProperty]
72+
private InfoMessageSeverity _severity = InfoMessageSeverity.Info;
73+
74+
[ObservableProperty]
75+
private string _message = string.Empty;
76+
77+
[ObservableProperty]
78+
private string _title = string.Empty;
79+
80+
[ObservableProperty]
81+
[NotifyPropertyChangedFor(nameof(HasAction))]
82+
private ICommand? _actionCommand;
83+
84+
[ObservableProperty]
85+
[NotifyPropertyChangedFor(nameof(HasAction))]
86+
private string? _actionTitle = "OK";
87+
88+
public bool HasAction =>
89+
ActionCommand is not null && ActionTitle is not null;
90+
91+
public void Close() =>
92+
ContainingCollection?.Remove(this);
93+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using CodeBreaker.Shared.Api;
2+
3+
namespace CodeBreaker.ViewModels.Components;
4+
5+
public class MoveViewModel
6+
{
7+
private readonly MoveDto _move;
8+
9+
public MoveViewModel(MoveDto move) =>
10+
_move = move;
11+
12+
public int MoveNumber => _move.MoveNumber;
13+
14+
public IReadOnlyList<string> GuessPegs => _move.GuessPegs;
15+
16+
public KeyPegsDto? KeyPegs => _move.KeyPegs;
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
3+
namespace CodeBreaker.ViewModels;
4+
5+
public partial class SelectedFieldViewModel : ObservableObject
6+
{
7+
[ObservableProperty]
8+
private string? _value;
9+
10+
public bool IsSet =>
11+
Value is not null && Value != string.Empty;
12+
13+
public void Reset() =>
14+
Value = null;
15+
}

0 commit comments

Comments
 (0)