Exemplo n.º 1
0
        private static void CheckPrerequisites()
        {
            // check prerequisites

            var nodes = new Queue <ResearchNode>(Nodes.OfType <ResearchNode>());

            // remove redundant prerequisites
            while (nodes.Count > 0)
            {
                var node = nodes.Dequeue();
                if (node.Research.prerequisites.NullOrEmpty())
                {
                    continue;
                }

                var ancestors = node.Research.prerequisites?.SelectMany(r => r.Ancestors()).ToList();
                var redundant = ancestors.Intersect(node.Research.prerequisites);
                if (redundant.Any())
                {
                    ResearchLog.Warning("\tredundant prerequisites for {0}: {1}", node.Research.LabelCap,
                                        string.Join(", ", redundant.Select(r => r.LabelCap).ToArray()) + ", fixing, please save");
                    foreach (var redundantPrerequisite in redundant)
                    {
                        ProfileManager.AddCommand("".Find(node.Research).Get(new { node.Research.prerequisites }).Remove().Find(redundantPrerequisite));
                        node.Research.prerequisites.Remove(redundantPrerequisite);
                    }
                }
            }

            // fix bad techlevels
            nodes = new Queue <ResearchNode>(Nodes.OfType <ResearchNode>());
            while (nodes.Count > 0)
            {
                var node = nodes.Dequeue();
                if (!node.Research.prerequisites.NullOrEmpty())
                {
                    // warn and fix badly configured techlevels
                    if (node.Research.prerequisites.Any(r => r.techLevel > node.Research.techLevel))
                    {
                        ResearchLog.Warning("\t{0} has a lower techlevel than (one of) it's prerequisites, fixing, please save",
                                            node.Research.defName);
                        TechLevel maxTech = node.Research.prerequisites.Max(r => r.techLevel);
                        ProfileManager.AddCommand("".Find(node.Research).Set(new { node.Research.techLevel }).Find(maxTech));
                        node.Research.techLevel = maxTech;

                        // re-enqeue all descendants
                        foreach (var descendant in node.Descendants.OfType <ResearchNode>())
                        {
                            nodes.Enqueue(descendant);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void DeleteDef(ItemDetail def)
        {
            ParseHelper.RemoveFromDefDatabase(def.keyObject);
            string command = "".Remove().Find(def.keyObject);

            ProfileManager.AddCommand(command);
            if (SelectedItemDef == def)
            {
                SelectedItemDef = null;
            }
            def.category.ItemDetailDefs.Remove(def);
            ParseHelper.RemoveFromDefDatabase(def);
            //Recache();
        }
Exemplo n.º 3
0
        public void AddDef(DetailCategory cat)
        {
            Def    newDef  = ParseHelper.MakeTypedObject(cat.subclassType) as Def;
            string newName = "0000NewDefPleaseChange";

            newDef.defName     = newName;
            newDef.label       = newName;
            newDef.description = newName;
            ParseHelper.AddToDefDatabase(newDef);
            ProfileManager.AddCommand("".Push().New(cat.subclassType));
            ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.defName }).Find(newDef.defName));
            ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.label }).Find(newDef.label));
            ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.description }).Find(newDef.description));
            ProfileManager.AddCommand("".Add().Pop());
            AddNewDefToCat(newDef, cat);
            //cat.Recache();
        }
Exemplo n.º 4
0
        public void AddCommand(string command, string childstr = null)
        {
            string toAdd = command;

            if (childstr != null)
            {
                toAdd += "".Get(field);
                toAdd += ":" + childstr;
            }

            if (parentDesc != null)
            {
                if (IsEnumerable(parentDesc.field.FieldType)) // we are a member of an enumerable
                {
                    string prepend = "";
                    // currentVal is us, the member of the enumerable
                    if (IsDirectEditable(parent.GetType())) // but wait, why are we here?
                    {
                        Verse.Log.Error("RimEditor: Trying to cascade down a directly editable stack; should be directly editing from dropdown menu");
                        //toAdd = prepend.From().Find(currentVal) + ":" + toAdd;
                    }
                    else
                    {
                        GenerateFromCommand(parentDesc.childType, parent, ref prepend);
                        toAdd = prepend + ":" + toAdd;
                    }
                }
                parentDesc.AddCommand(toAdd);
            }
            else if (typeof(Def).IsAssignableFrom(parent.GetType()))
            {
                toAdd = Find(parent) + ":" + toAdd;
                ProfileManager.AddCommand(toAdd);
            }
            else
            {
                Verse.Log.Error("RimEditor: Tried to add command with unknown parent of type " + parent.GetType());
            }

            command = null;
        }