예제 #1
0
    private void LoadPlayer()
    {
        if (initialiationState != InitialiationState.Authenticated)
        {
            Debug.LogWarning("Trying to load player when not authenticated.");
            return;
        }
        initialiationState = InitialiationState.Loading;

        Debug.Log("Loading buildings");
        gameSparksManager.GetPlayerBuildings((LogEventResponse response) => {
            if (response.HasErrors)
            {
                // handle bla
            }
            else
            {
                foreach (GSData buildingGSData in response.ScriptData.GetGSDataList("player_buildings"))
                {
                    // GSData buildingGSData = buildingWrapperGSData.GetGSData("building");
                    Building buildingData = (Building)GSDataHelpers.GSDataToObject(buildingGSData);
                    gameData.AddBuilding(buildingData);
                    BuildingBehavior newBuilding = Instantiate <BuildingBehavior>(farmPrefab);
                    newBuilding.SetPlaced(true);

                    newBuilding.transform.position = new Vector2(buildingData.position.x, buildingData.position.y);
                    dataGameObjectsMap.Add(buildingData, newBuilding.gameObject);
                }
            }
        });

        Debug.Log("Loading player");
    }
예제 #2
0
    private void InitUser()
    {
        gsAvailable = GS.Available;
        if (GS.Available)
        {
            Debug.Log("GS Available");
            initialiationState = InitialiationState.Available;
        }
        else
        {
            Debug.Log("GS Unavailable");
        }

        if (GS.Available && initialiationState == InitialiationState.Available)
        {
            initialiationState = InitialiationState.Authenticating;
            gsAuthenticated    = GS.Authenticated;
            if (GS.Authenticated)
            {
                initialiationState = InitialiationState.Authenticated;
                Debug.Log("Authenticated");
                LoadPlayer();
            }
            else
            {
                Debug.Log("Not authenticated");
                if (PlayerPrefs.GetInt("login_type") == (int)LoginType.UsernamePassword)
                {
                    // The user should be logged in with a real account, but isn't. should show an error and prompt to login here.
                    Debug.LogWarning("User should be logged in with user/pass, but isn't authenticated.");
                    initialiationState = InitialiationState.AuthError;
                }
                else
                {
                    gameSparksManager.AuthenticateAnonymous((response) => {
                        if (response.HasErrors)
                        {
                            // TODO: Error screen or something.
                            Debug.Log("Error logging in anonymously");
                            initialiationState = InitialiationState.AuthError;
                        }
                        else
                        {
                            // MMMk we're logged in kinda.
                            initialiationState = InitialiationState.Authenticated;
                            LoadPlayer();
                        }
                    });
                }
            }

            // GS.GameSparksAvailable -= GSAvailableHandler;
        }
    }
예제 #3
0
    // private void GSAuthenticatedHandler(string thing) {

    //  Debug.Log("auth changed: "+ thing);
    //  // gsAuthenticated = authenticated;
    //  // if (GS.Authenticated) {
    //  //  Debug.Log("Authenticated");

    //  // } else {
    //  //  Debug.Log("Not authenticated");

    //  // }
    // }

    // private void InitializeGame() {
    //  if (initialiationState != InitialiationState.NotInitialized) {
    //      return;
    //  }
    //  // initialiationState = InitialiationState.Initializing;



    // }

    public void Login(string username, string password, Action <bool, string> callback)
    {
        // TODO: Clear out old player data and GS.

        gameSparksManager.Authenticate(username, password, (response) => {
            if (response.HasErrors)
            {
                callback(false, "Wrong username or password.");
            }
            else
            {
                initialiationState = InitialiationState.Authenticated;
                LoadPlayer();
                callback(true, "");
                uiManager.SetLoggedInAnonymously(false);
                // uiManager
            }
        });
    }