diff --git a/SPRView.Net.CLI/Cli/InformationCommand.cs b/SPRView.Net.CLI/Cli/InformationCommand.cs index c3f7247..d4be6e8 100644 --- a/SPRView.Net.CLI/Cli/InformationCommand.cs +++ b/SPRView.Net.CLI/Cli/InformationCommand.cs @@ -14,11 +14,11 @@ public class InformationCommand : ICommand private string Pad(object src, int len = 12) { string? temp = src.ToString(); - if(temp == null) + if (temp == null) return string.Empty; if (len <= temp.Length) return temp; - while(temp.Length < len) + while (temp.Length < len) { temp += " "; } @@ -41,9 +41,9 @@ public ValueTask ExecuteAsync(IConsole console) console.Output.Write(line); } console.Output.Write("\tPalette:\n"); - for(int i = 0; i < spr.Palette.Length; i++) + for (int i = 0; i < spr.Palette.Length; i++) { - if(i % 16 == 0) + if (i % 16 == 0) console.Output.Write("\n\t\t"); Rgba32 rgba = spr.Palette.AtIndex(i); console.Output.Write("■ ".Pastel(Color.FromArgb(rgba.A, rgba.R, rgba.G, rgba.B))); diff --git a/SPRView.Net.CLI/Cli/PreviewCommand.cs b/SPRView.Net.CLI/Cli/PreviewCommand.cs index d004dd4..bdcfaaa 100644 --- a/SPRView.Net.CLI/Cli/PreviewCommand.cs +++ b/SPRView.Net.CLI/Cli/PreviewCommand.cs @@ -29,7 +29,7 @@ public ValueTask ExecuteAsync(IConsole console) int width = image.Width; int height = image.Height; float ratio = 1.0f; - if(width > height) + if (width > height) { ratio = (float)PreviewSize / width; width = PreviewSize; @@ -44,10 +44,10 @@ public ValueTask ExecuteAsync(IConsole console) image.Mutate(x => x.Resize(width, height)); for (int i = 0; i < height; i++) { - for(int j = 0; j < width; j++) + for (int j = 0; j < width; j++) { Rgba32 rgba = image[j, i]; - console.Output.Write("██".Pastel(System.Drawing.Color.FromArgb(rgba.A,rgba.R,rgba.G,rgba.B))); + console.Output.Write("██".Pastel(System.Drawing.Color.FromArgb(rgba.A, rgba.R, rgba.G, rgba.B))); } console.Output.Write('\n'); } diff --git a/SPRView.Net.Lib/Class/Sprite.cs b/SPRView.Net.Lib/Class/Sprite.cs index a86e445..32f6868 100644 --- a/SPRView.Net.Lib/Class/Sprite.cs +++ b/SPRView.Net.Lib/Class/Sprite.cs @@ -1,7 +1,6 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SPRView.Net.Lib.Interface; -using System.Diagnostics.CodeAnalysis; namespace SPRView.Net.Lib; public class CSprite : ISprite { @@ -60,7 +59,7 @@ public CSprite(Stream stream) } public CSprite(string? path) { - if(path == null) + if (path == null) throw new FileLoadException("Open a null invalid file path"); using FileStream fs = new(path, FileMode.Open); Init(fs); @@ -70,7 +69,7 @@ public CSprite(string? path) public static ISprite Create(Stream stream) { return new CSprite(stream); - } + } public static ISprite Create(string? path) { return new CSprite(path); @@ -87,7 +86,7 @@ public int GetFrames() public Image GetImage(int frame) { - if(frame < 0 || frame >= m_aryFrames.Count) + if (frame < 0 || frame >= m_aryFrames.Count) { throw new IndexOutOfRangeException("Frame index out of bound"); } diff --git a/SPRView.Net.Lib/Class/SpriteColorPalette.cs b/SPRView.Net.Lib/Class/SpriteColorPalette.cs index f4e8075..b7b6cb1 100644 --- a/SPRView.Net.Lib/Class/SpriteColorPalette.cs +++ b/SPRView.Net.Lib/Class/SpriteColorPalette.cs @@ -12,8 +12,8 @@ public Rgba32 AtIndex(int index) { return this[index]; } - private Rgba32[] _color = new Rgba32[size]; - private int _size = size; + private readonly Rgba32[] _color = new Rgba32[size]; + private readonly int _size = size; public int Size { get => _size; } public int Length { get => _color.Length; } public Rgba32 this[int index] diff --git a/SPRView.Net/ViewModel/CreateNewViewModel.cs b/SPRView.Net/ViewModel/CreateNewViewModel.cs index 7061222..46dfdb4 100644 --- a/SPRView.Net/ViewModel/CreateNewViewModel.cs +++ b/SPRView.Net/ViewModel/CreateNewViewModel.cs @@ -1,5 +1,4 @@ using Avalonia.Controls; -using Avalonia.Controls.Shapes; using Avalonia.Media.Imaging; using Avalonia.Platform.Storage; using Avalonia.Threading; @@ -44,10 +43,10 @@ protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) } public int PathSelected { get; set; } = 0; - private List m_aryImagePaths = []; + private readonly List m_aryImagePaths = []; public string[] ImagePaths { - get { return m_aryImagePaths.ToArray(); } + get { return [.. m_aryImagePaths]; } } #region Property @@ -124,7 +123,7 @@ public void MovedownImage() #endregion #region Export - private DispatcherTimer animation_timer; + private readonly DispatcherTimer animation_timer; public void StartPreview() { if (!animation_timer.IsEnabled) @@ -184,9 +183,9 @@ public bool SaveValid } public async void SaveToSpr() { - if(Export_Width % 2==1|| Export_Height % 2==1) + if (Export_Width % 2 == 1 || Export_Height % 2 == 1) { - var box = MessageBoxWindow.CreateMessageBox(Lang.CreateNew_Export_NotSQRTWarning, null, Lang.Shared_OK, Lang.Shared_Cancel); + var box = MessageBoxWindow.CreateMessageBox(Lang!.CreateNew_Export_NotSQRTWarning, null, Lang.Shared_OK, Lang.Shared_Cancel); box.Position = new Avalonia.PixelPoint(Parent.Position.X + (int)Parent.Width / 2, Parent.Position.Y + (int)Parent.Height / 2); await box.ShowDialog(Parent); } @@ -206,11 +205,11 @@ public async void SaveToSpr() { //量化 //降低一个维度,以便统一量化 - + int buffersize = 0; if (UnPackAnimate) { - foreach(var path in m_aryImagePaths) + foreach (var path in m_aryImagePaths) { SixLabors.ImageSharp.Image frame = SixLabors.ImageSharp.Image.Load(path); buffersize += frame.Frames.Count; @@ -334,7 +333,7 @@ public async void SaveToSpr() } } Progress = 200; - var box = MessageBoxWindow.CreateMessageBox("☑︎💾", null, Lang.Shared_OK, Lang.Shared_Cancel); + var box = MessageBoxWindow.CreateMessageBox("☑︎💾", null, Lang!.Shared_OK, Lang.Shared_Cancel); box.Position = new Avalonia.PixelPoint(Parent.Position.X + (int)Parent.Width / 2, Parent.Position.Y + (int)Parent.Height / 2); await box.ShowDialog(Parent); } diff --git a/SPRView.Net/ViewModel/MainWindowViewModel.cs b/SPRView.Net/ViewModel/MainWindowViewModel.cs index d6d0479..9e0dcde 100644 --- a/SPRView.Net/ViewModel/MainWindowViewModel.cs +++ b/SPRView.Net/ViewModel/MainWindowViewModel.cs @@ -348,7 +348,7 @@ public void SpriteInfoUpdateAll() #endregion #region Command - private DispatcherTimer animation_timer; + private readonly DispatcherTimer animation_timer; public bool IsTimerVliad { get => animation_timer.IsEnabled; diff --git a/SPRView.Net/Window/CreateNew.axaml b/SPRView.Net/Window/CreateNew.axaml index 69ac9fa..6223bd4 100644 --- a/SPRView.Net/Window/CreateNew.axaml +++ b/SPRView.Net/Window/CreateNew.axaml @@ -37,7 +37,6 @@