public void Connect(params WriteConnection[] connections) { for (var i = 0; i < this.connections.Length; i++) { Wire.Connect(this.engine, connections[i], this.connections[i]); } }
public void TestRun() { var simulation = new Simulation(10); var andGate = new AndGate(1, simulation); var notGate = new NotGate(1, simulation); Wire.Connect(andGate.Output, notGate.Input); Assert.AreEqual(Signal.Undefined, andGate.Output.Signal); Assert.AreEqual(Signal.Undefined, notGate.Output.Signal); andGate.Input1.Signal = Signal.On; andGate.Input2.Signal = Signal.Off; simulation.SimulateNextTimeframe(); // czas 0 - nie ma żadnych zdarzeń do przetworzenia simulation.SimulateNextTimeframe(); // czas 1 - zmiany sygnalu przetworzone na bramce and simulation.SimulateNextTimeframe(); // czas 2 - zmiana sygnalu przetworzona na bramce not Assert.AreEqual(Signal.Off, andGate.Output.Signal); Assert.AreEqual(Signal.On, notGate.Output.Signal); andGate.Input2.Signal = Signal.On; simulation.SimulateNextTimeframe(); // czas 3 - nie ma żadnych zdarzeń do przetworzenia simulation.SimulateNextTimeframe(); // czas 4 - zmiana sygnalu przetworzona na bramce and simulation.SimulateNextTimeframe(); // czas 5 - zmiana sygnalu przetworzona na bramce not Assert.AreEqual(Signal.On, andGate.Output.Signal); Assert.AreEqual(Signal.Off, notGate.Output.Signal); }
public void PowerWireLight() { PowerSupplier power = new PowerSupplier(); Wire wire = new Wire(); IndicatorLight light = new IndicatorLight(); wire.Connect(power.Output, light.Input); Assert.IsFalse(light.Lighting); power.On(); Assert.IsTrue(light.Lighting); power.On(); Assert.IsTrue(light.Lighting); power.Off(); Assert.IsFalse(light.Lighting); power.Off(); Assert.IsFalse(light.Lighting); power.Toggle(); Assert.IsTrue(light.Lighting); power.Toggle(); Assert.IsFalse(light.Lighting); power.Toggle(); Assert.IsTrue(light.Lighting); power.Toggle(); Assert.IsFalse(light.Lighting); power.On(); Assert.IsTrue(light.Lighting); light.Input.DisconnectEndpoint(); Assert.IsFalse(light.Lighting); power.On(); Assert.IsFalse(light.Lighting); }
public void ConnectSamePoint() { IInputEndpoint input1 = new InputEndpoint(); IInputEndpoint input2 = new InputEndpoint(); Wire wire = new Wire(input1, input2); wire.Connect(input1, input1); }
public void WireConnectReturnCorrectWire() { var source = new Output(); var target = new Input(); var wire = Wire.Connect(source, target); Assert.AreEqual(wire.Source, source); Assert.AreEqual(wire.Target, target); }
public FlipFlop(int delay, ISimulation simulation) : base(delay, simulation) { setNorGate = new NorGate(delay, simulation); resetNorGate = new NorGate(delay, simulation); Wire.Connect(setNorGate.Output, resetNorGate.Input1); Wire.Connect(resetNorGate.Output, setNorGate.Input2); }
public void ConnectInnerElements(Guid wireId, Guid sourceSocketId, Guid targetSocketId) { var sourceSocket = GetInnerOutputById(sourceSocketId); var targetSocket = GetInnerInputById(targetSocketId); var wire = Wire.Connect(sourceSocket, targetSocket); wire.Id = wireId; innerWires.Add(wire); }
public void ChangesTargetInputAfterSourceOutputChanged() { var source = new Output(); var target = new Input(); Wire.Connect(source, target); source.Signal = Signal.On; Assert.AreEqual(Signal.On, target.Signal); }
public void ConnectNullPointWithoutException() { Wire wire1 = new Wire(); Wire wire2 = new Wire(null, null); IInputEndpoint input = new InputEndpoint(); Wire wire3 = new Wire(input); Wire wire4 = new Wire(input, null); Wire wire5 = new Wire(null, input); Assert.IsNotNull(wire1); Assert.IsNotNull(wire2); Assert.IsNotNull(wire3); Assert.IsNotNull(wire4); Assert.IsNotNull(wire5); wire1.Connect(input, null); wire1.Connect(null, input); wire1.Connect(null, null); }
public void Load(string chipName, GameObject chipHolder) { var loadedChip = Instantiate(chipHolder); loadedChip.transform.parent = transform; List <Chip> topLevelChips = new List <Chip> (GetComponentsInChildren <Chip> ()); var subChips = GetComponentsInChildren <CustomChip> (includeInactive: true); for (int i = 0; i < subChips.Length; i++) { if (subChips[i].transform.parent == loadedChip.transform) { subChips[i].gameObject.SetActive(true); topLevelChips.Add(subChips[i]); } } //topLevelChips.Sort ((a, b) => a.chipSaveIndex.CompareTo (b.chipSaveIndex)); var wiringSaveData = ChipLoader.LoadWiringFile(SaveSystem.GetPathToWireSaveFile(chipName)); int wireIndex = 0; foreach (var savedWire in wiringSaveData.serializableWires) { Wire loadedWire = GameObject.Instantiate(wirePrefab, parent: loadedChip.transform); loadedWire.SetDepth(wireIndex); Pin parentPin = topLevelChips[savedWire.parentChipIndex].outputPins[savedWire.parentChipOutputIndex]; Pin childPin = topLevelChips[savedWire.childChipIndex].inputPins[savedWire.childChipInputIndex]; loadedWire.Connect(parentPin, childPin); loadedWire.SetAnchorPoints(savedWire.anchorPoints); FindObjectOfType <PinAndWireInteraction> ().LoadWire(loadedWire); //player.AddWire (loadedWire); if (childPin.chip is Bus) { childPin.transform.position = savedWire.anchorPoints[savedWire.anchorPoints.Length - 1]; } if (parentPin.chip is Bus) { parentPin.transform.position = savedWire.anchorPoints[0]; } wireIndex++; } this.loadedChipHolder = loadedChip; }
private void UpdateCircuit(bool should_update_anim = true) { if ((UnityEngine.Object)attachedWire != (UnityEngine.Object)null) { if (switchedOn) { attachedWire.Connect(); } else { attachedWire.Disconnect(); } } if (should_update_anim && wasOn != switchedOn) { KBatchedAnimController component = GetComponent <KBatchedAnimController>(); component.Play((!switchedOn) ? "on_pst" : "on_pre", KAnim.PlayMode.Once, 1f, 0f); component.Queue((!switchedOn) ? "off" : "on", KAnim.PlayMode.Once, 1f, 0f); Game.Instance.userMenu.Refresh(base.gameObject); } wasOn = switchedOn; }
public void ConnectLater() { IInputEndpoint input = new InputEndpoint(); Int32 receivedSignal = 0; IEndpoint senderPoint = null; input.Receive += (sdr, signal) => { senderPoint = sdr; receivedSignal = signal; }; IOutputEndpoint output = new OutputEndpoint(); Wire wire = new Wire(); wire.Connect(input, output); output.Produce(1); Assert.AreEqual(receivedSignal, 1); output.Produce(0); Assert.AreEqual(receivedSignal, 0); }
static ChipSaveData LoadChipWithWires(SavedChip chipToLoad, Dictionary <string, Chip> previouslyLoadedChips, Wire wirePrefab, ChipEditor chipEditor) { ChipSaveData loadedChipData = new ChipSaveData(); int numComponents = chipToLoad.savedComponentChips.Length; loadedChipData.componentChips = new Chip[numComponents]; loadedChipData.chipName = chipToLoad.name; loadedChipData.chipColour = chipToLoad.colour; loadedChipData.chipNameColour = chipToLoad.nameColour; loadedChipData.creationIndex = chipToLoad.creationIndex; List <Wire> wiresToLoad = new List <Wire>(); // Spawn component chips (the chips used to create this chip) // These will have been loaded already, and stored in the previouslyLoadedChips dictionary for (int i = 0; i < numComponents; i++) { SavedComponentChip componentToLoad = chipToLoad.savedComponentChips[i]; string componentName = componentToLoad.chipName; Vector2 pos = new Vector2((float)componentToLoad.posX, (float)componentToLoad.posY); if (!previouslyLoadedChips.ContainsKey(componentName)) { Debug.LogError("Failed to load sub component: " + componentName + " While loading " + chipToLoad.name); } Chip loadedComponentChip = GameObject.Instantiate(previouslyLoadedChips[componentName], pos, Quaternion.identity, chipEditor.chipImplementationHolder); loadedComponentChip.gameObject.SetActive(true); loadedChipData.componentChips[i] = loadedComponentChip; // Load input pin names for (int inputIndex = 0; inputIndex < componentToLoad.inputPins.Length && inputIndex < loadedChipData.componentChips[i].inputPins.Length; inputIndex++) { loadedChipData.componentChips[i].inputPins[inputIndex].pinName = componentToLoad.inputPins[inputIndex].name; } // Load output pin names for (int ouputIndex = 0; ouputIndex < componentToLoad.outputPins.Length && ouputIndex < loadedChipData.componentChips[i].outputPins.Length; ouputIndex++) { loadedChipData.componentChips[i].outputPins[ouputIndex].pinName = componentToLoad.outputPins[ouputIndex].name; } } // Connect pins with wires for (int chipIndex = 0; chipIndex < chipToLoad.savedComponentChips.Length; chipIndex++) { Chip loadedComponentChip = loadedChipData.componentChips[chipIndex]; for (int inputPinIndex = 0; inputPinIndex < loadedComponentChip.inputPins.Length && inputPinIndex < chipToLoad.savedComponentChips[chipIndex].inputPins.Length; inputPinIndex++) { SavedInputPin savedPin = chipToLoad.savedComponentChips[chipIndex].inputPins[inputPinIndex]; Pin pin = loadedComponentChip.inputPins[inputPinIndex]; // If this pin should receive input from somewhere, then wire it up to that pin if (savedPin.parentChipIndex != -1) { Pin connectedPin = loadedChipData.componentChips[savedPin.parentChipIndex].outputPins[savedPin.parentChipOutputIndex]; pin.cyclic = savedPin.isCylic; if (Pin.TryConnect(connectedPin, pin)) { Wire loadedWire = GameObject.Instantiate(wirePrefab, chipEditor.wireHolder); loadedWire.Connect(connectedPin, pin); wiresToLoad.Add(loadedWire); } } } } loadedChipData.wires = wiresToLoad.ToArray(); return(loadedChipData); }
void CheckWire(bool rightArm, float triggerValue, HingeJoint2D connector, CircleCollider2D col) { if (triggerValue > .5f && !connector.enabled) // if trigger down // find all nearby things on connect layer { int count = Physics2D.OverlapCircleNonAlloc(col.transform.position, col.radius * col.transform.localScale.x, overlapArr, 1 << 8); // find closest object Collider2D closestOverlap = null; float distance = float.PositiveInfinity; for (int i = 0; i < count; i++) { if (overlapArr[i] == rightCol || overlapArr[i] == leftCol) { continue; } float sqr = Vector2.SqrMagnitude(overlapArr[i].transform.position - col.transform.position); if (sqr < distance) { distance = sqr; closestOverlap = overlapArr[i]; } } // if found any object if (closestOverlap) { connector.enabled = true; Rigidbody2D closestRb = closestOverlap.GetComponent <Rigidbody2D>(); wire.Connect(rightArm, closestOverlap); if (rightArm) { rightMotorTime = 0.3f; } else { leftMotorTime = 0.3f; } if (closestRb) { connector.connectedBody = closestRb; } else { connector.connectedAnchor = closestOverlap.transform.position; } } } else if (triggerValue <= .5f && connector.enabled) // else disconnect if trigger isnt down { connector.connectedBody = null; connector.enabled = false; // lock it but dont pop it (to combat electricity) // this doesnt do shit because arms are all rigidbodies too so f this (saving for later) love john, godbless //if (wire.powered) { // Debug.Log("depower"); // float mag = rb2d.velocity.magnitude; // mag = Mathf.Min(mag, 1.0f); // rb2d.velocity = rb2d.velocity.normalized * mag; //} wire.Disconnect(rightArm); } }