예제 #1
0
        Table <int, ConnectionPart> GetConnections(int id, string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }

            FileManager   fileManager = new FileManager(file);
            EditorINIData iniContent;

            try
            {
                iniContent = fileManager.Read(FileEncoding.Automatic, SystemTemplate);
            }
            catch
            {
                // FileManager could throw an exception if the file can't be opened
                return(null);
            }

            Table <int, ConnectionPart> connections = new Table <int, ConnectionPart>();

            foreach (EditorINIBlock block in iniContent.Blocks)
            {
                if (block.Name.Equals("object", StringComparison.OrdinalIgnoreCase))
                {
                    string archetypeString = null;
                    string gotoString      = null;

                    foreach (EditorINIOption option in block.Options)
                    {
                        if (option.Values.Count > 0)
                        {
                            string value = option.Values[0].Value.ToString();
                            switch (option.Name.ToLowerInvariant())
                            {
                            case "archetype":
                                archetypeString = value;
                                break;

                            case "goto":
                                gotoString = value;
                                break;
                            }
                        }
                    }

                    if (archetypeString != null && gotoString != null)
                    {
                        ArchetypeInfo archetypeInfo = Archetype.TypeOf(archetypeString);
                        if (archetypeInfo != null)
                        {
                            ConnectionPart connection = new ConnectionPart
                            {
                                Id = GetConnectionId(BeforeSeperator(gotoString, ","))
                            };

                            switch (archetypeInfo.Type)
                            {
                            case ContentType.JumpGate:
                                connection.JumpGate = true;
                                break;

                            case ContentType.JumpHole:
                                connection.JumpHole = true;
                                break;
                            }

                            ConnectionPart existingConnection;
                            if (connections.TryGetValue(connection.Id, out existingConnection))
                            {
                                if (connection.JumpGate)
                                {
                                    existingConnection.JumpGate = true;
                                }

                                if (connection.JumpHole)
                                {
                                    existingConnection.JumpHole = true;
                                }
                            }
                            else if (id != connection.Id && connection.Id != -1)
                            {
                                connections.Add(connection);
                            }
                        }
                    }
                }
            }

            return(connections);
        }