コード例 #1
0
            public static Level Read(string line)
            {
                var parts         = line.Split(' ');
                int loadedVersion = int.Parse(parts[0]);

                if (Version != loadedVersion)
                {
                    if (loadedVersion >= LowestSupportedVersion)
                    {
                        Debug.Log(string.Format(
                                      "Current save version is {0}, but {1} found. Will be upgraded.", Version, loadedVersion));
                    }
                    else
                    {
                        Debug.LogError(string.Format("Expected version {0} but {1} found", Version, loadedVersion));
                        return(null);
                    }
                }

                string levelName = In(parts[1]);
                var    level     = new Level(levelName);

                // load properties
                for (int i = 2; i < parts.Length; i += 2)
                {
                    string        key = In(parts[i]);
                    PropertyValue value;

                    if (loadedVersion == 1)
                    {
                        bool val = bool.Parse(In(parts[i + 1]));
                        value = PropertyValue.FromBoolean(val);
                    }
                    else
                    {
                        value = PropertyValue.Read(parts[i + 1]);
                    }

                    // in versions 1 and 2 level select screen was saving 'locked' property
                    // with the wrong key
                    if (loadedVersion <= 2 && key == "locked")
                    {
                        key = PropertyLocked;
                        if (!level.properties.ContainsKey(key))
                        {
                            level.properties.Add(key, value);
                        }
                    }
                    else
                    {
                        level.properties.Add(key, value);
                    }
                }

                return(level);
            }
コード例 #2
0
            public bool SetPropertyBoolean(string key, bool val)
            {
                var prop = PropertyValue.FromBoolean(val);

                if (properties.ContainsKey(key) && properties[key].Equals(prop))
                {
                    return(false);
                }

                properties[key] = prop;
                return(true);
            }