Beispiel #1
0
        public void Split(ILinkData point)
        {
            int        index    = this.childrenInt.IndexOf(point);
            ILinkGroup newGroup = new LinkGroup(this.childrenInt.Skip(index + 1));

            newGroup.RecalculateCenter();
            this.childrenInt.RemoveRange(index, this.childrenInt.Count - index);
            this.RecalculateCenter();
        }
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.linkable = base.GetComp <CompLinkable>();
     if (this.linkable == null)
     {
         Log.Error("[LinkableDoors] This class does not have a component of Linkable.");
         return;
     }
     this.linkable.CallBack = this.CallBack;
 }
 public static void AttachGroupAround(ILinkData newObj)
 {
     LinkGroupUtility.CheckAround(newObj, (i, current) =>
     {
         int invert = LinkGroupUtility.Invert(i);
         if (current.CanLinkFromOther(i) && newObj.CanLinkFromOther(invert))
         {
             current.GroupParent.Concat(newObj.GroupParent);
             newObj.Notify_Linked(current, i);
             current.Notify_Linked(newObj, invert);
         }
     });
 }
        Link Build([NotNull] ILinkData linkData)
        {
            var dataType    = linkData.GetType();
            var builderType = typeof(ILinkBuilder <>).MakeGenericType(dataType);
            var buildMethod = builderType.GetMethod(nameof(ILinkBuilder <ILinkData> .Build), new[] { dataType });

            object builder;

            using (var scope = _serviceProvider.CreateScope())
            {
                builder = scope.ServiceProvider.GetRequiredService(builderType);
            }

            return((Link)buildMethod.Invoke(builder, new object[] { linkData }));
        }
 private static void CheckAround(ILinkData newObj, Func func)
 {
     for (int i = 0; i < 4; i++)
     {
         IntVec3 pos = newObj.Pos + GenAdj.CardinalDirections[i];
         foreach (var thing in newObj.Map.thingGrid.ThingsListAtFast(pos))
         {
             Building_LinkableDoor door    = thing as Building_LinkableDoor;
             ILinkData             current = door?.TryGetComp <CompLinkable>();
             if (current != null)
             {
                 func(i, current);
             }
         }
     }
 }
        public static void DetachGroupAround(ILinkData delObj)
        {
            ILinkGroup parent = delObj.GroupParent;

            if (parent.Children.Count() <= 1)
            {
                return;
            }
            if (parent.Children.First() == delObj || parent.Children.Last() == delObj)
            {
                parent.Remove(delObj);
                parent.RecalculateCenter();
            }
            else
            {
                parent.Split(delObj);
            }
            delObj.Reset();
            ILinkGroup result = new LinkGroup(delObj);
        }
Beispiel #7
0
 public HomeController(ILinkData linkData, ITagData tagData)
 {
     _linkData = linkData;
     _tagData  = tagData;
 }
Beispiel #8
0
 /// <summary>
 /// LinkData setter; used so can set data into a collection of specific type, while still maintaining an interface input
 /// </summary>
 /// <param name="linkData"></param>
 public void SetLinkData(ILinkData linkData)
 {
     //Note: complex type cannot be null, otherwise EF will throw!
     LinkData = (LinkData)linkData ?? new LinkData();
 }
Beispiel #9
0
 public LinkGroup(ILinkData newData)
 {
     this.Add(newData);
     newData.PosTag = PositionTag.Center;
 }
Beispiel #10
0
 public void Add(ILinkData newData)
 {
     this.childrenInt.Add(newData);
     newData.GroupParent = this;
 }
Beispiel #11
0
 public void Remove(ILinkData delData)
 {
     this.childrenInt.Remove(delData);
     delData.GroupParent = null;
 }
 public virtual void Notify_UnLinked(ILinkData other)
 {
     this.directLinks.Remove(other);
 }
 public static void Notify_LinkableDeSpawned(ILinkData delObj)
 {
     LinkGroupUtility.DetachGroupAround(delObj);
 }
        public static void Notify_LinkableSpawned(ILinkData newObj)
        {
            ILinkGroup result = new LinkGroup(newObj);

            LinkGroupUtility.AttachGroupAround(newObj);
        }
 public void RenderLinkCallback(FrameworkElement result, ILinkData linkAttribute)
 {
     src.RenderLinkCallback(result, linkAttribute.RawData as ITextRenderLinkAttribute);
 }
        /// <summary>
        /// Adds a link to an object; adds appropriate info to the LinksDiff.Upsert collection
        /// Does not save the data.  In order to materialise modified links, saving object is required.
        /// Saving requires calling Create / Update
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="parent"></param>
        /// <param name="child"></param>
        /// <param name="sortOrder"></param>
        /// <param name="linkData"></param>
        /// <returns></returns>
        public static TEntity AddLink <TEntity, T>(this TEntity parent, T child, int sortOrder = 0, ILinkData linkData = null)
            where TEntity : Base
            where T : Base
        {
            //grab a link if it exists, so it can be modified, or insert a new one
            var link = parent.Links.Upsert.FirstOrDefault(l => l.ParentUuid == parent.Uuid && l.ChildUuid == child.Uuid);

            if (link == null)
            {
                link = new Link()
                {
                    ParentTypeUuid = parent.TypeUuid,
                    ParentUuid     = parent.Uuid,
                    ChildUuid      = child.Uuid,
                    ChildTypeUuid  = child.TypeUuid
                };
                parent.Links.Upsert.Add(link);
            }

            //update the link data that can change
            link.SetLinkData(linkData);
            link.SortOrder = sortOrder;

            //since link is added also make sure to remove it from destroy diff as otherwise it would be first added to a db and then destroyed
            var destroy = parent.Links.Destroy.FirstOrDefault(d => d == child.Uuid);

            if (destroy != default(Guid))
            {
                parent.Links.Destroy.Remove(destroy);
            }

            return(parent);
        }
 public virtual void Notify_Linked(ILinkData other, int direction)
 {
     this.LineDirection = (direction == 0 || direction == 2) ? Rot4.East : Rot4.North;
     this.directLinks.Add(other, direction);
 }