Skip to content

Commit

Permalink
Editor: reset Room.SaveLoadEnabled on room upgrade
Browse files Browse the repository at this point in the history
This option was deprecated many years ago, but its value left intact with no way to disable.
  • Loading branch information
ivan-mogilko committed Oct 15, 2023
1 parent 1ca7622 commit 5ec52ba
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
8 changes: 5 additions & 3 deletions Common/game/roomstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,19 @@ typedef std::shared_ptr<Bitmap> PBitmap;
// Various room options
struct RoomOptions
{
// Index of the startup music in the room
// Index of the startup music in the room;
// this is a deprecated option, used before 3.2.* with old audio API.
int StartupMusic;
// If saving and loading game is disabled in the room
// If saving and loading game is disabled in the room;
// this is a deprecated option that affects only built-in save/load dialogs
bool SaveLoadDisabled;
// If player character is turned off in the room
bool PlayerCharOff;
// Apply player character's normal view when entering this room
int PlayerView;
// Room's music volume modifier
RoomVolumeMod MusicVolume;
// A collection of boolean options
// A collection of RoomFlags
int Flags;

RoomOptions();
Expand Down
22 changes: 21 additions & 1 deletion Editor/AGS.Editor/Components/RoomsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ private Room LoadNewRoomIntoMemory(UnloadedRoom newRoom, CompileMessages errors)
// TODO: group these in some UpdateRoomToNewVersion method
_loadedRoom.Modified = ImportExport.CreateInteractionScripts(_loadedRoom, errors);
_loadedRoom.Modified |= HookUpInteractionVariables(_loadedRoom);
_loadedRoom.Modified |= HandleObsoleteSettings(_loadedRoom, errors);
_loadedRoom.Modified |= AddPlayMusicCommandToPlayerEntersRoomScript(_loadedRoom, errors);
_loadedRoom.Modified |= AdjustRoomResolution(_loadedRoom);
// NOTE: currently the only way to know if the room was not affected by
Expand All @@ -846,10 +847,28 @@ private Room LoadNewRoomIntoMemory(UnloadedRoom newRoom, CompileMessages errors)
return _loadedRoom;
}

private bool AddPlayMusicCommandToPlayerEntersRoomScript(Room room, CompileMessages errors)
private bool HandleObsoleteSettings(Room room, CompileMessages errors)
{
#pragma warning disable 0612
bool scriptModified = false;
if (!room.SaveLoadEnabled)
{
// Simply add a warning in script comments, to let user know that something may be missing
room.Script.Text = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}",
"// WARNING: this Room had a \"Save/Load disabled\" setting, which is now deprecated,", Environment.NewLine,
"// and so it was removed during upgrade. If you like to restore this behavior,", Environment.NewLine,
"// you would have to implement it in script. (This warning is safe to remove)", Environment.NewLine, Environment.NewLine,
room.Script.Text);
room.SaveLoadEnabled = true;
}
return scriptModified;
#pragma warning restore 0612
}

private bool AddPlayMusicCommandToPlayerEntersRoomScript(Room room, CompileMessages errors)
{
#pragma warning disable 0612
bool scriptModified = false;
if (room.PlayMusicOnRoomLoad > 0)
{
AudioClip clip = _agsEditor.CurrentGame.FindAudioClipForOldMusicNumber(null, room.PlayMusicOnRoomLoad);
Expand All @@ -873,6 +892,7 @@ private bool AddPlayMusicCommandToPlayerEntersRoomScript(Room room, CompileMessa
}

return scriptModified;
#pragma warning restore 0612
}

private bool AdjustRoomResolution(Room room)
Expand Down
2 changes: 2 additions & 0 deletions Editor/AGS.Editor/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public static void ExportSprites(SpriteTools.ExportSpritesOptions options)

private void SetDefaultValuesForNewFeatures(Game game)
{
#pragma warning disable 0618
// TODO: this may be noticably if upgrading lots of items. Display some kind of
// progress window to notify user.

Expand Down Expand Up @@ -497,6 +498,7 @@ private void SetDefaultValuesForNewFeatures(Game game)
System.Version projectVersion = game.SavedXmlEditorVersion != null ? Types.Utilities.TryParseVersion(game.SavedXmlEditorVersion) : null;
if (projectVersion == null || projectVersion < editorVersion)
game.SetScriptAPIForOldProject();
#pragma warning restore 0618
}

private static int RemapAudioClipIDToFixedIndex(int id, Dictionary<int, int> audioIDToIndex)
Expand Down
4 changes: 2 additions & 2 deletions Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3748,9 +3748,9 @@ void convert_room_to_native(Room ^room, RoomStruct &rs)
rs.Edges.Left = room->LeftEdgeX;
rs.Options.MusicVolume = (RoomVolumeMod)room->MusicVolumeAdjustment;
rs.Options.PlayerView = room->PlayerCharacterView;
rs.Options.StartupMusic = room->PlayMusicOnRoomLoad;
rs.Options.StartupMusic = 0; // [OBSOLETE]
rs.Edges.Right = room->RightEdgeX;
rs.Options.SaveLoadDisabled = room->SaveLoadEnabled ? 0 : 1;
rs.Options.SaveLoadDisabled = false; // [OBSOLETE]
rs.Options.PlayerCharOff = room->ShowPlayerCharacter ? 0 : 1;
rs.Edges.Top = room->TopEdgeY;
rs.Width = room->Width;
Expand Down
18 changes: 6 additions & 12 deletions Editor/AGS.Types/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class Room : UnloadedRoom, IChangeNotification, ILoadedRoom
private int _rightEdgeX;
private int _topEdgeY;
private int _bottomEdgeY;
private int _playMusicOnRoomLoad;
private bool _saveLoadEnabled = true;
private bool _showPlayerCharacter = true;
private int _playerCharacterView;
private RoomVolumeAdjustment _musicVolumeAdjustment;
Expand Down Expand Up @@ -308,19 +306,15 @@ public bool BackgroundAnimationEnabled
set { _backgroundAnimEnabled = value; }
}

[Obsolete]
[Browsable(false)]
public int PlayMusicOnRoomLoad
{
get { return _playMusicOnRoomLoad; }
set { _playMusicOnRoomLoad = value; }
}
// NOTE: have to keep setter here because we load old rooms before upgrading them
public int PlayMusicOnRoomLoad { get; set; }

[Obsolete]
[Browsable(false)]
public bool SaveLoadEnabled
{
get { return _saveLoadEnabled; }
set { _saveLoadEnabled = value; }
}
// NOTE: have to keep setter here because we load old rooms before upgrading them
public bool SaveLoadEnabled { get; set; }

[Description("Whether the player character is visible on this screen")]
[DefaultValue(true)]
Expand Down

0 comments on commit 5ec52ba

Please sign in to comment.