예제 #1
0
 // Here if you add a new treetype
 public void PopulateFromSource(KerbalNode sourceNode, TreeType treeType = TreeType.YongeTech)
 {
     switch (treeType)
     {
     case TreeType.YongeTech:
         PopulateYongeTechNode(sourceNode);
         break;
     }
 }
예제 #2
0
        public void PopulateFromSource(KerbalNode node)
        {
            var v = node.Values;

            if (PartName == null)
            {
                PartName = v["name"].First();
            }

            if (v.ContainsKey("title"))
            {
                Title = v["title"].First();
            }

            if (v.ContainsKey("description"))
            {
                Description = v["description"].First();
            }

            if (v.ContainsKey("cost"))
            {
                int c;
                Int32.TryParse(v["cost"].First(), out c);
                Cost = c;
            }

            if (v.ContainsKey("TechRequired"))
            {
                TechRequired = v["TechRequired"].First();
            }

            if (v.ContainsKey("category"))
            {
                Category = v["category"].First();
            }
        }
예제 #3
0
 public abstract TechNode PopulateFromSource(KerbalNode sourceNode);
        public override TechNode PopulateFromSource(KerbalNode sourceNode)
        {
            TechNode newNode = new TechNode();
            var      v       = sourceNode.Values;

            newNode.NodePart = v.ContainsKey("nodeName") ? v["nodeName"].First() : "";

            double x;
            double y;

            newNode.Id = v.ContainsKey("id") ? v["id"].First() : "";

            if (v.ContainsKey("pos"))
            {
                var posString   = v["pos"].First();
                var coordinates = posString.Split(',');

                if (coordinates.Length >= 2)
                {
                    if (!Double.TryParse(coordinates[0], out x))
                    {
                        x = 0;
                    }

                    if (!Double.TryParse(coordinates[1], out y))
                    {
                        y = 0;
                    }
                    newNode.Pos = new Point(x, y);

                    decimal z;
                    if (!Decimal.TryParse(coordinates[2], out z))
                    {
                        newNode.Zlayer = -1;
                    }
                    newNode.Zlayer = (int)z;
                }
            }

            if (v.ContainsKey("icon"))
            {
                newNode.Icon = v["icon"].First();
            }

            if (v.ContainsKey("scale"))
            {
                var s = v["scale"].First();
                newNode.Scale = Double.Parse(s);
            }

            newNode.Title       = v.ContainsKey("title") ? v["title"].First() : "";
            newNode.Description = v.ContainsKey("description") ? v["description"].First() : "";

            newNode.AnyToUnlock         = false;
            newNode.HideEmpty           = false;
            newNode.HideIfNoBranchParts = false;
            if (v.ContainsKey("cost"))
            {
                int c;
                if (!Int32.TryParse(v["cost"].First(), out c))
                {
                    newNode.Cost = 0;
                }
                newNode.Cost = c;
            }
            if (v.ContainsKey("anyToUnlock"))
            {
                switch (v["anyToUnlock"].First().Trim().ToLower())
                {
                case "true":
                    newNode.AnyToUnlock = true;
                    break;
                }
            }
            if (v.ContainsKey("hideEmpty"))
            {
                switch (v["hideEmpty"].First().Trim().ToLower())
                {
                case "true":
                    newNode.HideEmpty = true;
                    break;
                }
            }
            if (v.ContainsKey("hideIfNoBranchParts"))
            {
                switch (v["hideIfNoBranchParts"].First().Trim().ToLower())
                {
                case "true":
                    newNode.HideIfNoBranchParts = true;
                    break;
                }
            }

            // Create an empty parents collection, populated during linking
            newNode.Parents = new List <TechNode>();
            newNode.Parts   = new List <string>();

            return(newNode);
        }
예제 #5
0
        public override TechNode PopulateFromSource(KerbalNode sourceNode)
        {
            TechNode newNode = new TechNode();
            var      v       = sourceNode.Values;

            newNode.NodePart = v.ContainsKey("nodepart") ? v["nodepart"].First() : "";

            double x;
            double y;

            newNode.Id = v.ContainsKey("id") ? v["id"].First() : "";

            if (v.ContainsKey("pos"))
            {
                var posString   = v["pos"].First();
                var coordinates = posString.Split(',');

                if (coordinates.Length >= 2)
                {
                    if (!Double.TryParse(coordinates[0], out x))
                    {
                        x = 0;
                    }

                    if (!Double.TryParse(coordinates[1], out y))
                    {
                        y = 0;
                    }
                    newNode.Pos = new Point(x, y);

                    decimal z;
                    if (!Decimal.TryParse(coordinates[2], out z))
                    {
                        newNode.Zlayer = -1;
                    }
                    newNode.Zlayer = (int)z;
                }
            }

            if (v.ContainsKey("icon"))
            {
                String iconString = v["icon"].First();
                int    id         = Array.FindIndex(IconStringConverter.IconString, row => row == iconString);
                if (id != -1)
                {
                    newNode.Icon = (IconsEnum)id;
                }
                else
                {
                    newNode.Icon = IconsEnum.RDicon_generic;
                }
            }

            if (v.ContainsKey("scale"))
            {
                var s = v["scale"].First();
                newNode.Scale = Double.Parse(s);
            }

            newNode.Title       = v.ContainsKey("title") ? v["title"].First() : "";
            newNode.Description = v.ContainsKey("description") ? v["description"].First() : "";

            newNode.AnyToUnlock         = false;
            newNode.HideEmpty           = false;
            newNode.HideIfNoBranchParts = false;
            if (v.ContainsKey("cost"))
            {
                int c;
                if (!Int32.TryParse(v["cost"].First(), out c))
                {
                    newNode.Cost = 0;
                }
                newNode.Cost = c;
            }
            if (v.ContainsKey("anyParent"))
            {
                switch (v["anyParent"].First().Trim().ToLower())
                {
                case "true":
                    newNode.AnyToUnlock = true;
                    break;
                }
            }
            if (v.ContainsKey("hideEmpty"))
            {
                switch (v["hideEmpty"].First().Trim().ToLower())
                {
                case "true":
                    newNode.HideEmpty = true;
                    break;
                }
            }
            if (v.ContainsKey("hideIfNoBranchParts"))
            {
                switch (v["hideIfNoBranchParts"].First().Trim().ToLower())
                {
                case "true":
                    newNode.HideIfNoBranchParts = true;
                    break;
                }
            }

            // Create an empty parents collection, populated during linking
            newNode.Parents = new List <TechNode>();

            var tmpParts = new List <string>();

            foreach (var child in sourceNode.Children.Where(child => child.Name == "Unlocks").Where(child => child.Values.ContainsKey("part")))
            {
                tmpParts.AddRange(child.Values["part"]);
            }
            newNode.Parts = new List <string>(tmpParts);

            return(newNode);
        }
예제 #6
0
        public void PopulateFromSource(
            KerbalNode sourceNode,
            TreeType treeType = TreeType.TechMananger)
        {
            var v = sourceNode.Values;

            NodeName = v.ContainsKey("name") ? v["name"].First() : "";

            double x;
            double y;

            switch (treeType)
            {
            case TreeType.TechMananger:
                TechId = v.ContainsKey("techID") ? v["techID"].First() : "";

                if (v.ContainsKey("pos"))
                {
                    var posString   = v["pos"].First();
                    var coordinates = posString.Split(',');

                    if (coordinates.Length >= 2)
                    {
                        if (!Double.TryParse(coordinates[0], out x))
                        {
                            x = 0;
                        }

                        if (!Double.TryParse(coordinates[1], out y))
                        {
                            y = 0;
                        }
                        Pos = new Point(x, y);

                        decimal z;
                        if (!Decimal.TryParse(coordinates[2], out z))
                        {
                            Zlayer = -1;
                        }
                        Zlayer = (int)z;
                    }
                }
                break;

            case TreeType.ATC:
                TechId = GenerateTechId();

                x = 0;
                y = 0;
                if (v.ContainsKey("posX"))
                {
                    if (!Double.TryParse(v["posX"].First(), out x))
                    {
                        x = 0;
                    }
                }

                if (v.ContainsKey("posY"))
                {
                    if (!Double.TryParse(v["posY"].First(), out y))
                    {
                        y = 0;
                    }
                }
                Pos = new Point(x, y);
                break;
            }

            if (v.ContainsKey("icon"))
            {
                Icon icon;
                if (!Enum.TryParse(v["icon"].First(), true, out icon))
                {
                    icon = Icon.UNDEFINED;
                }
                Icon = icon;
            }

            Title       = v.ContainsKey("title") ? v["title"].First() : "";
            Description = v.ContainsKey("description") ? v["description"].First() : "";

            AnyParent           = false;
            HideIfEmpty         = false;
            HideIfNoBranchParts = false;

            if (treeType == TreeType.ATC)
            {
                if (v.ContainsKey("scienceCost"))
                {
                    int c;
                    if (!Int32.TryParse(v["scienceCost"].First(), out c))
                    {
                        Cost = 0;
                    }
                    Cost = c;
                }
                if (v.ContainsKey("anyParentUnlocks"))
                {
                    switch (v["anyParentUnlocks"].First().Trim().ToLower())
                    {
                    case "true":
                        AnyParent = true;
                        break;
                    }
                }
                if (v.ContainsKey("hideIfNoparts"))
                {
                    switch (v["hideIfNoparts"].First().Trim().ToLower())
                    {
                    case "true":
                        HideIfEmpty = true;
                        break;
                    }
                }
            }
            else
            {
                if (v.ContainsKey("cost"))
                {
                    int c;
                    if (!Int32.TryParse(v["cost"].First(), out c))
                    {
                        Cost = 0;
                    }
                    Cost = c;
                }
                if (v.ContainsKey("anyParent"))
                {
                    switch (v["anyParent"].First().Trim().ToLower())
                    {
                    case "true":
                        AnyParent = true;
                        break;
                    }
                }
                if (v.ContainsKey("hideIfEmpty"))
                {
                    switch (v["hideIfEmpty"].First().Trim().ToLower())
                    {
                    case "true":
                        HideIfEmpty = true;
                        break;
                    }
                }
                if (v.ContainsKey("hideIfNoBranchParts"))
                {
                    switch (v["hideIfNoBranchParts"].First().Trim().ToLower())
                    {
                    case "true":
                        HideIfNoBranchParts = true;
                        break;
                    }
                }
            }

            // Create an empty parents collection, populated during linking
            Parents = new List <TechNode>();

            var tmpParts = new List <string>();

            foreach (var child in
                     sourceNode.Children.
                     Where(child => child.Name == "PARTS").
                     Where(child => child.Values.ContainsKey("name")))
            {
                tmpParts.AddRange(child.Values["name"]);
            }
            Parts = new List <string>(tmpParts);
        }
예제 #7
0
        private void PopulateYongeTechNode(KerbalNode sourceNode)
        {
            var v = sourceNode.Values;

            NodePart = v.ContainsKey("nodepart") ? v["nodepart"].First() : "";

            double x;
            double y;

            Id = v.ContainsKey("id") ? v["id"].First() : "";

            if (v.ContainsKey("pos"))
            {
                var posString   = v["pos"].First();
                var coordinates = posString.Split(',');

                if (coordinates.Length >= 2)
                {
                    if (!Double.TryParse(coordinates[0], out x))
                    {
                        x = 0;
                    }

                    if (!Double.TryParse(coordinates[1], out y))
                    {
                        y = 0;
                    }
                    Pos = new Point(x, y);

                    decimal z;
                    if (!Decimal.TryParse(coordinates[2], out z))
                    {
                        Zlayer = -1;
                    }
                    Zlayer = (int)z;
                }
            }

            if (v.ContainsKey("icon"))
            {
                Icon = v["icon"].First();
            }

            if (v.ContainsKey("scale"))
            {
                var s = v["scale"].First();
                Scale = Double.Parse(s);
            }

            Title       = v.ContainsKey("title") ? v["title"].First() : "";
            Description = v.ContainsKey("description") ? v["description"].First() : "";

            AnyToUnlock         = false;
            HideEmpty           = false;
            HideIfNoBranchParts = false;
            if (v.ContainsKey("cost"))
            {
                int c;
                if (!Int32.TryParse(v["cost"].First(), out c))
                {
                    Cost = 0;
                }
                Cost = c;
            }
            if (v.ContainsKey("anyParent"))
            {
                switch (v["anyParent"].First().Trim().ToLower())
                {
                case "true":
                    AnyToUnlock = true;
                    break;
                }
            }
            if (v.ContainsKey("hideEmpty"))
            {
                switch (v["hideEmpty"].First().Trim().ToLower())
                {
                case "true":
                    HideEmpty = true;
                    break;
                }
            }
            if (v.ContainsKey("hideIfNoBranchParts"))
            {
                switch (v["hideIfNoBranchParts"].First().Trim().ToLower())
                {
                case "true":
                    HideIfNoBranchParts = true;
                    break;
                }
            }

            // Create an empty parents collection, populated during linking
            Parents = new List <TechNode>();

            var tmpParts = new List <string>();

            foreach (var child in sourceNode.Children.Where(child => child.Name == "Unlocks").Where(child => child.Values.ContainsKey("part")))
            {
                tmpParts.AddRange(child.Values["part"]);
            }
            Parts = new List <string>(tmpParts);
        }