private void RegisterInventoryStructureInDatabase(DataInventoryStructure inventoryStructure)
 {
     foreach (var dataSlot in inventoryStructure.Slots)
     {
         _databaseCommands.RegisterSlot(dataSlot);
     }
 }
 public void RegisterInventoryInDatabase(DataInventoryStructure inventoryStructure,
                                         InventoryComponent inventoryComponent)
 {
     RegisterInventoryStructureInDatabase(inventoryStructure);
     inventoryComponent.SetInventoryStructure(inventoryStructure);
     BindSlotsComponentsToData(inventoryComponent);
 }
Exemple #3
0
        private bool IsValidStructureForThisInventory(DataInventoryStructure inventoryStructure)
        {
            var inventoryStructureSource = GetInventoryStructure();

            if (!inventoryStructureSource.DataInventory.Equals(inventoryStructure.DataInventory) ||
                inventoryStructureSource.Slots.Count != inventoryStructure.Slots.Count)
            {
                return(false);
            }

            var sourceCoords = GetCoords(inventoryStructureSource);
            var targetCoords = GetCoords(inventoryStructure);

            return(SameSlotsType(inventoryStructureSource, inventoryStructure) &&
                   new HashSet <Vector2Int>(sourceCoords).SetEquals(targetCoords));

            IEnumerable <Vector2Int> GetCoords(DataInventoryStructure structure) => structure.Slots.Select(slot => slot.Vector2Int);

            bool SameSlotsType(DataInventoryStructure first, DataInventoryStructure second) =>
            first.Slots.First().GetType() == second.Slots.First().GetType();
        }
Exemple #4
0
 public NoInitState(InventoryBinding inventoryDataBind, DataInventoryStructure inventoryStructure,
                    IEnumerable <DataEntity> dataEntitiesForLoad = null) : base(inventoryDataBind)
 {
     _inventoryStructure  = inventoryStructure;
     _dataEntitiesForLoad = dataEntitiesForLoad;
 }
Exemple #5
0
 private void CheckValidStructure(DataInventoryStructure inventoryStructure) =>
 Contract.Assert(IsValidStructureForThisInventory(inventoryStructure));
Exemple #6
0
 public void SetInventoryStructure(DataInventoryStructure inventoryStructure)
 {
     CheckValidStructure(inventoryStructure);
     SetDataSlots(inventoryStructure.Slots);
     SetDataInventory(inventoryStructure.DataInventory);
 }