feat: restore hooks for flags, quest progress, switch state

This commit is contained in:
2026-06-01 14:21:56 +02:00
parent 58352087c4
commit c392f80ed0
4 changed files with 68 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package thb.jeanluc.adventure.game;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -24,4 +25,10 @@ public class GameState {
public Set<String> all() {
return Collections.unmodifiableSet(flags);
}
/** Replaces all flags with the given collection (used by load). */
public void restore(Collection<String> newFlags) {
flags.clear();
flags.addAll(newFlags);
}
}

View File

@@ -1,5 +1,6 @@
package thb.jeanluc.adventure.game;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -46,4 +47,12 @@ public class QuestLog {
public Set<String> completed() {
return Collections.unmodifiableSet(completed);
}
/** Replaces all progress with the given stage map and completed set (load). */
public void restore(Map<String, Integer> stages, Collection<String> completedIds) {
stageIndex.clear();
stageIndex.putAll(stages);
completed.clear();
completed.addAll(completedIds);
}
}

View File

@@ -53,4 +53,14 @@ public class SwitchableItem extends Item {
public boolean isOn() {
return state;
}
/**
* Directly sets the on/off state without running effects or printing.
* Used only when restoring a saved game.
*
* @param state the state to restore
*/
public void setState(boolean state) {
this.state = state;
}
}