All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codingame.gameengine.module.viewport.ViewportModule Maven / Gradle / Ivy

The newest version!
package com.codingame.gameengine.module.viewport;

import java.util.HashSet;
import java.util.Set;

import com.codingame.gameengine.core.AbstractPlayer;
import com.codingame.gameengine.core.GameManager;
import com.codingame.gameengine.core.Module;
import com.codingame.gameengine.module.entities.GraphicEntityModule;
import com.codingame.gameengine.module.entities.Group;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * The ViewportModule allows you to create a zoomable/draggable container.
 * 
 * @see pixi-viewport
 * 
 */
@Singleton
public class ViewportModule implements Module {

    GameManager gameManager;
    @Inject GraphicEntityModule entityModule;
    Set registered = new HashSet<>();
    Set newEntityIds = new HashSet<>();

    @Inject
    ViewportModule(GameManager gameManager) {
        this.gameManager = gameManager;
        gameManager.registerModule(this);
    }

    @Override
    public void onGameInit() {
        sendFrameData();
    }

    @Override
    public void onAfterGameTurn() {
        sendFrameData();
    }

    @Override
    public void onAfterOnEnd() {
    }

    private void sendFrameData() {
        gameManager.setViewData("viewport", newEntityIds);

        newEntityIds.clear();
    }

    /**
     * Wraps the given Group in a Viewport.
     * 
     * @param group
     *            A group to wrap into a Viewport
     */
    public void createViewport(Group group) {
        int entityId = group.getId();
        if (!registered.contains(entityId)) {
            newEntityIds.add(entityId);
            registered.add(entityId);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy