forked from SteamWar/SteamWar
Migrate FightSystem modes and countdowns to GameCore
- Move shared arena-mode abstractions into GameCore - Adapt fight countdowns and APIs to the shared model - Add SteamWar issue audit workflow and SQL language settings
This commit is contained in:
@@ -19,41 +19,30 @@
|
||||
|
||||
package de.steamwar.towerrun.state;
|
||||
|
||||
import lombok.Getter;
|
||||
import de.steamwar.gamecore.state.GameStateMachine;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class GameState {
|
||||
@Getter
|
||||
private static GameStates currentState = GameStates.WAITING;
|
||||
private static final List<GameStateListener> gameStateListeners = new ArrayList<>();
|
||||
private static final GameStateMachine<GameStates> state = new GameStateMachine<>(GameStates.WAITING);
|
||||
|
||||
public static void addGameStateListener(GameStateListener gameStateListener) {
|
||||
gameStateListeners.add(gameStateListener);
|
||||
public static GameStateMachine<GameStates> getLifecycle() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static GameStates getCurrentState() {
|
||||
return state.getCurrentState();
|
||||
}
|
||||
|
||||
public static void nextState() {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = currentState.getNextState();
|
||||
gameStateChanges(oldState, currentState);
|
||||
state.transitionTo(state.getCurrentState().getNextState());
|
||||
}
|
||||
|
||||
static void setState(final GameStates newState) {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = newState;
|
||||
gameStateChanges(oldState, currentState);
|
||||
state.transitionTo(newState);
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = GameStates.WAITING;
|
||||
gameStateChanges(oldState, currentState);
|
||||
}
|
||||
|
||||
private static void gameStateChanges(GameStates oldState, GameStates newState) {
|
||||
gameStateListeners.forEach(gameStateListener -> gameStateListener.onGameStateChange(oldState, newState));
|
||||
state.transitionTo(GameStates.WAITING);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user