Speichern meldet Fehler und schützt unbrauchbare Stände
Lässt sich ein unbrauchbarer Spielstand nicht beiseitelegen, bleibt das Speichern gesperrt, bis ein Stand erfolgreich geladen wird; so wird er nie überschrieben. Ein gescheitertes automatisches Speichern zeigt SAVE_FAILED, und jedes gescheiterte Speichern wird protokolliert. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+18
-5
@@ -25,6 +25,9 @@ var hud: Hud
|
||||
|
||||
var _player_key: PackedByteArray
|
||||
var _next_dig_tick := 0
|
||||
## True while an unusable save could not be set aside. Saving is refused
|
||||
## then, so that the unusable save is never overwritten.
|
||||
var _save_blocked := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -72,7 +75,8 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_CLOSE_REQUEST and session != null:
|
||||
save_game()
|
||||
if not save_game():
|
||||
push_warning("the game could not be saved on close")
|
||||
_write_recording()
|
||||
|
||||
|
||||
@@ -90,9 +94,14 @@ func _start_from_save() -> bool:
|
||||
var loaded := GwSession.new()
|
||||
if not loaded.start_loaded(store.read_save()):
|
||||
var aside := store.set_aside_save()
|
||||
push_warning("save not usable (%s), kept as %s" % [loaded.last_error(), aside])
|
||||
if aside.is_empty():
|
||||
_save_blocked = true
|
||||
push_warning("save not usable (%s) and could not be set aside; saving is off" % loaded.last_error())
|
||||
else:
|
||||
push_warning("save not usable (%s), kept as %s" % [loaded.last_error(), aside])
|
||||
hud.flash("LOAD_FAILED")
|
||||
return false
|
||||
_save_blocked = false
|
||||
_enter(loaded)
|
||||
return true
|
||||
|
||||
@@ -112,8 +121,9 @@ func _enter(next: GwSession) -> void:
|
||||
|
||||
func _run_tick() -> void:
|
||||
_apply(session.step())
|
||||
if session.tick() % AUTOSAVE_TICKS == 0:
|
||||
save_game()
|
||||
if session.tick() % AUTOSAVE_TICKS == 0 and not save_game():
|
||||
hud.flash("SAVE_FAILED")
|
||||
push_warning("the automatic save failed")
|
||||
|
||||
|
||||
func _apply(events: Array[Dictionary]) -> void:
|
||||
@@ -153,8 +163,11 @@ func dig_at(tile: Vector2i) -> void:
|
||||
_next_dig_tick = session.tick() + GwSession.DIG_COOLDOWN_TICKS
|
||||
|
||||
|
||||
## Writes the running world as the save. Returns false if nothing was written.
|
||||
## Writes the running world as the save. Returns false if nothing was
|
||||
## written, also while an unusable save could not be set aside.
|
||||
func save_game() -> bool:
|
||||
if _save_blocked:
|
||||
return false
|
||||
return store.write_save(session.save())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user