Пример #1
0
 public void ExportInfo(ExportFlags exportFlags, string exportPath)
 {
     if (exportFlags.IsActive(ExportFlags.CityList))
     {
         ExportCities(exportFlags, exportPath);
     }
     if (exportFlags.IsActive(ExportFlags.CountryList))
     {
         ExportCountries(exportFlags, exportPath);
     }
     if (exportFlags.IsActive(ExportFlags.OverlayList))
     {
         ExportOverlays(exportFlags, exportPath);
     }
 }
Пример #2
0
        /// <summary>
        /// Creates a json file with the positions and names (w/ localizations) of all countries
        /// </summary>
        public void ExportCountries(ExportFlags exportFlags, string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }
            var countriesJArr = new JArray();

            foreach (var country in _countriesLookup.Values)
            {
                var countryJObj = JObject.FromObject(country);
                if (exportFlags.IsActive(ExportFlags.CityLocalizedNames))
                {
                    countryJObj["LocalizedNames"] = JObject.FromObject(country.LocalizedNames);
                }
                countriesJArr.Add(countryJObj);
            }
            File.WriteAllText(Path.Combine(path, "Countries.json"), countriesJArr.ToString(Formatting.Indented));
        }
Пример #3
0
        /// <summary>
        /// Creates a json file with the positions and names (w/ localizations) of all cities
        /// </summary>
        public void ExportCities(ExportFlags exportFlags, string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }
            var citiesJArr = new JArray();

            foreach (var city in Cities)
            {
                if (city.Hidden)
                {
                    continue;
                }
                var cityJObj = JObject.FromObject(city.City);
                cityJObj["X"] = city.X;
                cityJObj["Y"] = city.Z;
                if (_countriesLookup.ContainsKey(ScsHash.StringToToken(city.City.Country)))
                {
                    var country = _countriesLookup[ScsHash.StringToToken(city.City.Country)];
                    cityJObj["CountryId"] = country.CountryId;
                }
                else
                {
                    Log.Msg($"Could not find country for {city.City.Name}");
                }

                if (exportFlags.IsActive(ExportFlags.CityLocalizedNames))
                {
                    cityJObj["LocalizedNames"] = JObject.FromObject(city.City.LocalizedNames);
                }

                citiesJArr.Add(cityJObj);
            }
            File.WriteAllText(Path.Combine(path, "Cities.json"), citiesJArr.ToString(Formatting.Indented));
        }
Пример #4
0
        /// <summary>
        /// Saves all overlays as .png images.
        /// Creates a json file with all positions of said overlays
        /// </summary>
        /// <remarks>
        /// ZoomLevelVisibility flags: Multiple can be selected at the same time,
        /// eg. if value is 3 then 0 and 1 are both selected
        /// Selected = hidden (0-7 => numbers in game editor)
        /// 1 = (Nav map, 3D view, zoom 0) (0)
        /// 2 = (Nav map, 3D view, zoom 1) (1)
        /// 4 = (Nav map, 2D view, zoom 0) (2)
        /// 8 = (Nav map, 2D view, zoom 1) (3)
        /// 16 = (World map, zoom 0) (4)
        /// 32 = (World map, zoom 1) (5)
        /// 64 = (World map, zoom 2) (6)
        /// 128 = (World map, zoom 3) (7)
        /// </remarks>
        /// <param name="path"></param>
        public void ExportOverlays(ExportFlags exportFlags, string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }

            var saveAsPNG = exportFlags.IsActive(ExportFlags.OverlayPNGs);

            var overlayPath = Path.Combine(path, "Overlays");

            if (saveAsPNG)
            {
                Directory.CreateDirectory(overlayPath);
            }

            var overlaysJArr = new JArray();

            foreach (var overlay in MapOverlays)
            {
                if (overlay.Hidden)
                {
                    continue;
                }
                var overlayName = overlay.OverlayName;
                var b           = overlay.Overlay?.GetBitmap();
                if (b == null)
                {
                    continue;
                }
                var overlayJObj = new JObject
                {
                    ["X"] = overlay.X,
                    ["Y"] = overlay.Z,
                    ["ZoomLevelVisibility"] = overlay.ZoomLevelVisibility,
                    ["Name"]   = overlayName,
                    ["Type"]   = "Overlay",
                    ["Width"]  = b.Width,
                    ["Height"] = b.Height,
                };
                overlaysJArr.Add(overlayJObj);
                if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                {
                    b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                }
            }
            foreach (var company in Companies)
            {
                if (company.Hidden)
                {
                    continue;
                }
                var overlayName = ScsHash.TokenToString(company.OverlayToken);
                var point       = new PointF(company.X, company.Z);
                if (company.Nodes.Count > 0)
                {
                    var prefab = Prefabs.FirstOrDefault(x => x.Uid == company.Nodes[0]);
                    if (prefab != null)
                    {
                        var originNode = GetNodeByUid(prefab.Nodes[0]);
                        if (prefab.Prefab.PrefabNodes == null)
                        {
                            continue;
                        }
                        var mapPointOrigin = prefab.Prefab.PrefabNodes[prefab.Origin];

                        var rot = (float)(originNode.Rotation - Math.PI -
                                          Math.Atan2(mapPointOrigin.RotZ, mapPointOrigin.RotX) + Math.PI / 2);

                        var prefabstartX = originNode.X - mapPointOrigin.X;
                        var prefabStartZ = originNode.Z - mapPointOrigin.Z;
                        var companyPos   = prefab.Prefab.SpawnPoints.FirstOrDefault(x => x.Type == TsSpawnPointType.CompanyPos);
                        if (companyPos != null)
                        {
                            point = RenderHelper.RotatePoint(prefabstartX + companyPos.X, prefabStartZ + companyPos.Z,
                                                             rot,
                                                             originNode.X, originNode.Z);
                        }
                    }
                }
                var b = company.Overlay?.GetBitmap();
                if (b == null)
                {
                    continue;
                }
                var overlayJObj = new JObject
                {
                    ["X"]      = point.X,
                    ["Y"]      = point.Y,
                    ["Name"]   = overlayName,
                    ["Type"]   = "Company",
                    ["Width"]  = b.Width,
                    ["Height"] = b.Height,
                };
                overlaysJArr.Add(overlayJObj);
                if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                {
                    b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                }
            }
            foreach (var trigger in Triggers)
            {
                if (trigger.Hidden)
                {
                    continue;
                }
                var overlayName = trigger.OverlayName;
                var b           = trigger.Overlay?.GetBitmap();
                if (b == null)
                {
                    continue;
                }
                var overlayJObj = new JObject
                {
                    ["X"]      = trigger.X,
                    ["Y"]      = trigger.Z,
                    ["Name"]   = overlayName,
                    ["Type"]   = "Parking",
                    ["Width"]  = b.Width,
                    ["Height"] = b.Height,
                };
                overlaysJArr.Add(overlayJObj);
                if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                {
                    b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                }
            }
            foreach (var ferry in FerryConnections)
            {
                if (ferry.Hidden)
                {
                    continue;
                }
                var overlayName = ScsHash.TokenToString(ferry.OverlayToken);
                var b           = ferry.Overlay?.GetBitmap();
                if (b == null)
                {
                    continue;
                }
                var overlayJObj = new JObject
                {
                    ["X"]      = ferry.X,
                    ["Y"]      = ferry.Z,
                    ["Name"]   = overlayName,
                    ["Type"]   = (ferry.Train) ? "Train" : "Ferry",
                    ["Width"]  = b.Width,
                    ["Height"] = b.Height,
                };
                overlaysJArr.Add(overlayJObj);
                if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                {
                    b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                }
            }

            foreach (var prefab in Prefabs)
            {
                if (prefab.Hidden)
                {
                    continue;
                }
                var originNode = GetNodeByUid(prefab.Nodes[0]);
                if (prefab.Prefab.PrefabNodes == null)
                {
                    continue;
                }
                var mapPointOrigin = prefab.Prefab.PrefabNodes[prefab.Origin];

                var rot = (float)(originNode.Rotation - Math.PI -
                                  Math.Atan2(mapPointOrigin.RotZ, mapPointOrigin.RotX) + Math.PI / 2);

                var prefabStartX = originNode.X - mapPointOrigin.X;
                var prefabStartZ = originNode.Z - mapPointOrigin.Z;
                foreach (var spawnPoint in prefab.Prefab.SpawnPoints)
                {
                    var newPoint = RenderHelper.RotatePoint(prefabStartX + spawnPoint.X, prefabStartZ + spawnPoint.Z, rot,
                                                            originNode.X, originNode.Z);

                    var overlayJObj = new JObject
                    {
                        ["X"] = newPoint.X,
                        ["Y"] = newPoint.Y,
                    };

                    string overlayName;

                    switch (spawnPoint.Type)
                    {
                    case TsSpawnPointType.GasPos:
                    {
                        overlayName         = "gas_ico";
                        overlayJObj["Type"] = "Fuel";
                        break;
                    }

                    case TsSpawnPointType.ServicePos:
                    {
                        overlayName         = "service_ico";
                        overlayJObj["Type"] = "Service";
                        break;
                    }

                    case TsSpawnPointType.WeightStationPos:
                    {
                        overlayName         = "weigh_station_ico";
                        overlayJObj["Type"] = "WeightStation";
                        break;
                    }

                    case TsSpawnPointType.TruckDealerPos:
                    {
                        overlayName         = "dealer_ico";
                        overlayJObj["Type"] = "TruckDealer";
                        break;
                    }

                    case TsSpawnPointType.BuyPos:
                    {
                        overlayName         = "garage_large_ico";
                        overlayJObj["Type"] = "Garage";
                        break;
                    }

                    case TsSpawnPointType.RecruitmentPos:
                    {
                        overlayName         = "recruitment_ico";
                        overlayJObj["Type"] = "Recruitment";
                        break;
                    }

                    default:
                        continue;
                    }

                    overlayJObj["Name"] = overlayName;
                    var overlay = LookupOverlay(ScsHash.StringToToken(overlayName));
                    var b       = overlay.GetBitmap();
                    if (b == null)
                    {
                        continue;
                    }
                    overlayJObj["Width"]  = b.Width;
                    overlayJObj["Height"] = b.Height;
                    overlaysJArr.Add(overlayJObj);
                    if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                    {
                        b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                    }
                }

                var lastId = -1;
                foreach (var triggerPoint in prefab.Prefab.TriggerPoints)
                {
                    var newPoint = RenderHelper.RotatePoint(prefabStartX + triggerPoint.X, prefabStartZ + triggerPoint.Z, rot,
                                                            originNode.X, originNode.Z);

                    if (triggerPoint.TriggerId == lastId)
                    {
                        continue;
                    }
                    lastId = (int)triggerPoint.TriggerId;
                    var overlayJObj = new JObject
                    {
                        ["X"]    = newPoint.X,
                        ["Y"]    = newPoint.Y,
                        ["Name"] = "parking_ico",
                        ["Type"] = "Parking",
                    };

                    if (triggerPoint.TriggerActionToken != ScsHash.StringToToken("hud_parking"))
                    {
                        continue;
                    }

                    const string overlayName = "parking_ico";
                    var          overlay     = LookupOverlay(ScsHash.StringToToken(overlayName));
                    var          b           = overlay.GetBitmap();
                    if (b == null)
                    {
                        continue;
                    }
                    overlayJObj["Width"]  = b.Width;
                    overlayJObj["Height"] = b.Height;
                    overlaysJArr.Add(overlayJObj);
                    if (saveAsPNG && !File.Exists(Path.Combine(overlayPath, $"{overlayName}.png")))
                    {
                        b.Save(Path.Combine(overlayPath, $"{overlayName}.png"));
                    }
                }
            }
            File.WriteAllText(Path.Combine(path, "Overlays.json"), overlaysJArr.ToString(Formatting.Indented));
        }