Skip to content

Commit

Permalink
Editor: also use the ScriptGeneration utils when upgrading rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 13, 2023
1 parent 419f3c9 commit d9c12f0
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions Editor/AGS.Editor/Components/RoomsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,32 +859,17 @@ private bool AddPlayMusicCommandToPlayerEntersRoomScript(Room room, CompileMessa
return scriptModified;
}

string scriptName = room.Interactions.GetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD);
if (string.IsNullOrEmpty(scriptName))
string functionName = room.Interactions.GetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD);
if (string.IsNullOrEmpty(functionName))
{
scriptName = "Room_" + Room.EVENT_SUFFIX_ROOM_LOAD;
room.Interactions.SetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD, scriptName);
room.Script.Text += Environment.NewLine + "function " + scriptName + "()" +
Environment.NewLine + "{" + Environment.NewLine +
"}" + Environment.NewLine;
scriptModified = true;
}
int functionOffset = room.Script.Text.IndexOf(scriptName);
if (functionOffset < 0)
{
errors.Add(new CompileWarning("Room " + room.Number + ": Unable to find definition for " + scriptName + " to add Room Load music " + room.PlayMusicOnRoomLoad));
}
else
{
functionOffset = room.Script.Text.IndexOf('{', functionOffset);
functionOffset = room.Script.Text.IndexOf('\n', functionOffset) + 1;
string newScript = room.Script.Text.Substring(0, functionOffset);
newScript += " " + clip.ScriptName + ".Play();" + Environment.NewLine;
newScript += room.Script.Text.Substring(functionOffset);
room.Script.Text = newScript;
room.PlayMusicOnRoomLoad = 0;
scriptModified = true;
functionName = "Room_" + Room.EVENT_SUFFIX_ROOM_LOAD;
room.Interactions.SetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD, functionName);
}

room.Script.Text = ScriptGeneration.InsertFunction(room.Script.Text, functionName, "",
" " + clip.ScriptName + ".Play();", amendExisting: true, insertBeforeExistingCode: true);
room.PlayMusicOnRoomLoad = 0;
scriptModified = true;
}

return scriptModified;
Expand Down

0 comments on commit d9c12f0

Please sign in to comment.