Example #1
0
        private void AddElement(double sX, double sY, double dX, double dY, Element element)
        {
            var clone = CreateItem(dX, dY, element);
            Workbench.Children.Add(clone);

            var opAnim = new DoubleAnimation
            {
                From = 0,
                To = 1,
                Duration = TimeSpan.FromMilliseconds(50),
                FillBehavior = FillBehavior.Stop
            };

            var xAnim = new DoubleAnimation
            {
                From = sX,
                To = dX,
                Duration = TimeSpan.FromMilliseconds(150),
                FillBehavior = FillBehavior.Stop
            };

            var yAnim = new DoubleAnimation
            {
                From = sY,
                To = dY,
                Duration = TimeSpan.FromMilliseconds(150),
                FillBehavior = FillBehavior.Stop
            };

            clone.BeginAnimation(UIElement.OpacityProperty, opAnim);
            clone.BeginAnimation(Canvas.LeftProperty, xAnim);
            clone.BeginAnimation(Canvas.TopProperty, yAnim);
        }
Example #2
0
        private ElementContentItem CreateItem( double x, double y, Element element)
        {
            ElementContentItem item = new ElementContentItem();
            Canvas.SetLeft(item, x);
            Canvas.SetTop(item, y);
            item.Template = (ControlTemplate) Workbench.Resources["ElementItemTemplate"];
            item.Element = element;
            item.MouseDown += Element_MouseDown;
            item.MouseDoubleClick += Element_MouseDoubleClick;
            item.AllowDrop = true;

            return item;
        }
Example #3
0
 private void CopySources(Element src, Element dest)
 {
     // Perform a deep copy (ints are copy-by-value)
     foreach (ElementPair pair in src.Sources)
     {
         dest.Sources.Add(new ElementPair { Element1 = pair.Element1, Element2 = pair.Element2 });
     }
 }
Example #4
0
 public void SaveElement(Element element)
 {
     _Elements[element.Id] = element;
     ChangeDatabase();
 }
Example #5
0
 public Element Duplicate(Element e)
 {
     var clone = new Element
     {
         Id = GetNextElementId(),
         Name = string.Copy(e.Name),
         Prime = e.Prime,
         Icon = string.Copy(e.Icon),
     };
     CopySources(e, clone);
     return clone;
 }
Example #6
0
        public ExperimentResult DoExperiment(Element element1, Element element2)
        {
            // Start by finding all the elements which can be created by this pair
            List<Element> elements = new List<Element>();
            ElementPair reagents = new ElementPair() { Element1 = element1.Id, Element2 = element2.Id };
            foreach (KeyValuePair<int, Element> kvp in _Elements)
            {
                if (kvp.Value.Sources.Contains(reagents))
                {
                    // Possibly filter based on whether we have discovered this element
                    if (!OnlyUndiscovered || !IsElementDiscovered(kvp.Key))
                    {
                        elements.Add(kvp.Value);
                        _ElementsDiscovered[kvp.Key] = true;
                    }
                }
            }

            // Experiment is a success if we found (new) elements
            bool success = elements.Count > 0;
            if (success)
            {
                ProgressDirty = true;
                DoDiscoveredElementsChanged();
            }
            else
            {
                // If it wasn't a success, return the original two elements
                elements.Add(element1);
                elements.Add(element2);
            }

            // Return the result
            return new ExperimentResult() { Success = success, ElementsCreated = elements };
        }