Esempio n. 1
0
        static public void GetPartProperties()
        {
            AvailablePart part     = new AvailablePart();
            var           partType = part.GetType();

            DataDump.activeMod    = "PART";
            DataDump.activeModule = new Module("PART", "PART", partType);

            var fields = DataDump.activeModule.type.GetFields(BindingFlags.FlattenHierarchy |
                                                              BindingFlags.Instance |
                                                              BindingFlags.Public | BindingFlags.NonPublic |
                                                              BindingFlags.GetProperty |
                                                              BindingFlags.Static);
            Property p = new Property("PART", "PART");

            if (!ActiveLists.activePropertyList.ContainsKey(p.Key))
            {
                ActiveLists.activePropertyList.Add(p.Key, p);
            }
            foreach (var f in fields)
            {
                p.fields.Add(new FldInfo(f.Name, f.FieldType));
            }

            // p.fieldsFromReflection = fields;

            foreach (PropertyInfo prop in DataDump.activeModule.type.GetProperties(BindingFlags.FlattenHierarchy |
                                                                                   BindingFlags.Instance |
                                                                                   BindingFlags.Public |
                                                                                   BindingFlags.Static))
            {
                p.fields.Add(new FldInfo(prop.Name, prop.PropertyType));
            }
        }
Esempio n. 2
0
        public void GetUniqueModuleList()
        {
            bool started = false;

#if DEBUG
            foreach (var f in ActiveLists.activeFieldsList)
            {
                if (f.Value.enabled)
                {
                    Log.Info("fieldsList, key: " + f.Key + ", enabled: " + f.Value.enabled);
                }
            }
#endif

            DataDump.activeMod = "PART";
            AvailablePart part    = new AvailablePart();
            var           a       = part.GetType();
            Module        partmod = new Module("PART", "PART", a);
            //StartLine("");
            //started = true;



            if (ActiveLists.activePropertyList.TryGetValue(Property.GetKey(partmod.modName, partmod.moduleName), out Property p))
            {
                foreach (var s in p.fields) //FromReflection)
                {
                    if (!started)
                    {
                        StartLine(partmod.moduleName + "." + s.Name);
                        started = true;
                        for (var partAttr = PartAttrEnum.first + 1; partAttr < PartAttrEnum.last; partAttr++)
                        {
                            if (DataDump.partAttrs[(int)partAttr - 1] != null && DataDump.partAttrs[(int)partAttr - 1].enabled)
                            {
                                switch (partAttr)
                                {
                                case PartAttrEnum.DimensionsInfo:
                                    AppendLine("X");
                                    AppendLine("Y");
                                    AppendLine("Z");
                                    break;

                                case PartAttrEnum.Resources:
                                    for (int i = 1; i <= maxResources; i++)
                                    {
                                        AppendLine("Resource-" + i.ToString());
                                    }
                                    break;

                                default:
                                    AppendLine(PartAttrStr[(int)partAttr - 1] /* + "-pre" */);
                                    break;
                                }
                            }
                        }
                    }
                    Field field = new Field(partmod.modName, partmod.moduleName, s.Name);
                    if (ActiveLists.activeFieldsList.TryGetValue(field.ActiveKey, out field))
                    {
                        if (field.enabled)
                        {
                            if (!moduleInfoList.ContainsKey(partmod.moduleName))
                            {
                                moduleInfoList.Add(partmod.modName, new ModuleInfo(partmod.moduleName, 1, colCnt, 0));
                            }
                            else
                            {
                                moduleInfoList[partmod.moduleName].numFields++;
                            }
                            if (!started)
                            {
                            }
                            else
                            {
                                var str = partmod.moduleName;
                                if (str.Length > 6 && str.Substring(0, 5) == "Module")
                                {
                                    str = str.Substring(6);
                                }
                                AppendLine(str + "." + s.Name);
                            }
                        }
                    }
                }
            }

            Dictionary <string, string> colHeader = new Dictionary <string, string>();

            foreach (var m in ActiveLists.activeModuleList)
            {
                if (m.Value.enabled)
                {
                    Module mod = m.Value;
                    for (int i = 0; i < (mod.multipleModules ? 2 : 1); i++)
                    {
                        Log.Info("mod.multipleModules: " + mod.multipleModules);
                        if (ActiveLists.activePropertyList.TryGetValue(Property.GetKey(mod.modName, mod.moduleName), out p))
                        {
                            foreach (var s in p.fields) //FromReflection)
                            {
                                Field field = new Field(mod.modName, mod.moduleName, s.Name);
                                if (ActiveLists.activeFieldsList.TryGetValue(field.ActiveKey, out field))
                                {
                                    if (field.enabled)
                                    {
                                        if (mod.moduleName == null)
                                        {
                                            Log.Error("moduleName 2 is null");
                                        }
                                        if (!moduleInfoList.ContainsKey(mod.ModuleInfoKey(i)))
                                        {
                                            moduleInfoList.Add(mod.ModuleInfoKey(i), new ModuleInfo(mod.moduleName, 1, colCnt, i));
                                        }
                                        else
                                        {
                                            moduleInfoList[mod.ModuleInfoKey(i)].numFields++;
                                        }
                                        string str = mod.moduleName + (i == 0 ? "" : "-2") + "." + s.Name;
                                        if (!colHeader.ContainsKey(str))
                                        {
                                            colHeader.Add(str, str);
                                            if (!started)
                                            {
                                                StartLine(m.Value.moduleName + "." + s.Name);
                                                started = true;
                                            }
                                            else
                                            {
                                                AppendLine(m.Value.moduleName + "." + s.Name);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (started)
            {
                EndLine();
            }
            if (!onefilePerMod)
            {
                byte[] bytes = Encoding.ASCII.GetBytes(line.ToString());
                fs.Write(bytes, 0, line.Length);
#if false
                foreach (var m in moduleInfoList)
                {
                    Log.Info("Module: " + m.Value.moduleName + ", startingCol: " + m.Value.startingCol + ", numFields: " + m.Value.numFields);
                }
                Log.Info("headerLine: " + line.ToString());
#endif
            }
            else
            {
                headerLine = line;
                Log.Info("headerLine: " + headerLine.ToString());
            }
        }
Esempio n. 3
0
        void GetPartData(AvailablePart part)
        {
            bool    started = false;
            Vector3 pg      = new Vector3();

            StartLine(part.name);
            started = true;
            if (partAttrs[(int)PartAttrEnum.DimensionsInfo - 1] != null && partAttrs[(int)PartAttrEnum.DimensionsInfo - 1].enabled)
            {
                //
                // Now get the part dimensions: x,y,z
                //
                List <Bounds> list = new List <Bounds>();
                if (!(part.partPrefab.Modules.GetModule <LaunchClamp>(0) != null))
                {
                    Bounds[] partRendererBounds = PartGeometryUtil.GetPartRendererBounds(part.partPrefab);
                    int      num = partRendererBounds.Length;
                    for (int j = 0; j < num; j++)
                    {
                        Bounds bounds2 = partRendererBounds[j];
                        Bounds bounds3 = bounds2;
                        bounds3.size *= part.partPrefab.boundsMultiplier;
                        Vector3 size = bounds3.size;
                        bounds3.Expand(part.partPrefab.GetModuleSize(size, ModifierStagingSituation.CURRENT));
                        list.Add(bounds2);
                    }
                }

                pg = PartGeometryUtil.MergeBounds(list.ToArray(), part.partPrefab.transform.root).size;
#if false
                if (!started)
                {
                    StartLine(pg.x.ToString("F3"));
                }
                else
                {
                    AppendLine(pg.x.ToString("F3"));
                }
                AppendLine(pg.y.ToString("F3"));
                AppendLine(pg.z.ToString("F3"));
                started = true;
#endif
#if false
                string resources = "";
                foreach (AvailablePart.ResourceInfo r in part.resourceInfos)
                {
                    if (r.resourceName != "ElectricCharge" && r.resourceName != "Ablator")
                    {
                        resources += r.resourceName + ",";
                    }
                }
                if (resources != "")
                {
                    Log.Info("part: " + part.name + ", part.title: " + part.title + ", descr: " + part.description.Replace(",", ".") +
                             ", mass: " + part.partPrefab.mass + ", techRequired: " + part.TechRequired +
                             ", height x,y,z: " + pg.x.ToString() + ", " + pg.y.ToString() + ", " + pg.z.ToString() + "," + resources);
                }
#endif
            }

            DataDump.activeMod = "PART";
            var    a       = part.GetType();
            bool   b       = false;
            Module partmod = new Module("PART", "PART", a);
            // ConfigNode partNode = part.partConfig.GetNode("PART");
            //Log.Info("partConfig: " + part.partConfig);
            if (ActiveLists.activePropertyList.TryGetValue(Property.GetKey(partmod.modName, partmod.moduleName), out Property p))
            {
                foreach (FldInfo s in p.fields) //FromReflection)
                {
                    if (!b)
                    {
                        //string value = part.partConfig.GetValue(s.Name);


                        b = true;
                        for (var partAttr = PartAttrEnum.first + 1; partAttr < PartAttrEnum.last; partAttr++)
                        {
                            if (DataDump.partAttrs[(int)partAttr - 1] != null && DataDump.partAttrs[(int)partAttr - 1].enabled)
                            {
                                switch (partAttr)
                                {
                                case PartAttrEnum.DimensionsInfo:
                                    AppendLine(pg.x.ToString("F3"));
                                    AppendLine(pg.y.ToString("F3"));
                                    AppendLine(pg.z.ToString("F3"));
                                    break;

                                case PartAttrEnum.Resources:
                                    var nodes = part.partConfig.GetNodes("RESOURCE").ToList().OrderBy(r => r.GetValue("name"));
                                    int cnt   = 0;
                                    foreach (var n in nodes)
                                    {
                                        string name      = n.GetValue("name");
                                        string maxAmount = n.GetValue("maxAmount");

                                        if (cnt < maxResources)
                                        {
                                            AppendLine(name + ":" + maxAmount);
                                        }
                                        cnt++;
                                        if (cnt >= maxResources)
                                        {
                                            break;
                                        }
                                    }
                                    break;

                                case PartAttrEnum.TechRequired:
                                    AppendLine(part.TechRequired);
                                    break;

                                case PartAttrEnum.entryCost:
                                    AppendLine(part.entryCost);
                                    break;

                                case PartAttrEnum.cost:
                                    AppendLine(part.cost);
                                    break;

                                case PartAttrEnum.category:
                                    AppendLine(part.category.ToString());
                                    break;

                                default:
                                    string str = "n/a";
                                    str = "";

                                    if (!part.partConfig.TryGetValue(partAttr.ToString(), ref str))
                                    {
                                        if (useDefaultValues)
                                        {
                                            Part p1 = new Part();

                                            switch (partAttr)
                                            {
                                            case PartAttrEnum.breakingForce:
                                                str = p1.breakingForce.ToString();
                                                break;

                                            case PartAttrEnum.breakingtorque:
                                                str = p1.breakingTorque.ToString();
                                                break;

                                            case PartAttrEnum.minimum_drag:
                                                str = p1.minimum_drag.ToString();
                                                break;

                                            case PartAttrEnum.maximum_drag:
                                                str = p1.maximum_drag.ToString();
                                                break;

                                            case PartAttrEnum.angularDrag:
                                                str = p1.angularDrag.ToString();
                                                break;

                                            case PartAttrEnum.crashTolerance:
                                                str = p1.crashTolerance.ToString();
                                                break;

                                            case PartAttrEnum.maxTemp:
                                                str = p1.maxTemp.ToString();
                                                break;

                                            case PartAttrEnum.mass:
                                                AppendLine("Default: " + p1.mass);
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            Log.Error("data not found");
                                        }
                                    }

                                    //str = part.partConfig.GetValue(partAttr.ToString());

                                    AppendLine(str);

                                    break;
                                }
                            }
                        }
                    }

                    Field field = new Field(partmod.modName, partmod.moduleName, s.Name);
                    if (s.Name == "entryCost")
                    {
                        s.Name = "_entryCost";
                    }
                    if (ActiveLists.activeFieldsList.TryGetValue(field.ActiveKey, out field))
                    {
                        if (field != null && field.enabled)
                        {
                            string value = part.partConfig.GetValue(s.Name);
                            if (value == null || value == "")
                            {
                                Type fieldsType = typeof(AvailablePart);
                                // Get an array of FieldInfo objects.
                                FieldInfo[] fields = fieldsType.GetFields(BindingFlags.FlattenHierarchy |
                                                                          BindingFlags.Instance |
                                                                          BindingFlags.Public | BindingFlags.NonPublic |
                                                                          BindingFlags.Static);
                                foreach (var f in fields)
                                {
                                    string v = "";


                                    var    fieldtype = s.FieldType.ToString();
                                    string t         = "System.Collections.Generic";
                                    if (fieldtype.StartsWith(t))
                                    {
                                        fieldtype = fieldtype.Substring(t.Length + 1);
                                    }


                                    if (f.Name == s.Name)
                                    {
                                        switch (fieldtype)
                                        {
                                        case "System.Single":
                                            v     = "float";
                                            value = ((float)f.GetValue(part)).ToString();
                                            break;

                                        case "System.Double":
                                            v     = "double";
                                            value = ((double)f.GetValue(part)).ToString();
                                            break;

                                        case "System.Int32":
                                            v     = "int";
                                            value = ((int)f.GetValue(part)).ToString();
                                            break;

                                        case "System.UInt32":
                                            v     = "uint";
                                            value = ((uint)f.GetValue(part)).ToString();
                                            break;

                                        case "System.String":
                                            v     = "string";
                                            value = (string)f.GetValue(part);
                                            if (s.Name == "description")
                                            {
                                                value = StripHtml(value);
                                                if (value.Length > maxLen && s.Name == "description")
                                                {
                                                    value = value.Substring(0, maxLen);
                                                }
                                                value = value.Replace("\n", " ").Replace("\r", " ");
                                            }
                                            break;

                                        case "System.Boolean":
                                            v     = "boolean";
                                            value = ((bool)f.GetValue(part)).ToString();
                                            break;

                                        case "UnityEngine.Vector3":
                                            v     = "Vector3";
                                            value = ((Vector3)f.GetValue(part)).ToString();
                                            break;
                                        }
                                        break;
                                    }
                                    Log.Info("v: " + v);
                                }
                            }
                            if (!started)
                            {
                            }
                            else
                            {
                                AppendLine(value);
                            }
                        }
                    }
                    else
                    {
#if false
                        if (field == null)
                        {
                            Log.Error("GetPartData, field is null");
                        }
                        else if (field.ActiveKey == null)
                        {
                            Log.Error("GetPartData, field.ActiveKey is null");
                        }
                        else
                        {
                            Log.Error("GetPartData, not found: " + field.ActiveKey);
                        }
#endif
                    }
                }
            }
        }