Beispiel #1
0
        static string ProcessModulesInfo(string file, List <string> names)
        {
            string json = File.ReadAllText(file, Encoding.UTF8);

            JObject jo = new JObject();

            jo = JObject.Parse(json);

            JToken first  = jo.First;
            JToken first1 = first.First;
            JArray ja     = (JArray)first1;
            string pname  = ja.Path;

            string returnstring = "";

            foreach (JObject j in ja.Children())
            {
                string betternameprefix = "";
                string sym     = (string)j["symbol"];
                int    edid    = (int)j["edID"];
                double mass    = j["mass"] != null ? (double)j["mass"] : 0;
                string massstr = mass + (mass != Math.Floor(mass) ? "F" : "");

                double power    = j["power"] != null ? (double)j["power"] : 0;
                string powerstr = power + (power != Math.Floor(power) ? "F" : "");

                string infostr = "";
                if (j["ammo"] != null)
                {
                    infostr = infostr.AppendPrePad("Ammo:" + ((int)j["ammo"]).ToString(), ", ");
                    if (j["clip"] != null)
                    {
                        infostr += "/" + ((int)j["clip"]).ToString();
                    }
                }
                else if (j["rof"] != null)
                {
                    infostr = infostr.AppendPrePad("ROF:" + ((double)j["rof"]).ToString("0.#") + "/s", ", ");
                }

                if (j["damage"] != null)
                {
                    infostr = infostr.AppendPrePad("Damage:" + ((double)j["damage"]).ToString("0.#"), ", ");
                }
                if (j["fuel"] != null)
                {
                    infostr = infostr.AppendPrePad("Size:" + ((int)j["fuel"]).ToString() + "t", ", ");
                }
                if (j["optmass"] != null)
                {
                    infostr = infostr.AppendPrePad("OptMass:" + ((int)j["optmass"]).ToString() + "t", ", ");
                }
                if (j["maxmass"] != null)
                {
                    infostr = infostr.AppendPrePad("MaxMass:" + ((int)j["maxmass"]).ToString() + "t", ", ");
                }
                if (j["minmass"] != null)
                {
                    infostr = infostr.AppendPrePad("MinMass:" + ((int)j["minmass"]).ToString() + "t", ", ");
                }
                if (j["time"] != null)
                {
                    infostr = infostr.AppendPrePad("Time:" + ((int)j["time"]).ToString() + "s", ", ");
                }
                if (j["sysrate"] != null)
                {
                    infostr = infostr.AppendPrePad("Sys:" + ((double)j["sysrate"]).ToString("0.#MW") + ", Eng:" + ((double)j["engrate"]).ToString("0.#MW") + ", Wep:" + ((double)j["weprate"]).ToString("0.#MW"), ", ");
                }
                if (j["pgen"] != null)
                {
                    infostr = infostr.AppendPrePad("Power:" + ((double)j["pgen"]).ToString("0.#MW"), ", ");
                }
                if (j["range"] != null)
                {
                    double rng = ((double)j["range"]);
                    if (rng > 100)
                    {
                        infostr = infostr.AppendPrePad("Range:" + rng.ToString("0.#m"), ", ");
                    }
                    else
                    {
                        infostr = infostr.AppendPrePad("Range:" + rng.ToString("0.#km"), ", ");
                    }
                }
                if (j["shotspeed"] != null)
                {
                    infostr = infostr.AppendPrePad("Speed:" + ((int)j["shotspeed"]).ToString() + "m/s", ", ");
                }
                if (j["cargo"] != null)
                {
                    infostr = infostr.AppendPrePad("Size:" + ((int)j["cargo"]).ToString() + "t", ", ");
                }
                if (j["rebuildsperbay"] != null)
                {
                    infostr = infostr.AppendPrePad("Rebuilds:" + ((int)j["rebuildsperbay"]).ToString() + "t", ", ");
                }
                if (j["reload"] != null)
                {
                    infostr = infostr.AppendPrePad("Reload:" + ((double)j["reload"]).ToString("0.#s"), ", ");
                }
                if (j["shieldboost"] != null)
                {
                    infostr = infostr.AppendPrePad("Boost:" + (((double)j["shieldboost"])).ToString("0.0%"), ", ");
                }
                if (j["thermload"] != null)
                {
                    infostr = infostr.AppendPrePad("ThermL:" + ((double)j["thermload"]).ToString("0.#"), ", ");
                }
                if (j["repair"] != null)
                {
                    infostr = infostr.AppendPrePad("Repair:" + ((double)j["repair"]).ToString("0.#"), ", ");
                }
                if (j["rate"] != null)
                {
                    infostr = infostr.AppendPrePad("Rate:" + ((double)j["rate"]).ToString("0.#"), ", ");
                }

                if (j["explres"] != null)
                {
                    infostr = infostr.AppendPrePad("Explosive:" + ((double)j["explres"]).ToString("0.##%"), ", ");
                }
                if (j["kinres"] != null)
                {
                    infostr = infostr.AppendPrePad("Kinetic:" + ((double)j["kinres"]).ToString("0.##%"), ", ");
                }
                if (j["thermres"] != null)
                {
                    infostr = infostr.AppendPrePad("Thermal:" + ((double)j["thermres"]).ToString("0.##%"), ", ");
                }
                if (j["protection"] != null)
                {
                    infostr = infostr.AppendPrePad("Protection:" + ((double)j["protection"]).ToString("0.##"), ", ");
                }
                if (j["rangeLS"] != null && j["rangeLS"].ToString().Length > 0)
                {
                    infostr = infostr.AppendPrePad("Range:" + ((double)j["rangeLS"]).ToString("0.#ls"), ", ");
                }


                if (j["passengers"] != null)
                {
                    infostr = infostr.AppendPrePad("Passengers:" + ((int)j["passengers"]).ToString(), ", ");
                    if (j["grp"] != null)
                    {
                        string grp = (string)j["grp"];
                        if (grp == "pcq")
                        {
                            grp = "Luxury";
                        }
                        if (grp == "pci")
                        {
                            grp = "Business Class";
                        }
                        if (grp == "pce")
                        {
                            grp = "Economy";
                        }
                        if (grp == "pcm")
                        {
                            grp = "First Class";
                        }

                        betternameprefix = grp + " ";
                    }
                }

                infostr = infostr.Length > 0 ? "\"" + infostr + "\"" : "null";

                if (sym == null)      // missing from corolis data
                {
                    if (edid == 128671347)
                    {
                        sym = "Hpt_MiningLaser_Fixed_Small_Advanced";     // best guess
                    }
                    if (edid == 128671345)
                    {
                        sym = "Hpt_MultiCannon_Fixed_Small_Scatter";
                    }
                    if (edid == 128671342)
                    {
                        sym = "Hpt_PulseLaser_Fixed_Medium_Distruptor";
                    }
                }

                string bettername = GetBetterItemNameEvents(sym);
                bettername = betternameprefix + bettername.Replace("  ", " ").Trim();


                int first_  = sym.IndexOf("_");
                int second_ = first_ >= 0 ? sym.IndexOf("_", first_ + 1) : -1;

                string modtypename = second_ >= 0 ? sym.Substring(0, second_) : sym;

                if (modtypename == "Int_DroneControl")
                {
                    int third_ = sym.IndexOf("_", second_ + 1);
                    modtypename = sym.Substring(0, third_);
                }

                modtypename = modtypename.SplitCapsWord().Replace("Hpt_", "").Replace("Int_", "").Replace("_", " ");

                // Console.WriteLine("Compare " + modtypename);
                Tuple <string, string> modtype = MOD_PREFIX_TO_TYPE.Find(x => modtypename.IndexOf(x.Item1, StringComparison.InvariantCultureIgnoreCase) >= 0);
                modtypename = modtype?.Item2 ?? modtypename;

                sym = sym.ToLower();
                if (names.Contains(sym))
                {
                    returnstring += "**** is repeated";
                }

                bool massisnonint  = Math.Floor(mass) != mass;
                bool powerisnonint = Math.Floor(power) != power;

                names.Add(sym);
                string part = "            { \"" + sym + "\", new ShipModule(" + edid + ", " + massstr + ", " + powerstr + ", " +
                              infostr + "," +
                              "\"" + bettername + "\", \"" + modtypename + "\")}," + Environment.NewLine;
                returnstring += part;
            }

            return(returnstring);
        }
Beispiel #2
0
        static string ProcessModulesInfo(string file, List <string> names)
        {
            string json = File.ReadAllText(file, Encoding.UTF8);

            JObject jo = new JObject();

            jo = JObject.Parse(json);

            JArray array = jo.First().Array();

            string returnstring = "";

            foreach (JObject j in array)
            {
                string betternameprefix = "";
                string sym     = (string)j["symbol"];
                int    edid    = (int)j["edID"];
                double mass    = j["mass"] != null ? (double)j["mass"] : 0;
                string massstr = mass + (mass != Math.Floor(mass) ? "F" : "");

                double power    = j["power"] != null ? (double)j["power"] : 0;
                string powerstr = power + (power != Math.Floor(power) ? "F" : "");

                string infostr = "";
                if (j["ammo"] != null)
                {
                    infostr = infostr.AppendPrePad("Ammo:" + ((int)j["ammo"]).ToString(), ", ");
                    if (j["clip"] != null)
                    {
                        infostr += "/" + ((int)j["clip"]).ToString();
                    }
                }
                else if (j["rof"] != null)
                {
                    infostr = infostr.AppendPrePad("ROF:" + ((double)j["rof"]).ToString("0.#") + "/s", ", ");
                }

                if (j["damage"] != null)
                {
                    infostr = infostr.AppendPrePad("Damage:" + ((double)j["damage"]).ToString("0.#"), ", ");
                }
                if (j["fuel"] != null)
                {
                    infostr = infostr.AppendPrePad("Size:" + ((int)j["fuel"]).ToString() + "t", ", ");
                }
                if (j["optmass"] != null)
                {
                    infostr = infostr.AppendPrePad("OptMass:" + ((int)j["optmass"]).ToString() + "t", ", ");
                }
                if (j["maxmass"] != null)
                {
                    infostr = infostr.AppendPrePad("MaxMass:" + ((int)j["maxmass"]).ToString() + "t", ", ");
                }
                if (j["minmass"] != null)
                {
                    infostr = infostr.AppendPrePad("MinMass:" + ((int)j["minmass"]).ToString() + "t", ", ");
                }
                if (j["time"] != null)
                {
                    infostr = infostr.AppendPrePad("Time:" + ((int)j["time"]).ToString() + "s", ", ");
                }
                if (j["sysrate"] != null)
                {
                    infostr = infostr.AppendPrePad("Sys:" + ((double)j["sysrate"]).ToString("0.#MW") + ", Eng:" + ((double)j["engrate"]).ToString("0.#MW") + ", Wep:" + ((double)j["weprate"]).ToString("0.#MW"), ", ");
                }
                if (j["pgen"] != null)
                {
                    infostr = infostr.AppendPrePad("Power:" + ((double)j["pgen"]).ToString("0.#MW"), ", ");
                }
                if (j["range"] != null)
                {
                    double rng = ((double)j["range"]);
                    if (rng > 100)
                    {
                        infostr = infostr.AppendPrePad("Range:" + rng.ToString("0.#m"), ", ");
                    }
                    else
                    {
                        infostr = infostr.AppendPrePad("Range:" + rng.ToString("0.#km"), ", ");
                    }
                }
                if (j["shotspeed"] != null)
                {
                    infostr = infostr.AppendPrePad("Speed:" + ((int)j["shotspeed"]).ToString() + "m/s", ", ");
                }
                if (j["cargo"] != null)
                {
                    infostr = infostr.AppendPrePad("Size:" + ((int)j["cargo"]).ToString() + "t", ", ");
                }
                if (j["rebuildsperbay"] != null)
                {
                    infostr = infostr.AppendPrePad("Rebuilds:" + ((int)j["rebuildsperbay"]).ToString() + "t", ", ");
                }
                if (j["reload"] != null)
                {
                    infostr = infostr.AppendPrePad("Reload:" + ((double)j["reload"]).ToString("0.#s"), ", ");
                }
                if (j["shieldboost"] != null)
                {
                    infostr = infostr.AppendPrePad("Boost:" + (((double)j["shieldboost"])).ToString("0.0%"), ", ");
                }
                if (j["thermload"] != null)
                {
                    infostr = infostr.AppendPrePad("ThermL:" + ((double)j["thermload"]).ToString("0.#"), ", ");
                }
                if (j["repair"] != null)
                {
                    infostr = infostr.AppendPrePad("Repair:" + ((double)j["repair"]).ToString("0.#"), ", ");
                }
                if (j["rate"] != null)
                {
                    infostr = infostr.AppendPrePad("Rate:" + ((double)j["rate"]).ToString("0.#"), ", ");
                }

                if (j["explres"] != null)
                {
                    infostr = infostr.AppendPrePad("Explosive:" + ((double)j["explres"]).ToString("0.##%"), ", ");
                }
                if (j["kinres"] != null)
                {
                    infostr = infostr.AppendPrePad("Kinetic:" + ((double)j["kinres"]).ToString("0.##%"), ", ");
                }
                if (j["thermres"] != null)
                {
                    infostr = infostr.AppendPrePad("Thermal:" + ((double)j["thermres"]).ToString("0.##%"), ", ");
                }
                if (j["protection"] != null)
                {
                    infostr = infostr.AppendPrePad("Protection:" + ((double)j["protection"]).ToString("0.##"), ", ");
                }
                if (j["rangeLS"] != null && j["rangeLS"].ToString().Length > 0)
                {
                    infostr = infostr.AppendPrePad("Range:" + ((double)j["rangeLS"]).ToString("0.#ls"), ", ");
                }


                if (j["passengers"] != null)
                {
                    infostr = infostr.AppendPrePad("Passengers:" + ((int)j["passengers"]).ToString(), ", ");
                    if (j["grp"] != null)
                    {
                        string grp = (string)j["grp"];
                        if (grp == "pcq")
                        {
                            grp = "Luxury";
                        }
                        if (grp == "pci")
                        {
                            grp = "Business Class";
                        }
                        if (grp == "pce")
                        {
                            grp = "Economy";
                        }
                        if (grp == "pcm")
                        {
                            grp = "First Class";
                        }

                        betternameprefix = grp + " ";
                    }
                }

                infostr = infostr.Length > 0 ? "\"" + infostr + "\"" : "null";

                System.Diagnostics.Debug.Assert(sym != null);

                string bettername = GetBetterItemNameEvents(sym);                           // name to give it.. long description text..
                bettername = betternameprefix + bettername.Replace("  ", " ").Replace("Unk ", "").Trim();


                int first_  = sym.IndexOf("_");                                             // modtypename is the type of the module ("Cargo Rack" etc)
                int second_ = first_ >= 0 ? sym.IndexOf("_", first_ + 1) : -1;              //
                int third_  = (second_ >= 0) ? sym.IndexOf("_", second_ + 1) : -1;

                string modtypename = second_ >= 0 ? sym.Substring(0, second_) : sym;        // Modname is normally up to second _ (Int_CargoRack_...)

                if (modtypename.Equals("hpt_mining", StringComparison.InvariantCultureIgnoreCase))
                {
                    //    modtypename = sym.Substring(0,third_);
                }

                if (modtypename == "Int_DroneControl")                     // these need text to third item
                {
                    if (third_ == -1)
                    {
                        modtypename = sym;
                    }
                    else
                    {
                        modtypename = sym.Substring(0, third_);
                    }
                }

                modtypename = modtypename.SplitCapsWord().Replace("Hpt_", "", StringComparison.InvariantCultureIgnoreCase).Replace("Int_", "", StringComparison.InvariantCultureIgnoreCase).Replace("_", " ");

                Console.Write("Module Compare " + modtypename);

                Tuple <string, string> modtype = MOD_PREFIX_TO_TYPE.Find(x => modtypename.IndexOf(x.Item1, StringComparison.InvariantCultureIgnoreCase) >= 0);
                modtypename = modtype?.Item2 ?? modtypename;

                Console.WriteLine(".. " + modtypename);

                sym = sym.ToLowerInvariant();
                if (names.Contains(sym))
                {
                    returnstring += "**** is repeated";
                }

                bool massisnonint  = Math.Floor(mass) != mass;
                bool powerisnonint = Math.Floor(power) != power;

                names.Add(sym);
                string part = "            { \"" + sym + "\", new ShipModule(" + edid + ", " +
                              massstr + ", " +
                              powerstr + ", " +
                              infostr + "," +
                              "\"" + bettername + "\", " +
                              "\"" + modtypename + "\")}," + Environment.NewLine;
                returnstring += part;
            }

            return(returnstring);
        }