Пример #1
0
        /// <summary>
        /// Retrieve the amount of components to build the block to the given index
        /// </summary>
        /// <param name="block"></param>
        /// <param name="componentList"></param>
        /// <param name="level">integrity level </param>
        public static void GetMissingComponents(this IMySlimBlock block, Dictionary <string, int> componentList, IntegrityLevel level)
        {
            var blockDefinition = block.BlockDefinition as MyCubeBlockDefinition;

            if (blockDefinition.Components == null || blockDefinition.Components.Length == 0)
            {
                return;
            }

            if (level == IntegrityLevel.Create)
            {
                var component = blockDefinition.Components[0];
                componentList.Add(component.Definition.Id.SubtypeName, 1);
            }
            else
            {
                if (block.IsProjected())
                {
                    int maxIdx = level == IntegrityLevel.Functional ? blockDefinition.CriticalGroup + 1 : blockDefinition.Components.Length;
                    for (var idx = 0; idx < maxIdx; idx++)
                    {
                        var component = blockDefinition.Components[idx];
                        if (componentList.ContainsKey(component.Definition.Id.SubtypeName))
                        {
                            componentList[component.Definition.Id.SubtypeName] += component.Count;
                        }
                        else
                        {
                            componentList.Add(component.Definition.Id.SubtypeName, component.Count);
                        }
                    }
                }
                else
                {
                    block.GetMissingComponents(componentList);
                    if (level == IntegrityLevel.Functional)
                    {
                        for (var idx = blockDefinition.CriticalGroup + 1; idx < blockDefinition.Components.Length; idx++)
                        {
                            var component = blockDefinition.Components[idx];
                            if (componentList.ContainsKey(component.Definition.Id.SubtypeName))
                            {
                                var amount = componentList[component.Definition.Id.SubtypeName];
                                if (amount <= component.Count)
                                {
                                    componentList.Remove(component.Definition.Id.SubtypeName);
                                }
                                else
                                {
                                    componentList[component.Definition.Id.SubtypeName] -= component.Count;
                                }
                            }
                        }
                    }
                }
            }
        }