Exemple #1
0
    public static void SaveSeenShardData(ReisenGameProgress gameProgress)
    {
        List <Shard>  totalSeenShardData;
        ShardSaveData totalData = FetchSeenShardData();

        if (totalData != null)
        {
            totalSeenShardData = totalData.shardData;
        }
        else
        {
            totalSeenShardData = new List <Shard>();
        }

        foreach (Shard s in gameProgress.Player.ShardsAcquired)
        {
            if (!totalSeenShardData.Any(x => x.Id == s.Id))
            {
                totalSeenShardData.Add(s);
            }
        }

        ShardSaveData data = new ShardSaveData(totalSeenShardData);

        // 2
        string jsonSavePath = string.Format("{0}/{1}.json", Application.persistentDataPath, shardSaveDataName);

        Debug.Log(jsonSavePath);
        string jsonData = JsonUtility.ToJson(data, true);

        File.WriteAllText(jsonSavePath, jsonData);

        Debug.Log("Shard data Saved");
    }
Exemple #2
0
    public static ShardSaveData FetchSeenShardData()
    {
        // 1
        string jsonSavePath = string.Format("{0}/{1}.json", Application.persistentDataPath, shardSaveDataName);

        if (File.Exists(jsonSavePath))
        {
            Debug.Log("Attempting to load at " + jsonSavePath);
            ShardSaveData shardSave = JsonUtility.FromJson <ShardSaveData>(File.ReadAllText(jsonSavePath));
            Debug.Log("Shard data fetched");
            return(shardSave);
        }
        else
        {
            return(null);
        }
    }
    public void InitializeTitleMenu()
    {
        group.menuElements.Clear();

        bool hasSaveData = false;
        foreach (string saveName in SaveManager.saveNames)
        {
            GGJReisenSave saveData = SaveManager.FetchSaveData(saveName);
            hasSaveData |= saveData != null;
        }

        bool hasShardData = false;
        ShardSaveData shardData = SaveManager.FetchSeenShardData();
        hasShardData = hasShardData || (shardData != null);

        newGameElement.gameObject.SetActive(true);
        optionsElement.gameObject.SetActive(true);
        galleryElement.gameObject.SetActive(true);
        continueGameElement.gameObject.SetActive(hasSaveData);


        viewShardsElement.gameObject.SetActive(hasShardData);
        clearShardDataElement.gameObject.SetActive(hasShardData);

        int activeMenuElement = 0;
        if (hasSaveData)
        {
            AddMenuElement(continueGameElement, activeMenuElement);
            activeMenuElement++;
            UnityEngine.EventSystems.EventSystem.current.firstSelectedGameObject = continueGameElement.gameObject;
        }
        AddMenuElement(newGameElement, activeMenuElement);
        activeMenuElement++;

        if (hasShardData)
        {
            AddMenuElement(viewShardsElement, activeMenuElement);
            activeMenuElement++;
            AddMenuElement(clearShardDataElement, activeMenuElement);
            activeMenuElement++;
        }
        AddMenuElement(optionsElement, activeMenuElement);
        activeMenuElement++;

        AddMenuElement(galleryElement, activeMenuElement);
        activeMenuElement++;

        //setting navigation
        if (!hasSaveData || !hasShardData)
        {
            Navigation newGameNav = new Navigation();
            newGameNav.mode = Navigation.Mode.Explicit;
            Navigation optionsNav = new Navigation();
            optionsNav.mode = Navigation.Mode.Explicit;
            Navigation galleryNav = new Navigation();
            galleryNav.mode = Navigation.Mode.Explicit;

            if (!hasSaveData)
            {
                newGameNav.selectOnUp = galleryElement.GetComponent<Button>();
                optionsNav.selectOnDown = galleryElement.GetComponent<Button>();
                galleryNav.selectOnDown = newGameElement.GetComponent<Button>();
            }
            else
            {
                newGameNav.selectOnUp = continueGameElement.GetComponent<Button>();
                optionsNav.selectOnDown = galleryElement.GetComponent<Button>();
                galleryNav.selectOnDown = continueGameElement.GetComponent<Button>();
            }

            if (!hasShardData)
            {
                newGameNav.selectOnDown = optionsElement.GetComponent<Button>();
                optionsNav.selectOnUp = newGameElement.GetComponent<Button>();
                galleryNav.selectOnUp = optionsElement.GetComponent<Button>();
            }
            else
            {
                newGameNav.selectOnDown = viewShardsElement.GetComponent<Button>();
                optionsNav.selectOnUp = clearShardDataElement.GetComponent<Button>();
                galleryNav.selectOnUp = optionsElement.GetComponent<Button>();
            }

            newGameElement.GetComponent<Button>().navigation = newGameNav;
            optionsElement.GetComponent<Button>().navigation = optionsNav;
            galleryElement.GetComponent<Button>().navigation = galleryNav;
        }

        //dumb hacks we don't really care about groups anymore lol
        //group.menuElements.Clear();
        //group.FocusElement(group.currentMenuElementIndex);
    }