package it.polimi.ingsw.gc14.Network.RMI.Client;

import it.polimi.ingsw.gc14.Controller.ClientController;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCallback {

    private final ClientController clientController;

    public ClientCallbackImpl(ClientController clientController) throws RemoteException {
        this.clientController = clientController;
    }

    @Override
    public void onGameInit(Game model) throws RemoteException {
        clientController.setModel(model);   // setta il model
    }

    @Override
    public void onAction(NetworkEvent event) throws RemoteException {
        if(event.getIsError()) {
            System.out.println(event.toString());
        } else {
            event.apply(clientController.localController);      // delega tutto al controller
            //clientController.view.update();           TODO
        }
    }
}
