refactor: restructure code and fix some events not being applied
This commit is contained in:
@ -27,7 +27,7 @@ public class GameInstance {
|
||||
/** Constructs a new {@link GameInstance}. */
|
||||
public GameInstance(PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
|
||||
_state = new GameState(partyConfig, characterConfig, scenarioConfig);
|
||||
this.state = new GameStateView(_state);
|
||||
state = new GameStateView(_state);
|
||||
manager = new GameStateManager(_state);
|
||||
}
|
||||
|
||||
@ -36,16 +36,11 @@ public class GameInstance {
|
||||
* @param requests The requests to check
|
||||
* @return The list of resulting {@link Event}s or `null` if the check failed
|
||||
*/
|
||||
public Optional<List<Event>> checkRequestsAndApply(Request... requests) {
|
||||
public Optional<List<Event>> checkRequestsAndApply(ArrayList<Request> requests) {
|
||||
if(manager.processRequests(requests, true)) {
|
||||
ArrayList<Event> result = manager.apply();
|
||||
|
||||
ArrayList<Event> result2 = manager.checkPostPhase();
|
||||
manager.applyEvents(result2);
|
||||
|
||||
result.addAll(result2);
|
||||
|
||||
result.add(GameLogic.buildGameStateEvent(_state));
|
||||
result.addAll(manager.checkPostPhase());
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
@ -58,44 +53,10 @@ public class GameInstance {
|
||||
* @param requests The requests to check
|
||||
* @return Whether or not the given set of requests is valid
|
||||
*/
|
||||
public boolean checkRequests(Request... requests) {
|
||||
public boolean checkRequests(ArrayList<Request> requests) {
|
||||
return manager.processRequests(requests, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes and starts the game. Selected characters are given as a list of indices from the {@link CharacterConfig#characters} array.
|
||||
* @param selectedCharacters1 The characters selected by player 1
|
||||
* @param selectedCharacters2 The characters selected by player 2
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public ArrayList<Event> startGame(ArrayList<Integer> selectedCharacters1, ArrayList<Integer> selectedCharacters2) {
|
||||
ArrayList<Event> result = manager.initGame(selectedCharacters1, selectedCharacters2);
|
||||
manager.applyEvents(result);
|
||||
|
||||
ArrayList<Event> result2 = manager.startGame();
|
||||
manager.applyEvents(result2);
|
||||
|
||||
result.addAll(result2); //do not merge this, result needs to be applied before startGame is called
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a {@link EventType#GamestateEvent} for the current {@link GameState}.
|
||||
* @return The resulting event
|
||||
*/
|
||||
public Event getGameStateEvent() {
|
||||
return GameLogic.buildGameStateEvent(_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the current {@link GameState} based on the given one.
|
||||
* @param state The state to restore from
|
||||
*/
|
||||
public void setGameState(GameState state) {
|
||||
_state.restore(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies an array of {@link Event}s to the game state.
|
||||
* @param events The events to apply.
|
||||
@ -104,8 +65,30 @@ public class GameInstance {
|
||||
manager.applyEvents(events);
|
||||
}
|
||||
|
||||
protected GameState getState() {
|
||||
return _state;
|
||||
/**
|
||||
* Initializes and starts the game. Selected characters are given as a list of indices from the {@link CharacterConfig#characters} array.
|
||||
* @param selectedCharacters1 The characters selected by player 1
|
||||
* @param selectedCharacters2 The characters selected by player 2
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public ArrayList<Event> startGame(ArrayList<Integer> selectedCharacters1, ArrayList<Integer> selectedCharacters2) {
|
||||
return manager.startGame(selectedCharacters1, selectedCharacters2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a {@link EventType#GamestateEvent} for the current {@link GameState}.
|
||||
* @return The resulting event
|
||||
*/
|
||||
public Event getGameStateEvent() {
|
||||
return manager.getGameStateEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the current {@link GameState} based on the given {@link EventType#GamestateEvent}.
|
||||
* @param gameStateEvent The event to restore from
|
||||
*/
|
||||
public void applyGameStateEvent(Event gameStateEvent) {
|
||||
manager.applyEvent(gameStateEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user