Skip to content

Commit

Permalink
Replace build_type with boolean.
Browse files Browse the repository at this point in the history
In the olden days the launcher had to support many types of builds. These days only `MCC` and `Standalone` remain and someone already reused the MCC option for H3+ to flag whatever it's the newer version of that game generation.

Kept that behavior for now by converting this `enum` to a (nullable for technical reasons) boolean `alt_build`.
  • Loading branch information
num0005 committed Jun 26, 2024
1 parent a08a11d commit 0ce6da1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 36 deletions.
28 changes: 14 additions & 14 deletions Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public static bool halo_mcc
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.BuildType == build_type.release_mcc || toolkit_profile.Generation > ToolkitProfiles.GameGen.Halo2;
return toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -568,7 +568,7 @@ public static bool halo_ce_standalone
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo1 && toolkit_profile.BuildType == build_type.release_standalone;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo1 && !toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -580,7 +580,7 @@ public static bool halo_ce_mcc
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo1 && toolkit_profile.BuildType == build_type.release_mcc;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo1 && toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -604,7 +604,7 @@ public static bool halo_2_standalone
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && toolkit_profile.BuildType == build_type.release_standalone;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && !toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -616,7 +616,7 @@ public static bool halo_2_standalone_stock
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && !toolkit_profile.CommunityTools && toolkit_profile.BuildType == build_type.release_standalone;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && !toolkit_profile.CommunityTools && !toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -628,7 +628,7 @@ public static bool halo_2_standalone_community
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && toolkit_profile.CommunityTools && toolkit_profile.BuildType == build_type.release_standalone;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && toolkit_profile.CommunityTools && !toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -640,7 +640,7 @@ public static bool halo_2_mcc
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && toolkit_profile.BuildType == build_type.release_mcc;
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo2 && toolkit_profile.IsMCC;
}
return false;
}
Expand All @@ -664,7 +664,7 @@ public static bool halo_3_odst
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Halo3 && toolkit_profile.BuildType == build_type.release_mcc;
return toolkit_profile.IsODST;
}
return false;
}
Expand All @@ -676,7 +676,7 @@ public static bool halo_reach
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Gen4 && toolkit_profile.BuildType == build_type.release_standalone;
return toolkit_profile.IsReach;
}
return false;
}
Expand All @@ -688,7 +688,7 @@ public static bool halo_4
{
if (profile_mapping.Count > 0 && profile_index >= 0)
{
return toolkit_profile.Generation == ToolkitProfiles.GameGen.Gen4 && toolkit_profile.BuildType == build_type.release_mcc;
return toolkit_profile.IsH4;
}
return false;
}
Expand Down Expand Up @@ -828,22 +828,22 @@ private static ToolkitBase CreateToolkitFromProfile(ToolkitProfiles.ProfileSetti
switch (profile.Generation)
{
case ToolkitProfiles.GameGen.Halo1:
toolkit = profile.BuildType == build_type.release_standalone ?
toolkit = !profile.IsMCC ?
new H1Toolkit(profile, base_path, tool_paths) :
new H1AToolkit(profile, base_path, tool_paths);
break;
case ToolkitProfiles.GameGen.Halo2:
toolkit = profile.BuildType == build_type.release_standalone ?
toolkit = !profile.IsMCC ?
new H2Toolkit(profile, base_path, tool_paths) :
new H2AToolkit(profile, base_path, tool_paths);
break;
case ToolkitProfiles.GameGen.Halo3:
toolkit = profile.BuildType == build_type.release_standalone ?
toolkit = !profile.IsODST ?
toolkit = new H3Toolkit(profile, base_path, tool_paths) :
toolkit = new H3ODSTToolkit(profile, base_path, tool_paths);
break;
case ToolkitProfiles.GameGen.Gen4:
toolkit = profile.BuildType == build_type.release_standalone ?
toolkit = profile.IsReach ?
toolkit = new HRToolkit(profile, base_path, tool_paths) :
toolkit = new H4Toolkit(profile, base_path, tool_paths);
break;
Expand Down
13 changes: 2 additions & 11 deletions Launcher/PathSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,7 @@ private void profile_selection_SelectionChanged(object sender, SelectionChangedE
data_path.Text = ToolkitProfiles.SettingsList[profile_index].DataPath;
tag_path.Text = ToolkitProfiles.SettingsList[profile_index].TagPath;
gen_type.SelectedIndex = (int)ToolkitProfiles.SettingsList[profile_index].Generation - 1;
build_type profile_build = ToolkitProfiles.SettingsList[profile_index].BuildType;
switch (profile_build)
{
case build_type.release_standalone:
is_mcc.IsChecked = false;
break;
case build_type.release_mcc:
is_mcc.IsChecked = true;
break;
}
is_mcc.IsChecked = ToolkitProfiles.SettingsList[profile_index].IsAlternativeBuild;
community_tools.IsChecked = ToolkitProfiles.SettingsList[profile_index].CommunityTools;
verbose.IsChecked = ToolkitProfiles.SettingsList[profile_index].Verbose;
expert_mode.IsChecked = ToolkitProfiles.SettingsList[profile_index].ExpertMode;
Expand Down Expand Up @@ -354,7 +345,7 @@ void ProfileSave()
DataPath = data_path.Text,
TagPath = tag_path.Text,
Generation = (ToolkitProfiles.GameGen)(gen_type.SelectedIndex + 1),
BuildType = (bool)is_mcc.IsChecked ? build_type.release_mcc : build_type.release_standalone,
IsAlternativeBuild = (bool)is_mcc.IsChecked,
CommunityTools = (bool)community_tools.IsChecked,
Verbose = (bool)verbose.IsChecked,
ExpertMode = (bool)expert_mode.IsChecked,
Expand Down
10 changes: 5 additions & 5 deletions Launcher/ToolkitInterface/H2Toolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected virtual string sapienWindowClass
override public async Task ImportBitmaps(string path, string type, string compression, bool debug_plate)
{
string bitmaps_command = "bitmaps";
if (Profile.CommunityTools || Profile.BuildType == build_type.release_mcc)
if (Profile.CommunityTools || Profile.IsMCC)
{
bitmaps_command = "bitmaps-with-type";
await RunTool(ToolType.Tool, new List<string>() { bitmaps_command, path, type });
Expand Down Expand Up @@ -57,7 +57,7 @@ public override async Task BuildLightmap(string scenario, string bsp, LightmapAr
{
string quality = GetLightmapQuality(args);

if (args.instanceCount > 1 && (Profile.BuildType == build_type.release_mcc || Profile.CommunityTools)) // multi instance?
if (args.instanceCount > 1 && (Profile.IsMCC || Profile.CommunityTools)) // multi instance?
{
if (progress is not null)
progress.MaxValue += 1 + args.instanceCount;
Expand Down Expand Up @@ -109,7 +109,7 @@ async Task RunInstance(int index)
progress.DisableCancellation();
progress.MaxValue += 1;
}
await RunTool((args.NoAssert && Profile.BuildType == build_type.release_mcc) ? ToolType.ToolFast : ToolType.Tool, new() { "lightmaps", scenario, bsp, quality });
await RunTool((args.NoAssert && Profile.IsMCC) ? ToolType.ToolFast : ToolType.Tool, new() { "lightmaps", scenario, bsp, quality });
if (progress is not null)
progress.Report(1);
}
Expand All @@ -118,7 +118,7 @@ async Task RunInstance(int index)
private async Task RunMergeLightmap(string scenario, string bsp, int workerCount, bool useFast)
{

if (Profile.BuildType == build_type.release_mcc)
if (Profile.IsMCC)
{
await RunTool(useFast ? ToolType.ToolFast : ToolType.Tool, new List<string>()
{
Expand All @@ -143,7 +143,7 @@ private async Task RunMergeLightmap(string scenario, string bsp, int workerCount

private async Task<Utility.Process.Result> RunLightmapWorker(string scenario, string bsp, string quality, int workerCount, int index, bool useFast, CancellationToken cancelationToken, bool output)
{
if (Profile.BuildType == build_type.release_mcc)
if (Profile.IsMCC)
{
bool wereWeExperts = Profile.ElevatedToExpert;
Profile.ElevatedToExpert = true;
Expand Down
2 changes: 1 addition & 1 deletion Launcher/ToolkitInterface/ToolkitBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private List<string> GetArgsToPrepend()
{
List<string> args = new();

if (Profile.Generation != GameGen.Halo3 && Profile.BuildType == build_type.release_mcc)
if (Profile.Generation != GameGen.Halo3 && Profile.IsMCC)
{
if (!IsDefaultTagDirectory())
{
Expand Down
72 changes: 67 additions & 5 deletions Launcher/ToolkitProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public class ProfileSettingsLauncher

[JsonPropertyName("build_type")]
[JsonConverter(typeof(BuildTypeJsonConverter))]
public build_type BuildType { get; set; }
[Obsolete("Build type property is obsolute, use IsMcc, IsReach, IsODST and IsHalo4 instead")]
[JsonInclude]
public build_type BuildType { private get; set; }

[JsonPropertyName("alt_build")]
public bool? IsAlternativeBuild { get; set; }

[JsonPropertyName("community_tools")]
public bool CommunityTools { get; set; }
Expand All @@ -102,7 +107,7 @@ public class ProfileSettingsLauncher
public bool Verbose { get; set; }

[JsonPropertyName("expert_mode")]
private bool experMode { get; set; }
public bool ActualExpertMode { get; set; }

[JsonPropertyName("batch")]
public bool Batch { get; set; }
Expand All @@ -119,11 +124,59 @@ public class ProfileSettingsLauncher
[JsonIgnore]
public bool ExpertMode
{
get => experMode || ElevatedToExpert;
get => ActualExpertMode || ElevatedToExpert;
set
{
ElevatedToExpert = false;
experMode = value;
ActualExpertMode = value;
}
}

/// <summary>
/// Is this an MCC build?
/// </summary>
[JsonIgnore]
public bool IsMCC
{
get
{
return IsAlternativeBuild ?? false || Generation > GameGen.Halo2;
}
}

/// <summary>
/// is it ODST?
/// </summary>
[JsonIgnore]
public bool IsODST
{
get
{
return Generation == GameGen.Halo3 && (IsAlternativeBuild ?? false);
}
}

/// <summary>
/// Is it Halo Reach?
/// </summary>
[JsonIgnore]
public bool IsReach
{
get
{
return Generation == GameGen.Gen4 && (IsAlternativeBuild ?? false) == false;
}
}

/// <summary>
/// Is Halo 4 or H2A?
/// </summary>
[JsonIgnore]
public bool IsH4
{
get
{
return Generation == GameGen.Gen4 && (IsAlternativeBuild == true);
}
}

Expand Down Expand Up @@ -154,6 +207,11 @@ public void Upgrade()
Generation = GameGen.Invalid;
}
}

if (IsAlternativeBuild is null)
{
IsAlternativeBuild = BuildType == build_type.release_mcc;
}
#pragma warning restore 612, 618
}

Expand All @@ -162,6 +220,10 @@ public void PrepareForSave()
#pragma warning disable 612, 618
// downgrade generation for backwards compat
GameGenLegacy = (int)Generation - 1;
if (IsAlternativeBuild is bool altBuild)
{
BuildType = altBuild ? build_type.release_mcc : build_type.release_standalone;
}
#pragma warning restore 612, 618
}
}
Expand Down Expand Up @@ -238,7 +300,7 @@ public static int AddProfile()
var profile = new ProfileSettingsLauncher
{
ProfileName = String.Format("Profile {0}", count),
BuildType = build_type.release_standalone
IsAlternativeBuild = false,
};
_SettingsList.Add(profile);
return count;
Expand Down

0 comments on commit 0ce6da1

Please sign in to comment.