Disable loading room editor if the current house is damaged beyond repair, and re-enable loading a different house.

This commit is contained in:
elasota
2021-05-11 01:39:17 -04:00
parent 295db5f064
commit 318a5868d7
4 changed files with 31 additions and 15 deletions

View File

@@ -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);

View File

@@ -205,6 +205,7 @@ Boolean CreateNewHouse (void)
// Initializes all the structures for an empty (new) house.
#ifndef COMPILEDEMO
Boolean InitializeEmptyHouse (void)
{
houseType *thisHousePtr;
@@ -213,7 +214,8 @@ Boolean InitializeEmptyHouse (void)
if (thisHouse != nil)
thisHouse.Dispose();
thisHouse = NewHandle(sizeof(houseType) - sizeof(roomType)).StaticCast<houseType>();
const size_t houseSizeNoRooms = sizeof(sizeof(houseType) - sizeof(roomType));
thisHouse = NewHandle(houseSizeNoRooms).StaticCast<houseType>();
if (thisHouse == nil)
{
@@ -251,11 +253,18 @@ Boolean InitializeEmptyHouse (void)
UpdateMapWindow();
noRoomAtAll = true;
fileDirty = true;
UpdateMenus(false);
ReflectCurrentRoom(true);
return (true);
}
Boolean InitializeEmptyHouseInEditor (void)
{
if (!InitializeEmptyHouse())
return (false);
UpdateMenus(false);
ReflectCurrentRoom(true);
}
#endif
//-------------------------------------------------------------- RealRoomNumberCount

View File

@@ -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)
{

View File

@@ -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();
}