Search in sources :

Example 1 with Phase

use of com.voxelgameslib.voxelgameslib.api.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;
}
Also used : Phase(com.voxelgameslib.voxelgameslib.api.phase.Phase) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) Nullable(javax.annotation.Nullable)

Example 2 with Phase

use of com.voxelgameslib.voxelgameslib.api.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;
}
Also used : Phase(com.voxelgameslib.voxelgameslib.api.phase.Phase) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 3 with Phase

use of com.voxelgameslib.voxelgameslib.api.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();
        }
    }
}
Also used : Phase(com.voxelgameslib.voxelgameslib.api.phase.Phase) Feature(com.voxelgameslib.voxelgameslib.api.feature.Feature) TeamFeature(com.voxelgameslib.voxelgameslib.api.feature.features.TeamFeature) DuelFeature(com.voxelgameslib.voxelgameslib.api.feature.features.DuelFeature)

Aggregations

Phase (com.voxelgameslib.voxelgameslib.api.phase.Phase)3 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 Feature (com.voxelgameslib.voxelgameslib.api.feature.Feature)1 DuelFeature (com.voxelgameslib.voxelgameslib.api.feature.features.DuelFeature)1 TeamFeature (com.voxelgameslib.voxelgameslib.api.feature.features.TeamFeature)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1