Exemple #1
0
    public void Load()
    {
        QuickSaveReader reader = QuickSaveReader.Create("GuardianIdleSave");
        Equipment       item;
        string          key;

        for (int i = 0; i < slots.Count; i++)
        {
            key = "equipSlot" + i;

            if (reader.Exists(key))
            {
                string JsonString = reader.Read <string>(key);
                item = JsonUtility.FromJson <Equipment>(JsonString);

                string icon = reader.Read <string>(key + "_icon");
                item.SetIcon(icon);

                slots[i].AddItem(item);
            }
            else
            {
                // Saved slot is empty, clear the slot to prevent duplication
                slots[i].Clear();
            }
        }
    }
    public void QuickSaveReaderExample()
    {
        // Use a QuickSaveReader to read content from a file saved with QuickSaveWriter

        // An exception will be thrown if the root doesn't exist

#pragma warning disable 0219
        string  one;
        double  two;
        Vector2 three;
        Color   four;
#pragma warning restore 0219

        QuickSaveReader.Create("RootName")
        .Read <string>("Key1", (r) => { one = r; })
        .Read <double>("Key2", (r) => { two = r; })
        .Read <Vector2>("Key3", (r) => { three = r; })
        .Read <Color>("Key4", (r) => { four = r; });

        // OR

        QuickSaveReader reader = QuickSaveReader.Create("RootName");
        one   = reader.Read <string>("Key1");
        two   = reader.Read <double>("Key2");
        three = reader.Read <Vector2>("Key3");
        four  = reader.Read <Color>("Key4");
    }
    // Start is called before the first frame update
    void Start()
    {
        gameController            = GameObject.Find("GameController");
        mapManager                = gameController.GetComponent <ManageMap>();
        tutorialManager           = gameController.GetComponent <TutorialManager>();
        uiControl                 = gameController.GetComponent <UIControl>();
        turnManager               = gameController.GetComponent <TurnManager>();
        resourceAndUpgradeManager = gameController.GetComponent <ResourceAndUpgradeManager>();
        abilityController         = GameObject.Find("Player").GetComponent <AbilityController>();

        if (QuickSaveRoot.Exists(resourceAndUpgradeManager.ResourceAndUpgradeDataSaveFileName))                                //use the quicksave feature to check if a save file exists
        {
            QuickSaveReader instReader = QuickSaveReader.Create(resourceAndUpgradeManager.ResourceAndUpgradeDataSaveFileName); //create an instance of the quick save reader to pull in the save file
            MaxPlayerHealth  = instReader.Read <int>("currentMaxHealth");
            maxPlayerShields = instReader.Read <int>("currentMaxShields");
            uiControl.SetHealthState(maxPlayerHealth, currentPlayerHealth, maxPlayerShields, currentPlayerShields);
        }
        else
        {
            MaxPlayerHealth      = resourceAndUpgradeManager.CurrentMaxHealth;
            maxPlayerShields     = resourceAndUpgradeManager.CurrentMaxShields;
            currentPlayerHealth  = maxPlayerHealth;
            currentPlayerShields = maxPlayerShields;
            uiControl.SetHealthState(maxPlayerHealth, currentPlayerHealth, maxPlayerShields, currentPlayerShields);
        }

        movementController = gameObject.GetComponent <MovementController>();
    }
Exemple #4
0
        public static void LoadFileSettings()
        {
            if (selectedFile == "")
            {
                return;
            }

            QuickSaveReader reader = QuickSaveReader.Create(selectedFile);

            GameInfo.mapSeed    = reader.Read <int>(GameInfo.MAP_SEED);
            GameInfo.mapSize    = reader.Read <int>(GameInfo.MAP_SIZE);
            GameInfo.playerTeam = reader.Read <int>("playerTeam");
        }
Exemple #5
0
 public void LoadHighScores()
 {
     if (QuickSaveRoot.Exists("HighScoreFile"))                                //if a save file exists, load data from that file
     {
         QuickSaveReader instReader = QuickSaveReader.Create("HighScoreFile"); //create an instance of the quick save reader to pull in the save file
         highScoreObjectList = instReader.Read <List <HighScoreObject> >("HighScoreObjectList");
     }
 }
Exemple #6
0
    public void Load()
    {
        QuickSaveReader reader = QuickSaveReader.Create("GuardianIdleSave");

        if (reader.Exists("itemIdCounter"))
        {
            idCounter = reader.Read <int>("itemIdCounter");
        }
        else
        {
            idCounter = 0;
        }
    }
Exemple #7
0
    public void Load()
    {
        QuickSaveReader reader = QuickSaveReader.Create("GuardianIdleSave");
        Item            item;
        string          key;

        for (int i = 0; i < slots.Count; i++)
        {
            key = "invslot" + i;

            if (reader.Exists(key))
            {
                string JsonString = reader.Read <string>(key);
                string type       = reader.Read <string>(key + "_type");

                if (type == "equipment")
                {
                    item = JsonUtility.FromJson <Equipment>(JsonString);
                }
                else
                {
                    item = JsonUtility.FromJson <Item>(JsonString);
                }

                string icon = reader.Read <string>(key + "_icon");
                item.SetIcon(icon);

                Debug.Log("adding item to slot: " + i);
                slots[i].AddItem(item);
            }
            else
            {
                // Saved slot is empty, clear the slot to prevent duplication
                Debug.Log("clearing slot: " + i);
                slots[i].Clear();
            }
        }
    }
Exemple #8
0
    public void Awake()
    {
        continueButton = GameObject.Find("ContinueButton");
        musicSource    = GameObject.Find("Music").GetComponent <AudioSource>();
        musicVolume    = musicSource.volume;

        if (QuickSaveRoot.Exists(mapSaveName) || QuickSaveRoot.Exists(resourcesSaveName))
        {
            continueButton.SetActive(true);
        }
        else
        {
            continueButton.SetActive(false);
        }
        if (QuickSaveRoot.Exists("HighScoreFile"))                                //if a save file exists, load data from that file
        {
            QuickSaveReader instReader = QuickSaveReader.Create("HighScoreFile"); //create an instance of the quick save reader to pull in the save file
            highScoreObjectList = instReader.Read <List <HighScoreObject> >("HighScoreObjectList");
            highScorePanel.SetActive(true);
            allChildren = GameObject.Find("HighScoreVerticalLayoutGroup2").GetComponentsInChildren <TMP_Text>();
            int i = 0;
            foreach (TMP_Text child in allChildren)
            {
                if (i > 0)
                {
                    child.text = highScoreObjectList[i - 1].scoreString;
                }
                i++;
            }
            i           = 0;
            allChildren = GameObject.Find("HighScoreVerticalLayoutGroup3").GetComponentsInChildren <TMP_Text>();
            foreach (TMP_Text child in allChildren)
            {
                if (i > 0)
                {
                    child.text = highScoreObjectList[i - 1].scoreValue.ToString();
                }
                i++;
            }
            highScorePanel.SetActive(false);
        }
    }
Exemple #9
0
    public static Dictionary <string, float> LoadPriceMultipliers(QuickSaveReader reader = null)
    {
        reader ??= QSReader.Create("Market");
        var priceMultipliers = new Dictionary <string, float>();

        if (reader.Exists("Multipliers"))
        {
            priceMultipliers = reader.Read <Dictionary <string, float> >("Multipliers");
        }
        else
        {
            foreach (var seedName in SeedTypesInInventory)
            {
                if (!priceMultipliers.ContainsKey(seedName))
                {
                    priceMultipliers[seedName] = 1.0f;
                }
            }
        }
        return(priceMultipliers);
    }
Exemple #10
0
        public static void RestoreGame()
        {
            QuickSaveReader saveReader = QuickSaveReader.Create(LoadSaveScript.selectedFile);

            int indexCount = saveReader.Read <int>("indexCount");

            for (int index = 0; index < indexCount; index++)
            {
                BaseBehavior.Load(ref saveReader, index);
            }

            foreach (GameObject unitObject in GameObject.FindGameObjectsWithTag("Building").Concat(GameObject.FindGameObjectsWithTag("Unit")))
            {
                BaseBehavior unitBaseBehavior = unitObject.GetComponent <BaseBehavior>();
                unitBaseBehavior.RestoreBehavior();
            }

            Vector3    cameraPosition = saveReader.Read <Vector3>("cameraPosition");
            Quaternion cameraRotation = saveReader.Read <Quaternion>("cameraRotation");

            Camera.main.transform.position = cameraPosition;
            Camera.main.transform.rotation = cameraRotation;

            CameraController cameraController = Camera.main.GetComponent <CameraController>();

            cameraController.resources[BaseBehavior.ResourceType.Gold]  = saveReader.Read <float>("gold");
            cameraController.resources[BaseBehavior.ResourceType.Wood]  = saveReader.Read <float>("wood");
            cameraController.resources[BaseBehavior.ResourceType.Food]  = saveReader.Read <float>("food");
            cameraController.resources[BaseBehavior.ResourceType.Favor] = saveReader.Read <float>("favor");

            // Blind texture
            TerrainGenerator terrainGenerator = Terrain.activeTerrain.GetComponent <TerrainGenerator>();

            Color[] colors    = terrainGenerator.blindTexture2D.GetPixels();
            int[]   blindInfo = saveReader.Read <int[]>("blindTextureData");
            Color   newColor  = Color.white;

            newColor.a = 0;
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = blindInfo[i] == 1 ? Color.black : newColor;
            }
            terrainGenerator.blindTexture2D.SetPixels(colors);
            terrainGenerator.blindTexture2D.Apply();
            Graphics.Blit(terrainGenerator.blindTexture2D, terrainGenerator.blindTexture);
            terrainGenerator.initBlindTexture = true;

            try
            {
                // Binds
                for (int number = 1; number <= 9; number++)
                {
                    int[] binds = saveReader.Read <int[]>(new StringBuilder(15).AppendFormat("{0}_{1}", number, "bind").ToString());
                    int   i     = 0;
                    foreach (int bindObjectUniueId in binds)
                    {
                        cameraController.unitsBinds[KeyCode.Alpha0 + number].Add(BaseBehavior.GetObjectByUniqueId(bindObjectUniueId));
                        i++;
                    }
                }
            }
            catch (Exception e)
            { }

            selectedFile = "";
        }
Exemple #11
0
    private void LoadResourceAndUpgradeData()
    {
        if (QuickSaveRoot.Exists(resourceAndUpgradeDataSaveFileName))                                //if a save file exists, load data from that file
        {
            QuickSaveReader instReader = QuickSaveReader.Create(resourceAndUpgradeDataSaveFileName); //create an instance of the quick save reader to pull in the save file

            resources                     = instReader.Read <int>("resources");
            TotalResources                = instReader.Read <int>("totalResources");
            SolarSystemNumber             = instReader.Read <int>("solarSystemNumber");
            currentMaxLaserRange          = instReader.Read <int>("currentMaxLaserRange");
            currentMaxLaserRecharge       = instReader.Read <int>("currentMaxLaserRecharge");
            currentMaxRocketRange         = instReader.Read <int>("currentMaxRocketRange");
            currentMaxRocketReload        = instReader.Read <int>("currentMaxRocketReload");
            currentMaxRocketYield         = instReader.Read <int>("currentMaxRocketYield");
            currentMaxJumpRange           = instReader.Read <int>("currentMaxJumpRange");
            currentMaxJumpRecharge        = instReader.Read <int>("currentMaxJumpRecharge");
            currentMaxShieldBoost         = instReader.Read <int>("currentMaxShieldBoost");
            currentShieldOverboostActive  = instReader.Read <bool>("currentShieldOverboostActive");
            currentMaxShieldBoostRecharge = instReader.Read <int>("currentMaxShieldBoostRecharge");
            currentMaxHealth              = instReader.Read <int>("currentMaxHealth");
            currentMaxShields             = instReader.Read <int>("currentMaxShields");
            currentMaxSensorRange         = instReader.Read <int>("currentMaxSensorRange");

            rocketsInstalled     = instReader.Read <bool>("rocketsInstalled");
            jumpDriveInstalled   = instReader.Read <bool>("jumpDriveInstalled");
            shieldBoostInstalled = instReader.Read <bool>("shieldBoostInstalled");

            abilityController.maxLaserRange           = currentMaxLaserRange;
            abilityController.rocketRange             = currentMaxRocketRange;
            abilityController.rocketReloadTime        = currentMaxRocketReload;
            abilityController.maxJumpRange            = currentMaxJumpRange;
            abilityController.shieldBoostRechargeTime = CurrentMaxShieldBoostRecharge;
            movementController.Vision = CurrentMaxSensorRange;
            mapManager.UpdateFogOfWar(CurrentMaxSensorRange, gridlayout.WorldToCell(player.transform.position));

            playerHealthControl.currentPlayerHealth  = instReader.Read <int>("currentHealth");
            playerHealthControl.currentPlayerShields = instReader.Read <int>("currentShields");
            abilityController.jumpRange  = instReader.Read <int>("currentJumpCharge");
            abilityController.laserRange = instReader.Read <int>("currentLaserCharge");
            //Debug.Log("Laser range loaded as " + abilityController.laserRange);
            abilityController.currentShieldBoostCharge  = instReader.Read <int>("currentShieldBoostCharge");
            abilityController.currentRocketReloadAmount = instReader.Read <int>("currentRocketReload");

            laserRangeUpgradeCost          = instReader.Read <int>("laserRangeUpgradeCost");
            laserRechargeUpgradeCost       = instReader.Read <int>("laserRechargeUpgradeCost");
            rocketRangeUpgradeCost         = instReader.Read <int>("rocketRangeUpgradeCost");
            rocketReloadUpgradeCost        = instReader.Read <int>("rocketReloadUpgradeCost");
            rocketYieldUpgradeCost         = instReader.Read <int>("rocketYieldUpgradeCost");
            jumpRangeUpgradeCost           = instReader.Read <int>("jumpRangeUpgradeCost");
            jumpRechargeUpgradeCost        = instReader.Read <int>("jumpRechargeUpgradeCost");
            shieldBoostUpgradeCost         = instReader.Read <int>("shieldBoostUpgradeCost");
            shieldOverboostUpgradeCost     = instReader.Read <int>("shieldOverboostUpgradeCost");
            shieldBoostRechargeUpgradeCost = instReader.Read <int>("shieldBoostRechargeUpgradeCost");
            shieldMaxUpgradeCost           = instReader.Read <int>("shieldMaxUpgradeCost");
            healthMaxUpgradeCost           = instReader.Read <int>("healthMaxUpgradeCost");
            sensorRangeUpgradeCost         = instReader.Read <int>("sensorRangeUpgradeCost");

            threatLevel           = instReader.Read <float>("threatLevel");
            MaxThreatLevelCounter = instReader.Read <int>("maxThreatLevelCounter");

            uiController.SetHealthState(CurrentMaxHealth, playerHealthControl.currentPlayerHealth, CurrentMaxShields, playerHealthControl.currentPlayerShields);
            uiController.SetLaserCharge(abilityController.laserRange, currentMaxLaserRange);
            uiController.SetJumpCharge(abilityController.jumpRange, CurrentMaxJumpRange);
            uiController.SetShieldBoostRechargeState(abilityController.currentShieldBoostCharge, CurrentMaxShieldBoostRecharge);
            uiController.SetRocketReloadState(abilityController.currentRocketReloadAmount, CurrentMaxRocketReload);
            uiController.SetResourceCount(resources);
            uiController.SetUpgradeButtons();
            uiController.SetThreatLevelSlider(ThreatLevel);

            Debug.Log("Tried to load resources and upgrades");
        }
    }