Exemple #1
0
 private void Unsubscribe(AElementData elementData) {
     _subscribers[elementData].ForAll(d => d.Dispose());
     _subscribers.Remove(elementData);
 }
Exemple #2
0
 protected virtual void Subscribe(AElementData elementData) {
     _subscribers.Add(elementData, new List<IDisposable>());
     IList<IDisposable> anElementsSubscriptions = _subscribers[elementData];
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, float>(ed => ed.CurrentHitPoints, OnElementCurrentHitPointsChanged));
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, float>(ed => ed.MaxHitPoints, OnElementMaxHitPointsChanged));
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, CombatStrength>(ed => ed.DefensiveStrength, OnElementDefensiveStrengthChanged));
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, CombatStrength>(ed => ed.OffensiveStrength, OnElementOffensiveStrengthChanged));
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, float>(ed => ed.MaxWeaponsRange, OnElementMaxWeaponsRangeChanged));
     anElementsSubscriptions.Add(elementData.SubscribeToPropertyChanged<AElementData, float>(ed => ed.MaxSensorRange, OnElementMaxSensorRangeChanged));
 }
Exemple #3
0
        public virtual bool RemoveElement(AElementData elementData) {
            D.Assert(ElementsData.Contains(elementData), "Attempted to remove {0} {1} that is not present.".Inject(typeof(AElementData).Name, elementData.ParentName));
            bool isRemoved = ElementsData.Remove(elementData);

            UpdateComposition();
            Unsubscribe(elementData);
            RecalcPropertiesDerivedFromCombinedElements();
            return isRemoved;
        }
Exemple #4
0
 private void UpdateElementParentName(AElementData elementData) {
     //TODO something more than just assigning a parent name?
     D.Log("{0} OptionalParentName changing to {1}.", elementData.Name, ParentName);
     elementData.ParentName = ParentName;    // the name of the fleet, not the command
 }
Exemple #5
0
 private void VerifyOwner(AElementData elementData) {
     D.Assert(Owner != TempGameValues.NoPlayer, "{0} owner should be set before adding elements.".Inject(Name));
     if (elementData.Owner == TempGameValues.NoPlayer) {
         D.Warn("{0} owner should be set before adding element to {1}.", elementData.Name, Name);
         elementData.Owner = Owner;
     }
     else if (elementData.Owner != Owner) {
         D.Warn("{0} owner {1} is different from {2} owner {3}.", elementData.Name, elementData.Owner.LeaderName, Name, Owner.LeaderName);
         elementData.Owner = Owner;
     }
 }
Exemple #6
0
        public virtual void AddElement(AElementData elementData) {
            D.Assert(!ElementsData.Contains(elementData), "Attempted to add {0} {1} that is already present.".Inject(typeof(AElementData).Name, elementData.ParentName));
            VerifyOwner(elementData);
            UpdateElementParentName(elementData);
            ElementsData.Add(elementData);

            UpdateComposition();
            Subscribe(elementData);
            RecalcPropertiesDerivedFromCombinedElements();
        }