Skip to content

Commit

Permalink
Make the search dialog a bit more MVVM-y (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Dec 18, 2024
1 parent cea6d54 commit bd0fd73
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 257 deletions.
8 changes: 4 additions & 4 deletions src/SerialLoops.Lib/Items/ChibiItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public ChibiItem(Chibi chibi, int chibiIndex, Project project) : base($"CHIBI{ch
Chibi = chibi;
ChibiIndex = chibiIndex + 1;
string firstAnimationName = project.Grp.GetFileByIndex(Chibi.ChibiEntries[0].Animation).Name;
Name = $"CHIBI_{firstAnimationName[0..firstAnimationName.IndexOf('_')]}";
DisplayName = $"CHIBI_{firstAnimationName[0..firstAnimationName.IndexOf('_')]}";
TopScreenIndex = chibiIndices.IndexOf(firstAnimationName[0..3]);
Name = $"CHIBI_{firstAnimationName[..firstAnimationName.IndexOf('_')]}";
DisplayName = $"CHIBI_{firstAnimationName[..firstAnimationName.IndexOf('_')]}";
TopScreenIndex = chibiIndices.IndexOf(firstAnimationName[..3]);
ChibiEntries.AddRange(Chibi.ChibiEntries.Where(c => c.Animation > 0)
.Select(c => (project.Grp.GetFileByIndex(c.Animation).Name[0..^3], new ChibiGraphics(c, project))));
.Select(c => (project.Grp.GetFileByIndex(c.Animation).Name[..^3], new ChibiGraphics(c, project))));
ChibiEntries.ForEach(e => ChibiEntryModifications.Add(e.Name, false));
ChibiEntries.ForEach(e => ChibiAnimations.Add(e.Name, GetChibiAnimation(e.Name, project.Grp)));
}
Expand Down
30 changes: 19 additions & 11 deletions src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public List<ItemDescription> GetReferencesTo(Project project)
];
(string ScriptName, ScriptCommandInvocation command)[] bgScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => bgCommands.Contains(c.Command.Mnemonic)).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => bgCommands.Contains(c.Command.Mnemonic)).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == bg.Id || t.c.Command.Mnemonic == EventFile.CommandVerb.BG_FADE.ToString() && t.c.Parameters[1] == bg.Id).ToArray();
return project.Items.Where(i => bgScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

case ItemType.BGM:
BackgroundMusicItem bgm = (BackgroundMusicItem)this;
(string ScriptName, ScriptCommandInvocation comamnd)[] bgmScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.BGM_PLAY.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.BGM_PLAY.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == bgm.Index).ToArray();
return project.Items.Where(i => bgmScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

Expand All @@ -100,17 +100,25 @@ public List<ItemDescription> GetReferencesTo(Project project)
CharacterSpriteItem sprite = (CharacterSpriteItem)this;
(string ScriptName, ScriptCommandInvocation command)[] spriteScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.DIALOGUE.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.DIALOGUE.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[1] == sprite.Index).ToArray();
return project.Items.Where(i => spriteScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

case ItemType.Chess_Puzzle:
ChessPuzzleItem chessPuzzle = (ChessPuzzleItem)this;
(string ScriptName, ScriptCommandInvocation command)[] chessPuzzleScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany((sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.CHESS_LOAD.ToString()).Select(c => (e.Name[..^1], c)))))
.Where(t => t.c.Parameters[0] == chessPuzzle.ChessPuzzle.Index).ToArray();
return project.Items.Where(i => chessPuzzleScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

case ItemType.Chibi:
ChibiItem chibi = (ChibiItem)this;
references.AddRange(project.Items.Where(i => i.Type == ItemType.Script && project.Evt.Files.Where(e =>
e.MapCharactersSection?.Objects?.Any(t => t.CharacterIndex == chibi.ChibiIndex) ?? false).Select(e => e.Index).Contains(((ScriptItem)i).Event.Index)));
(string ScriptName, ScriptCommandInvocation command)[] chibiScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.CHIBI_ENTEREXIT.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.CHIBI_ENTEREXIT.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == chibi.TopScreenIndex).ToArray();
references.AddRange(project.Items.Where(i => chibiScriptUses.Select(s => s.ScriptName).Contains(i.Name)));
return references.Distinct().ToList();
Expand All @@ -127,7 +135,7 @@ public List<ItemDescription> GetReferencesTo(Project project)
MapItem map = (MapItem)this;
(string ScriptName, ScriptCommandInvocation command)[] mapScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.LOAD_ISOMAP.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.LOAD_ISOMAP.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == map.Map.Index).ToArray();
return project.Items.Where(i => i.Type == ItemType.Puzzle && ((PuzzleItem)i).Puzzle.Settings.MapId == map.QmapIndex)
.Concat(project.Items.Where(i => mapScriptUses.Select(s => s.ScriptName).Contains(i.Name))).ToList();
Expand All @@ -136,7 +144,7 @@ public List<ItemDescription> GetReferencesTo(Project project)
PlaceItem place = (PlaceItem)this;
(string ScriptName, ScriptCommandInvocation command)[] placeScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.SET_PLACE.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.SET_PLACE.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[1] == place.Index).ToArray();
return project.Items.Where(i => placeScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

Expand Down Expand Up @@ -165,7 +173,7 @@ public List<ItemDescription> GetReferencesTo(Project project)
SfxItem sfx = (SfxItem)this;
(string ScriptName, ScriptCommandInvocation command)[] sfxScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.SND_PLAY.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.SND_PLAY.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == sfx.Index).ToArray();
references.AddRange(project.Items.Where(i => sfxScriptUses.Select(s => s.ScriptName).Contains(i.Name)));
references.AddRange(project.Items.Where(c => c.Type == ItemType.Character && ((CharacterItem)c).MessageInfo.VoiceFont == sfx.Index));
Expand All @@ -175,19 +183,19 @@ public List<ItemDescription> GetReferencesTo(Project project)
TopicItem topic = (TopicItem)this;
(string ScriptName, ScriptCommandInvocation command)[] topicScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.TOPIC_GET.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.TOPIC_GET.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == topic.TopicEntry.Id).ToArray();
return project.Items.Where(i => topicScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();

case ItemType.Voice:
VoicedLineItem voicedLine = (VoicedLineItem)this;
(string ScriptName, ScriptCommandInvocation command)[] vceScriptUses = project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.DIALOGUE.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.DIALOGUE.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[5] == voicedLine.Index)
.Concat(project.Evt.Files.AsParallel().SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.VCE_PLAY.ToString()).Select(c => (e.Name[0..^1], c))))
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.VCE_PLAY.ToString()).Select(c => (e.Name[..^1], c))))
.Where(t => t.c.Parameters[0] == voicedLine.Index))
.ToArray();
return project.Items.Where(i => vceScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();
Expand All @@ -196,4 +204,4 @@ public List<ItemDescription> GetReferencesTo(Project project)
return references;
}
}
}
}
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/MapItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MapItem : Item
public MapItem(string name) : base(name, ItemType.Map)
{
}
public MapItem(MapFile map, int qmapIndex, Project project) : base(map.Name[0..^1], ItemType.Map)
public MapItem(MapFile map, int qmapIndex, Project project) : base(map.Name[..^1], ItemType.Map)
{
Map = map;
QmapIndex = qmapIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/PlaceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PlaceItem : Item, IPreviewableGraphic
public GraphicsFile PlaceGraphic { get; set; }
public string PlaceName { get; set; }

public PlaceItem(int index, GraphicsFile placeGrp) : base(placeGrp.Name[0..^3], ItemType.Place)
public PlaceItem(int index, GraphicsFile placeGrp) : base(placeGrp.Name[..^3], ItemType.Place)
{
Index = index;
CanRename = false;
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/PuzzleItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PuzzleItem : Item
public PuzzleFile Puzzle { get; set; }
public SKBitmap SingularityImage { get; set; }

public PuzzleItem(PuzzleFile puzzleFile, Project project, ILogger log) : base(puzzleFile.Name[0..^1], ItemType.Puzzle)
public PuzzleItem(PuzzleFile puzzleFile, Project project, ILogger log) : base(puzzleFile.Name[..^1], ItemType.Puzzle)
{
Puzzle = puzzleFile;
Refresh(project, log);
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ScriptItem(string name) : base(name, ItemType.Script)
}

public ScriptItem(EventFile evt, EventTable evtTbl, Func<string, string> localize, ILogger log) : base(
evt.Name[0..^1], ItemType.Script)
evt.Name[..^1], ItemType.Script)
{
Event = evt;
_localize = localize;
Expand Down
10 changes: 5 additions & 5 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
if (entry.BgIndex1 > 0)
{
GraphicsFile nameGraphic = Grp.GetFileByIndex(entry.BgIndex1);
string name = $"BG_{nameGraphic.Name[0..nameGraphic.Name.LastIndexOf('_')]}";
string name = $"BG_{nameGraphic.Name[..nameGraphic.Name.LastIndexOf('_')]}";
string bgNameBackup = name;
for (int j = 1; names.Contains(name); j++)
{
Expand Down Expand Up @@ -820,21 +820,21 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
tracker.Finished++;
foreach (SystemTexture extraSysTex in systemTextureFile.SystemTextures.Where(s => Grp.Files.AsParallel().Where(g => g.Name.StartsWith("XTR")).Distinct().Select(g => g.Index).Contains(s.GrpIndex)))
{
Items.Add(new SystemTextureItem(extraSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(extraSysTex.GrpIndex).Name[0..^3]}"));
Items.Add(new SystemTextureItem(extraSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(extraSysTex.GrpIndex).Name[..^3]}"));
tracker.Finished++;
}
// Exclude B12 as that's the nameplates we replace in the character items and PPT_001 as that's the puzzle phase singularity we'll be replacing in the puzzle items
// We also exclude the "special" graphics as they do not include all of them in the SYSTEX file (should be made to be edited manually)
foreach (SystemTexture sysSysTex in systemTextureFile.SystemTextures.Where(s => Grp.Files.AsParallel().Where(g => g.Name.StartsWith("SYS") && !g.Name.Contains("_SPC_") && g.Name != "SYS_CMN_B12DNX" && g.Name != "SYS_PPT_001DNX").Select(g => g.Index).Contains(s.GrpIndex)).DistinctBy(s => s.GrpIndex))
{
if (Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[0..^4].EndsWith("T6"))
if (Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[..^4].EndsWith("T6"))
{
// special case the ep headers
Items.Add(new SystemTextureItem(sysSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[0..^3]}", height: 192));
Items.Add(new SystemTextureItem(sysSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[..^3]}", height: 192));
}
else
{
Items.Add(new SystemTextureItem(sysSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[0..^3]}"));
Items.Add(new SystemTextureItem(sysSysTex, this, $"SYSTEX_{Grp.GetFileByIndex(sysSysTex.GrpIndex).Name[..^3]}"));
}
tracker.Finished++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Script/ScriptItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public override string ToString()
switch (Verb)
{
case CommandVerb.DIALOGUE:
str += $" {((DialogueScriptParameter)Parameters[0]).Line.Text.GetSubstitutedString(Project)[0..Math.Min(((DialogueScriptParameter)Parameters[0]).Line.Text.Length, 10)]}...";
str += $" {((DialogueScriptParameter)Parameters[0]).Line.Text.GetSubstitutedString(Project)[..Math.Min(((DialogueScriptParameter)Parameters[0]).Line.Text.Length, 10)]}...";
break;
case CommandVerb.GOTO:
str += $" {((ScriptSectionScriptParameter)Parameters[0]).Section.Name}";
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public override SKColor Read(ref Utf8JsonReader reader, Type typeToConvert, Json
byte.Parse(html[2..4], NumberStyles.HexNumber),
byte.Parse(html[4..6], NumberStyles.HexNumber),
byte.Parse(html[6..8], NumberStyles.HexNumber),
byte.Parse(html[0..2], NumberStyles.HexNumber)
byte.Parse(html[..2], NumberStyles.HexNumber)
);
}

Expand Down
Loading

0 comments on commit bd0fd73

Please sign in to comment.