Пример #1
0
        public static NodeLink?Create(ProductionNode supplier, ProductionNode consumer, Item item,
                                      float maxAmount = float.PositiveInfinity)
        {
            if (!supplier.Supplies(item) || !consumer.Consumes(item))
            {
                throw new InvalidOperationException($"Cannot connect {supplier} to {consumer} using item {item}");
            }

            if (consumer.InputLinks.Any(l => l.Item == item && l.Supplier == supplier))
            {
                return(null);
            }
            if (supplier.OutputLinks.Any(l => l.Item == item && l.Consumer == consumer))
            {
                return(null);
            }

            var link = new NodeLink(supplier, consumer, item, maxAmount);

            supplier.OutputLinks.Add(link);
            consumer.InputLinks.Add(link);
            supplier.Graph.InvalidateCaches();
            return(link);
        }
Пример #2
0
 public static bool CanLink(ProductionNode supplier, ProductionNode consumer, Item item)
 {
     return(supplier.Supplies(item) && consumer.Consumes(item));
 }