Esempio n. 1
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() == typeof(ConnectionFile))
            {
                ConnectionFile file = (ConnectionFile)obj;
                if (!file.GetStart()[0].Equals(startTable))
                {
                    return(false);
                }
                if (!file.GetStart()[1].Equals(startSeat))
                {
                    return(false);
                }
                if (!file.GetEnd()[0].Equals(endTable))
                {
                    return(false);
                }
                if (!file.GetEnd()[1].Equals(endSeat))
                {
                    return(false);
                }
                if (!file.GetStrength().Equals(GetStrength()))
                {
                    return(false);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
    //Helper method to spawn connections based on given connection file
    private static void SpawnConnection(ConnectionFile file)
    {
        //Find start and end gameObjects
        GameObject start = null, end = null;

        foreach (NeuronDesignation nd in loadedPlayers)
        {
            //Find start
            if (nd.isGivenNeuron(file.GetStart()[0], file.GetStart()[1]))
            {
                start = nd.GetObject();
            }
            //Find end
            else if (nd.isGivenNeuron(file.GetEnd()[0], file.GetEnd()[1]))
            {
                end = nd.GetObject();
            }
        }
        bool excitatory;

        if (file.GetStrength() > 0)
        {
            excitatory = true;
        }
        else
        {
            excitatory = false;
        }
        if (start && end)
        {
            GameObject player = NetworkManager.singleton.client.connection.playerControllers[0].gameObject;
            player.GetComponent <ConnectionManager>().AcceptConnection(start, end, file.GetStrength().ToString(), excitatory);
        }
    }
Esempio n. 3
0
    public static void ConnectionRemoved(Connection con)
    {
        ConnectionFile file;
        Controller     start = con.GetStart().GetComponent <Controller>();
        Controller     end   = con.GetEnd().GetComponent <Controller>();

        file = new ConnectionFile(start.GetTableNum(), end.GetTableNum(), start.GetSeatNum(), end.GetSeatNum(), con.connectionStrength);

        int endpoint = connectionsToReset.Count;          //Avoid changing list while iterating.

        for (int i = endpoint - 1; i >= 0; i--)
        {
            if (connectionsToReset[i].Equals(con.gameObject))
            {
                connectionsToReset.Remove(con.gameObject);
            }
        }

        endpoint = spawnedConnections.Count;
        for (int i = endpoint - 1; i >= 0; i--)
        {
            if (spawnedConnections[i].Equals(file))
            {
                spawnedConnections.Remove(file);
            }
        }
    }
Esempio n. 4
0
        private void CleanFileList(ConnectionFile connectionFile)
        {
            //var message = $"The file '{connectionFile.Path}' does not exist and will be removed from the list!";
            //MessageBox.Show(this, message, @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            //var index = tscbbConnectionsFile.SelectedIndex != 0 ? tscbbConnectionsFile.SelectedIndex - 1 : 0;
            //ConnectionsList.Instance.Files.Remove(connectionFile);
            //tscbbConnectionsFile.Items.Remove(tscbbConnectionsFile.SelectedItem);
            //tscbbConnectionsFile.SelectedIndex = index;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                var newCc = CrmConnections.LoadFromFile(txtFilePath.Text);
                OpenedFile = new ConnectionFile(newCc)
                {
                    Path     = txtFilePath.Text,
                    Name     = newCc.Name,
                    LastUsed = DateTime.Now
                };

                if (ConnectionsList.Instance.Files.Any(f => f.Name == OpenedFile.Name))
                {
                    int    cloneId = 1;
                    string newName = OpenedFile.Name ?? "New File";

                    while (ConnectionsList.Instance.Files.FirstOrDefault(f => f.Name == newName) != null)
                    {
                        var rule = new System.Text.RegularExpressions.Regex(".* \\(" + cloneId + "\\)$");
                        if (rule.IsMatch(newName))
                        {
                            cloneId++;
                            newName = $"{OpenedFile?.Name?.Replace($" ({cloneId - 1})", "") ?? "New File"} ({cloneId})";
                        }
                        else
                        {
                            newName = $"{newName} ({cloneId})";
                        }
                    }

                    OpenedFile.Name = newName;

                    MessageBox.Show(this, $"A connection file with this name already exists!\n\nIt has been renamed to '{newName}'", "Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                ConnectionManager.ConfigurationFile = txtFilePath.Text;
                ConnectionsList.Instance.Files.First(f => f.Path == txtFilePath.Text).Name = OpenedFile.Name;
                ConnectionManager.Instance.LoadConnectionsList();
                ConnectionsList.Instance.Save();

                OpenedFilePath = txtFilePath.Text;

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(this, "It seems something went wrong when loading your file: " + error,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 6
0
    public static void ConnectionMade(Connection con)
    {
        ConnectionFile file;
        Controller     start = con.GetStart().GetComponent <Controller>();
        Controller     end   = con.GetEnd().GetComponent <Controller>();

        file = new ConnectionFile(start.GetTableNum(), end.GetTableNum(), start.GetSeatNum(), end.GetSeatNum(), con.connectionStrength);
        connectionsToReset.Add(con.gameObject);
        if (!spawnedConnections.Contains(file))
        {
            spawnedConnections.Add(file);
        }
    }
Esempio n. 7
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CrmConnections cc   = new CrmConnections(txtConnectionName.Text);
            var            file = new ConnectionFile(cc)
            {
                Path     = txtFilePath.Text,
                Name     = txtConnectionName.Text,
                LastUsed = DateTime.Now
            };

            if (ConnectionsList.Instance.Files.Any(f => f.Name == cc.Name))
            {
                int    cloneId = 1;
                string newName = file.Name;

                while (ConnectionsList.Instance.Files.FirstOrDefault(f => f.Name == newName) != null)
                {
                    var rule = new System.Text.RegularExpressions.Regex(".* \\(" + cloneId + "\\)$");
                    if (rule.IsMatch(newName))
                    {
                        cloneId++;
                        newName = $"{cc.Name.Replace($" ({cloneId - 1})", "")} ({cloneId})";
                    }
                    else
                    {
                        newName = $"{newName} ({cloneId})";
                    }
                }

                file.Name = newName;

                MessageBox.Show(this, $@"A connection file with this name already exists!\n\nIt has been renamed to '{newName}'", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            cc.SerializeToFile(txtFilePath.Text);
            ConnectionsList.Instance.Save();

            CreatedFilePath = txtFilePath.Text;

            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 8
0
        /// <summary>
        /// Creates or updates a Crm connection
        /// </summary>
        /// <param name="isCreation">Indicates if it is a connection creation</param>
        /// <param name="connectionToUpdate">Details of the connection to update</param>
        /// <param name="connectionFile">List of connections where the connection is edited from</param>
        /// <returns>Created or updated connection</returns>
        public ConnectionDetail EditConnection(bool isCreation, ConnectionDetail connectionToUpdate, ConnectionFile connectionFile = null)
        {
            var cForm = new ConnectionWizard2(connectionToUpdate)
            {
                StartPosition = FormStartPosition.CenterParent
            };

            if (cForm.ShowDialog(innerAppForm) == DialogResult.OK)
            {
                if (isCreation)
                {
                    if (connectionFile == null)
                    {
                        if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                                d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null &&
                            !string.IsNullOrEmpty(cForm.CrmConnectionDetail.ConnectionName))
                        {
                            ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);
                        }

                        ConnectionManager.Instance.SaveConnectionsFile();
                    }
                    else
                    {
                        var connections = CrmConnections.LoadFromFile(connectionFile.Path);
                        if (connections.Connections.FirstOrDefault(
                                d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null &&
                            !string.IsNullOrEmpty(cForm.CrmConnectionDetail.ConnectionName))
                        {
                            connections.Connections.Add(cForm.CrmConnectionDetail);
                        }

                        connections.SerializeToFile(connectionFile.Path);
                    }
                }
                else
                {
                    if (connectionFile == null)
                    {
                        ConnectionManager.Instance.ConnectionsList.Connections
                        .Where(x => x.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                        .ToList()
                        .ForEach(x => x.UpdateAfterEdit(cForm.CrmConnectionDetail));

                        ConnectionManager.Instance.SaveConnectionsFile();
                    }
                    else
                    {
                        var connections = CrmConnections.LoadFromFile(connectionFile.Path);
                        foreach (ConnectionDetail detail in connections.Connections)
                        {
                            if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                            {
                                detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                            }
                        }

                        connections.SerializeToFile(connectionFile.Path);
                    }
                }

                return(cForm.CrmConnectionDetail);
            }

            return(null);
        }
Esempio n. 9
0
    public static void LoadGame(string file)
    {
        StreamReader reader = new StreamReader(file);

        while (!reader.EndOfStream)
        {
            string line = reader.ReadLine();

            //Check if neural connection, sensor connection, muscle connection, or neuron parameter
            string checkNeural = line.Substring(0, 5);
            string checkSensor = line.Substring(0, 6);
            string checkMuscle = line.Substring(0, 6);
            string checkParam  = line.Substring(0, 6);

            if (checkNeural.Equals("Start"))
            {
                //Neural connection, move ahead
                ConnectionFile con;
                //Strip off the formatting to get to numbers
                line = line.Substring(9);                 //Start table number
                int startTable;
                if (!int.TryParse(line.Substring(0, 1), out startTable))
                {
                    Debug.LogError("Start Table format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //Start seat number
                int startSeat;
                if (!int.TryParse(line.Substring(0, 1), out startSeat))
                {
                    Debug.LogError("Start Seat format incorrect");
                    continue;
                }
                line = line.Substring(10);                 //End table number
                int endTable;
                if (!int.TryParse(line.Substring(0, 1), out endTable))
                {
                    Debug.LogError("End Table format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //End seat number
                int endSeat;
                if (!int.TryParse(line.Substring(0, 1), out endSeat))
                {
                    Debug.LogError("End Seat format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //Strength
                float strength;
                if (!float.TryParse(line, out strength))
                {
                    Debug.LogError("Strength format incorrect");
                    continue;
                }
                con = new ConnectionFile(startTable, endTable, startSeat, endSeat, strength);
                connectionsToLoad.Add(con);
            }
            else if (checkSensor.Equals("Sensor"))
            {
                //Sensor connection, move ahead
                SensorConnectionFile sen;
                //Strip off the formatting to get to numbers
                line = line.Substring(10);                 //Sensor table number
                int sensorTable;
                if (!int.TryParse(line.Substring(0, 1), out sensorTable))
                {
                    Debug.LogError("Sensor Table format incorrect");
                    continue;
                }
                line = line.Substring(11);                 //Sensor location
                Sensor.SensorLocation location;
                switch (line.Substring(0, 1))
                {
                case "P": {
                    //Backward
                    location = Sensor.SensorLocation.Backward;
                    break;
                }

                case "A": {
                    //Forward
                    location = Sensor.SensorLocation.Forward;
                    break;
                }

                default: {
                    //Incorrect
                    Debug.LogError("Sensor Location format incorrect");
                    continue;
                }
                }
                line = line.Substring(10);                 //End table number
                int endTable;
                if (!int.TryParse(line.Substring(0, 1), out endTable))
                {
                    Debug.LogError("End Table format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //End seat number
                int endSeat;
                if (!int.TryParse(line.Substring(0, 1), out endSeat))
                {
                    Debug.LogError("End Seat format incorrect");
                    continue;
                }
                sen = new SensorConnectionFile(sensorTable, location, endTable, endSeat);
                sensorConnectionsToLoad.Add(sen);
            }
            else if (checkMuscle.Equals("Muscle"))
            {
                //Muscle connection, move ahead
                MuscleConnectionFile mus;
                //Strip off the formatting to get to numbers
                line = line.Substring(10);                 //Muscle table number
                int muscleTable;
                if (!int.TryParse(line.Substring(0, 1), out muscleTable))
                {
                    Debug.LogError("Muscle Table format incorrect");
                    continue;
                }
                line = line.Substring(7);                 //Muscle type
                MuscleType type;
                switch (line.Substring(0, 1))
                {
                case "B": {
                    //Backward
                    type = MuscleType.Backward;
                    break;
                }

                case "F": {
                    //Forward
                    type = MuscleType.Forward;
                    break;
                }

                case "D": {
                    //Stance
                    type = MuscleType.Stance;
                    break;
                }

                default: {
                    //Incorrect
                    Debug.LogError("Muscle Type format incorrect");
                    continue;
                }
                }
                line = line.Substring(12);                 //Start table number
                int startTable;
                if (!int.TryParse(line.Substring(0, 1), out startTable))
                {
                    Debug.LogError("Start Table format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //Start seat number
                int startSeat;
                if (!int.TryParse(line.Substring(0, 1), out startSeat))
                {
                    Debug.LogError("Start Seat format incorrect");
                    continue;
                }
                mus = new MuscleConnectionFile(muscleTable, type, startTable, startSeat);
                muscleConnectionsToLoad.Add(mus);
            }
            else if (checkParam.Equals("Neuron"))
            {
                //Neuron parameters, move ahead
                NeuronFile neu;
                //Strip off the formatting to get to numbers
                line = line.Substring(10);                 //Table number
                int table;
                if (!int.TryParse(line.Substring(0, 1), out table))
                {
                    Debug.LogError("Table format incorrect");
                    continue;
                }
                line = line.Substring(6);                 //Seat number
                int seat;
                if (!int.TryParse(line.Substring(0, 1), out seat))
                {
                    Debug.LogError("Seat format incorrect");
                    continue;
                }
                line = line.Substring(7);                 //Resting threshold
                float  rest;
                string number = Regex.Match(line, @"[0-9\.]+").Value;
                if (!float.TryParse(number, out rest))
                {
                    Debug.LogError("Resting Threshold format incorrect");
                    continue;
                }
                line = line.Substring(4 + number.Length);                 //Recovery threshold
                float rec;
                number = Regex.Match(line, @"[0-9\.]+").Value;
                if (!float.TryParse(number, out rec))
                {
                    Debug.LogError("Recovery Threshold format incorrect");
                    continue;
                }
                line = line.Substring(4 + number.Length);                 //Absolute refractory period
                float abs;
                number = Regex.Match(line, @"[0-9\.]+").Value;
                if (!float.TryParse(number, out abs))
                {
                    Debug.LogError("Absolute Refractory Period format incorrect");
                    continue;
                }
                line = line.Substring(4 + number.Length);                 //Relative refractory period
                float rel;
                if (!float.TryParse(line, out rel))
                {
                    Debug.LogError("Relative Refractory Period format incorrect");
                    continue;
                }
                neu = new NeuronFile(table, seat, rest, rec, abs, rel);
                neuronSettingsToLoad.Add(neu);
            }
            else if (line.Equals(string.Empty))
            {
                //Empty file, don't bother reading
                return;
            }
            else
            {
                //Incorrect formatting, send error and stop
                Debug.LogError("Save file incorrect.  Please fix before loading.");
                return;
            }
        }
        reader.Close();
        Debug.Log("Game Loaded!");

        //Reset all connections.  Done once here so it isn't done several times in PlayerEntered.
        ResetConnections();
        spawnedConnections       = new List <ConnectionFile>();  //Must be reset on load so ghost connections don't pop back up.
        spawnedSensorConnections = new List <SensorConnectionFile>();
        spawnedMuscleConnections = new List <MuscleConnectionFile>();
        adjustedNeuronSettings   = new List <NeuronFile>();

        //Spawn connections for players already in scene.
        foreach (NeuronDesignation nd in loadedPlayers)
        {
            if (nd.GetObject() != null)
            {
                PlayerEntered(nd.GetObject(), nd.GetTableNum(), nd.GetSeatNum(), true);
            }
        }
    }