Skip to content

Commit 62a1c7b

Browse files
authored
Add more commands to the script editor on Avalonia (haroohie-club#421)
1 parent 8abcbb6 commit 62a1c7b

File tree

75 files changed

+1805
-249
lines changed

Some content is hidden

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

75 files changed

+1805
-249
lines changed

src/SerialLoops.Lib/Items/ChessPuzzleItem.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using HaruhiChokuretsuLib.Archive;
1+
using HaruhiChokuretsuLib.Archive;
52
using HaruhiChokuretsuLib.Archive.Data;
63
using HaruhiChokuretsuLib.Archive.Graphics;
74
using HaruhiChokuretsuLib.Util;

src/SerialLoops.Lib/Items/ScriptItem.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public ScriptItem(EventFile evt, EventTable evtTbl, Func<string, string> localiz
3838

3939
public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(Project project, ILogger log)
4040
{
41+
ScriptCommandInvocation currentCommand = null;
4142
try
4243
{
4344
Dictionary<ScriptSection, List<ScriptItemCommand>> commands = [];
@@ -46,6 +47,7 @@ public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(P
4647
commands.Add(section, []);
4748
foreach (ScriptCommandInvocation command in section.Objects)
4849
{
50+
currentCommand = command;
4951
commands[section].Add(ScriptItemCommand.FromInvocation(command, section,
5052
commands[section].Count, Event, project, _localize, log));
5153
}
@@ -56,8 +58,8 @@ public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(P
5658
catch (Exception ex)
5759
{
5860
log.LogException(
59-
string.Format(project.Localize("Error getting script command tree for script {0} ({1})"),
60-
DisplayName, Name), ex);
61+
string.Format(project.Localize("Error getting script command tree for script {0} ({1}): {2} {3}"),
62+
DisplayName, Name, currentCommand?.Command.Mnemonic ?? "NULL_COMMAND", string.Join(", ", currentCommand?.Parameters ?? [])), ex);
6163
return null;
6264
}
6365
}
@@ -207,7 +209,7 @@ public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemC
207209
if (commands is null)
208210
{
209211
log.LogWarning($"No path found to current command.");
210-
preview.ErrorImage = "SerialLoops.Graphics.ScriptPreviewError.png";
212+
preview.ErrorImage = "avares://SerialLoops/Assets/Graphics/ScriptPreviewError.png";
211213
return preview;
212214
}
213215

@@ -702,7 +704,7 @@ public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemC
702704
};
703705
}
704706

705-
if (spriteShakeParam.ShakeEffect != SpriteShakeScriptParameter.SpriteShakeEffect.NONE &&
707+
if (spriteShakeParam.ShakeEffect != SpriteShakeScriptParameter.SpriteShakeEffect.NO_SHAKE &&
706708
sprites.ContainsKey(character))
707709
{
708710
switch (spriteShakeParam.ShakeEffect)
@@ -796,6 +798,28 @@ public ScriptPreview GetScriptPreview(Dictionary<ScriptSection, List<ScriptItemC
796798
((TopicScriptParameter)currentCommand.Parameters[0]).TopicId);
797799
}
798800

801+
// Draw SELECT choices
802+
if (currentCommand.Verb == CommandVerb.SELECT)
803+
{
804+
preview.CurrentChocies = [];
805+
if (((OptionScriptParameter)currentCommand.Parameters[0]).Option.Id > 0)
806+
{
807+
preview.CurrentChocies.Add(((OptionScriptParameter)currentCommand.Parameters[0]).Option.Text);
808+
}
809+
if (((OptionScriptParameter)currentCommand.Parameters[1]).Option.Id > 0)
810+
{
811+
preview.CurrentChocies.Add(((OptionScriptParameter)currentCommand.Parameters[1]).Option.Text);
812+
}
813+
if (((OptionScriptParameter)currentCommand.Parameters[2]).Option.Id > 0)
814+
{
815+
preview.CurrentChocies.Add(((OptionScriptParameter)currentCommand.Parameters[2]).Option.Text);
816+
}
817+
if (((OptionScriptParameter)currentCommand.Parameters[3]).Option.Id > 0)
818+
{
819+
preview.CurrentChocies.Add(((OptionScriptParameter)currentCommand.Parameters[3]).Option.Text);
820+
}
821+
}
822+
799823
return preview;
800824
}
801825

@@ -1021,6 +1045,30 @@ public static (SKBitmap PreviewImage, string ErrorImage) GeneratePreviewImage(Sc
10211045
canvas.DrawBitmap(topicFlyout, 256 - topicFlyout.Width, verticalOffset + 128);
10221046
}
10231047

1048+
// Draw select choices
1049+
if (preview.CurrentChocies?.Count > 0)
1050+
{
1051+
List<SKBitmap> choiceGraphics = [];
1052+
foreach (string choice in preview.CurrentChocies)
1053+
{
1054+
SKBitmap choiceGraphic = new(218, 18);
1055+
SKCanvas choiceCanvas = new(choiceGraphic);
1056+
choiceCanvas.DrawRect(1, 1, 216, 16, new() { Color = new(146, 146, 146) });
1057+
choiceCanvas.DrawRect(2, 2, 214, 14, new() { Color = new(69, 69, 69) });
1058+
int choiceWidth = project.LangCode.Equals("ja") ? choice.Length * 14 : choice.Sum(c => project.FontReplacement.ReverseLookup(c).Offset);
1059+
choiceCanvas.DrawHaroohieText(choice, DialogueScriptParameter.Paint00, project, (218 - choiceWidth) / 2, 2);
1060+
choiceCanvas.Flush();
1061+
choiceGraphics.Add(choiceGraphic);
1062+
}
1063+
1064+
int graphicY = (192 - (choiceGraphics.Count * 18 + (choiceGraphics.Count - 1) * 8)) / 2 + 184;
1065+
foreach (SKBitmap choiceGraphic in choiceGraphics)
1066+
{
1067+
canvas.DrawBitmap(choiceGraphic, 19, graphicY);
1068+
graphicY += 26;
1069+
}
1070+
}
1071+
10241072
canvas.Flush();
10251073
return (previewBitmap, null);
10261074
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public BgmModeScriptParameter(string name, short mode) : base(name, ParameterTyp
1414

1515
public enum BgmMode : short
1616
{
17-
START = 2,
18-
STOP = 4,
17+
Start = 2,
18+
Stop = 4,
1919
}
2020

2121
public override BgmModeScriptParameter Clone(Project project, EventFile eventFile)
2222
{
2323
return new(Name, (short)Mode);
2424
}
25-
}
25+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public override ColorMonochromeScriptParameter Clone(Project project, EventFile
1919

2020
public enum ColorMonochrome : short
2121
{
22-
CUSTOM = 0,
22+
CUSTOM_COLOR = 0,
2323
BLACK = 1,
2424
WHITE = 2,
2525
}
26-
}
26+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override PaletteEffectScriptParameter Clone(Project project, EventFile ev
2020

2121
public enum PaletteEffect : short
2222
{
23-
DEFAULT = 216,
23+
DEFAULT_PALETTE = 216,
2424
INVERTED = 217,
2525
GRAYSCALE = 218,
2626
SEPIA = 219,
@@ -89,4 +89,4 @@ public static SKPaint GetPaletteEffectPaint(PaletteEffect effect)
8989
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
9090
]),
9191
};
92-
}
92+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public override SpriteShakeScriptParameter Clone(Project project, EventFile even
1919

2020
public enum SpriteShakeEffect : short
2121
{
22-
NONE = 0,
22+
NO_SHAKE = 0,
2323
SHAKE_CENTER = 1,
2424
BOUNCE_HORIZONTAL_CENTER = 2,
2525
BOUNCE_HORIZONTAL_CENTER_WITH_SMALL_SHAKES = 3,
2626
SHAKE_RIGHT = 4,
2727
SHAKE_LEFT = 5,
2828
}
29-
}
29+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public override TextEntranceEffectScriptParameter Clone(Project project, EventFi
1919

2020
public enum TextEntranceEffect : short
2121
{
22-
NORMAL = 0,
22+
NORMAL_TEXT_ENTRANCE = 0,
2323
SHRINK_IN = 1,
2424
TERMINAL_TYPING = 2,
2525
}
26-
}
26+
}

src/SerialLoops.Lib/Script/ScriptItemCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ public List<ScriptItemCommand> WalkCommandGraph(Dictionary<ScriptSection, List<S
7777
{
7878
List<ScriptItemCommand> commands = [];
7979

80-
Func<ScriptSectionEdge, double> weightFunction = new((ScriptSectionEdge edge) =>
81-
{
82-
return 1;
83-
});
80+
Func<ScriptSectionEdge, double> weightFunction = new((ScriptSectionEdge edge) => 1);
8481

8582
if (Section != commandTree.Keys.First())
8683
{

src/SerialLoops.Lib/Script/ScriptPreview.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ScriptPreview
1919
public List<PositionedSprite> Sprites { get; set; } = [];
2020
public ScriptItemCommand LastDialogueCommand { get; set; }
2121
public TopicItem Topic { get; set; }
22+
public List<string> CurrentChocies { get; set; }
2223
public bool ChessMode { get; set; }
2324
public ChessPuzzleItem ChessPuzzle { get; set; }
2425
public string ErrorImage { get; set; }

src/SerialLoops.Lib/Util/Extensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ public static void CollectGarbage(this EventFile evt)
106106
}
107107
}
108108
}
109+
110+
// Collect dialogue garbage
111+
IEnumerable<string> dialogueContainingCommands = new[] { CommandVerb.DIALOGUE, CommandVerb.PIN_MNL }.Select(c => c.ToString());
112+
List<UsedIndex> dialogueUsedIndices = [];
113+
foreach (ScriptCommandInvocation dialogueCommand in evt.ScriptSections.SelectMany(s => s.Objects)
114+
.Where((c => dialogueContainingCommands.Contains(c.Command.Mnemonic))))
115+
{
116+
dialogueUsedIndices.Add(new() { Command = dialogueCommand, Index = dialogueCommand.Parameters[0] });
117+
}
118+
119+
if (dialogueUsedIndices.DistinctBy(i => i.Index).Count() < evt.DialogueSection.Objects.Count)
120+
{
121+
for (short i = 0; i < evt.DialogueSection.Objects.Count; i++)
122+
{
123+
if (dialogueUsedIndices.All(idx => idx.Index != i))
124+
{
125+
evt.DialogueSection.Objects.RemoveAt(i);
126+
evt.DialogueLines.RemoveAt(i--);
127+
for (int j = 0; j < dialogueUsedIndices.Count; j++)
128+
{
129+
if (dialogueUsedIndices[j].Index >= i)
130+
{
131+
dialogueUsedIndices[j].Command.Parameters[0]--;
132+
dialogueUsedIndices[j].Index--;
133+
}
134+
}
135+
}
136+
}
137+
}
109138
}
110139

111140
private class UsedIndex

0 commit comments

Comments
 (0)