Skip to content

Commit

Permalink
無効な範囲の場合エラーにする
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Nov 28, 2024
1 parent 401781d commit 5997c63
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
19 changes: 3 additions & 16 deletions Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace ArtNet.Editor.DmxRecorder
Expand All @@ -9,7 +10,7 @@ public abstract class RecorderSettings : ScriptableObject, ISerializationCallbac
private const int MaxPathLength = 259;

[SerializeField] private bool _enabled = true;
[SerializeField] protected UniverseFilter _universeFilter;
[SerializeField] protected UniverseFilter _universeFilter = new();
[SerializeField] protected FileGenerator _fileGenerator;
[SerializeField] private int _take = 1;

Expand Down Expand Up @@ -46,21 +47,7 @@ protected RecorderSettings()

protected internal virtual void GetErrors(List<string> errors)
{
if (_universeFilter.Enabled)
{
if (_universeFilter.InvalidFilterTextFormat())
{
errors.Add("Invalid universe filter text format");
}
else if (_universeFilter.ParseFilterText(out var universeList) == false)
{
errors.Add("Invalid universe filter text");
}
else if (universeList.Count == 0)
{
errors.Add("Universe filter is empty");
}
}
_universeFilter.GetErrors(errors);

if (string.IsNullOrEmpty(FileGenerator.FileName))
{
Expand Down
22 changes: 22 additions & 0 deletions Assets/ArtNet/Editor/DmxRecorder/UniverseFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ public bool InvalidFilterTextFormat()
return _invalidFilterTextRegex.IsMatch(FilterText);
}

public void GetErrors(List<string> errors)
{
if (Enabled == false) return;

if (InvalidFilterTextFormat())
{
errors.Add("Invalid universe filter text format");
}
else if (ParseFilterText(out var universeList) == false)
{
errors.Add("Invalid universe filter text");
}
else if (universeList.Count == 0)
{
errors.Add("Universe filter is empty");
}
else if (universeList.Any(u => u is < 0 or > 0x7FFF))
{
errors.Add("Universe filter contains invalid universe numbers. Valid range is 0-32767");
}
}

public bool IsMatch(int universe)
{
if (_enabled == false) return true;
Expand Down
2 changes: 1 addition & 1 deletion Assets/ArtNet/Editor/DmxRecorder/UniverseFilterDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class UniverseFilterDrawer : TargetedPropertyDrawer<UniverseFilter>
private static class Styles
{
internal static readonly GUIContent UniverseFilterLabel = new("Universe Filter", "Filter the universes to record");
internal static readonly GUIContent FilterTextInfo = new("Enter the universes to record. Example: 1-3, 5, 7-9");
internal static readonly GUIContent FilterTextInfo = new("Enter the universes to record. Example: 0-2, 4, 7-9");
}

private UniverseFilter _target;
Expand Down

0 comments on commit 5997c63

Please sign in to comment.