Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr.Abc committed Aug 5, 2024
1 parent f51111f commit f8a731e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 33 deletions.
8 changes: 4 additions & 4 deletions SPRView.Net.CLI/Cli/InformationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 += " ";
}
Expand All @@ -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)));
Expand Down
6 changes: 3 additions & 3 deletions SPRView.Net.CLI/Cli/PreviewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
Expand Down
7 changes: 3 additions & 4 deletions SPRView.Net.Lib/Class/Sprite.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions SPRView.Net.Lib/Class/SpriteColorPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 8 additions & 9 deletions SPRView.Net/ViewModel/CreateNewViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
Expand Down Expand Up @@ -44,10 +43,10 @@ protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
}

public int PathSelected { get; set; } = 0;
private List<string> m_aryImagePaths = [];
private readonly List<string> m_aryImagePaths = [];
public string[] ImagePaths
{
get { return m_aryImagePaths.ToArray(); }
get { return [.. m_aryImagePaths]; }
}

#region Property
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion SPRView.Net/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion SPRView.Net/Window/CreateNew.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<Button Content="{CompiledBinding Lang.CreateNew_RemoveImage}" Command="{CompiledBinding RemoveImage}" MinWidth="150"/>
<RepeatButton Content="{CompiledBinding Lang.CreateNew_MoveDownImage}" Command="{CompiledBinding MovedownImage}" MinWidth="150"/>
</UniformGrid>

<TextBlock Margin="0 5" Text="{CompiledBinding Lang.CreateNew_Type}"/>
<ComboBox SelectedIndex="{CompiledBinding Type}" MinWidth="300">
<ComboBoxItem Content="{CompiledBinding Lang.CreateNew_Type_ParallelUpright}"/>
Expand Down
15 changes: 6 additions & 9 deletions SPRView.Net/Window/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ namespace SPRView.Net;

public partial class MessageBoxWindow : Window
{
public MessageBoxWindow()
{
InitializeComponent();
}
public MessageBoxWindow() => InitializeComponent();
public static MessageBoxWindow CreateMessageBox(string message, string? title = null, string? ok = null, string? cancel = null)
{
var box = new MessageBoxWindow();
box.FindControl<TextBlock>("Message").Text = message;
box.FindControl<TextBlock>("Message")!.Text = message;
if (title != null)
box.FindControl<TextBlock>("Title").Text = title;
if(ok != null)
box.FindControl<Button>("OK").Content = ok;
box.FindControl<TextBlock>("Title")!.Text = title;
if (ok != null)
box.FindControl<Button>("OK")!.Content = ok;
if (cancel != null)
box.FindControl<Button>("Cancel").Content = cancel;
box.FindControl<Button>("Cancel")!.Content = cancel;
return box;
}
public void Button_Click(object? obj, RoutedEventArgs e)
Expand Down

0 comments on commit f8a731e

Please sign in to comment.