void Awake()
    {
        if (transform.parent != null && transform.parent.gameObject.layer == 5)
        {
            return;
        }                                                                                   // don't do this in the UI cuz it won't be visible

        ChildInputs = GetComponentsInChildren <CircuitInput>();

        if (GetComponentInChildren <Wire>())
        {
            return;
        }                                               // if it's on a cloned board it'll already have a wire

        InputInputConnection connection = Instantiate(References.Prefabs.Wire, transform).AddComponent <InputInputConnection>();

        connection.Input1 = ChildInputs[0];
        connection.Input2 = ChildInputs[1];

        connection.DrawWire();
        connection.unbreakable = true;
        StuffConnector.LinkConnection(connection);

        DestroyImmediate(connection.GetComponent <BoxCollider>());
    }
Exemplo n.º 2
0
 // destroys an input-input connection
 public static void DestroyIIConnection(InputInputConnection connection)
 {
     connection.Input1.IIConnections.Remove(connection);
     connection.Input2.IIConnections.Remove(connection);
     RecalculateCluster(connection.Input1.Cluster); // recalculate the clusters, since they might (probably, in fact) need changing now
     Object.Destroy(connection.gameObject);         // destroy the physical connection
 }
Exemplo n.º 3
0
    // determines which type of connection a wire is and passes it off to the appropriate destroyer
    public static void DestroyWire(GameObject wire)
    {
        InputInputConnection IIConnection = wire.GetComponent <InputInputConnection>();

        if (IIConnection != null)
        {
            DestroyIIConnection(IIConnection);
            return; // just for that teeny tiny completely insignificant amount of extra performance, stop the function here if it's an IIConnection
        }

        InputOutputConnection IOConnection = wire.GetComponent <InputOutputConnection>();

        if (IOConnection != null)
        {
            DestroyIOConnection(IOConnection);
        }
    }
    // if the wire is an IIConnection, queue mesh recalculation in the cluster. If it's IO, queue mesh recalculation in the output.
    // currently only used by stuffrotater for rotating wires
    public static void QueueWireMeshRecalculation(GameObject wire)
    {
        if (wire.tag != "Wire")
        {
            return;
        }

        InputInputConnection IIConnection = wire.GetComponent <InputInputConnection>();

        if (IIConnection != null)
        {
            IIConnection.Input1.Cluster.QueueMeshRecalculation();
            return;
        }

        wire.GetComponent <InputOutputConnection>().Output.QueueMeshRecalculation();
    }
    // Triggers WireCluster.ConnectInput in the appropriate cases for a connection. Covers possible cases.
    public static void LinkInputs(InputInputConnection connection)
    {
        CircuitInput input1 = connection.Input1;
        CircuitInput input2 = connection.Input2;

        if (input1 == null || input2 == null)
        {
            Debug.LogError("This wire doesn't have its inputs set!"); return;
        }

        if (input1.Cluster == null && input2.Cluster == null) // if neither input has a cluster, create a new one and add them to it
        {
            WireCluster NewCluster = Object.Instantiate(Prefabs.Cluster).GetComponent <WireCluster>();
            NewCluster.ConnectInput(input1);
            NewCluster.ConnectInput(input2);

            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...
        }

        else if (input1.Cluster == input2.Cluster) // if they're both part of the same cluster already, mesh recalculation needs to happen to incorporate the new wire
        {
            input1.Cluster.QueueMeshRecalculation();
        }

        else if (input1.Cluster != null && input2.Cluster != null && input1.Cluster != input2.Cluster) // if both inputs are part of a cluster, merge those clusters
        {
            JoinClusters(input1.Cluster, input2.Cluster);
        }

        else if (input1.Cluster != null && input2.Cluster == null) // if one input is part of a cluster, connect the other to that cluster
        {
            input1.Cluster.ConnectInput(input2);
        }

        else if (input1.Cluster == null && input2.Cluster != null) // ditto
        {
            input2.Cluster.ConnectInput(input1);
        }

        else
        {
            Debug.Log("no input connection case found");
        }
    }
Exemplo n.º 6
0
        protected override void CircuitLogicUpdate()
        {
            var ChildInputs = GetComponentsInChildren <CircuitInput>();

            if (!this.Inputs[2].On && IIC != null)
            {
                StuffDeleter.DestroyIIConnection(IIC);
                IIC = null;
            }

            if (GetComponentsInChildren <Wire>().Length < 1 && this.Inputs[2].On)
            {
                InputInputConnection inputInputConnection = Instantiate(Prefabs.Wire, base.transform).AddComponent <InputInputConnection>();
                inputInputConnection.Input1 = ChildInputs[0];
                inputInputConnection.Input2 = ChildInputs[1];
                inputInputConnection.DrawWire();
                inputInputConnection.unbreakable = true;
                StuffConnector.LinkConnection(inputInputConnection);
                IIC = inputInputConnection;
            }
        }
    public static bool CurrentWirePlacementIsValid()
    {
        // below: some invalid placement conditions. We must do CanConnect as well as CanFindPoints because each can sometimes return true while the other returns false; sorry, future me, but I'm too lazy to type out exactly what those scenarios are. Figure it out yourself you ungrateful piece of shit
        if (ConnectionExists(SelectedPeg, PegBeingLookedAt) || !WireBeingPlaced.GetComponent <Wire>().CanFindPoints())
        {
            return(false);
        }

        InputInputConnection IIconnection = WireBeingPlaced.GetComponent <InputInputConnection>();

        if (IIconnection != null)
        {
            // for the edge case of color displays
            if (ComponentPlacer.FullComponent(IIconnection.Point1) == ComponentPlacer.FullComponent(IIconnection.Point2))
            {
                return(false);
            }
        }

        // a snapping peg may only have one non-snapped connection
        SnappingPeg TheSnappyPeg = SelectedPeg.GetComponent <SnappingPeg>();

        if (TheSnappyPeg == null)
        {
            TheSnappyPeg = PegBeingLookedAt.GetComponent <SnappingPeg>();
        }
        if (TheSnappyPeg != null)
        {
            int MaxConnections = TheSnappyPeg.SnappedConnection == null ? 1 : 2;
            if (TheSnappyPeg.IIConnections.Count + TheSnappyPeg.IOConnections.Count >= MaxConnections)
            {
                return(false);
            }
        }

        return(true);
    }
    public static SavedObjectV2 CreateSavedObjectFrom(ObjectInfo worldsave)
    {
        //SavedObjectV2 newsavedobject = SaveManager.ObjectTypeToSavedObjectType(save.ObjectType);

        SavedObjectV2 newsavedobject = null;

        switch (worldsave.ComponentType)
        {
        case ComponentType.CustomObject:
            newsavedobject = new SavedCustomObject();
            CreateCustomSavedObject((SavedCustomObject)newsavedobject, worldsave);
            break;

        case ComponentType.CircuitBoard:
            CircuitBoard board = worldsave.GetComponent <CircuitBoard>();
            newsavedobject = new SavedCircuitBoard
            {
                x     = board.x,
                z     = board.z,
                color = board.GetBoardColor
            };
            break;

        case ComponentType.Wire:
            InputInputConnection IIConnection = worldsave.GetComponent <InputInputConnection>();
            newsavedobject = new SavedWire
            {
                InputInput = IIConnection,
                length     = worldsave.transform.localScale.z
            };
            break;

        case ComponentType.Button:
            newsavedobject = new SavedButton();
            break;

        case ComponentType.PanelButton:
            newsavedobject = new SavedPanelButton();
            break;

        case ComponentType.Delayer:
            Delayer delayer = worldsave.GetComponent <Delayer>();
            newsavedobject = new SavedDelayer
            {
                OutputOn   = delayer.Output.On,
                DelayCount = delayer.DelayCount
            };
            break;

        case ComponentType.Display:
            Display display = worldsave.GetComponentInChildren <Display>();
            newsavedobject = new SavedDisplay
            {
                Color = display.DisplayColor
            };
            break;

        case ComponentType.PanelDisplay:
            Display paneldisplay = worldsave.GetComponentInChildren <Display>();
            newsavedobject = new SavedPanelDisplay
            {
                Color = paneldisplay.DisplayColor
            };
            break;

        case ComponentType.Inverter:
            Inverter notgate = worldsave.GetComponent <Inverter>();
            newsavedobject = new SavedInverter
            {
                OutputOn = notgate.Output.On
            };
            break;

        case ComponentType.Label:
            Label label = worldsave.GetComponent <Label>();
            newsavedobject = new SavedLabel
            {
                text     = label.text.text,
                FontSize = label.text.fontSize
            };
            break;

        case ComponentType.PanelLabel:
            Label panellabel = worldsave.GetComponent <Label>();
            newsavedobject = new SavedPanelLabel
            {
                text     = panellabel.text.text,
                FontSize = panellabel.text.fontSize
            };
            break;

        case ComponentType.Switch:     // SWITCH-F*****G-CEPTION
            Switch circuitswitch = worldsave.GetComponentInChildren <Switch>();
            newsavedobject = new SavedSwitch
            {
                on = circuitswitch.On
            };
            break;

        case ComponentType.PanelSwitch:
            Switch panelswitch = worldsave.GetComponentInChildren <Switch>();
            newsavedobject = new SavedPanelSwitch
            {
                on = panelswitch.On
            };
            break;

        case ComponentType.Peg:
            newsavedobject = new SavedPeg();
            break;

        case ComponentType.ThroughPeg:
            newsavedobject = new SavedThroughPeg();
            break;

        case ComponentType.Blotter:
            Blotter blotter = worldsave.GetComponent <Blotter>();
            newsavedobject = new SavedBlotter
            {
                OutputOn = blotter.Output.On
            };
            break;

        case ComponentType.ThroughBlotter:
            Blotter throughblotter = worldsave.GetComponent <Blotter>();
            newsavedobject = new SavedThroughBlotter
            {
                OutputOn = throughblotter.Output.On
            };
            break;

        case ComponentType.ColorDisplay:
            newsavedobject = new SavedColorDisplay();
            break;

        case ComponentType.PanelColorDisplay:
            newsavedobject = new SavedPanelColorDisplay();
            break;

        case ComponentType.Noisemaker:
            Noisemaker noisemaker = worldsave.GetComponentInChildren <Noisemaker>();
            newsavedobject = new SavedNoisemaker
            {
                ToneFrequency = noisemaker.ToneFrequency
            };
            break;

        case ComponentType.SnappingPeg:
            newsavedobject = new SavedSnappingPeg();
            break;

        case ComponentType.Mount:
            newsavedobject = new SavedMount();
            break;

        case ComponentType.VerticalSnappingPeg:
            newsavedobject = new SavedVerticalSnappingPeg();
            break;

        case ComponentType.none:
            Debug.LogError("BIG ERROR tried to save a component with no type!");
            break;
        }

        newsavedobject.LocalPosition    = worldsave.transform.localPosition;
        newsavedobject.LocalEulerAngles = worldsave.transform.localEulerAngles;

        if (newsavedobject.CanHaveChildren)
        {
            newsavedobject.Children = FindChildSaves(worldsave);
        }

        return(newsavedobject);
    }