use of com.voxelgameslib.voxelgameslib.phase.Phase in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractGame method saveGameDefinition.
@Override
@Nonnull
public GameDefinition saveGameDefinition() {
GameDefinition definition = new GameDefinition();
definition.setGameMode(getGameMode());
definition.setMaxPlayers(getMaxPlayers());
definition.setMinPlayers(getMinPlayers());
List<Phase> phases = new ArrayList<>();
Phase phase = activePhase;
while (phase != null) {
phases.add(phase);
phase = phase.getNextPhase();
}
definition.setPhases(phases);
definition.setGameData(gameData);
return definition;
}
use of com.voxelgameslib.voxelgameslib.phase.Phase in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractGame method initGameFromDefinition.
@Override
public void initGameFromDefinition(@Nonnull GameDefinition gameDefinition) {
setMaxPlayers(gameDefinition.getMaxPlayers());
setMinPlayers(gameDefinition.getMinPlayers());
activePhase = gameDefinition.getPhases().get(0);
gameData = gameDefinition.getGameData();
// fix stuff
for (int i = 0; i < gameDefinition.getPhases().size(); i++) {
Phase nextPhase;
if (gameDefinition.getPhases().size() > i + 1) {
nextPhase = gameDefinition.getPhases().get(i + 1);
} else {
log.severe("Couldn't fix next phase for phase " + gameDefinition.getPhases().get(i).getName());
return;
}
Phase currPhase = gameDefinition.getPhases().get(i);
currPhase.setNextPhase(nextPhase);
currPhase.setGame(this);
for (Feature feature : currPhase.getFeatures()) {
feature.setPhase(currPhase);
}
for (Feature feature : currPhase.getFeatures()) {
feature.init();
}
}
}
use of com.voxelgameslib.voxelgameslib.phase.Phase in project VoxelGamesLibv2 by VoxelGamesLib.
the class GameTypeAdapter method deserialize.
@Override
@Nullable
public Phase deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context) throws JsonParseException {
try {
JsonObject jsonObject = json.getAsJsonObject();
// default path
String name = jsonObject.get("className").getAsString();
Class clazz = Class.forName(name);
Phase phase = context.deserialize(json, clazz);
injector.injectMembers(phase);
return phase;
} catch (Exception e) {
log.log(Level.WARNING, "Could not deserialize phase:\n" + json.toString(), e);
}
return null;
}
Aggregations