fix: add configs to GameInstance and fix GameState snapshots

This commit is contained in:
2021-05-31 18:07:43 +02:00
parent ab011e54da
commit 7c36ea5c5c
4 changed files with 31 additions and 9 deletions

View File

@ -3,6 +3,9 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.Request;
import java.util.Observer;
@ -22,8 +25,8 @@ public class GameInstance {
private final EventEmitter emitter = new EventEmitter();
/** Constructs a new {@link GameInstance}. */
public GameInstance(IntVector2 mapSize) {
_state = new GameState(mapSize);
public GameInstance(PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
_state = new GameState(partyConfig, characterConfig, scenarioConfig);
this.state = new GameStateView(_state);
manager = new GameStateManager(_state);
}

View File

@ -2,6 +2,9 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import java.util.ArrayList;
import java.util.Arrays;
@ -12,6 +15,10 @@ class GameState {
/** The size of the map */
public final IntVector2 mapSize;
public final PartyConfig partyConfig;
public final CharacterConfig characterConfig;
public final ScenarioConfig scenarioConfig;
/** The list of {@link Entity}s inside the game */
public final EntityManager entities = new EntityManager();
@ -40,11 +47,13 @@ class GameState {
public final WinConditionManager winConditions = new WinConditionManager();
/**
* Constructs a new {@link GameState}.
* @param mapSize The size of the map
* Constructs a new {@link GameState} with the given config.
*/
public GameState(IntVector2 mapSize) {
this.mapSize = mapSize;
public GameState(PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
this.mapSize = new IntVector2(scenarioConfig.scenario[0].length, scenarioConfig.scenario.length);
this.partyConfig = partyConfig;
this.characterConfig = characterConfig;
this.scenarioConfig = scenarioConfig;
}
/**
@ -52,10 +61,12 @@ class GameState {
* @return The cloned game state
*/
public GameState snapshot() {
GameState clone = new GameState(this.mapSize);
GameState clone = new GameState(partyConfig, characterConfig, scenarioConfig);
clone.entities.cloneFrom(entities);
clone.unvomitedStones = new HashSet<>(unvomitedStones);
clone.roundNumber = roundNumber;
clone.turnOrder = new ArrayList<>();
@ -85,6 +96,8 @@ class GameState {
entities.cloneFrom(state.entities);
unvomitedStones = new HashSet<>(state.unvomitedStones);
roundNumber = state.roundNumber;
turnOrder = new ArrayList<>();