From 318a5868d789432b2b7b7818c5394079efe5a5bf Mon Sep 17 00:00:00 2001 From: elasota Date: Tue, 11 May 2021 01:39:17 -0400 Subject: [PATCH] Disable loading room editor if the current house is damaged beyond repair, and re-enable loading a different house. --- GpApp/GliderProtos.h | 1 + GpApp/House.cpp | 31 ++++++++++++++++++++----------- GpApp/HouseIO.cpp | 6 ++++++ GpApp/Menu.cpp | 8 ++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/GpApp/GliderProtos.h b/GpApp/GliderProtos.h index 0b7be6c..6f06ce5 100644 --- a/GpApp/GliderProtos.h +++ b/GpApp/GliderProtos.h @@ -106,6 +106,7 @@ Boolean ReadScoresFromDisk (void); Boolean CreateNewHouse (void); // --- House.c Boolean InitializeEmptyHouse (void); +Boolean InitializeEmptyHouseInEditor (void); SInt16 RealRoomNumberCount (void); SInt16 GetFirstRoomNumber (void); void WhereDoesGliderBegin (Rect *, SInt16); diff --git a/GpApp/House.cpp b/GpApp/House.cpp index d5fb26f..f00ccc5 100644 --- a/GpApp/House.cpp +++ b/GpApp/House.cpp @@ -205,24 +205,26 @@ Boolean CreateNewHouse (void) // Initializes all the structures for an empty (new) house. #ifndef COMPILEDEMO + Boolean InitializeEmptyHouse (void) { houseType *thisHousePtr; Str255 tempStr; - + if (thisHouse != nil) thisHouse.Dispose(); - - thisHouse = NewHandle(sizeof(houseType) - sizeof(roomType)).StaticCast(); - + + const size_t houseSizeNoRooms = sizeof(sizeof(houseType) - sizeof(roomType)); + thisHouse = NewHandle(houseSizeNoRooms).StaticCast(); + if (thisHouse == nil) { YellowAlert(kYellowUnaccounted, 1); return (false); } - + thisHousePtr = *thisHouse; - + thisHousePtr->version = kHouseVersion; thisHousePtr->firstRoom = -1; thisHousePtr->timeStamp = 0L; @@ -230,17 +232,17 @@ Boolean InitializeEmptyHouse (void) thisHousePtr->initial.h = 32; thisHousePtr->initial.v = 32; ZeroHighScores(); - + GetLocalizedString(11, tempStr); PasStringCopy(tempStr, thisHousePtr->banner); GetLocalizedString(12, tempStr); PasStringCopy(tempStr, thisHousePtr->trailer); thisHousePtr->hasGame = false; thisHousePtr->nRooms = 0; - + wardBitSet = false; phoneBitSet = false; - + numberRooms = 0; mapLeftRoom = 60; mapTopRoom = 50; @@ -251,10 +253,17 @@ Boolean InitializeEmptyHouse (void) UpdateMapWindow(); noRoomAtAll = true; fileDirty = true; + + return (true); +} + +Boolean InitializeEmptyHouseInEditor (void) +{ + if (!InitializeEmptyHouse()) + return (false); + UpdateMenus(false); ReflectCurrentRoom(true); - - return (true); } #endif diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 37e2985..b877b3f 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -170,6 +170,9 @@ Boolean OpenHouse (Boolean read) Boolean readOK = ReadHouse(houseStream, theHousesSpecs[thisHouseIndex].m_dir != PortabilityLayer::VirtualDirectories::kGameData); houseStream->Close(); + if (!readOK) + CloseHouse(); + return readOK; } @@ -1964,7 +1967,10 @@ Boolean ReadHouse (GpIOStream *houseStream, bool untrusted) #endif if (thisHouse != nil) + { thisHouse.Dispose(); + thisHouse = nil; + } if (byteCount < houseType::kBinaryDataSize) { diff --git a/GpApp/Menu.cpp b/GpApp/Menu.cpp index 2422581..a326528 100644 --- a/GpApp/Menu.cpp +++ b/GpApp/Menu.cpp @@ -72,12 +72,12 @@ void UpdateMenusNonEditMode (void) DisableMenuItem(gameMenu, iOpenSavedGame); if (houseOpen) { - EnableMenuItem(gameMenu, iLoadHouse); + EnableMenuItem(optionsMenu, iEditor); EnableMenuItem(optionsMenu, iHighScores); } else { - DisableMenuItem(gameMenu, iLoadHouse); + DisableMenuItem(optionsMenu, iEditor); DisableMenuItem(optionsMenu, iHighScores); } } @@ -86,7 +86,7 @@ void UpdateMenusNonEditMode (void) EnableMenuItem(gameMenu, iNewGame); EnableMenuItem(gameMenu, iTwoPlayer); EnableMenuItem(gameMenu, iOpenSavedGame); - EnableMenuItem(gameMenu, iLoadHouse); + EnableMenuItem(optionsMenu, iEditor); EnableMenuItem(optionsMenu, iHighScores); } if (demoHouseIndex == -1) @@ -515,7 +515,7 @@ void DoHouseMenu (short theItem) case iNewHouse: if (CreateNewHouse()) { - whoCares = InitializeEmptyHouse(); + whoCares = InitializeEmptyHouseInEditor(); whoCares = WriteHouse(false); // Save initial house so it's not an empty file if reloaded immediately OpenCloseEditWindows(); }