Example #1
0
        public static void Load()
        {
            //get saved text from file with key, default null if no file exists
            string text = SaveLoad.LoadText(SAVE_KEY);

            if (text == null)
            {
                return;
            }

            //split text up into lines
            string[] lines = text.Split('\n');

            //iterate over lines
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                //split line up into separate strings
                string[] entry = line.Split('|');
                //ignore line if not correct format
                if (entry.Length != 3)
                {
                    continue;
                }

                //get information about the data entry
                string parameterName     = entry[0].ToLower();
                string parameterTypeName = entry[1];
                Type   parameterType     = Type.GetType(parameterTypeName);
                string valueString       = entry[2];

                //check and make sure a parameter with that name exists
                StatTracker stat = GetTracker(parameterName);
                if (stat == null)
                {
                    SteamPunkConsole.WriteLine($"Error on line {i + 1} \"{line}\": no parameter with name \"{parameterName}\" found.");
                    continue;
                }

                //check and make sure field type matches given type
                if (stat.FieldType != parameterType)
                {
                    SteamPunkConsole.WriteLine($"Error on line {i + 1} \"{line}\": parameter type \"{parameterTypeName}\" does not match the expected type \"{stat.FieldType}\".");
                    continue;
                }

                //set value of matching field
                bool parsedSuccessfully = stat.SetValue(valueString);

                if (!parsedSuccessfully)
                {
                    SteamPunkConsole.WriteLine($"Error on line {i + 1} \"{line}\": value \"{valueString}\" could not be parsed as a \"{parameterType}\".");
                    continue;
                }
            }

            SteamPunkConsole.WriteLine("Load Successful");
        }
Example #2
0
        public static void SetStat(string statName, string value)
        {
            StatTracker stat = GetTracker(statName);

            if (stat == null)
            {
                return;
            }
            bool successful = stat.SetValue(value);

            if (successful)
            {
                SteamPunkConsole.WriteLine($"{stat.name} set to {value}.");
            }
        }