Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
panxuc authored Apr 10, 2024
2 parents 5671592 + f7c65bc commit d0d0dfe
Show file tree
Hide file tree
Showing 19 changed files with 1,173 additions and 460 deletions.
11 changes: 11 additions & 0 deletions logic/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@

<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />

<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />

<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Maui.Core" Version="2.88.7" />

</ItemGroup>


Expand All @@ -85,6 +90,9 @@
<Compile Update="Old\PlayerStatusBar.xaml.cs">
<DependentUpon>PlayerStatusBar.xaml</DependentUpon>
</Compile>
<Compile Update="View\CircleLabel.xaml.cs">
<DependentUpon>CircleLabel.xaml</DependentUpon>
</Compile>
</ItemGroup>


Expand All @@ -95,6 +103,9 @@
<MauiXaml Update="Old\PlayerStatusBar.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\CircleLabel.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 15 additions & 9 deletions logic/Client/Interact/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text.Json;
using System.Threading.Tasks;

namespace Client.Interact
namespace installer.Data
{
public enum LanguageOption
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public record ConfigDataFile
public string UserName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public bool Remembered { get; set; } = false;
public Command Commands { get; set; } = new Command();
public CommandFile Commands { get; set; } = new CommandFile();
}

public class Command
Expand Down Expand Up @@ -207,8 +207,9 @@ public ConfigData(string? p = null, bool autoSave = true)
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"THUAI7.json") : p;
file = new ConfigDataFile();

com = new Command(file.Commands);
ReadFile();

if (autoSave)
OnMemoryChanged += (_, _) => SaveFile();
watcher = new FileSystemWatcher(Directory.GetParent(path)?.FullName ?? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
Expand All @@ -221,6 +222,8 @@ public ConfigData(string? p = null, bool autoSave = true)
| NotifyFilters.LastWrite
| NotifyFilters.Security
| NotifyFilters.Size;
watcher.IncludeSubdirectories = false;
watcher.EnableRaisingEvents = true;
watcher.Changed += (_, _) =>
{
ReadFile();
Expand All @@ -235,7 +238,7 @@ public void ReadFile()
using (FileStream s = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
using (StreamReader r = new StreamReader(s))
{
var f = JsonSerializer.Deserialize<ConfigDataFile>(path);
var f = JsonSerializer.Deserialize<ConfigDataFile>(r.ReadToEnd());
if (f is null)
throw new JsonException();
else file = f;
Expand All @@ -245,11 +248,13 @@ public void ReadFile()
{
file = new ConfigDataFile();
}
file.Commands.OnMemoryChanged += (_, _) => OnMemoryChanged?.Invoke(this, new EventArgs());
com = new Command(file.Commands);
com.OnMemoryChanged += (_, _) => OnMemoryChanged?.Invoke(this, new EventArgs());
}

public void SaveFile()
{
file.Commands = com.file;
using FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
using StreamWriter sw = new StreamWriter(fs);
fs.SetLength(0);
Expand All @@ -263,6 +268,7 @@ public void SaveFile()
protected string path;
protected ConfigDataFile file;
protected FileSystemWatcher watcher;
protected Command com;

public string Description
{
Expand Down Expand Up @@ -350,15 +356,15 @@ public bool Remembered

public Command Commands
{
get => file.Commands;
get => com;
set
{
var temp = file.Commands;
file.Commands = value;
var temp = com;
com = value;
if (temp != value)
OnMemoryChanged?.Invoke(this, new EventArgs());
}
}
}

}
}
32 changes: 17 additions & 15 deletions logic/Client/Interact/JsonInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,26 @@ static string[] JsonInteract()
return cominfo;
}

public static string[] FileInteract()
{
string[] cominfo = new string[10];
ConfigData d = new();
if (d.Commands.Launched == false)
{
cominfo[0] = d.Commands.IP;
cominfo[1] = d.Commands.Port;
cominfo[2] = d.Commands.PlayerID;
cominfo[3] = d.Commands.TeamID;
cominfo[4] = d.Commands.ShipType;

d.Commands.Launched = true;
}
//public static string[] FileInteract()
//{
// string[] cominfo = new string[10];
// ConfigData d = new();
// if (d.Commands.Launched == false)
// {
// cominfo[0] = d.Commands.IP;
// cominfo[1] = d.Commands.Port;
// cominfo[2] = d.Commands.PlayerID;
// cominfo[3] = d.Commands.TeamID;
// cominfo[4] = d.Commands.ShipType;
// }
//}
// d.Commands.Launched = true;
// }


return cominfo;
}
// return cominfo;
//}

}
}
6 changes: 4 additions & 2 deletions logic/Client/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Client.ViewModel;
using Microsoft.Extensions.Logging;
using SkiaSharp.Views.Maui.Controls.Hosting;

namespace Client
{
Expand All @@ -10,6 +11,7 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseSkiaSharp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand All @@ -19,8 +21,8 @@ public static MauiApp CreateMauiApp()
#if DEBUG
builder.Logging.AddDebug();
#endif
builder.Services.AddSingleton<GeneralViewModel>();
builder.Services.AddSingleton<MainPage>();
//builder.Services.AddSingleton<GeneralViewModel>();
//builder.Services.AddSingleton<MainPage>();
return builder.Build();
}
}
Expand Down
123 changes: 123 additions & 0 deletions logic/Client/Model/DrawCircLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Model
{
public class DrawCircLabel : BindableObject
{
private float x;
public float X
{
get
{
return x;
}
set
{
x = value;
OnPropertyChanged();
OnPropertyChanged(nameof(Thick));
}
}
private float y;
public float Y
{
get
{
return y;
}
set
{
y = value;
OnPropertyChanged();
OnPropertyChanged(nameof(Thick));
}
}
private Thickness thick;
public Thickness Thick
{
get
{
thick.Left = x;
thick.Top = y;
return thick;
}
set
{
thick = value;
OnPropertyChanged();
}
}
private float radius;
public float Radius
{
get
{
return radius;
}
set
{
radius = value;
OnPropertyChanged();
}
}
private Color color;
public Color Color
{
get
{
return color;
}
set
{
color = value;
OnPropertyChanged();
}
}
private string text;
public string Text
{
get
{
return text;
}
set
{
text = value;
OnPropertyChanged();
}
}

private float fontSize;
public float FontSize
{
get
{
return fontSize;
}
set
{
fontSize = value;
OnPropertyChanged();
}
}

private Color textColor;
public Color TextColor
{
get
{
return textColor;
}
set
{
textColor = value;
OnPropertyChanged();
}
}

}
}
3 changes: 2 additions & 1 deletion logic/Client/Model/MapPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum MapPatchType
Community = 8,
Fort = 9,
WormHole = 10,
Null = 11
Null = 11,
Construction = 12
};

public class MapPatch : BindableObject
Expand Down
9 changes: 7 additions & 2 deletions logic/Client/Model/Player.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -51,6 +52,7 @@ public int Score
}
}


private ObservableCollection<Ship> ships;
public ObservableCollection<Ship> Ships
{
Expand All @@ -60,8 +62,11 @@ public ObservableCollection<Ship> Ships
}
set
{
ships = value;
OnPropertyChanged();
if (value != null && value.Count > 0)
{
ships = value;
OnPropertyChanged(nameof(Ships));
}
}
}
}
Expand Down
Loading

0 comments on commit d0d0dfe

Please sign in to comment.