Esempio n. 1
0
        private static SchematicMetadata GenerateMetaData(string metadataPath, string name, Schematic schematic)
        {
            var metadata = new SchematicMetadata();

            metadata.Name = name;

            for (int Y = 0; Y <= schematic.YMax; Y++)
            {
                for (int Z = 0; Z <= schematic.ZMax; Z++)
                {
                    for (int X = 0; X <= schematic.XMax; X++)
                    {
                        if (schematic.Blocks.GetLength(0) > X &&
                            schematic.Blocks.GetLength(1) > Y &&
                            schematic.Blocks.GetLength(2) > Z &&
                            schematic.Blocks[X, Y, Z] != null)
                        {
                            var block = schematic.Blocks[X, Y, Z].MappedBlock;

                            if (block.CSIndex != ColonyBuiltIn.ItemTypes.AIR.Id)
                            {
                                var buildType = ItemTypes.GetType(block.CSIndex);

                                if (!buildType.Name.Contains("bedend"))
                                {
                                    var index = block.CSIndex;

                                    if (!string.IsNullOrWhiteSpace(buildType.ParentType) && !buildType.Name.Contains("grass") && !buildType.Name.Contains("leaves"))
                                    {
                                        index = ItemTypes.GetType(buildType.ParentType).ItemIndex;
                                    }

                                    if (metadata.Blocks.TryGetValue(index, out var blockMeta))
                                    {
                                        blockMeta.Count++;
                                    }
                                    else
                                    {
                                        blockMeta = new SchematicBlockMetadata();
                                        blockMeta.Count++;
                                        blockMeta.ItemId = index;

                                        metadata.Blocks.Add(blockMeta.ItemId, blockMeta);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            metadata.MaxX = schematic.XMax;
            metadata.MaxY = schematic.YMax;
            metadata.MaxZ = schematic.ZMax;

            JSON.Serialize(metadataPath, metadata.JsonSerialize());

            return(metadata);
        }
Esempio n. 2
0
        public static bool TryGetSchematicMetadata(string name, int colonyId, out SchematicMetadata metadata)
        {
            try
            {
                if (TryGetScematicMetadataFilePath(name + METADATA_FILEEXT, out string savePath))
                {
                    var json = JSON.Deserialize(savePath);
                    metadata = JsonConvert.DeserializeObject <SchematicMetadata>(json.ToString());
                }
                else
                {
                    metadata = GenerateMetaData(name, colonyId);
                }
            }
            catch (Exception ex)
            {
                metadata = null;
                SettlersLogger.LogError(ex, "error getting metadata for schematic {0}", name);
            }

            return(metadata != null);
        }