Пример #1
0
        public void ApplyStorageAttributesPatch(StorageAttributesPatch storageAttributesPatch, StorageAttributesWrapper storageAttributesWrapper)
        {
            applyPropertyPatch(storageAttributesPatch.LinkToPlayerBank, () => storageAttributesWrapper.LinkToPlayerBank);
            applyPropertyPatch(storageAttributesPatch.IsResourceController, () => storageAttributesWrapper.IsResourceController);

            var loadout = storageAttributesWrapper.InventoryLoadout.ToList();

            foreach (var kvp in storageAttributesPatch.InventoryLoadout)
            {
                var inventoryId    = kvp.Key;
                var inventoryPatch = kvp.Value;

                using (logger.BeginScope($"InventoryBinding: {inventoryId}"))
                {
                    var index = loadout.FindIndex(b => b.InventoryID == inventoryId);

                    InventoryAttributesWrapper inventoryAttributesWrapper;

                    if (index < 0)
                    {
                        index = loadout.Count;

                        var name = $"SUBSYSTEM-{storageAttributesWrapper.Name}-{inventoryId}";
                        logger.Log($"(created InventoryAttributes: {name})");

                        inventoryAttributesWrapper = new InventoryAttributesWrapper(
                            name: name,
                            inventoryId: inventoryId
                            );
                    }
                    else
                    {
                        var inventoryBinding = loadout[index];
                        inventoryAttributesWrapper = new InventoryAttributesWrapper(inventoryBinding.InventoryAttributes);
                    }

                    ApplyInventoryAttributesPatch(inventoryPatch, inventoryAttributesWrapper);

                    var newBinding = new InventoryBinding(
                        inventoryID: inventoryId,
                        inventoryBindingIndex: index,
                        inventoryAttributes: inventoryAttributesWrapper
                        );

                    if (index == loadout.Count)
                    {
                        loadout.Add(newBinding);
                    }
                    else
                    {
                        loadout[index] = newBinding;
                    }
                }
            }

            storageAttributesWrapper.InventoryLoadout = loadout.ToArray();
        }
Пример #2
0
        public static void UpdateGrid()
        {
            var _lastupdatedTime = DateTime.Now;

            while (true)
            {
                Thread.Sleep(50);
                if ((DateTime.Now - _lastupdatedTime).TotalSeconds >= 1)
                {
                    if (Form1.instance.WindowState == FormWindowState.Minimized)
                    {
                        continue;
                    }

                    _lastupdatedTime = DateTime.Now;
                    if (Form1.instance.BuildingGrid.InvokeRequired)
                    {
                        var           newbuild = InventoryBinding.GetItems();
                        MethodInvoker meth     = () =>
                        {
                            foreach (DataGridViewTextBoxColumn clmn in Form1.instance.InventoryGrid.Columns)
                            {
                                clmn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                clmn.Resizable    = DataGridViewTriState.False;
                            }

                            foreach (var bld in newbuild)
                            {
                                if (InventoryBinding.Items.Where(n => n.ID == bld.ID).FirstOrDefault() == null)
                                {
                                    InventoryBinding.Items.Add(bld);
                                }
                                else
                                {
                                    var old = InventoryBinding.Items.First(n => n.ID == bld.ID);
                                    if (old.Amount != bld.Amount)
                                    {
                                        old.Amount = bld.Amount;
                                    }
                                }
                            }

                            Form1.instance.BuildingGrid.Refresh();
                            Form1.instance.BuildingGrid.Update();
                        };

                        Form1.instance.BuildingGrid.BeginInvoke(meth);
                    }
                }
            }
        }
Пример #3
0
 internal BindState(InventoryBinding inventoryDataBind, DataInventory dataInventory) : base(inventoryDataBind)
 {
     DataInventory = dataInventory;
 }
Пример #4
0
 public NoInitState(InventoryBinding inventoryDataBind, DataInventoryStructure inventoryStructure,
                    IEnumerable <DataEntity> dataEntitiesForLoad = null) : base(inventoryDataBind)
 {
     _inventoryStructure  = inventoryStructure;
     _dataEntitiesForLoad = dataEntitiesForLoad;
 }
Пример #5
0
 public UnbindState(InventoryBinding inventoryDataBind, DataInventory dataInventory) : base(inventoryDataBind)
 {
     DataInventory = dataInventory;
 }
Пример #6
0
        protected override void Apply(AttributeLoader loader, object wrapperObj)
        {
            if (!(wrapperObj is StorageAttributesWrapper wrapper))
            {
                throw new System.InvalidCastException();
            }

            loader.ApplyPPatch(LinkToPlayerBank, () => wrapper.LinkToPlayerBank);
            loader.ApplyPPatch(IsResourceController, () => wrapper.IsResourceController);

            var loadout = wrapper.InventoryLoadout.ToList();

            loader.logger.BeginScope($"Available inventory IDs: {String.Join(", ", loadout.Select(x => x.InventoryID).ToArray())}").Dispose();

            foreach (var kvp in InventoryLoadout)
            {
                var inventoryId    = kvp.Key;
                var inventoryPatch = kvp.Value;

                using (loader.logger.BeginScope($"InventoryBinding: {inventoryId}"))
                {
                    var index = loadout.FindIndex(b => b.InventoryID == inventoryId);

                    InventoryAttributesWrapper inventoryAttributesWrapper;

                    if (index < 0)
                    {
                        index = loadout.Count;

                        var name = $"SUBSYSTEM-{wrapper.Name}-{inventoryId}";
                        loader.logger.Log($"(created InventoryAttributes: {name})");

                        inventoryAttributesWrapper = new InventoryAttributesWrapper(
                            name: name,
                            inventoryId: inventoryId
                            );
                    }
                    else
                    {
                        var inventoryBinding = loadout[index];
                        inventoryAttributesWrapper = new InventoryAttributesWrapper(inventoryBinding.InventoryAttributes);
                    }

                    inventoryPatch.Apply(loader, inventoryAttributesWrapper, null);

                    var newBinding = new InventoryBinding(
                        inventoryID: inventoryId,
                        inventoryBindingIndex: index,
                        inventoryAttributes: inventoryAttributesWrapper
                        );

                    if (index == loadout.Count)
                    {
                        loadout.Add(newBinding);
                    }
                    else
                    {
                        loadout[index] = newBinding;
                    }
                }
            }

            wrapper.InventoryLoadout = loadout.ToArray();
        }