Skip to content

Commit 0324ec2

Browse files
authored
Add editor commands in the Avalonia branch (haroohie-club#425)
1 parent 62a1c7b commit 0324ec2

File tree

49 files changed

+1528
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1528
-292
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ csharp_style_conditional_delegate_call = true:suggestion
127127
csharp_style_prefer_index_operator = false:none
128128
csharp_style_prefer_range_operator = false:none
129129
csharp_style_pattern_local_over_anonymous_function = false:none
130+
resharper_csharp_trailing_comma_in_multiline_lists = true
130131

131132
# Space preferences
132133
csharp_space_after_cast = false

src/SerialLoops.Lib/Build.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ private static bool DoBuild(string directory, Project project, Config config, IL
167167

168168
// Save files to disk
169169
tracker.Focus("Writing Replaced Archives", 3);
170-
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "dat.bin"), dat.GetBytes(), log))
170+
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "dat.bin"), dat?.GetBytes(), log))
171171
{
172172
return false;
173173
}
174-
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "evt.bin"), evt.GetBytes(), log))
174+
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "evt.bin"), evt?.GetBytes(), log))
175175
{
176176
return false;
177177
}
178-
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "grp.bin"), grp.GetBytes(), log))
178+
if (!IO.WriteBinaryFile(Path.Combine(directory, "rom", "data", "grp.bin"), grp?.GetBytes(), log))
179179
{
180180
return false;
181181
}
@@ -187,7 +187,7 @@ private static bool DoBuild(string directory, Project project, Config config, IL
187187
try
188188
{
189189
File.WriteAllBytes(ndsProjectFile, project.Settings.File.Write());
190-
}
190+
}
191191
catch (IOException exc)
192192
{
193193
log.LogException("Failed to write NitroPacker NDS project file to disk", exc);
@@ -417,4 +417,4 @@ private static void ReplaceSingleBinaryFile(ArchiveFile<GraphicsFile> archive, s
417417
log.LogException(string.Format(localize("Failed replacing animation file {0} in grp.bin with file '{1}'"), index, filePath), ex);
418418
}
419419
}
420-
}
420+
}

src/SerialLoops.Lib/Items/ScriptItem.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using SerialLoops.Lib.Script.Parameters;
1010
using SerialLoops.Lib.Util;
1111
using SkiaSharp;
12+
using SoftCircuits.Collections;
1213
using static HaruhiChokuretsuLib.Archive.Event.EventFile;
1314

1415
namespace SerialLoops.Lib.Items;
@@ -29,19 +30,18 @@ public ScriptItem(EventFile evt, EventTable evtTbl, Func<string, string> localiz
2930
evt.Name[0..^1], ItemType.Script)
3031
{
3132
Event = evt;
32-
UpdateEventTableInfo(evtTbl);
3333
_localize = localize;
3434

3535
PruneLabelsSection(log);
3636
Graph.AddVertexRange(Event.ScriptSections);
3737
}
3838

39-
public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(Project project, ILogger log)
39+
public OrderedDictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(Project project, ILogger log)
4040
{
4141
ScriptCommandInvocation currentCommand = null;
4242
try
4343
{
44-
Dictionary<ScriptSection, List<ScriptItemCommand>> commands = [];
44+
OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commands = [];
4545
foreach (ScriptSection section in Event.ScriptSections)
4646
{
4747
commands.Add(section, []);
@@ -64,7 +64,7 @@ public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(P
6464
}
6565
}
6666

67-
public void CalculateGraphEdges(Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ILogger log)
67+
public void CalculateGraphEdges(OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ILogger log)
6868
{
6969
try
7070
{
@@ -194,7 +194,7 @@ public void CalculateGraphEdges(Dictionary<ScriptSection, List<ScriptItemCommand
194194
}
195195
}
196196

197-
public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree,
197+
public ScriptPreview GetScriptPreview(OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commandTree,
198198
ScriptItemCommand currentCommand, Project project, ILogger log)
199199
{
200200
ScriptPreview preview = new();
@@ -1069,12 +1069,36 @@ public static (SKBitmap PreviewImage, string ErrorImage) GeneratePreviewImage(Sc
10691069
}
10701070
}
10711071

1072+
// Draw select choices
1073+
if (preview.CurrentChocies?.Count > 0)
1074+
{
1075+
List<SKBitmap> choiceGraphics = [];
1076+
foreach (string choice in preview.CurrentChocies)
1077+
{
1078+
SKBitmap choiceGraphic = new(218, 18);
1079+
SKCanvas choiceCanvas = new(choiceGraphic);
1080+
choiceCanvas.DrawRect(1, 1, 216, 16, new() { Color = new(146, 146, 146) });
1081+
choiceCanvas.DrawRect(2, 2, 214, 14, new() { Color = new(69, 69, 69) });
1082+
int choiceWidth = project.LangCode.Equals("ja") ? choice.Length * 14 : choice.Sum(c => project.FontReplacement.ReverseLookup(c).Offset);
1083+
choiceCanvas.DrawHaroohieText(choice, DialogueScriptParameter.Paint00, project, (218 - choiceWidth) / 2, 2);
1084+
choiceCanvas.Flush();
1085+
choiceGraphics.Add(choiceGraphic);
1086+
}
1087+
1088+
int graphicY = (192 - (choiceGraphics.Count * 18 + (choiceGraphics.Count - 1) * 8)) / 2 + 184;
1089+
foreach (SKBitmap choiceGraphic in choiceGraphics)
1090+
{
1091+
canvas.DrawBitmap(choiceGraphic, 19, graphicY);
1092+
graphicY += 26;
1093+
}
1094+
}
1095+
10721096
canvas.Flush();
10731097
return (previewBitmap, null);
10741098
}
10751099

10761100
public (SKBitmap PreviewImage, string ErrorImage) GeneratePreviewImage(
1077-
Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ScriptItemCommand currentCommand,
1101+
OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commandTree, ScriptItemCommand currentCommand,
10781102
Project project, ILogger log)
10791103
{
10801104
return GeneratePreviewImage(GetScriptPreview(commandTree, currentCommand, project, log), project);

src/SerialLoops.Lib/Project.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
694694

695695
try
696696
{
697-
tracker.Focus("Scripts", Evt.Files.Count - 5);
697+
tracker.Focus("Scripts", Evt.Files.Count - NON_SCRIPT_EVT_FILES.Length);
698698
Items.AddRange(Evt.Files.AsParallel()
699-
.Where(e => !NON_SCRIPT_EVT_FILES.Contains(e.Name))
699+
.Where(e => !NON_SCRIPT_EVT_FILES.Contains(e?.Name))
700700
.Select(e =>
701701
{
702702
tracker.Finished++;

src/SerialLoops.Lib/Script/Parameters/DialogueScriptParameter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public DialogueScriptParameter(string name, DialogueLine line) : base(name, Para
1616

1717
public override DialogueScriptParameter Clone(Project project, EventFile eventFile)
1818
{
19-
DialogueLine line = new(Line.Text.GetOriginalString(project), eventFile);
20-
eventFile.DialogueSection.Objects.Insert(eventFile.DialogueSection.Objects.Count - 1, line);
19+
DialogueLine line = new(Line.Text.GetOriginalString(project), eventFile) { Speaker = Line.Speaker };
20+
eventFile.DialogueSection.Objects.Add(line);
2121
return new(Name, line);
2222
}
2323

@@ -101,4 +101,4 @@ public override DialogueScriptParameter Clone(Project project, EventFile eventFi
101101
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
102102
}),
103103
};
104-
}
104+
}

src/SerialLoops.Lib/Script/Parameters/SfxModeScriptParameter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override SfxModeScriptParameter Clone(Project project, EventFile eventFil
1919

2020
public enum SfxMode : short
2121
{
22-
START = 6,
23-
STOP = 7,
22+
Start = 6,
23+
Stop = 7,
2424
}
25-
}
25+
}

src/SerialLoops.Lib/Script/ScriptItemCommand.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SerialLoops.Lib.Items;
1212
using SerialLoops.Lib.Script.Parameters;
1313
using SerialLoops.Lib.Util;
14+
using SoftCircuits.Collections;
1415
using static HaruhiChokuretsuLib.Archive.Event.EventFile;
1516

1617
namespace SerialLoops.Lib.Script;
@@ -73,7 +74,7 @@ public ScriptItemCommand(CommandVerb verb, params ScriptParameter[] parameters)
7374
UpdateDisplay();
7475
}
7576

76-
public List<ScriptItemCommand> WalkCommandGraph(Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree, AdjacencyGraph<ScriptSection, ScriptSectionEdge> graph)
77+
public List<ScriptItemCommand> WalkCommandGraph(OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commandTree, AdjacencyGraph<ScriptSection, ScriptSectionEdge> graph)
7778
{
7879
List<ScriptItemCommand> commands = [];
7980

@@ -247,7 +248,7 @@ private static List<ScriptParameter> GetScriptParameters(ScriptCommandInvocation
247248
switch (i)
248249
{
249250
case 0:
250-
parameters.Add(new SfxScriptParameter(localize("Sound"), (SfxItem)project.Items.First(s => s.Type == ItemDescription.ItemType.SFX && ((SfxItem)s).Index == parameter)));
251+
parameters.Add(new SfxScriptParameter(localize("Sound"), (SfxItem)project.Items.FirstOrDefault(s => s.Type == ItemDescription.ItemType.SFX && ((SfxItem)s).Index == parameter)));
251252
break;
252253
case 1:
253254
parameters.Add(new SfxModeScriptParameter(localize("Mode"), parameter));
@@ -592,13 +593,13 @@ private static List<ScriptParameter> GetScriptParameters(ScriptCommandInvocation
592593
switch (i)
593594
{
594595
case 0:
595-
parameters.Add(new ScriptSectionScriptParameter(localize("Clear Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.First(l => l.Id == parameter).Name.Replace("/", ""))));
596+
parameters.Add(new ScriptSectionScriptParameter(localize("Clear Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.FirstOrDefault(l => l.Id == parameter)?.Name.Replace("/", ""))));
596597
break;
597598
case 1:
598-
parameters.Add(new ScriptSectionScriptParameter(localize("Miss Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.First(l => l.Id == parameter).Name.Replace("/", ""))));
599+
parameters.Add(new ScriptSectionScriptParameter(localize("Miss Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.FirstOrDefault(l => l.Id == parameter)?.Name.Replace("/", ""))));
599600
break;
600601
case 2:
601-
parameters.Add(new ScriptSectionScriptParameter(localize("Miss 2 Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.First(l => l.Id == parameter).Name.Replace("/", ""))));
602+
parameters.Add(new ScriptSectionScriptParameter(localize("Miss 2 Block"), eventFile.ScriptSections.FirstOrDefault(s => s.Name == eventFile.LabelsSection.Objects.FirstOrDefault(l => l.Id == parameter)?.Name.Replace("/", ""))));
602603
break;
603604
}
604605
break;
@@ -734,16 +735,19 @@ private static DialogueLine GetDialogueLine(short index, EventFile eventFile)
734735

735736
public ScriptItemCommand Clone()
736737
{
737-
return new()
738+
ScriptItemCommand clonedCommand = new()
738739
{
739-
Invocation = Invocation,
740+
Invocation = Invocation.Clone(Script, Project),
740741
Verb = Verb,
741742
Parameters = Parameters.Select(p => p.Clone(Project, Script)).ToList(),
742743
Section = Section,
743744
Index = Index,
744745
Script = Script,
745746
Project = Project,
746747
};
748+
clonedCommand.UpdateDisplay();
749+
750+
return clonedCommand;
747751
}
748752

749753
}

src/SerialLoops.Lib/Script/ScriptTemplate.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using SerialLoops.Lib.Items;
88
using SerialLoops.Lib.Script.Parameters;
99
using SerialLoops.Lib.Util;
10+
using SoftCircuits.Collections;
1011

1112
namespace SerialLoops.Lib.Script;
1213

@@ -25,7 +26,7 @@ public ScriptTemplate(params TemplateSection[] sections)
2526
Sections = sections;
2627
}
2728

28-
public ScriptTemplate(string templateName, string templateDescription, Dictionary<ScriptSection, List<ScriptItemCommand>> commands, Project project)
29+
public ScriptTemplate(string templateName, string templateDescription, OrderedDictionary<ScriptSection, List<ScriptItemCommand>> commands, Project project)
2930
{
3031
Name = templateName;
3132
Description = templateDescription;
@@ -36,12 +37,11 @@ public void Apply(ScriptItem script, Project project, ILogger log)
3637
{
3738
foreach (TemplateSection section in Sections)
3839
{
39-
int sectionIndex = script.Event.ScriptSections.FindIndex(s => s.Name == section.Name);
40-
if (sectionIndex < 0)
40+
if (script.Event.ScriptSections.FindIndex(s => s.Name == section.Name) < 0)
4141
{
42-
sectionIndex = script.Event.ScriptSections.Count;
4342
script.Event.LabelsSection.Objects.Add(new() { Id = (short)(script.Event.LabelsSection.Objects.Count > 0 ? script.Event.LabelsSection.Objects.Max(l => l.Id) + 1 : 1001), Name = section.Name });
4443
script.Event.ScriptSections.Add(new() { Name = section.Name, CommandsAvailable = EventFile.CommandsAvailable });
44+
script.Event.NumSections++;
4545
}
4646
}
4747
// We add the sections first and then do it a second time in order to allow ScriptSectionParameters to be able to find their sections
@@ -355,10 +355,10 @@ public ScriptParameter ParseAndApply(Project project, EventFile evt, ILogger log
355355
return new DialoguePropertyScriptParameter(localizedName, (CharacterItem)project.Items.First(i => i.Type == ItemDescription.ItemType.Character && (short)((CharacterItem)i).MessageInfo.Character == short.Parse(value)));
356356

357357
case ScriptParameter.ParameterType.DIALOGUE:
358-
string[] dialougeValues = value.Split("||");
359-
DialogueLine line = new(dialougeValues[1].GetOriginalString(project), evt)
358+
string[] dialogueValues = value.Split("||");
359+
DialogueLine line = new(dialogueValues[1].GetOriginalString(project), evt)
360360
{
361-
Speaker = ((CharacterItem)project.Items.First(i => i.Type == ItemDescription.ItemType.Character && (short)((CharacterItem)i).MessageInfo.Character == short.Parse(dialougeValues[0]))).MessageInfo.Character
361+
Speaker = ((CharacterItem)project.Items.First(i => i.Type == ItemDescription.ItemType.Character && (short)((CharacterItem)i).MessageInfo.Character == short.Parse(dialogueValues[0]))).MessageInfo.Character
362362
};
363363
evt.DialogueSection.Objects.Add(line);
364364
evt.DialogueLines.Add(line);

src/SerialLoops.Lib/SerialLoops.Lib.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="7.3.0.3" />
1515
<PackageReference Include="HaruhiChokuretsuLib" Version="0.45.2" />
1616
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
17-
<PackageReference Include="NitroPacker.Core" Version="2.5.1" />
17+
<PackageReference Include="NitroPacker.Core" Version="2.6.0" />
1818
<PackageReference Include="NLayer" Version="1.16.0" />
1919
<PackageReference Include="NLayer.NAudioSupport" Version="1.4.0" />
2020
<PackageReference Include="QuikGraph" Version="2.5.0" />
2121
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
22+
<PackageReference Include="SoftCircuits.OrderedDictionary" Version="3.2.0" />
2223
<PackageReference Include="Topten.RichTextKit" Version="0.4.167" />
2324
<PackageReference Include="VCDiff" Version="4.0.1" />
2425
</ItemGroup>

0 commit comments

Comments
 (0)