Skip to content

Commit

Permalink
Implement script sections for script editor (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Feb 7, 2023
1 parent a88d383 commit f65dbea
Show file tree
Hide file tree
Showing 47 changed files with 518 additions and 84 deletions.
61 changes: 61 additions & 0 deletions src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,78 @@
using HaruhiChokuretsuLib.Archive.Event;
using QuikGraph;
using SerialLoops.Lib.Script;
using SerialLoops.Lib.Script.Parameters;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using static HaruhiChokuretsuLib.Archive.Event.EventFile;

namespace SerialLoops.Lib.Items
{
public class ScriptItem : Item
{
public EventFile Event { get; set; }
public AdjacencyGraph<ScriptSection, ScriptSectionEdge> Graph { get; set; } = new();

public ScriptItem(string name) : base(name, ItemType.Script)
{
}
public ScriptItem(EventFile evt) : base(evt.Name[0..^1], ItemType.Script)
{
Event = evt;

Graph.AddVertexRange(Event.ScriptSections);
}

public void CalculateGraphEdges(Dictionary<ScriptSection, List<ScriptItemCommand>> commandTree)
{
foreach (ScriptSection section in commandTree.Keys)
{
bool @continue = false;
foreach (ScriptItemCommand command in commandTree[section])
{
if (command.Verb == CommandVerb.INVEST_START)
{
Graph.AddEdge(new() { Source = section, Target = ((ScriptSectionScriptParameter)command.Parameters[4]).Section });
Graph.AddEdgeRange(Event.ScriptSections.Where(s =>
Event.LabelsSection.Objects.Where(l =>
Event.MapCharactersSection.Objects.Select(c => c.TalkScriptBlock).Contains(l.Id))
.Select(l => l.Name.Replace("/", "")).Contains(s.Name)).Select(s => new ScriptSectionEdge() { Source = section, Target = s }));
@continue = true;
}
else if (command.Verb == CommandVerb.GOTO)
{
Graph.AddEdge(new() { Source = section, Target = ((ScriptSectionScriptParameter)command.Parameters[0]).Section });
continue;
}
else if (command.Verb == CommandVerb.VGOTO)
{
Graph.AddEdge(new() { Source = section, Target = ((ScriptSectionScriptParameter)command.Parameters[1]).Section });
}
else if (command.Verb == CommandVerb.CHESS_VGOTO)
{
Graph.AddEdgeRange(command.Parameters.Cast<ScriptSectionScriptParameter>()
.Where(p => p.Section is not null).Select(p => new ScriptSectionEdge() { Source = section, Target = p.Section }));
}
else if (command.Verb == CommandVerb.SELECT)
{
Graph.AddEdgeRange(Event.ScriptSections.Where(s =>
Event.LabelsSection.Objects.Where(l =>
command.Parameters.Where(p => p.Type == ScriptParameter.ParameterType.OPTION).Cast<OptionScriptParameter>()
.Where(p => p.Option.Id > 0).Select(p => p.Option.Id).Contains(l.Id)).Select(l => l.Name.Replace("/", "")).Contains(s.Name))
.Select(s => new ScriptSectionEdge() { Source = section, Target = s }));
@continue = true;
}
}
if (@continue)
{
continue;
}
if (section != commandTree.Keys.Last())
{
Graph.AddEdge(new() { Source = section, Target = commandTree.Keys.ElementAt(commandTree.Keys.ToList().IndexOf(section) + 1) });
}
}
}

public override void Refresh(Project project)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class BgScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class BgScrollDirectionScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class BgmModeScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class BgmScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class BoolScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChessFileScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChessPieceScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Security.Cryptography.X509Certificates;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChessSpaceScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChibiEmoteScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChibiEnterExitScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ChibiScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ColorMonochromeScriptParameter : ScriptParameter
{
public ColorMonochrome ColorType { get; set; }

public ColorMonochromeScriptParameter(string name, short colorType) : base(name, ParameterType.COLOR_MONOCHROME)
{
ColorType = (ColorMonochrome)colorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SkiaSharp;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ColorScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ConditionalScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HaruhiChokuretsuLib.Archive.Data;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class DialoguePropertyScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HaruhiChokuretsuLib.Archive.Event;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class DialogueScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class EpisodeHeaderScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class FlagScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ItemScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class MapScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HaruhiChokuretsuLib.Archive.Event;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class OptionScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class PaletteEffectScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class PlaceScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ScreenScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HaruhiChokuretsuLib.Archive.Event;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ScriptSectionScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public abstract class ScriptParameter
{
Expand All @@ -10,7 +10,7 @@ protected ScriptParameter(string name, ParameterType type)
Name = name;
Type = type;
}

public enum ParameterType
{
BG,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SfxModeScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SfxScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class ShortScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SpriteEntranceScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SpriteExitScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SpriteScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class SpriteShakeScriptParameter : ScriptParameter
{
Expand All @@ -16,7 +16,7 @@ public enum SpriteShakeEffect : short
BOUNCE_HORIZONTAL_CENTER = 2,
BOUNCE_HORIZONTAL_CENTER_WITH_SMALL_SHAKES = 3,
SHAKE_RIGHT = 4,
SHAKE_LEFT = 5,
SHAKE_LEFT = 5,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class TextEntranceEffectScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class TopicScriptParameter : ScriptParameter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class TransitionScriptParameter : ScriptParameter
{
Expand All @@ -16,7 +16,7 @@ public enum TransitionEffect
WIPE_DIAGONAL_RIGHT_DOWN = 2,
BLINDS = 3,
BLINDS2 = 4,
WIPE_LEFT = 5,
WIPE_LEFT = 5,
WIPE_UP = 6,
WIPE_DIAGONAL_LEFT_UP = 7,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SerialLoops.Lib.Script
namespace SerialLoops.Lib.Script.Parameters
{
public class VoiceLineScriptParameter : ScriptParameter
{
Expand Down
Loading

0 comments on commit f65dbea

Please sign in to comment.