Skip to content

Commit

Permalink
added support for multiple versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfds committed May 31, 2024
1 parent d93f004 commit d659cc4
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 163 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia/Core/Controls/DownloadsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<DataGridTextColumn Header="Size" Binding="{Binding FileSizeString}" />
<DataGridTextColumn Header="Score" Binding="{Binding Score}" />
<DataGridTextColumn Header="Downloads" Binding="{Binding Installs}" />
<DataGridTextColumn Header="Status" Binding="{Binding Status}" FontWeight="Bold" />
<DataGridTextColumn Header="Updated" Binding="{Binding UpdateDateString}" SortMemberPath="UpdateDate" />
<DataGridTextColumn Header="Status" Binding="{Binding Status}" FontWeight="Bold" />
</DataGrid.Columns>
</DataGrid>

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia/Core/ViewModels/ModsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ private void ModCheckboxPressed(object? obj)

if (!mod.IsEnabled)
{
Game.InstalledAddonsProvider.DisableAddon(mod.Id);
Game.InstalledAddonsProvider.DisableAddon(new(mod.Id, mod.Version));
}
else if (mod.IsEnabled)
{
Game.InstalledAddonsProvider.EnableAddon(mod.Id);
Game.InstalledAddonsProvider.EnableAddon(new(mod.Id, mod.Version));
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/ClientCommon/Config/ConfigProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Helpers;
using Common;
using Common.Enums;
using Common.Helpers;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -106,9 +107,9 @@ public HashSet<string> DisabledAutoloadMods
get => [.. _dbContext.DisabledAddons.Select(x => x.AddonId)];
}

public void ChangeModState(string addonId, bool isEnabled)
public void ChangeModState(AddonVersion addonId, bool isEnabled)
{
var existing = _dbContext.DisabledAddons.Find([addonId]);
var existing = _dbContext.DisabledAddons.Find([addonId.Id]);

if (existing is null)
{
Expand All @@ -118,7 +119,7 @@ public void ChangeModState(string addonId, bool isEnabled)
}
else
{
_dbContext.DisabledAddons.Add(new() { AddonId = addonId });
_dbContext.DisabledAddons.Add(new() { AddonId = addonId.Id });
}
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/ClientCommon/Config/ConfigProviderFake.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Common.Enums;
using Common;
using Common.Enums;

namespace ClientCommon.Config;

Expand Down Expand Up @@ -30,5 +31,5 @@ public sealed class ConfigProviderFake : IConfigProvider

public void AddScore(string addonId, bool isUpvote) => throw new NotImplementedException();

public void ChangeModState(string addonId, bool isEnabled) => throw new NotImplementedException();
public void ChangeModState(AddonVersion addonId, bool isEnabled) => throw new NotImplementedException();
}
5 changes: 3 additions & 2 deletions src/ClientCommon/Config/IConfigProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Common.Enums;
using Common;
using Common.Enums;
using static ClientCommon.Config.ConfigProvider;

namespace ClientCommon.Config;
Expand Down Expand Up @@ -26,5 +27,5 @@ public interface IConfigProvider

void AddPlaytime(string addonId, TimeSpan playTime);
void AddScore(string addonId, bool isUpvote);
void ChangeModState(string addonId, bool isEnabled);
void ChangeModState(AddonVersion addonId, bool isEnabled);
}
28 changes: 28 additions & 0 deletions src/Common/AddonVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics.CodeAnalysis;

namespace Common;

public readonly struct AddonVersion
{
public required readonly string Id { get; init; }
public required readonly string? Version{ get; init; }

[SetsRequiredMembers]
public AddonVersion(
string title,
string? version
)
{
Id = title;
Version = version;
}

[SetsRequiredMembers]
public AddonVersion(
string title
)
{
Id = title;
Version = null;
}
}
6 changes: 3 additions & 3 deletions src/Common/Interfaces/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public interface IGame
/// <summary>
/// Get list of official addons and custom campaigns
/// </summary>
Dictionary<string, IAddon> GetCampaigns();
Dictionary<AddonVersion, IAddon> GetCampaigns();

/// <summary>
/// Get list of custom maps
/// </summary>
Dictionary<string, IAddon> GetSingleMaps();
Dictionary<AddonVersion, IAddon> GetSingleMaps();

/// <summary>
/// Get list of autoload mods
/// </summary>
Dictionary<string, IAddon> GetAutoloadMods(bool enabledOnly);
Dictionary<AddonVersion, IAddon> GetAutoloadMods(bool enabledOnly);
}
}
6 changes: 3 additions & 3 deletions src/Common/Interfaces/IInstalledAddonsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IInstalledAddonsProvider
/// Get installed addons
/// </summary>
/// <param name="addonType">Addon type</param>
Dictionary<string, IAddon> GetInstalledAddons(AddonTypeEnum addonType);
Dictionary<AddonVersion, IAddon> GetInstalledAddons(AddonTypeEnum addonType);

/// <summary>
/// Create cache of installed addons
Expand All @@ -36,12 +36,12 @@ public interface IInstalledAddonsProvider
/// Disable addon
/// </summary>
/// <param name="id">Addon id</param>
void DisableAddon(string id);
void DisableAddon(AddonVersion id);

/// <summary>
/// Enable addon
/// </summary>
/// <param name="id">Addon id</param>
void EnableAddon(string id);
void EnableAddon(AddonVersion id);
}
}
11 changes: 6 additions & 5 deletions src/Games/Games/BaseGame.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ClientCommon.Helpers;
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Helpers;
using Common.Interfaces;
Expand Down Expand Up @@ -88,7 +89,7 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
public virtual Dictionary<string, IAddon> GetCampaigns()
public virtual Dictionary<AddonVersion, IAddon> GetCampaigns()
{
var originalCampaigns = GetOriginalCampaigns();

Expand All @@ -112,7 +113,7 @@ public virtual Dictionary<string, IAddon> GetCampaigns()


/// <inheritdoc/>
public virtual Dictionary<string, IAddon> GetSingleMaps()
public virtual Dictionary<AddonVersion, IAddon> GetSingleMaps()
{
var maps = InstalledAddonsProvider.GetInstalledAddons(AddonTypeEnum.Map);

Expand All @@ -121,13 +122,13 @@ public virtual Dictionary<string, IAddon> GetSingleMaps()


/// <inheritdoc/>
public virtual Dictionary<string, IAddon> GetAutoloadMods(bool enabledOnly)
public virtual Dictionary<AddonVersion, IAddon> GetAutoloadMods(bool enabledOnly)
{
var mods = InstalledAddonsProvider.GetInstalledAddons(AddonTypeEnum.Mod);

if (enabledOnly)
{
Dictionary<string, IAddon> enabled = new(StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> enabled = new();

foreach (var mod in mods)
{
Expand Down Expand Up @@ -166,7 +167,7 @@ private void Cleanup()
/// Get list of original campaigns
/// </summary>
/// <returns></returns>
protected abstract Dictionary<string, IAddon> GetOriginalCampaigns();
protected abstract Dictionary<AddonVersion, IAddon> GetOriginalCampaigns();


/// <summary>
Expand Down
9 changes: 5 additions & 4 deletions src/Games/Games/BloodGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Enums.Addons;
using Common.Helpers;
Expand Down Expand Up @@ -39,12 +40,12 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
protected override Dictionary<string, IAddon> GetOriginalCampaigns()
protected override Dictionary<AddonVersion, IAddon> GetOriginalCampaigns()
{
Dictionary<string, IAddon> campaigns = new(2, StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> campaigns = new(2);

var bloodId = nameof(GameEnum.Blood).ToLower();
campaigns.Add(bloodId, new BloodCampaign()
campaigns.Add(new(bloodId), new BloodCampaign()
{
Id = bloodId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -82,7 +83,7 @@ protected override Dictionary<string, IAddon> GetOriginalCampaigns()
{
var bloodCpId = nameof(BloodAddonEnum.BloodCP).ToLower();

campaigns.Add(bloodCpId, new BloodCampaign()
campaigns.Add(new(bloodCpId), new BloodCampaign()
{
Id = bloodCpId,
Type = AddonTypeEnum.Official,
Expand Down
17 changes: 9 additions & 8 deletions src/Games/Games/DukeGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Enums.Addons;
using Common.Enums.Versions;
Expand Down Expand Up @@ -74,15 +75,15 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
protected override Dictionary<string, IAddon> GetOriginalCampaigns()
protected override Dictionary<AddonVersion, IAddon> GetOriginalCampaigns()
{
Dictionary<string, IAddon> campaigns = new(6, StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> campaigns = new(6);

if (IsBaseGameInstalled &&
GameInstallFolder != DukeWTInstallPath)
{
var dukeId = nameof(GameEnum.Duke3D).ToLower();
campaigns.Add(dukeId, new DukeCampaign()
campaigns.Add(new(dukeId), new DukeCampaign()
{
Id = dukeId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -115,7 +116,7 @@ Duke Nukem 3D is a first-person shooter developed and published by **3D Realms**
if (IsWorldTourInstalled)
{
var dukeWtId = nameof(DukeVersionEnum.Duke3D_WT).ToLower();
campaigns.Add(dukeWtId, new DukeCampaign()
campaigns.Add(new(dukeWtId), new DukeCampaign()
{
Id = dukeWtId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -150,7 +151,7 @@ Duke Nukem 3D is a first-person shooter developed and published by **3D Realms**
if (IsCaribbeanInstalled)
{
var dukeVacaId = nameof(DukeAddonEnum.DukeVaca).ToLower();
campaigns.Add(dukeVacaId, new DukeCampaign()
campaigns.Add(new(dukeVacaId), new DukeCampaign()
{
Id = dukeVacaId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -183,7 +184,7 @@ Duke Nukem 3D is a first-person shooter developed and published by **3D Realms**
if (IsNuclearWinterInstalled)
{
var dukeNwId = nameof(DukeAddonEnum.DukeNW).ToLower();
campaigns.Add(dukeNwId, new DukeCampaign()
campaigns.Add(new(dukeNwId), new DukeCampaign()
{
Id = dukeNwId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -215,7 +216,7 @@ Duke Nukem must travel to the North Pole in order to stop the brainwashed Santa
if (IsDukeDCInstalled)
{
var dukeDcId = nameof(DukeAddonEnum.DukeDC).ToLower();
campaigns.Add(dukeDcId, new DukeCampaign()
campaigns.Add(new(dukeDcId), new DukeCampaign()
{
Id = dukeDcId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -250,7 +251,7 @@ Duke Nukem must travel to the North Pole in order to stop the brainwashed Santa
if (IsDuke64Installed)
{
var duke64Id = nameof(GameEnum.Duke64).ToLower();
campaigns.Add(duke64Id, new DukeCampaign()
campaigns.Add(new(duke64Id), new DukeCampaign()
{
Id = duke64Id,
Type = AddonTypeEnum.Official,
Expand Down
7 changes: 4 additions & 3 deletions src/Games/Games/FuryGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Helpers;
using Common.Interfaces;
Expand Down Expand Up @@ -28,14 +29,14 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
protected override Dictionary<string, IAddon> GetOriginalCampaigns()
protected override Dictionary<AddonVersion, IAddon> GetOriginalCampaigns()
{
Dictionary<string, IAddon> campaigns = new(1, StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> campaigns = new(1);

if (IsBaseGameInstalled)
{
var furyId = nameof(GameEnum.Fury).ToLower();
campaigns.Add(furyId, new FuryCampaign()
campaigns.Add(new(furyId), new FuryCampaign()
{
Id = furyId,
Type = AddonTypeEnum.Official,
Expand Down
11 changes: 6 additions & 5 deletions src/Games/Games/RedneckGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Enums.Addons;
using Common.Enums.Versions;
Expand Down Expand Up @@ -45,14 +46,14 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
protected override Dictionary<string, IAddon> GetOriginalCampaigns()
protected override Dictionary<AddonVersion, IAddon> GetOriginalCampaigns()
{
Dictionary<string, IAddon> campaigns = new(3, StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> campaigns = new(3);

if (IsBaseGameInstalled)
{
var redneckId = nameof(GameEnum.Redneck).ToLower();
campaigns.Add(redneckId, new RedneckCampaign()
campaigns.Add(new(redneckId), new RedneckCampaign()
{
Id = redneckId,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -86,7 +87,7 @@ protected override Dictionary<string, IAddon> GetOriginalCampaigns()
if (IsRoute66Installed)
{
var redneckR66Id = nameof(RedneckAddonEnum.Route66).ToLower();
campaigns.Add(redneckR66Id, new RedneckCampaign()
campaigns.Add(new(redneckR66Id), new RedneckCampaign()
{
Id = redneckR66Id,
Type = AddonTypeEnum.Official,
Expand Down Expand Up @@ -117,7 +118,7 @@ protected override Dictionary<string, IAddon> GetOriginalCampaigns()
if (IsAgainInstalled)
{
var redneckRaId = nameof(GameEnum.RidesAgain).ToLower();
campaigns.Add(redneckRaId, new RedneckCampaign()
campaigns.Add(new(redneckRaId), new RedneckCampaign()
{
Id = redneckRaId,
Type = AddonTypeEnum.Official,
Expand Down
7 changes: 4 additions & 3 deletions src/Games/Games/SlaveGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ClientCommon.Providers;
using Common;
using Common.Enums;
using Common.Helpers;
using Common.Interfaces;
Expand Down Expand Up @@ -28,14 +29,14 @@ PlaytimeProvider playtimeProvider


/// <inheritdoc/>
protected override Dictionary<string, IAddon> GetOriginalCampaigns()
protected override Dictionary<AddonVersion, IAddon> GetOriginalCampaigns()
{
Dictionary<string, IAddon> campaigns = new(1, StringComparer.OrdinalIgnoreCase);
Dictionary<AddonVersion, IAddon> campaigns = new(1);

if (IsBaseGameInstalled)
{
var slaveId = nameof(GameEnum.Exhumed).ToLower();
campaigns.Add(slaveId, new SlaveCampaign()
campaigns.Add(new(slaveId), new SlaveCampaign()
{
Id = slaveId,
Type = AddonTypeEnum.Official,
Expand Down
Loading

0 comments on commit d659cc4

Please sign in to comment.