Skip to content

Commit

Permalink
Add some more script command editors (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jan 25, 2025
1 parent 44d473b commit 92ff24a
Show file tree
Hide file tree
Showing 24 changed files with 660 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public ScriptPreview GetScriptPreview(OrderedDictionary<ScriptSection, List<Scri
if (commands[i].Verb == CommandVerb.CHIBI_ENTEREXIT)
{
if (((ChibiEnterExitScriptParameter)commands[i].Parameters[1]).Mode ==
ChibiEnterExitScriptParameter.ChibiEnterExitType.ENTER)
ChibiEnterExitScriptParameter.ChibiEnterExitType.Enter)
{
ChibiItem chibi = ((ChibiScriptParameter)commands[i].Parameters[0]).Chibi;
if (!chibis.Contains(chibi))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override ChibiEnterExitScriptParameter Clone(Project project, EventFile e

public enum ChibiEnterExitType
{
ENTER = 0,
EXIT = 1,
Enter = 0,
Exit = 1,
}
}
63 changes: 63 additions & 0 deletions src/SerialLoops/Assets/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/SerialLoops/Assets/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3059,4 +3059,25 @@ This action is irreversible.</value>
<data name="No Character" xml:space="preserve">
<value>None</value>
</data>
<data name="Map Character Set" xml:space="preserve">
<value>Map Character Set</value>
</data>
<data name="EXCLAMATION_POINT" xml:space="preserve">
<value>Exclamation Point</value>
</data>
<data name="LIGHT_BULB" xml:space="preserve">
<value>Light Bulb</value>
</data>
<data name="ANGER_MARK" xml:space="preserve">
<value>Anger Mark</value>
</data>
<data name="MUSIC_NOTE" xml:space="preserve">
<value>Music Note</value>
</data>
<data name="SWEAT_DROP" xml:space="preserve">
<value>Sweat Drop</value>
</data>
<data name="Enter" xml:space="preserve">
<value>Enter</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ScenarioEditorViewModel(ScenarioItem scenario, MainWindowViewModel window
private async void Add()
{
int selectedIndex = Math.Min(_scenario.Scenario.Commands.Count - 1, Commands.IndexOf(SelectedCommand));
ScenarioVerb? newVerb = await new AddScenarioCommandDialog { DataContext = new AddScenarioCommandDialogViewModel() }.ShowDialog<ScenarioVerb>(Window.Window);
ScenarioVerb? newVerb = await new AddScenarioCommandDialog { DataContext = new AddScenarioCommandDialogViewModel() }.ShowDialog<ScenarioVerb?>(Window.Window);
if (newVerb is not null)
{
int param = newVerb switch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using DynamicData;
using HaruhiChokuretsuLib.Util;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using SerialLoops.Assets;
using SerialLoops.Lib.Items;
using SerialLoops.Lib.Script;
using SerialLoops.Lib.Script.Parameters;

namespace SerialLoops.ViewModels.Editors.ScriptCommandEditors;

public class ChibiEmoteScriptCommandEditorViewModel(ScriptItemCommand command, ScriptEditorViewModel scriptEditor, ILogger log) : ScriptCommandEditorViewModel(command, scriptEditor, log)
{
public ObservableCollection<ChibiItem> Chibis { get; } = new(scriptEditor.Window.OpenProject.Items
.Where(i => i.Type == ItemDescription.ItemType.Chibi).Cast<ChibiItem>());
public ChibiItem Chibi
{
get => ((ChibiScriptParameter)Command.Parameters[0]).Chibi;
set
{
((ChibiScriptParameter)Command.Parameters[0]).Chibi = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[0] = (short)value.TopScreenIndex;
this.RaisePropertyChanged();
ScriptEditor.UpdatePreview();
Script.UnsavedChanges = true;
}
}

public ObservableCollection<LocalizedChibiEmote> ChibiEmotes { get; } = new(Enum
.GetValues<ChibiEmoteScriptParameter.ChibiEmote>()
.Select(e => new LocalizedChibiEmote(e)));

public LocalizedChibiEmote ChibiEmote
{
get => new(((ChibiEmoteScriptParameter)Command.Parameters[1]).Emote);
set
{
((ChibiEmoteScriptParameter)Command.Parameters[1]).Emote = value.Emote;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[1] = (short)value.Emote;
this.RaisePropertyChanged();
ScriptEditor.UpdatePreview();
Script.UnsavedChanges = true;
}
}
}

public struct LocalizedChibiEmote(ChibiEmoteScriptParameter.ChibiEmote chibiEmote)
{
public ChibiEmoteScriptParameter.ChibiEmote Emote { get; } = chibiEmote;

public string DisplayName => Strings.ResourceManager.GetString(Emote.ToString());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices.JavaScript;
using HaruhiChokuretsuLib.Util;
using ReactiveUI;
using SerialLoops.Assets;
using SerialLoops.Lib.Items;
using SerialLoops.Lib.Script;
using SerialLoops.Lib.Script.Parameters;

namespace SerialLoops.ViewModels.Editors.ScriptCommandEditors;

public class ChibiEnterExitScriptCommandEditorViewModel(ScriptItemCommand command, ScriptEditorViewModel scriptEditor, ILogger log) : ScriptCommandEditorViewModel(command, scriptEditor, log)
{
public ObservableCollection<ChibiItem> Chibis { get; } = new(scriptEditor.Window.OpenProject.Items.Where(
i => i.Type == ItemDescription.ItemType.Chibi).Cast<ChibiItem>());
public ChibiItem Chibi
{
get => ((ChibiScriptParameter)Command.Parameters[0]).Chibi;
set
{
((ChibiScriptParameter)Command.Parameters[0]).Chibi = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[0] = (short)value.TopScreenIndex;
this.RaisePropertyChanged();
ScriptEditor.UpdatePreview();
Script.UnsavedChanges = true;
}
}

public ObservableCollection<LocalizedChibiEnterExitType> EnterExitModes { get; } = new(Enum.GetValues<ChibiEnterExitScriptParameter.ChibiEnterExitType>()
.Select(t => new LocalizedChibiEnterExitType(t)));
public LocalizedChibiEnterExitType EnterExitMode
{
get => new(((ChibiEnterExitScriptParameter)Command.Parameters[1]).Mode);
set
{
((ChibiEnterExitScriptParameter)Command.Parameters[1]).Mode = value.Mode;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[1] = (short)value.Mode;
this.RaisePropertyChanged();
ScriptEditor.UpdatePreview();
Script.UnsavedChanges = true;
}
}

public short Delay
{
get => ((ShortScriptParameter)Command.Parameters[2]).Value;
set
{
((ShortScriptParameter)Command.Parameters[2]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[2] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}
}

public readonly struct LocalizedChibiEnterExitType(ChibiEnterExitScriptParameter.ChibiEnterExitType type)
{
public ChibiEnterExitScriptParameter.ChibiEnterExitType Mode { get; } = type;
public string DisplayName { get; } = Strings.ResourceManager.GetString(type.ToString());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using HaruhiChokuretsuLib.Util;
using ReactiveUI;
using SerialLoops.Lib.Script;
using SerialLoops.Lib.Script.Parameters;

namespace SerialLoops.ViewModels.Editors.ScriptCommandEditors;

public class Global2DScriptCommandEditorViewModel(ScriptItemCommand command, ScriptEditorViewModel scriptEditor, ILogger log) : ScriptCommandEditorViewModel(command, scriptEditor, log)
{
public short Value
{
get => ((ShortScriptParameter)Command.Parameters[0]).Value;
set
{
((ShortScriptParameter)Command.Parameters[0]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[0] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Linq;
using HaruhiChokuretsuLib.Util;
using ReactiveUI;
using SerialLoops.Lib.Script;
using SerialLoops.Lib.Script.Parameters;

namespace SerialLoops.ViewModels.Editors.ScriptCommandEditors;

public class InvestStartScriptCommandEditorViewModel(
ScriptItemCommand scriptCommand,
ScriptEditorViewModel scriptEditor,
ILogger log)
: ScriptCommandEditorViewModel(scriptCommand, scriptEditor, log)
{
public short MapCharacterSet
{
get => ((ShortScriptParameter)Command.Parameters[0]).Value;
set
{
((ShortScriptParameter)Command.Parameters[0]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[0] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}
public short Unknown1
{
get => ((ShortScriptParameter)Command.Parameters[1]).Value;
set
{
((ShortScriptParameter)Command.Parameters[1]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[1] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}

public short Unknown2
{
get => ((ShortScriptParameter)Command.Parameters[2]).Value;
set
{
((ShortScriptParameter)Command.Parameters[2]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[2] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}

public short Unknown3
{
get => ((ShortScriptParameter)Command.Parameters[3]).Value;
set
{
((ShortScriptParameter)Command.Parameters[3]).Value = value;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[3] = value;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}

public ReactiveScriptSection EndScriptSection
{
get => ScriptEditor.ScriptSections.First(s =>
s.Section.Name.Equals(((ScriptSectionScriptParameter)Command.Parameters[4]).Section.Name));
set
{
((ScriptSectionScriptParameter)Command.Parameters[4]).Section = value.Section;
Script.Event.ScriptSections[Script.Event.ScriptSections.IndexOf(Command.Section)]
.Objects[Command.Index].Parameters[4] =
Script.Event.LabelsSection.Objects.First(l => l.Name.Replace("/", "").Equals(value.Name)).Id;
this.RaisePropertyChanged();
Script.UnsavedChanges = true;
}
}
}
Loading

0 comments on commit 92ff24a

Please sign in to comment.