internal ConsumerNode(EquipmentNetwork equipmentNetwork, Equipment equipment) : base(equipmentNetwork, equipment) { ConsumerComponent = equipment.GetComponent <ElectricityConsumer>(); Assert.IsNotNull(ConsumerComponent); Assert.IsNull(equipment.GetComponent <ElectricityProducer>()); }
/// <summary> /// Constructs new node and subscribes for Equipment.EnabledChanged. /// </summary> protected Node(EquipmentNetwork equipmentNetwork, Equipment equipment) //It's private { Assert.IsTrue(equipment.TargetEnabled, "Tried to create node that \"don't want\" to be enabled."); EquipmentNetwork = equipmentNetwork; Equipment = equipment; equipment.EnabledChanged += OnEquipmentEnabledChanged; }
/// <summary> /// Constructs new ElectricitySubsystem for given Spacecraft. /// </summary> public ElectricitySubsystem(Spacecraft spacecraft) { Spacecraft = spacecraft; EquipmentNetwork = new EquipmentNetwork(); Spacecraft.EquipmentTrackingSubsystem.EquipmentConnected += OnEquipmentConnected; Spacecraft.EquipmentTrackingSubsystem.EquipmentDisconnected += OnEquipmentDisconnected; EquipmentNetwork.PowerStateChanged += InvokePowerStateChanged; }
/// <summary> /// Factory method that creates a node corresponding to equipment's electricity components. /// </summary> public static Node CreateNode(EquipmentNetwork equipmentNetwork, Equipment equipment) { var producer = equipment.GetComponent <ElectricityProducer>(); var consumer = equipment.GetComponent <ElectricityConsumer>(); if (producer == null && consumer == null) { throw new ArgumentException("Attempted to create node for non-electrical equipment"); } if (producer != null && consumer == null) { return(new ProducerNode(equipmentNetwork, equipment)); } if (producer == null && consumer != null) { return(new ConsumerNode(equipmentNetwork, equipment)); } throw new ArgumentException("Electricity subsystem currently doesn't support electricity " + "consumer and producer being on equipment simultaneously. " + "If it's really needed, implement desired behaviour."); }
private void InvokePowerStateChanged(EquipmentNetwork sender) { PowerStateChanged?.Invoke(this); }