예제 #1
0
 public bool AddConnection(IBoxModel source, IBoxModel target)
 {
     if (source == null || target == null)
     {
         return(false);                                  //ech
     }
     if (!_boxes.ContainsKey(source.Id) || !_boxes.ContainsKey(target.Id))
     {
         throw new Exception($"AddConnection: Boxes not in list _boxes s[{source.Id}]t[{target.Id}]");
     }
     // NO CHAINSSSS
     if (source.HasSources || target.HasTargets)
     {
         return(false);
     }
     if (source.MaxOutConnections > source.TargetBoxes.Count() &&
         target.MaxInConnections > target.SourceBoxes.Count())
     {
         if (GetEndpointSources(source).Any(x => x.Id == target.Id))
         {
             return(false); // uuuuu spierdalaj
         }
         source.TargetBoxes.Add(target);
         target.SourceBoxes.Add(source);
         return(true);
     }
     return(false); //spierdalaj
 }
예제 #2
0
        public void AddBox(IBoxModel box, BoxPoint point)
        {
            var square = Instantiate(SquarePrefab, new Vector3(point.X, point.Y), new Quaternion());
            var action = square.GetComponent <MouseAction>();

            action.MainEditorModel = this;
            action.BoxModel        = box;
            _boxes.Add(box.Id, box);
        }
 public static void Populate(this BoxModelSerializable modelS, IBoxModel model)
 {
     modelS.Id                = model.Id;
     modelS.BoxColor          = model.BoxColor;
     modelS.BoxShape          = model.BoxShape;
     modelS.BoxType           = model.BoxType;
     modelS.TargetBoxes       = model.TargetBoxes.Select(x => x.Id).ToList();
     modelS.SourceBoxes       = model.SourceBoxes.Select(x => x.Id).ToList();
     modelS.HasTargets        = model.HasTargets;
     modelS.HasSources        = model.HasSources;
     modelS.MaxOutConnections = model.MaxOutConnections;
     modelS.MaxInConnections  = model.MaxInConnections;
 }
예제 #4
0
 public void RemoveConnection(IBoxModel source, IBoxModel target)
 {
     if (source == null || target == null)
     {
         return;
     }
     if (!_boxes.ContainsKey(source.Id) || !_boxes.ContainsKey(target.Id))
     {
         throw new Exception($"RemoveConnection: Boxes not in list _boxes s[{source.Id}]t[{target.Id}]");
     }
     if (!source.TargetBoxes.Remove(target) || !target.SourceBoxes.Remove(source))
     {
         throw new Exception("Boxes were not connected s[{source.Id}]t[{target.Id}]");
     }
 }
예제 #5
0
        private List <IBoxModel> GetEndpointSources(IBoxModel box)
        {
            List <IBoxModel> sourceBoxes = new List <IBoxModel>();

            if (!box.HasSources)
            {
                sourceBoxes.Add(box);
            }

            foreach (var sourceBox in box.SourceBoxes)
            {
                sourceBoxes.AddRange(GetEndpointSources(sourceBox));
            }

            return(sourceBoxes);
        }