Skip to content

Commit 55b8a7a

Browse files
committed
Make quarry parameter of new script action default to quarry type inferred from the script's name if possible
1 parent 281580b commit 55b8a7a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/TSMapEditor/UI/Windows/ScriptsWindow.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,36 @@ private ScriptActionEntry CreateNewScriptActionEntry(int actionId)
517517

518518
switch (scriptActionType.ParamType)
519519
{
520+
case TriggerParamType.Quarry:
521+
if (editedScript != null)
522+
{
523+
// Check if the script action already has an attack quarry action. If yes, default to "attack anything".
524+
if (editedScript.Actions.Exists(ae =>
525+
{
526+
var otherScriptActionType = map.EditorConfig.ScriptActions.GetValueOrDefault(actionId);
527+
if (otherScriptActionType != null && otherScriptActionType.ParamType == TriggerParamType.Quarry)
528+
{
529+
return true;
530+
}
531+
532+
return false;
533+
}))
534+
{
535+
entry.Argument = 1; // QUARRY_ANY (attack anything)
536+
break;
537+
}
538+
539+
// Default to a quarry type existing in the name of the action.
540+
for (int i = 0; i < scriptActionType.PresetOptions.Count; i++)
541+
{
542+
if (editedScript.Name.Contains(scriptActionType.PresetOptions[i].Text, StringComparison.OrdinalIgnoreCase))
543+
{
544+
entry.Argument = i;
545+
break;
546+
}
547+
}
548+
}
549+
break;
520550
case TriggerParamType.Waypoint:
521551
Waypoint wp = map.GetFirstUnusedWaypoint();
522552
if (wp != null)

0 commit comments

Comments
 (0)