package eu.jonahbauer.wizard.client.libgdx.state;

import eu.jonahbauer.wizard.client.libgdx.Client;
import eu.jonahbauer.wizard.client.libgdx.screens.LoadingScreen;

import java.util.Optional;

public class AwaitingConnection extends Awaiting {
    
    @Override
    public Optional<ClientState> onEnter(Client client) {
        System.out.println("Awaiting connection...");
        client.getGame().setScreen(new LoadingScreen(client.getGame()));
        return super.onEnter(client);
    }
    
    @Override
    public Optional<ClientState> onOpen(Client client) {
        System.out.println("Connection established.");
        return Optional.of(new AwaitingJoinLobby());
    }
    
    @Override
    public Optional<ClientState> onClose(Client client, int code, String reason, boolean remote) {
        System.out.printf("Connection could not be established. (code=%d, reason=%s)%n", code, reason);
        return Optional.of(new Menu());
    }
}
