Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask if uses want to overwrite save file when creating save with existing name #1371

Conversation

ayrtondenner
Copy link
Contributor

Fix #1347

After discussion in issue thread, I implemented the following logic:

  • If writing name in first slot
    • If no savefile exists with same name, then create savefile
    • If savefile found, open overwrite messagebox
  • If writing in existing slot, open overwrite messagebox

I also encapsulated overwrite messagebox call in SaveMenu::askUserIfWantToOverrideSavedGame

}
}

void SaveMenu::askUserIfWantToOverrideSavedGame(sp<SaveMetadata> saveMetadata)
{
auto saveName = saveMetadata->getName();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, if something can be const, I think it should be declared as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean in the parameter, like this?

void SaveMenu::askUserIfWantToOverrideSavedGame(const sp<SaveMetadata> saveMetadata)

return !pathExists;
}

sp<SaveMetadata> SaveManager::getSaveGameIfExists(const UString &name) const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to your change, as it's just following what's already there, but I really need to remove the sp<> wrapper here - it's not really a thing that needs shared ownership and arguably a bit unnecessary.

if (parent->Name == newSaveItemId)
{
if (saveManager.newSaveGame(saveName, currentState))
auto saveGameMetadata = saveManager.getSaveGameIfExists(saveName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be const?

}
});

std::function<void()> onNo = std::function<void()>([this] { clearTextEdit(activeTextEdit); });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be auto? The type is already defined in the rhs


sp<SaveMetadata> SaveManager::getSaveGameIfExists(const UString &name) const
{
auto saveList = getSaveList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can be const?

@ayrtondenner
Copy link
Contributor Author

ayrtondenner commented Mar 15, 2024

@JonnyH I added some more const values, let me know if I missed some.

@JonnyH
Copy link
Collaborator

JonnyH commented Mar 15, 2024

Thanks, looks good.

I think c++ really should be "const-by-default", and force you to state if variables are mutable. I just find it makes it much easier to reason about code if you don't have to worry about variables changing :)

@JonnyH JonnyH merged commit 16608c0 into OpenApoc:master Mar 15, 2024
3 checks passed
@ayrtondenner ayrtondenner deleted the issue-1347-ask-if-overwrite-when-saving-file-with-same-name branch March 15, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants