public void Visit(CircuitBoard circuit) { foreach (var node in inputNodes) { visitRecursively(new List <string>(), node); } }
public static void NewBoardBeingPlaced(GameObject NewBoard) { if (NewBoard == null) { return; } DestroyBoardBeingPlaced(); BoardBeingPlaced = NewBoard; NewBoard.transform.parent = ReferenceObject.transform; CircuitBoardBeingPlaced = NewBoard.GetComponent <CircuitBoard>(); SetRotationState(); CapPlacingOffset(); StuffPlacer.BoardRotationLockAngle = Mathf.Round(StuffPlacer.BoardRotationLockAngle / 90f) * 90; // fixes being able to place boards at non-right angles by locking rotation beforehand StuffPlacer.RotationAboutUpVector = Mathf.RoundToInt(StuffPlacer.RotationAboutUpVector / 90) * 90f; if (!BoardBeingPlaced.GetComponent <ObjectInfo>()) { BoardBeingPlaced.AddComponent <ObjectInfo>().ComponentType = ComponentType.CircuitBoard; } BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(NewBoard); StuffPlacer.NewThingBeingPlaced(ReferenceObject); }
public static PlaceBoardPacket BuildFromBoard(CircuitBoard board, Transform parent) { var netObj = board.GetComponent <NetObject>(); if (netObj == null) { netObj = board.gameObject.AddComponent <NetObject>(); netObj.NetID = NetObject.GetNewID(); } var packet = new PlaceBoardPacket { AuthorID = NetworkClient.Instance.PlayerID, ParentBoardID = parent?.GetComponent <NetObject>()?.NetID ?? 0, Position = board.transform.position, EulerAngles = board.transform.eulerAngles }; var savedObj = SavedObjectUtilities.CreateSavedObjectFrom(board.gameObject); using (var mem = new MemoryStream()) { BinFormatter.Serialize(mem, savedObj); packet.SavedBoard = mem.ToArray(); } return(packet); }
public void Place() { if (!CurrentPlacementIsValid) { SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething); return; } StuffPlacer.RemoveOutlineFromObject(BoardBeingStacked); StuffPlacer.SetStateOfAllBoxCollidersIn(BoardBeingStacked, true); FloatingPointRounder.RoundIn(BoardBeingStacked, true); SnappingPeg.TryToSnapIn(BoardBeingStacked); MegaMeshManager.AddComponentsIn(StackedBoard); foreach (VisualUpdaterWithMeshCombining visualboi in StackedBoard.GetComponentsInChildren <VisualUpdaterWithMeshCombining>()) { visualboi.AllowedToCombineOnStable = true; } SoundPlayer.PlaySoundAt(Sounds.PlaceOnBoard, BoardBeingStacked); BoardBeingStacked = null; BoardBeingStackedCircuitBoard = null; AllSubBoardsInvolvedWithStacking = new List <GameObject>(); Done(); }
public bool LoadedMount = false; // set in LoadSaveObject private void Start() { if (!LoadedMount)// only do this for new mounts. This is uncomfortably hacky { GameObject TheBoardPart = Instantiate(References.Prefabs.CircuitBoard, transform); TheBoardPart.transform.localPosition = new Vector3(-0.15f, 0.65f, -0.15f); TheBoardPart.transform.localEulerAngles = new Vector3(0, 90, 90); TheBoardPart.AddComponent <ObjectInfo>().ComponentType = ComponentType.CircuitBoard; TheBoardPart.tag = "PlaceOnlyCircuitBoard"; Destroy(TheBoardPart.GetComponent <MegaMeshComponent>()); CircuitBoard board = TheBoardPart.GetComponent <CircuitBoard>(); board.CreateCuboid(); board.SetBoardColor(Color.white); // necessary for the board to appear in the selection menu MegaMeshManager.RemoveComponentImmediatelyOf(TheBoardPart); if (gameObject.layer == 5) { TheBoardPart.layer = 5; } if (StuffPlacer.GetThingBeingPlaced == gameObject) { StuffPlacer.NewThingBeingPlaced(gameObject); } // holy shit this is a terrible line of code. God damn. } else { transform.GetChild(1).tag = "PlaceOnlyCircuitBoard"; // this tag is applied to prevent actions like board moving and painting } Destroy(this); }
private void LoadCircuitBoard(Image image) { circuitBoard = CircuitBoard.FromImage(image); update = true; bitmap?.Dispose(); bitmap = new Bitmap1(Dx.D2D.Context, new Size2(image.Width, image.Height), new BitmapProperties1(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Ignore))); ResetTransformation(); }
private void ShowCircuitBtn_Click(object sender, RoutedEventArgs e) { string[] lines = Filereader.Instance.readFile(); circuitBoard = Fileparser.Instance.ParseCircuit(lines); if (circuitBoard != null) { drawCircuit(); } }
private static void LoadCircuitBoard(GameObject LoadedObject, SavedCircuitBoard save) { CircuitBoard board = LoadedObject.GetComponent <CircuitBoard>(); board.x = save.x; board.z = save.z; board.SetBoardColor(save.color); board.CreateCuboid(); }
public void Visit(CircuitBoard circuit) { // Choosing to only throw a exception and warn the user that the board is unusable because technically boards with infinite loops can be made // They just can't be used foreach (var node in inputNodes) { visitRecursively(new List <string>(), node); } }
public Circuitry() { var centralPort = new Point(0, 0); var wireOne = new Wire(_commandsWireOne, centralPort); var wireTwo = new Wire(_commandsWireTwo, centralPort); _circuitBoard = new CircuitBoard(centralPort, new List <Wire> { wireOne, wireTwo }); }
private static void LoadCircuitBoard(GameObject LoadedObject, SavedObject save) { object[] data = save.CustomDataArray; CircuitBoard board = LoadedObject.GetComponent <CircuitBoard>(); board.x = (int)data[0]; board.z = (int)data[1]; board.SetBoardColor((Color)data[2]); board.CreateCuboid(); }
public static void CreateNewBoard(int x, int z) { GameObject NewBoard = Object.Instantiate(References.Prefabs.CircuitBoard, BoardPlacer.ReferenceObject.transform); // set the board's dimensions CircuitBoard board = NewBoard.GetComponent <CircuitBoard>(); board.x = x; board.z = z; board.CreateCuboid(); BoardPlacer.NewBoardBeingPlaced(NewBoard); }
public override string Run() { var contents = Tools.GetFileContents("dec3"); var wireList = WireParser.Parse(contents); var circBoard = new CircuitBoard(wireList); var result = circBoard.CalculateManhattanDistance(); sb.AppendLine($"\n\tPart 1: {result.ToString()}"); result = circBoard.CalculateFewestSteps(); sb.AppendLine($"\n\tPart 2: {result.ToString()}"); return(sb.ToString()); }
public GameObject Board(int width, int height, Vector3 position, Quaternion rotation, Transform parent = null) { GameObject board = UnityEngine.Object.Instantiate(boardPlacer.BoardPrefab, position, rotation, parent); CircuitBoard circuit = board.GetComponent <CircuitBoard>(); circuit.x = width; circuit.z = height; circuit.CreateCuboid(); StuffPlacer.DestroyIntersectingConnections(board); DestroyInvalidWiresOnBoard(board); MegaMesh.AddMeshesFrom(board); MegaBoardMeshManager.AddBoardsFrom(board); SetChildCircuitsMegaMeshStatus(board, true); return(board); }
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); }
public CircuitBoard BuildCircuit(string[] _lines) { CircuitBoard board = new CircuitBoard(); string[] lines = _lines; if (lines == null) { return(null); } bool parseNeighbours = false; var nodes = new List <CircuitNode>(); foreach (var line in lines) { if (IsDescription(line)) { parseNeighbours = true; continue; } else if ((parseNeighbours && !IsComment(line))) // post-description of logic { var split = line.Split(':'); var name = split[0]; var neighbours = split[1].Trim(';').Split(','); var node = nodes.Find(x => x.Name == name); foreach (var n in neighbours) { string clean = Regex.Replace(n, "[^A-Za-z0-9]", ""); var neighbourNode = nodes.Find(x => x.Name == clean); node.Edges.Add(clean); if (node.Type.Contains("INPUT_LOW")) { node.inputValue(0); } else if (node.Type.Contains("INPUT_HIGH")) { node.inputValue(1); } neighbourNode.inputValue(node.value); } } else if (!IsComment(line) && line != "") // pre-description of logic { string[] split = line.Split(':'); string name = split[0].Trim(); string type = split[1].Trim(';').Trim(); INodeSelectionStrategy strategy; if (SpecialNodeSelectionStrategy.types.Contains(type.ToUpper())) { strategy = new SpecialNodeSelectionStrategy(); } else { strategy = new DefaultNodeSelectionStrategy(); } var node = factory.Create(strategy.GetNodeType(type)); node.Name = name; node.Type = type; nodes.Add(node); } } board.circuitNodes = nodes; return(board); }
/// <summary> /// Converts SaveThisObject into serializable data structures /// </summary> /// <param name="obj">The SaveThisObject to convert</param> /// <returns>A serializable Datum containing the data in the SaveThisObject</returns> public static Datum Convert(SaveThisObject obj) { bool panel = obj.ObjectType.StartsWith("Panel") || obj.ObjectType == "Through Blotter"; Datum result = null; switch (obj.ObjectType) { case "CircuitBoard": List <Datum> children = new List <Datum>(obj.transform.childCount); CircuitBoard comp = obj.GetComponent <CircuitBoard>(); foreach (Transform child in obj.transform) { SaveThisObject save = child.GetComponent <SaveThisObject>(); if (save != null) { children.Add(Convert(save)); } } Renderer renderer = obj.GetComponent <Renderer>(); result = new BoardDatum { width = comp.x, height = comp.z, children = children.ToArray(), color = renderer.material.color }; break; case "Wire": result = new WireDatum { isInputInput = obj.GetComponent <InputInputConnection>() != null, localScale = obj.transform.localScale }; break; case "Inverter": NotGate gate = obj.GetComponent <NotGate>(); result = new InverterDatum { inputOn = gate.Input.On, outputOn = gate.Output.On }; break; case "Peg": result = new PegDatum { isOn = obj.GetComponent <CircuitInput>().On }; break; case "Delayer": Delayer delayer = obj.GetComponent <Delayer>(); result = new DelayerDatum { inputOn = delayer.Input.On, outputOn = delayer.Output.On, delayCount = delayer.DelayCount }; break; case "Through Peg": CircuitInput[] inputs = obj.GetComponentsInChildren <CircuitInput>(); result = new ThroughPegDatum { isOn = inputs[0].On }; break; case "Switch": case "Panel Switch": result = new SwitchDatum { panel = panel, isOn = obj.GetComponent <Switch>().On }; break; case "Button": case "Panel Button": Button button = obj.GetComponent <Button>(); result = new ButtonDatum { panel = panel, isOn = button.output.On, downTime = button.ButtonDownTime }; break; case "Display": case "Panel Display": result = new DisplayDatum { panel = panel, isOn = obj.GetComponent <global::Display>().Input.On }; break; case "Label": case "Panel Label": Label label = obj.GetComponent <Label>(); result = new LabelDatum { panel = panel, text = label.text.text, fontSize = label.text.fontSize }; break; case "Blotter": case "Through Blotter": Blotter blotter = obj.GetComponent <Blotter>(); result = new BlotterDatum { through = panel, inputOn = blotter.Input.On, outputON = blotter.Output.On }; break; } result.localPosition = obj.transform.localPosition; result.localAngles = obj.transform.localEulerAngles; return(result); }
Fileparser() { circuitBoard = new CircuitBoard(); circuitBuilder = new CircuitBuilder(); }
public CircuitBoard ParseCircuit(string[] _lines) { circuitBoard = circuitBuilder.BuildCircuit(_lines); return(circuitBoard); }
// Use this for initialization void Start() { //_speed = 50; //_rotation_speed = 90; _maxSpeed = 3; maxWidth = calculateMaxWidth(); maxHeight = calculateMaxHeight(); shipVelocity = new Vector2(0,0); shipAngle = 0; //Debug.Log ("ShipComponentLength0: "+ shipMap.GetLength(0) + ", shipcomponentLength1: "+ shipMap.GetLength(1)); //Debug.Log ("MaxWidth: " + maxWidth + ", maxHeight: " + maxHeight); componentArray = new GameObject[7, 5]; int xPosition = -100; int yPosition = 100; circuitBoardScript = GetComponent("CircuitBoard") as CircuitBoard; for(int i = 0; i < shipMap.GetLength(0); ++i) { xPosition = -300; for(int j = 0; j < shipMap.GetLength(1); ++j) { int val = shipMap[i,j]; switch(val) { case 1: { componentArray[i,j] = (GameObject)Instantiate(passthroughPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 2: { componentArray[i,j] = (GameObject)Instantiate(powersupplyPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 3: { componentArray[i,j] = (GameObject)Instantiate(thrusterPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 4: { componentArray[i,j] = (GameObject)Instantiate(gunPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } default: { break; } } xPosition += tileX; } yPosition -= tileY; } circuitBoardScript.setGameObjectArray(ref shipMap, ref maxWidth, ref maxHeight); //this.transform.position = new Vector2(1.736f, -125.52f); followship = Camera.main.GetComponent("FollowShip") as FollowShip; followship.player = this.transform; followship.circuitBoardScript = circuitBoardScript; followship.enabled = true; //FollowShip temp = Camera.main.GetComponent("FollowShip") as FollowShip; //temp.player = this.transform; //temp.circuitBoardScript = circuitBoardScript; //temp.enabled = true; centerofMass = computeCenterOfMass(); }
// Use this for initialization void Awake() { instance = this; }
public InfiniteLoopValidator(CircuitBoard circuit) { this.circuit = circuit; circuit.RefreshInputNodes(); this.inputNodes = circuit.inputNodes; }
// chirst, what a giant f*****g method // I may be wrong, but I think this is one of the rare cases where refactoring to smaller methods won't really help... private static void MoveOnBoard(RaycastHit hit, bool AllowEdgePlacement = false) { // some important variables for later in the function Vector3 LocalPosition = hit.collider.transform.InverseTransformPoint(hit.point); CircuitBoard ParentBoard = hit.collider.gameObject.GetComponent <CircuitBoard>(); Vector2Int BoardCoordinates = new Vector2Int(Mathf.RoundToInt((LocalPosition.x - 0.15f) / 0.3f), Mathf.RoundToInt((LocalPosition.z - 0.15f) / 0.3f)); // get the integer coordinates on the board by converting from the 0.3 scale // get the proper y position and direction to point // this is a fairly messy logic chain that could definitely be cleaned up a lot... float YPosition = 0; bool edge = true; Vector3 LocalRotation = Vector3.zero; Transform parentboard = hit.collider.transform; if (AllowEdgePlacement && hit.normal == parentboard.right) { LocalRotation = MoveOnBoardData.Right; } else if (AllowEdgePlacement && hit.normal == -parentboard.right) { LocalRotation = MoveOnBoardData.Left; } else if (AllowEdgePlacement && hit.normal == parentboard.forward) { LocalRotation = MoveOnBoardData.Forward; } else if (AllowEdgePlacement && hit.normal == -parentboard.forward) { LocalRotation = MoveOnBoardData.Back; } else { edge = false; if (LocalPosition.y > 0) { LocalRotation = MoveOnBoardData.Top; YPosition = 0.075f; } else { LocalRotation = MoveOnBoardData.Bottom; YPosition = -0.075f; } } // cap the coordinates before determining the position if (BoardCoordinates.x >= ParentBoard.x) { BoardCoordinates.x = ParentBoard.x - 1; } if (BoardCoordinates.y >= ParentBoard.z) { BoardCoordinates.y = ParentBoard.z - 1; } if (BoardCoordinates.x < 0) { BoardCoordinates.x = 0; } if (BoardCoordinates.y < 0) { BoardCoordinates.y = 0; } ThingBeingPlaced.transform.parent = hit.collider.transform; // when placing on a board, we should parent it to that board ThingBeingPlaced.transform.localPosition = new Vector3(BoardCoordinates.x + 0.5f, YPosition / 0.3f, BoardCoordinates.y + 0.5f) * 0.3f; // the +0.5fs are to make it within the grid, not on the lines ThingBeingPlaced.transform.localEulerAngles = LocalRotation; // apply rotation about the up vector float ThisRotationAboutUpVector = RotationAboutUpVector + 180; // +180 is so that stuff faces away from you rather than towards you if (!edge) // placing angle has no effect when on an edge. By extension, neither does rotation lock. { if (RotationLocked) { ThisRotationAboutUpVector -= BoardRotationLockAngle + 180; } // look, I don't know why, okay? It just works. else { // angle is based on viewing angle if rotation lock is off ThingBeingPlaced.transform.forward = FirstPersonInteraction.FirstPersonCamera.transform.forward; ThisRotationAboutUpVector -= Mathf.RoundToInt(ThingBeingPlaced.transform.localEulerAngles.y / 90) * 90; // I've no idea why this needs to be minus and not plus, but it doesn't work properly with plus ThingBeingPlaced.transform.localEulerAngles = LocalRotation; } } ThingBeingPlaced.transform.Rotate(ThingBeingPlaced.transform.up, ThisRotationAboutUpVector, Space.World); // since the boardcoordinates are capped, edge boards will be placed by default half a unit inside the board. This fixes that if (edge) { ThingBeingPlaced.transform.Translate(hit.normal * 0.15f, Space.World); } MostRecentBoardPlacementWasOnEdge = edge; }
public void Visit(CircuitBoard circuit) { circuit.circuitNodes.ForEach(CircuitNode => drawEdges(CircuitNode)); }
// Use this for initialization void Start() { //_speed = 50; //_rotation_speed = 90; _maxSpeed = 3; maxWidth = calculateMaxWidth(); maxHeight = calculateMaxHeight(); shipVelocity = new Vector2(0, 0); shipAngle = 0; //Debug.Log ("ShipComponentLength0: "+ shipMap.GetLength(0) + ", shipcomponentLength1: "+ shipMap.GetLength(1)); //Debug.Log ("MaxWidth: " + maxWidth + ", maxHeight: " + maxHeight); componentArray = new GameObject[7, 5]; int xPosition = -100; int yPosition = 100; circuitBoardScript = GetComponent("CircuitBoard") as CircuitBoard; for (int i = 0; i < shipMap.GetLength(0); ++i) { xPosition = -300; for (int j = 0; j < shipMap.GetLength(1); ++j) { int val = shipMap[i, j]; switch (val) { case 1: { componentArray[i, j] = (GameObject)Instantiate(passthroughPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 2: { componentArray[i, j] = (GameObject)Instantiate(powersupplyPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 3: { componentArray[i, j] = (GameObject)Instantiate(thrusterPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } case 4: { componentArray[i, j] = (GameObject)Instantiate(gunPrefab, new Vector3(xPosition, yPosition, 0), Quaternion.identity); break; } default: { break; } } xPosition += tileX; } yPosition -= tileY; } circuitBoardScript.setGameObjectArray(ref shipMap, ref maxWidth, ref maxHeight); //this.transform.position = new Vector2(1.736f, -125.52f); followship = Camera.main.GetComponent("FollowShip") as FollowShip; followship.player = this.transform; followship.circuitBoardScript = circuitBoardScript; followship.enabled = true; //FollowShip temp = Camera.main.GetComponent("FollowShip") as FollowShip; //temp.player = this.transform; //temp.circuitBoardScript = circuitBoardScript; //temp.enabled = true; centerofMass = computeCenterOfMass(); }
public NoDeadEndValidator(CircuitBoard circuit) { this.circuit = circuit; circuit.RefreshInputNodes(); this.inputNodes = circuit.inputNodes; }