-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made ModuleContext and renamed it to DefaultModuleContext
- Loading branch information
Showing
2 changed files
with
56 additions
and
49 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Bannerlord.LauncherManager/Utils/DefaultModuleContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Bannerlord.LauncherManager.Models; | ||
using Bannerlord.ModuleManager; | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Bannerlord.LauncherManager.Utils; | ||
|
||
public class DefaultModuleContext<TModuleViewModel> where TModuleViewModel : class, IModuleViewModel | ||
{ | ||
private readonly IDictionary<string, TModuleViewModel> _lookup; | ||
public DefaultModuleContext(IEnumerable<TModuleViewModel> moduleVMs) | ||
{ | ||
_lookup = moduleVMs.ToDictionary(x => x.ModuleInfoExtended.Id, x => x); | ||
} | ||
public DefaultModuleContext(IDictionary<string, TModuleViewModel> lookup) | ||
{ | ||
_lookup = lookup; | ||
} | ||
|
||
public bool GetIsValid(ModuleInfoExtended module) | ||
{ | ||
if (FeatureIds.LauncherFeatures.Contains(module.Id)) | ||
return true; | ||
|
||
return _lookup[module.Id].IsValid; | ||
} | ||
public bool GetIsSelected(ModuleInfoExtended module) | ||
{ | ||
if (FeatureIds.LauncherFeatures.Contains(module.Id)) | ||
return false; | ||
|
||
return _lookup[module.Id].IsSelected; | ||
} | ||
public void SetIsSelected(ModuleInfoExtended module, bool value) | ||
{ | ||
if (FeatureIds.LauncherFeatures.Contains(module.Id)) | ||
return; | ||
_lookup[module.Id].IsSelected = value; | ||
} | ||
public bool GetIsDisabled(ModuleInfoExtended module) | ||
{ | ||
if (FeatureIds.LauncherFeatures.Contains(module.Id)) | ||
return false; | ||
|
||
return _lookup[module.Id].IsDisabled; | ||
} | ||
public void SetIsDisabled(ModuleInfoExtended module, bool value) | ||
{ | ||
if (FeatureIds.LauncherFeatures.Contains(module.Id)) | ||
return; | ||
_lookup[module.Id].IsDisabled = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters