Exemple #1
0
    public static ClientState State(this PriselClient priselClient)
    {
        ClientState state = priselClient.GetState <ClientState>() ?? new ClientState();

        priselClient.SetState(state);
        return(state);
    }
Exemple #2
0
    private async Task Connect()
    {
        PriselClient client = PriselClient.Instance;

        client.ServerUrl = "ws://localhost:3000";
        await client.Connect();

        client.SetState(new ClientState());
    }
Exemple #3
0
 // Update is called once per frame
 private static void AttemptDisconnect(PlayModeStateChange state)
 {
     if (state == PlayModeStateChange.ExitingPlayMode)
     {
         PriselClient client = PriselClient.Instance;
         if (client.IsConnected)
         {
             Debug.Log("exiting play mode, force closing socket");
             _ = client.Close();
         }
     }
 }
Exemple #4
0
    public static async Task AttemptConnect()
    {
        PriselClient client = PriselClient.Instance;

        if (!client.IsConnected)
        {
            client.ServerUrl = "ws://localhost:3000";
            await client.Connect();

            client.SetState(new ClientState());
            Debug.Log("Connected!!!");
        }
    }
Exemple #5
0
    // Start is called before the first frame update
    void Start()
    {
        Client = PriselClient.Instance;
        var clientState = Client.State();

        if (!Client.IsConnected)
        {
            NextState = new LoginState();
        }
        else if (String.IsNullOrEmpty(clientState.UserId))
        {
            NextState = new LoginState();
        }
        else if (String.IsNullOrEmpty(clientState.RoomId))
        {
            NextState = new JoinModeState();
        }
    }
Exemple #6
0
    public static async Task AttemptStartGame()
    {
        await AttemptCreateRoom();

        PriselClient client      = PriselClient.Instance;
        var          clientState = client.State();

        if (!clientState.GameStarted)
        {
            var response = await client.StartGame();

            if (response.IsStatusOk())
            {
                client.State().GameStarted = true;
                Debug.Log("Successfully started game");
            }
            else
            {
                Debug.Log($"start game failed because {response.StatusMessage()}");
            }
        }
    }
Exemple #7
0
    public static async Task AttemptCreateRoom()
    {
        await AttemptLogin();

        PriselClient client      = PriselClient.Instance;
        var          clientState = client.State();

        if (String.IsNullOrEmpty(clientState.RoomId))
        {
            var response = await client.CreateRoom("room");

            if (response.IsStatusOk())
            {
                clientState.RoomName = response.Payload.CreateRoomResponse.Room.Name;
                clientState.RoomId   = response.Payload.CreateRoomResponse.Room.Id;
                Debug.Log($"Successfully create room with room name {clientState.RoomName}, roomId {clientState.RoomId}");
            }
            else
            {
                Debug.Log($"create room failed because {response.StatusMessage()}");
            }
        }
    }
Exemple #8
0
    public static async Task AttemptLogin()
    {
        await AttemptConnect();

        PriselClient client = PriselClient.Instance;

        var clientState = client.State();

        if (String.IsNullOrEmpty(clientState.UserId))
        {
            var response = await client.Login(USERNAME);

            if (response.IsStatusOk())
            {
                clientState.UserId   = response.Payload.LoginResponse.UserId;
                clientState.Username = USERNAME;
                Debug.Log($"Successfully login with username {clientState.Username}, userId {clientState.UserId}");
            }
            else
            {
                Debug.Log($"login failed because {response.StatusMessage()}");
            }
        }
    }
Exemple #9
0
 public static void ClearState(this PriselClient priselClient)
 {
     priselClient.SetState(new ClientState());
 }