Esempio n. 1
0
    private void TryCommit()
    {
        CellCoordinates _end = m_passedThrough.Peek();
        GridObject      end  = m_gridManager.GetCell(_end);

        if (end == null)
        {
            Log("WireManager: Commit attempted on an empty cell " + _end.ToString() + ", ending mode.");
            ResetMode();
            return;
        }
        if (m_passedThrough.Count < 3)
        {
            Log("WireManager: Commit attempted with too few cells passed through.");
            ResetMode();
            return;
        }

        // Generate wire objects
        List <CellCoordinates> coordinates = new List <CellCoordinates>(m_passedThrough);

        coordinates.Reverse();         // Probably?
        Wire toCreate = new Wire(coordinates.GetRange(1, coordinates.Count - 2).ToArray(), coordinates[0], coordinates[coordinates.Count - 1]);

        // Insert wire into grid
        m_gridManager.InsertObject(toCreate);
        m_gameplayManager.UpdateGiblets(toCreate.Entry);
        m_gameplayManager.UpdateGiblets(toCreate.Exit);

        Log("WireManager: Successfully committed at " + _end.ToString());
        ResetMode();
    }
Esempio n. 2
0
    ///////////////////////// Helpers /////////////////////////
    private void StartDragging(CellCoordinates _start)
    {
        GridObject gridObject = m_gridManager.GetCell(_start);

        if (gridObject != null && (gridObject.ObjectType == GridObjectType.Gate || gridObject.ObjectType == GridObjectType.Input))
        {
            Log("WireManager: Starting drag from " + _start.ToString());
            m_passedThrough.Push(_start);
            m_isDragging = true;
        }
    }
Esempio n. 3
0
        public override void OnGUI(
            Rect position, SerializedProperty property, GUIContent label
            )
        {
            CellCoordinates coordinates = new CellCoordinates(
                property.FindPropertyRelative("x").intValue,
                property.FindPropertyRelative("z").intValue
                );

            position = EditorGUI.PrefixLabel(position, label);
            GUI.Label(position, coordinates.ToString());
        }
Esempio n. 4
0
    private void PassThroughCell(CellCoordinates _cell)
    {
        if (m_passedThrough.Peek() != _cell)
        {
            CellCoordinates head = m_passedThrough.Pop();
            if (_cell != head && IsAdjacentTo(_cell, head))
            {
                // Wait till we move, and only consider if it is adjacent
                if (m_passedThrough.Count >= 1)
                {
                    CellCoordinates prev = m_passedThrough.Pop();
                    if (_cell == prev)
                    {
                        // Early out if we went backwards
                        Log("WireManager: Going backwards to " + _cell.ToString());
                        m_passedThrough.Push(prev);
                        return;
                    }
                    m_passedThrough.Push(prev);
                }
                else
                {
                    // This is the first move, assert that we head onto a valid OUTPUT of our starting gate
                    GridObject gridObject = m_gridManager.GetCell(head);
                    switch (gridObject.ObjectType)
                    {
                    case GridObjectType.Input:
                    {
                        InputCell input = (InputCell)gridObject;
                        if (input.Exit != _cell)
                        {
                            m_passedThrough.Push(head);                                       // Put the head back on and early out, this is not the exit cell
                            return;
                        }
                        break;
                    }

                    case GridObjectType.Gate:
                    {
                        Gate gate    = (Gate)gridObject;
                        bool isValid = false;
                        foreach (CellCoordinates output in gate.Outputs)
                        {
                            if (output == _cell)
                            {
                                isValid = true;
                            }
                        }
                        if (!isValid)
                        {
                            m_passedThrough.Push(head);                                       // We are not over any valid output cell, put the head back on and early out
                            return;
                        }
                        break;
                    }

                    default:
                    {
                        Debug.LogError("WireManager: PassThrough found starting position that wasn't a Gate or Input.");
                        m_passedThrough.Push(head);                                   // Put the head back on and early out
                        return;
                    }
                    }
                }
                m_passedThrough.Push(head);                   // Put the head back on, moving forwards

                GridObject headObject = m_gridManager.GetCell(head);
                if ((m_passedThrough.Count == 1 || headObject == null || (headObject.ObjectType != GridObjectType.Gate && headObject.ObjectType != GridObjectType.Output)) &&
                    !m_passedThrough.Contains(_cell))
                {
                    // Check we haven't been here before on this path, and that we haven't already arrived at a destination
                    GridObject cellObject = m_gridManager.GetCell(_cell);
                    if (cellObject == null)
                    {
                        // Cell is unoccupied, add it
                        Log("WireManager: Passing through " + _cell.ToString());
                        m_passedThrough.Push(_cell);
                    }
                    else
                    {
                        // Need to check it's a valid goal and we arrived in an acceptable way
                        switch (cellObject.ObjectType)
                        {
                        case GridObjectType.Gate:
                        {
                            Gate gate    = (Gate)cellObject;
                            bool isValid = false;
                            foreach (CellCoordinates input in gate.Inputs)
                            {
                                if (input == head)
                                {
                                    isValid = true;
                                    break;
                                }
                            }
                            if (isValid)
                            {
                                // Head lines up with an input for this gate so add Gate as end point
                                Log("WireManager: Passing through " + _cell.ToString());
                                m_passedThrough.Push(_cell);
                            }
                            else
                            {
                                return;
                            }
                            break;
                        }

                        case GridObjectType.Output:
                        {
                            OutputCell output = (OutputCell)cellObject;
                            if (output.Entry == head)
                            {
                                // Entry of Output lines up with head, so add Output as end point
                                Log("WireManager: Passing through " + _cell.ToString());
                                m_passedThrough.Push(_cell);
                            }
                            else
                            {
                                ;
                                return;
                            }
                            break;
                        }

                        default:
                        {
                            return;
                        }
                        }
                    }
                }
                return;
            }
            m_passedThrough.Push(head);               // Put the head back on, no new additions
        }
    }