void GetBlockRequestSettings(IMyTerminalBlock block)
        {
            InventoryRequests[block] = new Dictionary <MyItemType, int>();

            if (iniParser.TryParse(block.CustomData) && iniParser.ContainsSection(kInventoryRequestSection))
            {
                iniParser.GetKeys(iniKeyScratchpad);
                foreach (var key in iniKeyScratchpad)
                {
                    if (key.Section != kInventoryRequestSection)
                    {
                        continue;
                    }
                    var count = iniParser.Get(key).ToInt32();
                    if (count == 0)
                    {
                        continue;
                    }
                    var type = MyItemType.Parse(key.Name);

                    var inventory = block.GetInventory(block.InventoryCount - 1);
                    itemTypeScratchpad.Clear();
                    inventory.GetAcceptedItems(itemTypeScratchpad);
                    if (!itemTypeScratchpad.Contains(type))
                    {
                        continue;
                    }

                    InventoryRequests[block][type] = count;
                }
            }
        }
Esempio n. 2
0
 public VISItemType(string type)
 {
     try
     {
         Type  = MyItemType.Parse(type);
         Valid = true;
     }
     catch (Exception)
     {
         Valid = false;
         Type  = EmptyType;
     }
 }
//         void BuildDictionaryFromCustomData<TKey,TValue>(ExecutionContext context, IMyTerminalBlock block, string section, Func<string, TKey> funcKeyParse, Func<MyIniValue, TValue> funcValueParse, Action<TKey,TValue> funcWrite) // Dictionary<MyIniValue, TValue> dictionary )
//         {
//             var Parser = context.IniParser;
//             if (Parser.TryParse(block.CustomData) && Parser.ContainsSection(section))
//             {
//                 var TODOiniKeyScratchpad = new List<MyIniKey>();
//                 Parser.GetKeys(TODOiniKeyScratchpad);
//                 foreach (var iniKey in iniKeyScratchpad)
//                 {
//                     if (iniKey.Section != section)
//                         continue;
//
//                     var value = valueParse(Parser.Get(iniKey));
//                     if (value == null)
//                         continue;
//
//                     var key = keyParse(iniKey.Name);
//                     if (key == null)
//                         continue;
//
//                 }
//             }
//         }

        void GetBlockRequestSettings(IMyTerminalBlock block)
        {
            InventoryRequests[block.EntityId] = new Dictionary <MyItemType, int>();

            var Parser = Context.IniParser;

            if (Parser.TryParse(block.CustomData) && Parser.ContainsSection(InventoryRequestSection))
            {
                // TODO: Replace with
                //         public void GetKeys(string section, List<MyIniKey> keys);
                Parser.GetKeys(iniKeyScratchpad);
                foreach (var key in iniKeyScratchpad)
                {
                    if (key.Section != InventoryRequestSection)
                    {
                        continue;
                    }
                    var count = Parser.Get(key).ToInt32();
                    if (count == 0)
                    {
                        continue;
                    }
                    var type = MyItemType.Parse(key.Name);

                    var inventory = block.GetInventory(block.InventoryCount - 1);
                    itemTypeScratchpad.Clear();
                    inventory.GetAcceptedItems(itemTypeScratchpad);
                    if (!itemTypeScratchpad.Contains(type))
                    {
                        continue;
                    }

                    InventoryRequests[block.EntityId][type] = count;

                    if (!TotalInventoryRequests.ContainsKey(type))
                    {
                        TotalInventoryRequests[type] = 0;
                    }
                    TotalInventoryRequests[type] += count;
                    if (!SortedInventory.Contains(type))
                    {
                        SortedInventory.Add(type);
                    }
                }
            }
        }
Esempio n. 4
0
 public MyItemType asMyItemType()
 {
     return(MyItemType.Parse(asComponent()));
 }