Skip to content

Commit

Permalink
autosave fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Feb 22, 2025
1 parent db885d4 commit 0f88d84
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion qml/Cell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Item {
diagonalSum = row + col

grid.cellsCreated++
if (grid.cellsCreated === GameState.gridSizeX * GameState.gridSizeY) {
if (grid.cellsCreated === GameState.gridSizeX * GameState.gridSizeY && !GameState.gridFullyInitialized) {
GameState.gridFullyInitialized = true
cellItem.root.startInitialLoadTimer()
}
Expand Down
1 change: 1 addition & 0 deletions qml/GameState.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ QtObject {
property var mines: []
property var numbers: []
property int cellSize: getCellSize()
property bool bypassAutoSave: false

function getCellSize() {
const size = GameSettings.cellSize
Expand Down
20 changes: 8 additions & 12 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ApplicationWindow {
return
}

if (GameSettings.loadLastGame && GameState.gameStarted && !GameState.gameOver) {
if (GameSettings.loadLastGame && GameState.gameStarted && !GameState.gameOver && !GameState.bypassAutoSave) {
close.accepted = false
if (!isSaving) {
isClosing = true
Expand Down Expand Up @@ -51,6 +51,7 @@ ApplicationWindow {

Connections {
target: GameCore
enabled: !SaveManager.manualSave
function onSaveCompleted(success) {
root.isSaving = false
Qt.quit()
Expand Down Expand Up @@ -261,21 +262,16 @@ ApplicationWindow {
function checkInitialGameState() {
if (!GameState.gridFullyInitialized) return

if (!GameCore.showWelcome) {
let internalSaveData = GameCore.loadGameState("internalGameState.json")
if (internalSaveData) {
if (SaveManager.loadGame(internalSaveData)) {
GameCore.deleteSaveFile("internalGameState.json")
GameState.isManuallyLoaded = false
} else {
console.error("Failed to load internal game state")
grid.initGame()
}
let internalSaveData = GameCore.loadGameState("internalGameState.json")
if (internalSaveData) {
if (SaveManager.loadGame(internalSaveData)) {
GameCore.deleteSaveFile("internalGameState.json")
GameState.isManuallyLoaded = false
} else {
console.error("Failed to load internal game state")
grid.initGame()
}
} else {
GameCore.deleteSaveFile("internalGameState.json")
grid.initGame()
}

Expand Down
3 changes: 3 additions & 0 deletions qml/SaveManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.odizinne.retr0mine 1.0
Item {
id: saveManager
property var grid: null
property var manualSave: false

function setGrid(gridReference) {
grid = gridReference
Expand Down Expand Up @@ -165,6 +166,8 @@ Item {
if (cell.safeQuestioned) saveData.gameState.safeQuestionedCells.push(i)
}

console.log("pass")
GameCore.saveGameState(JSON.stringify(saveData), filename)
SaveManager.manualSave = false
}
}
1 change: 1 addition & 0 deletions qml/SaveWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Popup {
enabled: false
onClicked: {
if (saveNameField.text.trim()) {
SaveManager.manualSave = true
SaveManager.saveGame(saveNameField.text.trim() + ".json")
control.visible = false
}
Expand Down
2 changes: 2 additions & 0 deletions qml/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ApplicationWindow {
Layout.preferredWidth: restoreDefaultsPopup.buttonWidth
Layout.fillWidth: true
onClicked: {
GameState.bypassAutoSave = true
GameCore.resetRetr0Mine()
}
}
Expand Down Expand Up @@ -1013,6 +1014,7 @@ ApplicationWindow {
if (GameState.gameStarted && !GameState.gameOver) {
SaveManager.saveGame("internalGameState.json")
}
GameState.bypassAutoSave = true
GameCore.restartRetr0Mine(currentIndex)
}
}
Expand Down

0 comments on commit 0f88d84

Please sign in to comment.