Пример #1
0
        internal static BlockDefinition[] Load(bool global, Level lvl)
        {
            BlockDefinition[] defs = null;
            string            path = global ? GlobalPath : "blockdefs/lvl_" + lvl.MapName + ".json";

            try {
                if (File.Exists(path))
                {
                    string json = File.ReadAllText(path);
                    defs = JsonConvert.DeserializeObject <BlockDefinition[]>(json);
                }
            } catch (Exception ex) {
                Logger.LogError(ex);
            }
            if (defs == null)
            {
                defs = new BlockDefinition[Block.Count];
            }

            // File was probably manually modified - fix it up
            if (defs.Length < Block.Count)
            {
                Logger.Log(LogType.Warning, "Expected " + Block.Count + " blocks in " + path + ", but only had " + defs.Length);
                Array.Resize(ref defs, Block.Count);
            }

            for (int i = 0; i < Block.Count; i++)
            {
                if (defs[i] != null && defs[i].Name == null)
                {
                    defs[i] = null;
                }
            }

            for (int i = 0; i < Block.Count; i++)
            {
                BlockDefinition def = defs[i];
                if (def == null)
                {
                    continue;
                }

                if (!def.Version2)
                {
                    def.Version2 = true;
                    def.SetSideTex(def.SideTex);
                }
            }
            return(defs);
        }