Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DesertCar and transformation support #1

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EnvimixForTM2020/EnvimixForTM2020.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
2 changes: 2 additions & 0 deletions EnvimixForTM2020/EnvimixForTM2020Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
98 changes: 94 additions & 4 deletions EnvimixForTM2020/EnvimixForTM2020Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class EnvimixForTM2020Tool : ITool, IHasOutput<IEnumerable<NodeFile<CGame
{
private readonly CGameCtnChallenge map;

private static readonly string[] cars = new[] { "CarSport", "CarSnow", "CharacterPilot" };
private static readonly string[] cars = new[] { "CarSport", "CarSnow", "CarRally", "CarDesert", "CharacterPilot" };
private static readonly string[] envs = new[] { "Stadium", "Snow", "Rally", "Desert" };

public EnvimixForTM2020Config Config { get; set; } = new();

Expand All @@ -30,32 +31,63 @@ public IEnumerable<NodeFile<CGameCtnChallenge>> 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)
{
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:
Expand Down Expand Up @@ -88,5 +120,63 @@ public IEnumerable<NodeFile<CGameCtnChallenge>> 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<string> prevGateBlocks, IList<string> 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++] };
}
}
}
2 changes: 1 addition & 1 deletion EnvimixForTM2020CLI/EnvimixForTM2020CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Loading