package com.codingame.game.modules;


import com.codingame.game.engine.Viewer;
import com.codingame.gameengine.core.AbstractPlayer;
import com.codingame.gameengine.core.GameManager;
import com.codingame.gameengine.core.Module;
import com.google.inject.Inject;
import com.google.inject.Singleton;


@Singleton
public class MyViewModule implements Module
{
    private GameManager<AbstractPlayer> gameManager;
    private String data="";
    public Viewer viewer;

    @Inject
    MyViewModule(GameManager<AbstractPlayer> gameManager)
    {
        this.gameManager = gameManager;
        gameManager.registerModule(this);
    }

    private String prepareInitGridInfo()
    {
        StringBuilder sb = new StringBuilder();


        return sb.toString();
    }

    /**
     * Called at the beginning of the game
     */
    @Override
    public void onGameInit()
    {
        gameManager.setViewGlobalData("MyViewModule", prepareInitGridInfo());
    }

    public void addData(String data)
    {
        this.data += data;
    }

    /**
     * Called at the end of every turn, after the Referee's gameTurn()
     */
    @Override
    public void onAfterGameTurn()
    {
        if (data.length()>0) gameManager.setViewData("MyViewModule", data);
        data = "";
    }

    /**
     * Called at the end of the game, after the Referee's onEnd()
     */
    @Override
    public void onAfterOnEnd()
    {
    }
}