Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamEnderKing authored Apr 27, 2024
2 parents 87fc955 + 299d5f0 commit 75deb4b
Show file tree
Hide file tree
Showing 79 changed files with 1,015 additions and 658 deletions.
32 changes: 12 additions & 20 deletions installer/Data/ConfigFileData.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
//using installer.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace installer.Data
{
Expand Down Expand Up @@ -135,13 +129,13 @@ public record ConfigDataFile
public string UserName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public bool Remembered { get; set; } = false;
public CommandFile Commands { get; set; } = new CommandFile();
public List<Player> Players { get; set; } = new List<Player>();
public CommandFile Commands { get; set; } = new();
public List<Player> Players { get; set; } = [];
}

public class Command
{
public Command(CommandFile? f = null) => file = f ?? new CommandFile();
public Command(CommandFile? f = null) => file = f ?? new();

Check warning on line 138 in installer/Data/ConfigFileData.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-logic

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public event EventHandler? OnMemoryChanged;

Check warning on line 139 in installer/Data/ConfigFileData.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-logic

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public CommandFile file;
public bool Enabled
Expand Down Expand Up @@ -299,7 +293,7 @@ public ConfigData(string? p = null, bool autoSave = true)
path = string.IsNullOrEmpty(p) ? Path.Combine(dataDir, "config.json") : p;
file = new ConfigDataFile();
com = new Command(file.Commands);
Players = new ObservableCollection<Player>();
Players = [];
Players.CollectionChanged += (sender, args) =>
{
if (args.NewItems is not null)
Expand All @@ -321,14 +315,12 @@ public void ReadFile()
{
try
{
using (FileStream s = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
using (StreamReader r = new StreamReader(s))
{
var f = JsonSerializer.Deserialize<ConfigDataFile>(r.ReadToEnd());
if (f is null)
throw new JsonException();
else file = f;
}
using FileStream s = new(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
using StreamReader r = new(s);
var f = JsonSerializer.Deserialize<ConfigDataFile>(r.ReadToEnd());
if (f is null)
throw new JsonException();
else file = f;
}
catch (Exception)
{
Expand All @@ -344,8 +336,8 @@ public void SaveFile()
{
file.Commands = com.file;
file.Players = new List<Player>(Players);
using FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
using StreamWriter sw = new StreamWriter(fs);
using FileStream fs = new(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
using StreamWriter sw = new(fs);
fs.SetLength(0);
sw.Write(JsonSerializer.Serialize(file));
sw.Flush();
Expand Down
17 changes: 6 additions & 11 deletions installer/Model/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

#pragma warning disable CA1416

Expand Down Expand Up @@ -52,9 +47,9 @@ public string Color
public abstract class Logger : IDisposable
{
private int jobID = 0;
public List<Logger> Partner = new List<Logger>();
public List<Logger> Partner = [];
public string PartnerInfo = string.Empty;
public Dictionary<LogLevel, int> CountDict = new Dictionary<LogLevel, int>
public Dictionary<LogLevel, int> CountDict = new()
{
{ LogLevel.Trace, 0 }, { LogLevel.Debug, 1 },
{ LogLevel.Information, 2 }, { LogLevel.Warning, 3 },
Expand Down Expand Up @@ -202,7 +197,7 @@ public class FileLogger : Logger
{
private DateTime time = DateTime.MinValue;
private string path;
private Mutex mutex = new Mutex();
private readonly Mutex mutex = new();
public string Path
{
get => path; set
Expand Down Expand Up @@ -341,8 +336,8 @@ protected override void Log(LogLevel logLevel, string message)
}
public class ListLogger : Logger
{
protected ConcurrentQueue<LogRecord> Queue = new ConcurrentQueue<LogRecord>();
public ObservableCollection<LogRecord> List = new ObservableCollection<LogRecord>();
protected ConcurrentQueue<LogRecord> Queue = new();
public ObservableCollection<LogRecord> List = [];
public override DateTime LastRecordTime => DateTime.Now;
private Timer timer;
private DateTime time;

Check warning on line 343 in installer/Model/Logger.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-install

The field 'ListLogger.time' is never used
Expand Down
11 changes: 3 additions & 8 deletions logic/Client/Interact/CommandLineProcess.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Diagnostics;

namespace Client.Interact
{
public static class CommandLineProcess
{
public static void StartProcess()
{
ProcessStartInfo startInfo = new ProcessStartInfo
ProcessStartInfo startInfo = new()
{
FileName = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false
};

Process process = new Process { StartInfo = startInfo };
Process process = new() { StartInfo = startInfo };
process.Start();

// 写入命令行
Expand Down
10 changes: 2 additions & 8 deletions logic/Client/Model/Player.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace Client.Model
{
Expand Down Expand Up @@ -58,7 +52,7 @@ public ObservableCollection<Ship> Ships
{
get
{
return ships ?? (ships = new ObservableCollection<Ship>());
return ships ??= [];
}
set
{
Expand Down
25 changes: 12 additions & 13 deletions logic/Client/Old/PlayerStatusBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Client.Util;
using Protobuf;

Expand All @@ -12,9 +11,9 @@ enum PlayerRole
Red, //the down player
Blue //the up player
};
PlayerRole myRole;
readonly PlayerRole myRole;
private double lengthOfHpSlide = 240;
List<ShipLabel> shipLabels = new List<ShipLabel>();
readonly List<ShipLabel> shipLabels = [];
public PlayerStatusBar(Grid parent, int Row, int Column, int role)
{
InitializeComponent();
Expand Down Expand Up @@ -116,7 +115,7 @@ public void SetShipValue(MessageOfShip ship)
{
if (ship.TeamId == (long)PlayerTeam.Red && myRole == PlayerRole.Red || ship.TeamId == (long)PlayerTeam.Blue && myRole == PlayerRole.Blue)
{
ShipLabel shipLabel = new ShipLabel();
ShipLabel shipLabel = new();
shipLabel.name.Text = ship.ShipType.ToString() + ship.PlayerId.ToString();
shipLabel.producer.Text = ship.ProducerType.ToString();
shipLabel.armor.Text = ship.ArmorType.ToString();
Expand All @@ -140,15 +139,15 @@ public void SlideLengthSet()
}
public class ShipLabel
{
public Label name = new Label() { Text = "name" };
public Label producer = new Label() { Text = "producer" };
public Label constructor = new Label() { Text = "constructor" };
public Label armor = new Label() { Text = "armor" };
public Label shield = new Label() { Text = "shield" };
public Label weapon = new Label() { Text = "weapon" };
public Label status = new Label() { Text = "IDLE" };
public Label name = new() { Text = "name" };
public Label producer = new() { Text = "producer" };
public Label constructor = new() { Text = "constructor" };
public Label armor = new() { Text = "armor" };
public Label shield = new() { Text = "shield" };
public Label weapon = new() { Text = "weapon" };
public Label status = new() { Text = "IDLE" };
public double lengthOfShipHpSlide = 80;
public BoxView hpSlide = new BoxView() { Color = Colors.Red, WidthRequest = 80, HeightRequest = 3, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.End };
public Grid shipStatusGrid = new Grid();
public BoxView hpSlide = new() { Color = Colors.Red, WidthRequest = 80, HeightRequest = 3, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.End };
public Grid shipStatusGrid = new();
};
}
6 changes: 3 additions & 3 deletions logic/Client/PlaybackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PlaybackClient
private readonly double playbackSpeed;
private readonly int frameTimeInMilliseconds;
public MessageReader? Reader;
private SemaphoreSlim sema;
private readonly SemaphoreSlim sema;
public SemaphoreSlim Sema => sema;
public PlaybackClient(string fileName, double playbackSpeed = 1.0, int frameTimeInMilliseconds = 50)
{
Expand Down Expand Up @@ -63,8 +63,8 @@ public PlaybackClient(string fileName, double playbackSpeed = 1.0, int frameTime
bool endFile = false;
bool mapFlag = false; // 是否获取了地图
int[,] map = new int[50, 50];
long frame = (long)(this.frameTimeInMilliseconds / this.playbackSpeed);
var mapCollecter = new MessageReader(this.fileName);
long frame = (long)(frameTimeInMilliseconds / playbackSpeed);
var mapCollecter = new MessageReader(fileName);
while (!mapFlag)
{
var msg = mapCollecter.ReadOne();
Expand Down
24 changes: 10 additions & 14 deletions logic/Client/Util/UtilInfo.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using Protobuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Util
{
public static class UtilInfo
{
public static Dictionary<ShipType, string> ShipTypeNameDict = new Dictionary<ShipType, string>{
public static readonly Dictionary<ShipType, string> ShipTypeNameDict = new()
{
{ ShipType.NullShipType, "Null" },
{ ShipType.CivilianShip, "Civilian" },
{ ShipType.MilitaryShip, "Military" },
{ ShipType.FlagShip, "FlagShip" }
};

public static Dictionary<ShipState, string> ShipStateNameDict = new Dictionary<ShipState, string>
public static readonly Dictionary<ShipState, string> ShipStateNameDict = new()
{
{ ShipState.Idle, "Idle" },
{ ShipState.Producing, "Producing" },
Expand All @@ -30,7 +26,7 @@ public static class UtilInfo

};

public static Dictionary<ArmorType, string> ShipArmorTypeNameDict = new Dictionary<ArmorType, string>
public static readonly Dictionary<ArmorType, string> ShipArmorTypeNameDict = new()
{
//{ ArmorType.NullArmorType, "Null" },
//{ ArmorType.Armor1, "Armor1" },
Expand All @@ -42,31 +38,31 @@ public static class UtilInfo
{ ArmorType.Armor3, "🪖🌟" }
};

public static Dictionary<ShieldType, string> ShipShieldTypeNameDict = new Dictionary<ShieldType, string>
public static readonly Dictionary<ShieldType, string> ShipShieldTypeNameDict = new()
{
{ ShieldType.NullShieldType, "Null" },
{ ShieldType.Shield1, "🛡️🔸" },
{ ShieldType.Shield2, "🛡️⭐" },
{ ShieldType.Shield3, "🛡️🌟" }
};

public static Dictionary<ConstructorType, string> ShipConstructorNameDict = new Dictionary<ConstructorType, string>
public static readonly Dictionary<ConstructorType, string> ShipConstructorNameDict = new()
{
{ ConstructorType.NullConstructorType, "Null" },
{ ConstructorType.Constructor1, "🔨🔸" },
{ ConstructorType.Constructor2, "🔨⭐" },
{ ConstructorType.Constructor3, "🔨🌟" }
};

public static Dictionary<ProducerType, string> ShipProducerTypeNameDict = new Dictionary<ProducerType, string>
public static readonly Dictionary<ProducerType, string> ShipProducerTypeNameDict = new()
{
{ ProducerType.NullProducerType, "Null" },
{ ProducerType.Producer1, "⛏🔸" },
{ ProducerType.Producer2, "⛏⭐" },
{ ProducerType.Producer3, "⛏🌟" }
};

public static Dictionary<WeaponType, string> ShipWeaponTypeNameDict = new Dictionary<WeaponType, string>
public static readonly Dictionary<WeaponType, string> ShipWeaponTypeNameDict = new()
{
{ WeaponType.NullWeaponType, "Null" },
{ WeaponType.Lasergun, "Lasergun" },
Expand All @@ -79,8 +75,8 @@ public static class UtilInfo
public static bool isRedPlayerShipsEmpty = true;
public static bool isBluePlayerShipsEmpty = false;

public static int unitWidth = 10;
public static int unitHeight = 10;
public const int unitWidth = 10;
public const int unitHeight = 10;
}


Expand Down
8 changes: 4 additions & 4 deletions logic/Client/View/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class MainPage : ContentPage
{
private bool UIinitiated = false;

GeneralViewModel viewModel;
readonly GeneralViewModel viewModel;
public MainPage()
{
viewModel = new GeneralViewModel();
Expand Down Expand Up @@ -113,9 +113,9 @@ public MainPage()
//InitiateObjects();
UIinitiated = true;
}
private Label[,] mapPatches_ = new Label[50, 50];
private List<CircleLabel> shipCirc = new List<CircleLabel>();
private List<CircleLabel> bulletCirc = new List<CircleLabel>();
private readonly Label[,] mapPatches_ = new Label[50, 50];
private readonly List<CircleLabel> shipCirc = [];
private readonly List<CircleLabel> bulletCirc = [];
private readonly IDispatcherTimer timer;
private long counter;
public float unitWidth = 10;
Expand Down
Loading

0 comments on commit 75deb4b

Please sign in to comment.