Skip to content

Commit

Permalink
Nullable for SerialLoops and test project
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 committed Nov 12, 2024
1 parent bfa6ac8 commit 6449f51
Show file tree
Hide file tree
Showing 80 changed files with 732 additions and 684 deletions.
8 changes: 4 additions & 4 deletions src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemC
(!bgReverted && (commands[i].Verb == CommandVerb.BG_DISPCG ||
commands[i].Verb == CommandVerb.BG_FADE)))
{
BackgroundItem background = ((BgScriptParameter)commands[i].Parameters[0]).Background;
BackgroundItem? background = ((BgScriptParameter)commands[i].Parameters[0]).Background;

preview.Background = background;
preview.BgScrollCommand = bgScrollCommand;
Expand Down Expand Up @@ -472,7 +472,7 @@ public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemC
case SpriteExitScriptParameter.SpriteExitTransition.FADE_OUT_CENTER:
case SpriteExitScriptParameter.SpriteExitTransition.FADE_OUT_LEFT:
if (sprites.ContainsKey(prevCharacter) && previousSprites.ContainsKey(prevCharacter) &&
((SpriteScriptParameter)previousCommand.Parameters[1]).Sprite.Sprite.Character ==
((SpriteScriptParameter)previousCommand.Parameters[1]).Sprite?.Sprite.Character ==
prevCharacter.MessageInfo.Character)
{
sprites.Remove(prevCharacter);
Expand Down Expand Up @@ -944,7 +944,7 @@ preview.BgScrollCommand is not null &&
// Draw character sprites
foreach (PositionedSprite sprite in preview.Sprites)
{
SKBitmap spriteBitmap = sprite.Sprite.GetClosedMouthAnimation(project)[0].Frame;
SKBitmap? spriteBitmap = sprite.Sprite?.GetClosedMouthAnimation(project)[0].Frame;
canvas.DrawBitmap(spriteBitmap, sprite.Positioning.GetSpritePosition(spriteBitmap),
sprite.PalEffect);
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ preview.BgScrollCommand is not null &&
}

public (SKBitmap? PreviewImage, string? ErrorImage) GeneratePreviewImage(
Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ScriptItemCommand currentCommand,
Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ScriptItemCommand? currentCommand,
Project project, ILogger log)
{
return GeneratePreviewImage(GetScriptPreview(commandTree, currentCommand, project, log), project);
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public static void ClearOrCreateCaches(string cachesDirectory, ILogger log)
Directory.CreateDirectory(vceCache);
}

public ItemDescription? FindItem(string name)
public ItemDescription? FindItem(string? name)
{
if (string.IsNullOrEmpty(name))
{
Expand Down
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/Script/Parameters/BgScriptParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace SerialLoops.Lib.Script.Parameters;

public class BgScriptParameter(string name, BackgroundItem background, bool kinetic)
public class BgScriptParameter(string name, BackgroundItem? background, bool kinetic)
: ScriptParameter(name, ParameterType.BG)
{
public BackgroundItem Background { get; set; } = background;
public BackgroundItem? Background { get; set; } = background;
public bool Kinetic { get; set; } = kinetic;
public override short[] GetValues(object? obj = null) => [(short)(Background?.Id ?? 0)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace SerialLoops.Lib.Script.Parameters;

public class SpriteScriptParameter(string name, CharacterSpriteItem sprite)
public class SpriteScriptParameter(string name, CharacterSpriteItem? sprite)
: ScriptParameter(name, ParameterType.SPRITE)
{
public CharacterSpriteItem Sprite { get; set; } = sprite;
public CharacterSpriteItem? Sprite { get; set; } = sprite;
public override short[] GetValues(object? obj = null) => [(short)(Sprite?.Index ?? 0)];

public override SpriteScriptParameter Clone(Project project, EventFile eventFile)
Expand Down
8 changes: 4 additions & 4 deletions src/SerialLoops.Lib/Script/SpritePositioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class SpritePositioning
public int X { get; set; }
public int Layer { get; set; }

public SKPoint GetSpritePosition(SKBitmap sprite)
public SKPoint GetSpritePosition(SKBitmap? sprite)
{
return new SKPoint(X, 384 - sprite.Height);
return sprite is null ? new() : new(X, 384 - sprite.Height);
}

public enum SpritePosition
Expand All @@ -23,7 +23,7 @@ public enum SpritePosition

public struct PositionedSprite
{
public CharacterSpriteItem Sprite { get; set; }
public CharacterSpriteItem? Sprite { get; set; }
public SpritePositioning Positioning { get; set; }
public SKPaint PalEffect { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/SerialLoops/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SerialLoops;

public partial class App : Application
{
private IClassicDesktopStyleApplicationLifetime _desktop;
private IClassicDesktopStyleApplicationLifetime? _desktop;

public override void Initialize()
{
Expand All @@ -37,21 +37,21 @@ public override void OnFrameworkInitializationCompleted()

private void About_Click(object? sender, EventArgs e)
{
((MainWindow)_desktop.MainWindow).ViewModel.AboutCommand.Execute(Unit.Default);
((MainWindow)_desktop!.MainWindow!).ViewModel!.AboutCommand.Execute(Unit.Default);
}

private void Preferences_Click(object? sender, EventArgs e)
{
((MainWindow)_desktop.MainWindow).ViewModel.PreferencesCommand.Execute(Unit.Default);
((MainWindow)_desktop!.MainWindow!).ViewModel!.PreferencesCommand.Execute(Unit.Default);
}

private void Updates_Click(object? sender, EventArgs e)
{
((MainWindow)_desktop.MainWindow).ViewModel.CheckForUpdatesCommand.Execute(Unit.Default);
((MainWindow)_desktop!.MainWindow!).ViewModel!.CheckForUpdatesCommand.Execute(Unit.Default);
}

private void Logs_Click(object? sender, EventArgs e)
{
((MainWindow)_desktop.MainWindow).ViewModel.ViewLogsCommand.Execute(Unit.Default);
((MainWindow)_desktop!.MainWindow!).ViewModel!.ViewLogsCommand.Execute(Unit.Default);
}
}
}
6 changes: 3 additions & 3 deletions src/SerialLoops/Controls/LabelWithIcon.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace SerialLoops.Controls;

public partial class LabelWithIcon : UserControl
{
public string Icon
public string? Icon
{
get => IconPath.Path;
set => IconPath.Path = $"avares://SerialLoops/Assets/Icons/{value}.svg";
}

public string Text
public string? Text
{
get => LabelText.Text;
set => LabelText.Text = value;
Expand All @@ -21,4 +21,4 @@ public LabelWithIcon()
InitializeComponent();
}

}
}
10 changes: 5 additions & 5 deletions src/SerialLoops/Controls/LinkButton.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SerialLoops.Controls;

public partial class LinkButton : UserControl
{
public string Icon
public string? Icon
{
get => IconPath.Path;
set
Expand All @@ -15,13 +15,13 @@ public string Icon
IconPath.IsVisible = !string.IsNullOrEmpty(value);
}
}
public string Text
public string? Text
{
get => LinkText.Text;
set => LinkText.Text = value;
}
public delegate void OnClickDelegate(object sender, EventArgs e);
public OnClickDelegate OnClick { get; set; }
public delegate void OnClickDelegate(object? sender, EventArgs e);
public OnClickDelegate? OnClick { get; set; }

public LinkButton()
{
Expand All @@ -35,4 +35,4 @@ private void Action_Execute(object? sender, RoutedEventArgs e)
OnClick?.Invoke(sender, e);
}
}
}
}
5 changes: 3 additions & 2 deletions src/SerialLoops/Controls/LoopyProgressTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public LoopyProgressTracker(string processVerb = "")
processVerb = Strings.Loading_;
}

_processVerb = processVerb;
_loadingProgress = new() { Width = 390 };
_loadingItem = new();
Orientation = Avalonia.Layout.Orientation.Vertical;
Expand Down Expand Up @@ -50,7 +51,7 @@ public int Total
}
}

private string _currentlyLoading;
private string _currentlyLoading = string.Empty;
public string CurrentlyLoading
{
get => _currentlyLoading;
Expand All @@ -60,4 +61,4 @@ public string CurrentlyLoading
Dispatcher.UIThread.Invoke(() => _loadingItem.Text = _currentlyLoading);
}
}
}
}
47 changes: 28 additions & 19 deletions src/SerialLoops/Controls/OptionsGroup.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace SerialLoops.Controls;

public partial class OptionsGroup : UserControl
{
public string Text { get; set; }
public string Text { get; set; } = string.Empty;

public OptionsGroup()
{
Expand Down Expand Up @@ -57,13 +57,13 @@ public override void Render(DrawingContext context)
{
base.Render(context);
this.TryFindResource("GroupLineColor", ActualThemeVariant, out object? brush);
context.DrawRectangle(new Pen((ImmutableSolidColorBrush)brush), new Rect(RenderTransformOrigin.Point, new Point(RenderTransformOrigin.Point.X + Bounds.Size.Width - 2, RenderTransformOrigin.Point.Y + Bounds.Size.Height - 2)), 5);
context.DrawRectangle(new Pen((ImmutableSolidColorBrush)brush!), new Rect(RenderTransformOrigin.Point, new Point(RenderTransformOrigin.Point.X + Bounds.Size.Width - 2, RenderTransformOrigin.Point.Y + Bounds.Size.Height - 2)), 5);
}
}

public abstract class Option
{
public string OptionName { get; set; }
public string OptionName { get; set; } = string.Empty;

public bool Enabled { get; set; } = true;

Expand Down Expand Up @@ -97,13 +97,19 @@ public Grid GetOptionRow()
}
public class TextOption : Option
{
public Action<string> OnChange { get; set; }
protected TextBox _textBox;
public Action<string?>? OnChange { get; set; }
protected TextBox? _textBox;

public string Value
public string? Value
{
get => _textBox.Text;
set => _textBox.Text = value;
get => _textBox?.Text;
set
{
if (_textBox is not null)
{
_textBox.Text = value;
}
}
}

public TextOption()
Expand All @@ -122,25 +128,28 @@ protected override Control GetControl()
VerticalAlignment = VerticalAlignment.Center,
IsEnabled = Enabled,
};
panel.Children.Add(_textBox);
if (_textBox is not null)
{
panel.Children.Add(_textBox);
}
return panel;
}
}

public class ComboBoxOption : Option
{
public Action<string> OnChange { get; set; }
public Action<string?>? OnChange { get; set; }
protected ComboBox _comboBox { get; set; }

public string Value
{
get => (string)((ComboBoxItem)_comboBox.Items[_comboBox.SelectedIndex]).Tag;
set => _comboBox.SelectedIndex = _comboBox.Items.ToList().FindIndex(i => value.Equals((string)((ComboBoxItem)i).Tag));
get => (string)((ComboBoxItem)_comboBox.Items[_comboBox.SelectedIndex]!).Tag!;
set => _comboBox.SelectedIndex = _comboBox.Items.ToList().FindIndex(i => value.Equals((string)((ComboBoxItem)i!).Tag!));
}

public ComboBoxOption(List<(string Key, string Value)> options)
{
_comboBox = new ComboBox();
_comboBox = new();
_comboBox.Items.AddRange(options.Select(o => new ComboBoxItem { Tag = o.Key, Content = o.Value }));
_comboBox.SelectionChanged += (sender, args) => { OnChange?.Invoke(Value); };
}
Expand All @@ -162,7 +171,7 @@ protected override Control GetControl()

public class BooleanOption : Option
{
public Action<bool> OnChange { get; set; }
public Action<bool?>? OnChange { get; set; }

public bool Value
{
Expand Down Expand Up @@ -239,10 +248,10 @@ protected override Control GetControl()

public class FileOption : Option
{
public Action<string> OnChange { get; set; }
public Action<string?>? OnChange { get; set; }
protected Window _window;

public string Path
public string? Path
{
get => _pathBox.Text;
set
Expand Down Expand Up @@ -281,7 +290,7 @@ protected override Control GetControl()

protected virtual async Task SelectButton_OnClick()
{
IStorageFile file = await _window.ShowOpenFilePickerAsync(string.Empty, []);
IStorageFile? file = await _window.ShowOpenFilePickerAsync(string.Empty, []);
if (file is not null)
{
_pathBox.Text = file.Path.LocalPath;
Expand All @@ -297,10 +306,10 @@ public FolderOption(Window window) : base(window)

protected override async Task SelectButton_OnClick()
{
IStorageFolder folder = await _window.ShowOpenFolderPickerAsync(string.Empty);
IStorageFolder? folder = await _window.ShowOpenFolderPickerAsync(string.Empty);
if (folder is not null)
{
_pathBox.Text = folder.Path.LocalPath;
}
}
}
}
8 changes: 4 additions & 4 deletions src/SerialLoops/Controls/SKCropResizeCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected virtual void OnPaintSurface(SKSurface surface)
SelectionAreaLocation?.Y ?? 0f,
(SelectionAreaLocation?.X ?? 0f) + (FinalBitmap?.Width ?? 0f),
(SelectionAreaLocation?.Y ?? 0f) + (FinalBitmap?.Height ?? 0f));
finalCanvas.DrawImage(surface.Snapshot(), surfaceRect, new SKRect(0, 0, FinalBitmap.Width, FinalBitmap.Height),
finalCanvas.DrawImage(surface.Snapshot(), surfaceRect, new SKRect(0, 0, FinalBitmap?.Width ?? 0, FinalBitmap?.Height ?? 0),
new() { FilterQuality = SKFilterQuality.High });
finalCanvas.Flush();
}
Expand All @@ -154,7 +154,7 @@ protected virtual void OnPaintSurface(SKSurface surface)
uiPath.AddRect(areaRect);
uiPath.FillType = SKPathFillType.EvenOdd;
this.TryFindResource("CropResizeOverlayColor", ActualThemeVariant, out object? color);
canvas.DrawPath(uiPath, new SKPaint { Color = ((Color)color).ToSKColor() });
canvas.DrawPath(uiPath, new SKPaint { Color = ((Color)(color ?? Colors.White)).ToSKColor() });

canvas.Flush();
}
Expand Down Expand Up @@ -213,7 +213,7 @@ protected override void OnPointerMoved(PointerEventArgs e)
base.OnPointerMoved(e);
e.Handled = true;
PointerPoint point = e.GetCurrentPoint(this);

if (!point.Properties.IsLeftButtonPressed)
{
_lastPointerPosition = point.Position;
Expand All @@ -239,4 +239,4 @@ protected override void OnPointerMoved(PointerEventArgs e)
}
_lastPointerPosition = point.Position;
}
}
}
6 changes: 3 additions & 3 deletions src/SerialLoops/Models/ITreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace SerialLoops.Models;
public interface ITreeItem
{
public string Text { get; set; }
public Avalonia.Svg.Svg Icon { get; set; }
public ObservableCollection<ITreeItem> Children { get; set; }
public Avalonia.Svg.Svg? Icon { get; set; }
public ObservableCollection<ITreeItem>? Children { get; set; }
public bool IsExpanded { get; set; }
public Control GetDisplay();
}
}
Loading

0 comments on commit 6449f51

Please sign in to comment.