Ejemplo n.º 1
0
 public override int[] GetJointCoords(Component.Rotation r)
 {
     switch (r)
     {
         case Rotation.cw0:
             return new int[] { JointLocs0cw[0], JointLocs0cw[1], JointLocs0cw[2], JointLocs0cw[3], JointLocs0cw[4], JointLocs0cw[5] };
         case Rotation.cw90:
         case Rotation.cw180:
         case Rotation.cw270:
         default:
             return new int[0];
     }
 }
Ejemplo n.º 2
0
 public override int[] GetJointCoords(Component.Rotation r)
 {
     switch (r)
     {
         case Rotation.cw0:
             return new int[] { JointLocs0cw[0], JointLocs0cw[1] };
         case Rotation.cw90:
             break;
         case Rotation.cw180:
             break;
         case Rotation.cw270:
             break;
         default:
             break;
     }
     return base.GetJointCoords(r);
 }
Ejemplo n.º 3
0
 public String GetMapOverlayToolTip(Component c = null)
 {
     if (c == null)
     {
         return ((float)((int)(Joints[0].SendingVoltage * 10)) / 10f).ToString() + " V";
     }
     else
     {
         if (c is Properties.IMagnetic)
         {
             float l = (c as Properties.IMagnetic).GetFieldForce(Graphics.Center.X, Graphics.Center.Y).Length() / MaxMagnetForce;
             l = l > 1 ? 1 : l < 0 ? 0 : l;
             return ((float)((int)(MaxVoltage * l * 10)) / 10f).ToString() + " V";
         }
         else
         {
             return "0 V";
         }
     }
 }
Ejemplo n.º 4
0
 public void GetStruck(Component origin, float voltage, int time)
 {
     (Logics as Logics.AdvancedJointLogics).AddSource(new Logics.AdvancedJointLogics.VoltageSource(time, voltage));
 }
Ejemplo n.º 5
0
 public RotatableConnector(Component c1, Component c2)
 {
     _connectedComponent1 = c1;
     _connectedComponent2 = c2;
     constructor();
 }
Ejemplo n.º 6
0
 public String GetMapOverlayToolTip(Component c = null)
 {
     if (c == null)
     {
         return ((int)((Logics as Logics.PhotoresistorLogics).Brightness * 100)).ToString() + " %";
     }
     else
     {
         if (!(c is Properties.ILightEmitting))
             return "0 %";
         else
             return ((int)((c as Properties.ILightEmitting).GetBrightness(Graphics.Center.X, Graphics.Center.Y) * 100)).ToString() + " %";
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets point to a specificvalue
 /// </summary>
 /// <param name="x">X</param>
 /// <param name="y">Y</param>
 /// <param name="v">Value</param>
 public void SetPoint(Component sender, float x, float y)
 {
     int divider = 64 * MicroWorld.Graphics.GUI.GridDraw.Step;
     GetChunk(x, y).data[(int)Math.Abs(x % divider) / 8, (int)Math.Abs(y % divider) / 8] = (short)(sender == null ? 0 : sender.typeID);
 }
Ejemplo n.º 8
0
 public bool IsInRange(Component c)
 {
     return Math.Sqrt(Math.Pow(c.Graphics.Position.X + c.Graphics.GetSize().X / 2 - Graphics.Position.X - Graphics.GetSize().X / 2, 2) +
                      Math.Pow(c.Graphics.Position.Y + c.Graphics.GetSize().Y / 2 - Graphics.Position.Y - Graphics.GetSize().Y / 2, 2)) < Luminosity;
 }
Ejemplo n.º 9
0
        public override void Remove()
        {
            if (!IsRemovable) return;
            for (int i = 0; i < Joints.Length; i++)
            {
                Joints[i].IsRemovable = true;
                Joints[i].ContainingComponents.Remove(this);
            }
            W.IsRemovable = true;

            W.Remove();
            for (int i = 0; i < Joints.Length; i++)
            {
                Joints[i].CanRemove = true;
                if (Joints[i].ConnectedWires.Count == 0)
                {
                    Joints[i].Remove();
                }
            }

            var a = connector;
            connectedComponent = null;
            if (a != null) a.Disconnect();//leave this as is. prevents stack overflow
            base.Remove();
        }
Ejemplo n.º 10
0
 public void Disconnect()
 {
     connector = null;
     connectedComponent = null;
 }
Ejemplo n.º 11
0
 void GlobalEvents_onComponentMoved(Component sender)
 {
     UpdateComponentsList();
 }
Ejemplo n.º 12
0
 public bool CanConnect(Component c)
 {
     return connectedComponent == null;
 }
Ejemplo n.º 13
0
 public override void Remove()
 {
     if (!IsRemovable) return;
     var a = connector;
     connectedComponent = null;
     if (a != null) a.Disconnect();//leave this as is. prevents stack overflow
     base.Remove();
 }
Ejemplo n.º 14
0
        public override void PostLoad()
        {
            base.PostLoad();

            if (con != Int32.MinValue && con != -1)
            {
                connectedComponent = ComponentsManager.GetComponent(com);
                connector = ComponentsManager.GetComponent(con) as RotatableConnector;
            }
        }
Ejemplo n.º 15
0
 void GlobalEvents_onComponentRemovedByPlayer(Component sender)
 {
     if (sender is MovementDetector)
         UpdateLasers();
 }
Ejemplo n.º 16
0
 void GlobalEvents_onComponentMoved(Component sender)
 {
     UpdateLasers();
 }
Ejemplo n.º 17
0
 public void Connect(Component c, RotatableConnector rc)
 {
     connector = rc;
     connectedComponent = c;
 }
Ejemplo n.º 18
0
 void GlobalEvents_onComponentRemovedByPlayer(Component sender)
 {
     UpdateComponentsList();
 }
Ejemplo n.º 19
0
        public override void PostLoad()
        {
            base.PostLoad();

            Joints[0] = (Joint)Components.ComponentsManager.GetComponent(j0);
            Joints[1] = (Joint)Components.ComponentsManager.GetComponent(j1);
            W = (Wire)Components.ComponentsManager.GetComponent(w);
            Resistance = res;
            if (com != -1)
            {
                connectedComponent = ComponentsManager.GetComponent(com);
                connector = ComponentsManager.GetComponent(con) as RotatableConnector;
            }

            for (int i = 0; i < Joints.Length; i++)
            {
                Joints[i].ContainingComponents.Add(this);
            }
        }
Ejemplo n.º 20
0
 public String GetMapOverlayToolTip(Component c = null)
 {
     if (c == null)
     {
         return W.IsConnected ? "Connected" : "Disconnected";
     }
     else
     {
         if (c is Properties.IMagnetic)
         {
             return (c as Properties.IMagnetic).GetFieldForce(Graphics.Center.X, Graphics.Center.Y).Length() >
                 (Logics as Logics.ReedSwitchLogics).RequiredField ? "Connected" : "Disconnected";
         }
         else
         {
             return "Disconnected";
         }
     }
 }
Ejemplo n.º 21
0
 public bool CanConnect(Component c)
 {
     return connector == null && c is Properties.IRotatable;
 }
Ejemplo n.º 22
0
 public override void SetRotation(Component.Rotation rot)
 {
     if (rot.GetHashCode() > 1) rot = (Component.Rotation)(rot.GetHashCode() - 2);
     base.SetRotation(rot);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Sets a line to a specific value
        /// </summary>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="v"></param>
        public void SetLine(Component sender, float x1, float y1, float x2, float y2)
        {
            short v = (short)(sender == null ? 0 : sender.typeID);
            if (y1 > y2)
            {
                float t = y1;
                y1 = y2;
                y2 = t;
            }
            if (x1 > x2)
            {
                float t = x1;
                x1 = x2;
                x2 = t;
            }

            if (x1 == x2)
            {
                for (int y = (int)y1; y < (int)y2; y++)
                {
                    SetPoint(x1, y, v);
                }
            }
            if (y1 == y2)
            {
                for (int x = (int)x1; x < (int)x2; x++)
                {
                    SetPoint(x, y1, v);
                }
            }
            else
            {
                if (Math.Abs(x1 - x2) > Math.Abs(y1 - y2))//dx>dy
                {
                    for (float x = x1; x != x2; x += Math.Sign(x2 - x1))
                    {
                        float y = y1 + (y2 - y1) * (x / (x2 - x1));
                        SetPoint(x, y, v);
                    }
                }
                else//dx<dy
                {
                    for (float y = y1; y != y2; y += Math.Sign(y2 - y1))
                    {
                        float x = x1 + (x2 - x1) * (y / (y2 - y1));
                        SetPoint(x, y, v);
                    }
                }
            }
        }
Ejemplo n.º 24
0
 public void Disconnect()
 {
     if (ConnectedComponent1 is Properties.IRotator)
         (ConnectedComponent1 as Properties.IRotator).Disconnect();
     if (ConnectedComponent1 is Properties.IRotatable)
         (ConnectedComponent1 as Properties.IRotatable).Disconnect();
     if (ConnectedComponent2 is Properties.IRotator)
         (ConnectedComponent2 as Properties.IRotator).Disconnect();
     if (ConnectedComponent2 is Properties.IRotatable)
         (ConnectedComponent2 as Properties.IRotatable).Disconnect();
     ConnectedComponent1 = null;
     ConnectedComponent2 = null;
     Remove();
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Sets rectangle to a specific value
 /// </summary>
 /// <param name="x">X</param>
 /// <param name="y">Y</param>
 /// <param name="w">W</param>
 /// <param name="h">H</param>
 /// <param name="v">Value</param>
 public void SetRectangle(Component sender, float x, float y, float w, float h)
 {
     //if (x < 0 && x + w >= 0)
     //    w++;
     //if (y < 0 && y + h >= 0)
     //    h++;
     /*
     int divider = 64 * MicroWorld.Graphics.GUI.GridDraw.Step;
     if ((int)(x / divider) == (int)((x + w) / divider) && (int)(y / divider) == (int)((y + h) / divider))
     {
         var c = GetChunk(x, y);
         int dx = (int)(x % divider) / 8;
         int dy = (int)(y % divider) / 8;
         for (int i = 0; i < w / MicroWorld.Graphics.GUI.GridDraw.Step; i++)
         {
             for (int j = 0; j < h / MicroWorld.Graphics.GUI.GridDraw.Step; j++)
             {
                 c.data[dx + i, dy + j] = v;
             }
         }
     }
     else
     //*/
     //{
     //TODO
     short v = (short)(sender == null ? 0 : sender.typeID);
     for (int i = 0; i < w; i += 8)
     {
         for (int j = 0; j < h; j += 8)
         {
             SetPoint(x + i, y + j, v);
         }
     }
     //}
 }
Ejemplo n.º 26
0
        public override void PostLoad()
        {
            base.PostLoad();

            ConnectedComponent1 = ComponentsManager.GetComponent(c1);
            ConnectedComponent2 = ComponentsManager.GetComponent(c2);
        }