Skip to content

Commit

Permalink
[HS-1471] cleanup dialogoptions in various places
Browse files Browse the repository at this point in the history
  • Loading branch information
baughj committed Jul 28, 2024
1 parent c6790eb commit 4ddd476
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 60 deletions.
30 changes: 1 addition & 29 deletions hybrasyl/Subsystems/Dialogs/OptionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,7 @@ public bool RunCheckExpression(DialogOption option, DialogInvocation invocation)
return !ret.Return.CastToBool() || ret.Return.CastToBool();
}

public void AddDialogOption(string option, string callback = null, string checkExpression = null)
{
Options.Add(new DialogOption
{
OptionText = option,
CallbackFunction = callback,
CheckExpression = checkExpression
});
}

public void AddDialogOption(string option, JumpDialog jumpTo, string checkExpression = null)
{
Options.Add(new DialogOption
{
OptionText = option,
JumpDialog = jumpTo,
CheckExpression = checkExpression,
});
}

public void AddDialogOption(string option, DialogSequence sequence, string checkExpression = null)
{
Options.Add(new DialogOption
{
OptionText = option,
OverrideSequence = sequence,
CheckExpression = checkExpression
});
}
public void AddDialogOption(DialogOption option) => Options.Add(option);

public bool HandleResponse(int optionSelected, DialogInvocation invocation)
{
Expand Down
44 changes: 13 additions & 31 deletions hybrasyl/Subsystems/Scripting/HybrasylWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ public HybrasylDialogSequence NewEndSequence(string simpleDialog, string callbac
return null;
}

if (name == null)
sequence = new DialogSequence(Guid.NewGuid().ToString());
else
sequence = new DialogSequence(name);
sequence = name == null ? new DialogSequence(Guid.NewGuid().ToString()) : new DialogSequence(name);

var dialog = new SimpleDialog(simpleDialog);

Expand Down Expand Up @@ -301,38 +298,23 @@ public HybrasylDialog NewOptionsDialog(string displayText, HybrasylDialogOptions

var dialog = new OptionsDialog(displayText);
foreach (DictionaryEntry entry in dialogOptions.Options)
if (entry.Value is string)
// Callback
{
dialog.AddDialogOption(entry.Key as string, entry.Value as string);
}
else if (entry.Value is HybrasylDialog)
{
var hd = entry.Value as HybrasylDialog;
if (hd.DialogType == typeof(JumpDialog))
// Dialog jump
dialog.AddDialogOption(entry.Key as string, hd.Dialog as JumpDialog);
else
GameLog.ScriptingError(
"NewOptionsDialog: one or more passed option(s) uses type {type} - only jump dialogs are allowed currently",
entry.Value.GetType().Name);
}
else if (entry.Value is null)
// This is JUST an option, with no callback or jump dialog. The dialog handler will process the option itself.
{
dialog.AddDialogOption(entry.Key as string);
}
else if (entry.Value is HybrasylDialogSequence)
{
if (entry.Value is null)
{
var hds = entry.Value as HybrasylDialogSequence;
dialog.AddDialogOption(entry.Key as string, hds.Sequence);
GameLog.ScriptingError(
$"NewOptionsDialog: expected DialogOption, but null was encountered");
return null;
}
else

if (entry.Value is not DialogOption o)
{
GameLog.ScriptingError(
"NewOptionsDialog: one or more passed option(s) was an unknown type {type} - this will not work",
entry.Value.GetType().Name);
$"NewOptionsDialog: expected DialogOption, but {entry.Value.GetType()} was encountered");
return null;
}
dialog.AddDialogOption(o);

}

if (dialog.OptionCount == 0)
GameLog.ScriptingError(
Expand Down

0 comments on commit 4ddd476

Please sign in to comment.