Skip to content

Commit b83a393

Browse files
authored
Fixup bugs: chess puzzle view, BGM loop properties, layout editor, nameplate editing, character sprite saving (#555)
1 parent d4926d9 commit b83a393

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

src/SerialLoops.Lib/Items/CharacterItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SKBitmap GetNewNameplate(SKBitmap blankNameplate, SKBitmap blankNameplate
5656
newCanvas.DrawBitmap(blankNameplate, new SKPoint(0, 0));
5757

5858
double widthFactor = 1.0;
59-
int totalWidth = NameplateProperties.Name.CalculateHaroohieTextWidth(project);
59+
int totalWidth = NameplateProperties.Name.CalculateHaroohieTextWidthReplaced(project);
6060
if (totalWidth > 53)
6161
{
6262
widthFactor = 53.0 / totalWidth;
@@ -134,7 +134,7 @@ public SKBitmap GetNewNameplate(SKBitmap blankNameplate, SKBitmap blankNameplate
134134
{
135135
newNameplate.SetPixel(x, y, NameplateProperties.OutlineColor);
136136
}
137-
if (transparent && pixel.Red == 0 && pixel.Green == 128 && pixel.Blue == 0)
137+
if (transparent && pixel is { Red: 0, Green: 128, Blue: 0 })
138138
{
139139
newNameplate.SetPixel(x, y, SKColors.Transparent);
140140
}

src/SerialLoops.Lib/Items/CharacterSpriteItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Linq;
4+
using System.Text.Json;
45
using HaruhiChokuretsuLib.Archive;
56
using HaruhiChokuretsuLib.Archive.Data;
67
using HaruhiChokuretsuLib.Archive.Graphics;
@@ -186,7 +187,7 @@ public class CharacterSpriteGraphics(CharacterSprite sprite, ArchiveFile<Graphic
186187

187188
public void Write(Project project, ILogger log)
188189
{
189-
IO.WriteBinaryFile(Path.Combine("assets", "graphics", $"{BodyLayout.Index:X3}.lay"), BodyLayout.GetBytes(), project, log);
190+
IO.WriteStringFile(Path.Combine("assets", "graphics", $"{BodyLayout.Index:X3}.lay"), JsonSerializer.Serialize(BodyLayout.LayoutEntries, Project.SERIALIZER_OPTIONS), project, log);
190191

191192
foreach (GraphicsFile bodyTexture in BodyTextures)
192193
{

src/SerialLoops.Lib/Util/Extensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ public static SKPaint GetColorFilter(this SKColor color)
408408
};
409409
}
410410

411-
public static int CalculateHaroohieTextWidth(this string str, Project project)
411+
public static int CalculateHaroohieTextWidthReplaced(this string str, Project project)
412+
{
413+
return str.CalculateHaroohieTextWidth(project, replaced: true);
414+
}
415+
416+
public static int CalculateHaroohieTextWidth(this string str, Project project, bool replaced = false)
412417
{
413418
if (project.LangCode.Equals("ja"))
414419
{
@@ -417,10 +422,10 @@ public static int CalculateHaroohieTextWidth(this string str, Project project)
417422
int strWidth = 0;
418423
for (int i = 0; i < str.Length; i++)
419424
{
420-
FontReplacement fr = project.FontReplacement.ReverseLookup(str[i]);
425+
FontReplacement fr = replaced ? project.FontReplacement[str[i]] : project.FontReplacement.ReverseLookup(str[i]);
421426
if ((fr?.CauseOffsetAdjust ?? false) && i < str.Length - 1)
422427
{
423-
FontReplacement nextFr = project.FontReplacement.ReverseLookup(str[i + 1]);
428+
FontReplacement nextFr = replaced ? project.FontReplacement[str[i + 1]] : project.FontReplacement.ReverseLookup(str[i + 1]);
424429
if (nextFr?.TakeOffsetAdjust ?? false)
425430
{
426431
strWidth += fr.Offset - 1;

src/SerialLoops/ViewModels/Editors/LayoutEditorViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public LayoutEntryWithImage SelectedLayoutEntry
3434
_selectedLayoutEntry.IsSelected = false;
3535
}
3636
this.RaiseAndSetIfChanged(ref _selectedLayoutEntry, value);
37-
_selectedLayoutEntry.IsSelected = true;
37+
if (_selectedLayoutEntry is not null)
38+
{
39+
_selectedLayoutEntry.IsSelected = true;
40+
}
3841
}
3942
}
4043

src/SerialLoops/Views/Dialogs/BgmLoopPropertiesDialog.axaml.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Avalonia.Controls;
23
using Avalonia.Interactivity;
34
using SerialLoops.ViewModels.Dialogs;
@@ -66,15 +67,20 @@ private void EndSlider_ValueChanged(object sender, Avalonia.Controls.Primitives.
6667
private void StartSampleBox_OnValueChanged(object sender, NumericUpDownValueChangedEventArgs e)
6768
{
6869
BgmLoopPropertiesDialogViewModel viewModel = (BgmLoopPropertiesDialogViewModel)DataContext;
69-
if (StartSampleBox.Value > EndSampleBox.Value)
70+
if (StartSampleBox is null || EndSampleBox is null || StartSampleSlider is null)
7071
{
71-
StartSampleBox.ValueChanged -= StartSampleBox_OnValueChanged;
72-
StartSampleBox.Value = EndSampleBox.Value;
72+
return;
73+
}
74+
if (StartSampleBox.Value > EndSampleBox.Value && EndSampleBox.Value != 0)
75+
{
76+
StartSampleBox!.ValueChanged -= StartSampleBox_OnValueChanged;
77+
StartSampleBox.Value = EndSampleBox!.Value;
7378
StartSampleBox.ValueChanged += StartSampleBox_OnValueChanged;
7479
return;
7580
}
81+
7682
StartSampleSlider.ValueChanged -= StartSlider_ValueChanged;
77-
StartSampleSlider.Value = (double)StartSampleBox.Value!;
83+
StartSampleSlider.Value = (double)(StartSampleBox?.Value ?? (decimal)viewModel!.LoopPreview.GetTimestampFromSample(viewModel.LoopPreview.StartSample));
7884
StartSampleSlider.ValueChanged += StartSlider_ValueChanged;
7985

8086
viewModel!.LoopPreview.StartSample = viewModel.LoopPreview.GetSampleFromTimestamp(StartSampleSlider.Value);
@@ -84,15 +90,20 @@ private void StartSampleBox_OnValueChanged(object sender, NumericUpDownValueChan
8490
private void EndSampleBox_OnValueChanged(object sender, NumericUpDownValueChangedEventArgs e)
8591
{
8692
BgmLoopPropertiesDialogViewModel viewModel = (BgmLoopPropertiesDialogViewModel)DataContext;
87-
if (EndSampleBox.Value < StartSampleBox.Value)
93+
if (StartSampleBox is null || EndSampleBox is null || EndSampleBox is null)
8894
{
89-
EndSampleBox.ValueChanged -= EndSampleBox_OnValueChanged;
90-
EndSampleBox.Value = StartSampleBox.Value;
95+
return;
96+
}
97+
if (EndSampleBox.Value < StartSampleBox?.Value)
98+
{
99+
EndSampleBox!.ValueChanged -= EndSampleBox_OnValueChanged;
100+
EndSampleBox.Value = StartSampleBox!.Value;
91101
EndSampleBox.ValueChanged += EndSampleBox_OnValueChanged;
92102
return;
93103
}
104+
94105
EndSampleSlider.ValueChanged -= EndSlider_ValueChanged;
95-
EndSampleSlider.Value = (double)EndSampleBox.Value!;
106+
EndSampleSlider.Value = (double)(EndSampleBox?.Value ?? (decimal)viewModel!.LoopPreview.GetTimestampFromSample(viewModel.LoopPreview.EndSample))!;
96107
EndSampleSlider.ValueChanged += EndSlider_ValueChanged;
97108

98109
viewModel!.LoopPreview.EndSample = viewModel.LoopPreview.GetSampleFromTimestamp(EndSampleSlider.Value);

src/SerialLoops/Views/Editors/ChessPuzzleEditorView.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
<ItemsControl.DataTemplates>
5151
<DataTemplate DataType="vm:ChessPieceOnBoard">
5252
<Panel PointerEntered="ChessPiece_OnPointerEntered" PointerExited="ChessPiece_OnPointerExited" Opacity="0.5">
53-
<Image Source="{Binding Image, Converter={x:Static utility:SLConverters.SKBitmapToAvaloniaConverter}}"/>
53+
<Image Source="{Binding Image, Converter={x:Static utility:SLConverters.SKBitmapToAvaloniaConverter}}"
54+
Opacity="2.0"/>
5455
</Panel>
5556
</DataTemplate>
5657
</ItemsControl.DataTemplates>

0 commit comments

Comments
 (0)