Ejemplo n.º 1
0
        public static void UpdateStates(CircuitStatePacket packet)
        {
            foreach (var state in packet.States)
            {
                var netObj = NetObject.GetByNetId(state.Key.Key);

                if (netObj == null || !netObj.enabled)
                {
                    continue;
                }

                var ios = netObj.GetComponentsInChildren <CircuitOutput>();

                if (ios.Length <= state.Key.Value)
                {
                    continue;
                }

                var io = ios[state.Key.Value];

                CurrentlyUpdating = io;
                io.On             = state.Value;
            }

            CurrentlyUpdating      = null;
            HasCalledCircuitUpdate = true;
        }
Ejemplo n.º 2
0
        protected override void OnAwake()
        {
            Input = GetComponentInChildren <CircuitInput>();
            Input.CircuitLogicComponent = this;

            Output = GetComponentInChildren <CircuitOutput>();
        }
Ejemplo n.º 3
0
        public static bool TryGetKeyFromOutput(CircuitOutput output, out StateKey key, bool clearCache = false)
        {
            if (clearCache || !KeysCache.TryGetValue(output, out key))
            {
                var component = ComponentPlacer.FullComponent(output.transform);

                var netObj = component.GetComponent <NetObject>();

                if (netObj == null)
                {
                    key = default(StateKey);
                    return(false);
                }

                byte ioIndex = 0;

                foreach (var item in component.GetComponentsInChildren <CircuitOutput>())
                {
                    if (item == output)
                    {
                        break;
                    }

                    ioIndex++;
                }

                key = KeysCache[output] = new KeyValuePair <int, byte>(netObj.NetID, ioIndex);
            }

            return(true);
        }
Ejemplo n.º 4
0
 public static void SetOutputState(CircuitOutput output, bool value, bool clearCache = false)
 {
     if (ComponentActions.TryGetKeyFromOutput(output, out var key, clearCache))
     {
         CurrentState[key] = Updated[key] = value;
     }
 }
 // connectedoutputs list management
 public void ConnectOutput(CircuitOutput penis)
 {
     ConnectedOutputs.Add(penis);
     if (penis.On != On)
     {
         QueueCircuitLogicUpdate();
     }
 }
    // check if there is already a connection between two pegs
    public static bool ConnectionExists(GameObject peg1, GameObject peg2)
    {
        if (peg1 == null || peg2 == null)
        {
            return(true);
        }
        if (peg1.tag == "Output" && peg2.tag == "Output")
        {
            return(true);
        }                                                                  // technically this should return null or something, but aside from the fact that booleans are non-nullable, we should disable any connection between two outputs

        // find the types that each thing is by trying to access its CircuitInput or Output
        CircuitInput  thing1input  = peg1.GetComponent <CircuitInput>();
        CircuitOutput thing1output = peg1.GetComponent <CircuitOutput>();
        CircuitInput  thing2input  = peg2.GetComponent <CircuitInput>();
        CircuitOutput thing2output = peg2.GetComponent <CircuitOutput>();

        if (thing1input != null && thing2input != null) // if this would be an InputInputConnection
        {
            foreach (InputInputConnection connection in thing1input.IIConnections)
            {
                // return true if any of the point's connections have the two things as points. Probably there's a terser way to do this but sadly I don't know that particular nuance of C#.
                if (connection.Input1 == thing1input && connection.Input2 == thing2input)
                {
                    return(true);
                }
                if (connection.Input1 == thing2input && connection.Input2 == thing1input)
                {
                    return(true);
                }
            }
        }

        else if (thing1input != null && thing2output != null) // if this would be an InputOutputConnection and thing1 is the input
        {
            foreach (InputOutputConnection connection in thing1input.IOConnections)
            {
                if (connection.Input == thing1input && connection.Output == thing2output)
                {
                    return(true);
                }
            }
        }

        else if (thing1output != null && thing2input != null) // if this would be an InputOutputConnection and thing2 is the input
        {
            foreach (InputOutputConnection connection in thing2input.IOConnections)
            {
                if (connection.Input == thing2input && connection.Output == thing1output)
                {
                    return(true);
                }
            }
        }

        // if none of the true cases were found, return false
        return(false);
    }
Ejemplo n.º 7
0
    // destroys an output
    public static void DestroyOutput(CircuitOutput output)
    {
        InputOutputConnection[] DestroyTheseIOs = output.GetIOConnections().ToArray();
        foreach (InputOutputConnection connection in DestroyTheseIOs)
        {
            DestroyIOConnection(connection);
        }

        // destroy the physical object now that all the behind the scenes circuitry stuff is out of the way
        Object.Destroy(output.gameObject);
    }
 public override void SetPegsBasedOnPoints()
 {
     if (Point1.parent.tag == "Input")
     {
         Input  = Point1.parent.GetComponent <CircuitInput>();
         Output = Point2.parent.GetComponent <CircuitOutput>();
     }
     else
     {
         Input  = Point2.parent.GetComponent <CircuitInput>();
         Output = Point1.parent.GetComponent <CircuitOutput>();
     }
 }
Ejemplo n.º 9
0
        public static bool set_On(CircuitOutput __instance, bool value)
        {
            if (Network.IsClient && ComponentActions.CurrentlyUpdating != __instance)
            {
                return(false);
            }

            if (Network.IsServer)
            {
                var component = ComponentPlacer.FullComponent(__instance.transform);
                var netObj    = component.GetComponent <NetObject>();

                if (netObj == null)
                {
                    component.AddComponent <NetObject>();
                }

                CircuitStatePacket.SetOutputState(__instance, value);
            }

            return(true);
        }
    // joins an output with an input by sticking the output in the cluster of the input
    public static void LinkInputOutput(InputOutputConnection connection)
    {
        CircuitInput  input  = connection.Input;
        CircuitOutput output = connection.Output;

        if (input == null || output == null)
        {
            Debug.LogError("this wire didn't have its input/output set!"); return;
        }

        if (input.Cluster != null)
        {
            input.Cluster.ConnectOutput(output);
        }

        else
        {
            WireCluster NewCluster = Object.Instantiate(Prefabs.Cluster).GetComponent <WireCluster>();
            NewCluster.ConnectInput(input);
            NewCluster.ConnectOutput(output);
            NewCluster.transform.parent = ProperClusterParent(NewCluster); // this is also done the next frame when the cluster recalculates its mesh. The reason it is being done here is because when a board is cloned, it gets new clusters, and those need to be children of the board during the same frame they start existing so that autocombineonstable can be set to false for them by StuffPlacer.NewThingBeingPlaced. My hope is that it doesn't affect performance, but I'm pretty nervous about it...
        }
    }
 public void RemoveOutput(CircuitOutput penis)
 {
     ConnectedOutputs.Remove(penis);
 }
Ejemplo n.º 12
0
 protected override void OnAwake()
 {
     Input  = GetComponentInChildren <CircuitInput>();
     Output = GetComponentInChildren <CircuitOutput>();
 }