diff --git a/EnvimixForTM2020/EnvimixForTM2020.csproj b/EnvimixForTM2020/EnvimixForTM2020.csproj index 97833aa..ee43694 100644 --- a/EnvimixForTM2020/EnvimixForTM2020.csproj +++ b/EnvimixForTM2020/EnvimixForTM2020.csproj @@ -1,7 +1,7 @@ - 1.0.1 + 1.1.0 net7.0 enable enable diff --git a/EnvimixForTM2020/EnvimixForTM2020Config.cs b/EnvimixForTM2020/EnvimixForTM2020Config.cs index d05f497..7c05a96 100644 --- a/EnvimixForTM2020/EnvimixForTM2020Config.cs +++ b/EnvimixForTM2020/EnvimixForTM2020Config.cs @@ -7,6 +7,8 @@ public class EnvimixForTM2020Config : Config public string MapNameFormat { get; set; } = "$<{0}$> - {1}"; public bool IncludeCarSport { get; set; } = true; public bool IncludeCarSnow { get; set; } = true; + public bool IncludeCarRally { get; set; } = true; + public bool IncludeCarDesert { get; set; } = false; public bool IncludeCharacterPilot { get; set; } = false; public ValidationMode ValidationMode { get; set; } = ValidationMode.Real; public bool GenerateDefaultCarVariant { get; set; } diff --git a/EnvimixForTM2020/EnvimixForTM2020Tool.cs b/EnvimixForTM2020/EnvimixForTM2020Tool.cs index 44e6f71..e53ab55 100644 --- a/EnvimixForTM2020/EnvimixForTM2020Tool.cs +++ b/EnvimixForTM2020/EnvimixForTM2020Tool.cs @@ -12,7 +12,8 @@ public class EnvimixForTM2020Tool : ITool, IHasOutput> Produce() var includes = new[] { - Config.IncludeCarSport, Config.IncludeCarSnow, Config.IncludeCharacterPilot + Config.IncludeCarSport, Config.IncludeCarSnow, Config.IncludeCarRally, Config.IncludeCarDesert, Config.IncludeCharacterPilot }; var prevPlayerModel = map.PlayerModel; + var prevAuthorTime = map.TMObjective_AuthorTime; + var prevGoldTime = map.TMObjective_GoldTime; + var prevSilverTime = map.TMObjective_SilverTime; + var prevBronzeTime = map.TMObjective_BronzeTime; + + var defaultCar = map.PlayerModel?.Id; + if (string.IsNullOrEmpty(defaultCar)) + { + defaultCar = "CarSport"; + } + var defaultMapUid = map.MapUid; var defaultMapName = map.MapName; + var prevGateBlocks = map.GetBlocks() + .Select(x => x.Name) + .Where(IsTransformationGate) + .ToList(); + + var prevGateItems = map.GetAnchoredObjects() + .Select(x => x.ItemModel.Id) + .Where(IsTransformationGate) + .ToList(); + for (int i = 0; i < cars.Length; i++) { var car = cars[i]; + var env = envs.Length > i ? envs[i] : null; var include = includes[i]; if (!include) @@ -47,15 +70,24 @@ public IEnumerable> Produce() continue; } - if (!Config.GenerateDefaultCarVariant) + if (!Config.GenerateDefaultCarVariant && car == defaultCar) { - if (map.Collection == 26 && car == "CarSport") continue; + continue; } map.PlayerModel = (car, 10003, ""); map.MapUid = $"{Convert.ToBase64String(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString()))[..10]}{defaultMapUid.Substring(9, 10)}ENVIMIX"; map.MapName = string.Format(Config.MapNameFormat, defaultMapName, car); + if (env is null) + { + RestoreGates(prevGateBlocks, prevGateItems); + } + else + { + ChangeGates(env); + } + switch (Config.ValidationMode) { case ValidationMode.None: @@ -88,5 +120,63 @@ public IEnumerable> Produce() // Return to previous to temporarily fix the mutability issue map.PlayerModel = prevPlayerModel; map.MapName = defaultMapName; + + map.TMObjective_AuthorTime = prevAuthorTime; + map.TMObjective_GoldTime = prevGoldTime; + map.TMObjective_SilverTime = prevSilverTime; + map.TMObjective_BronzeTime = prevBronzeTime; + + RestoreGates(prevGateBlocks, prevGateItems); + } + + private static bool IsTransformationGate(string name) + { + return name.Contains("Gameplay") && envs.Any(env => name.Contains($"Gameplay{env}")); + } + + private void ChangeGates(string envimixEnvironment) + { + foreach (var block in map.GetBlocks().Where(block => block.Name.Contains("Gameplay"))) + { + for (int i = 0; i < envs.Length; i++) + { + var env = envs[i]; + + if (block.Name.Contains($"Gameplay{env}")) + { + block.Name = block.Name.Replace(env, envimixEnvironment); + } + } + } + + foreach (var item in map.GetAnchoredObjects().Where(item => item.ItemModel.Id.Contains("Gameplay"))) + { + for (int i = 0; i < envs.Length; i++) + { + var env = envs[i]; + + if (item.ItemModel.Id.Contains($"Gameplay{env}")) + { + item.ItemModel = item.ItemModel with { Id = item.ItemModel.Id.Replace(env, envimixEnvironment) }; + } + } + } + } + + private void RestoreGates(IList prevGateBlocks, IList prevGateItems) + { + var index = 0; + + foreach (var block in map.GetBlocks().Where(block => IsTransformationGate(block.Name))) + { + block.Name = prevGateBlocks[index++]; + } + + index = 0; + + foreach (var item in map.GetAnchoredObjects().Where(item => IsTransformationGate(item.ItemModel.Id))) + { + item.ItemModel = item.ItemModel with { Id = prevGateItems[index++] }; + } } } \ No newline at end of file diff --git a/EnvimixForTM2020CLI/EnvimixForTM2020CLI.csproj b/EnvimixForTM2020CLI/EnvimixForTM2020CLI.csproj index 0095249..2691399 100644 --- a/EnvimixForTM2020CLI/EnvimixForTM2020CLI.csproj +++ b/EnvimixForTM2020CLI/EnvimixForTM2020CLI.csproj @@ -1,7 +1,7 @@ - 1.0.1 + 1.1.0 Exe net7.0 enable