package thb.jeanluc.adventure.game;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/** Named world flags. A flag is "set" (true) when present in the set. */
public class GameState {

    private final Set<String> flags = new LinkedHashSet<>();

    public boolean isSet(String flag) {
        return flags.contains(flag);
    }

    public void set(String flag) {
        flags.add(flag);
    }

    public void clear(String flag) {
        flags.remove(flag);
    }

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