-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lazy loading for skill level info
- Loading branch information
Showing
12 changed files
with
87 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
19 changes: 19 additions & 0 deletions
19
src/common/Edelstein.Common.Utilities/Templates/TemplateCollection.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,19 @@ | ||
using System.Collections.Immutable; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Utilities.Templates; | ||
|
||
public class TemplateCollection<TTemplate>( | ||
IReadOnlyDictionary<int, TTemplate> templates | ||
) : | ||
ITemplateCollection<TTemplate> | ||
where TTemplate : ITemplate | ||
{ | ||
public int Count => templates.Count; | ||
|
||
public Task<TTemplate?> Retrieve(int key) | ||
=> Task.FromResult(templates.TryGetValue(key, out var result) ? result : default); | ||
|
||
public Task<ICollection<TTemplate>> RetrieveAll() | ||
=> Task.FromResult<ICollection<TTemplate>>(templates.Values.ToImmutableArray()); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/common/Edelstein.Common.Utilities/Templates/TemplateCollectionProvider.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,20 @@ | ||
using System.Collections.Frozen; | ||
using System.Collections.Immutable; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Utilities.Templates; | ||
|
||
public class TemplateCollectionProvider<TTemplate>( | ||
IReadOnlyDictionary<int, ITemplateProvider<TTemplate>> providers | ||
) : | ||
ITemplateCollection<TTemplate> | ||
where TTemplate : ITemplate | ||
{ | ||
public int Count => providers.Count; | ||
|
||
public async Task<TTemplate?> Retrieve(int key) | ||
=> providers.TryGetValue(key, out var provider) ? await provider.Provide() : default; | ||
|
||
public async Task<ICollection<TTemplate>> RetrieveAll() | ||
=> await Task.WhenAll(providers.Values.Select(p => p.Provide())); | ||
} |
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
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
3 changes: 2 additions & 1 deletion
3
...col/Edelstein.Protocol.Gameplay/Models/Characters/Skills/Templates/ISkillTemplateLevel.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
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
11 changes: 11 additions & 0 deletions
11
src/protocol/Edelstein.Protocol.Utilities/Templates/ITemplateCollection.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,11 @@ | ||
using Edelstein.Protocol.Utilities.Repositories.Methods; | ||
|
||
namespace Edelstein.Protocol.Utilities.Templates; | ||
|
||
public interface ITemplateCollection<TTemplate> : | ||
IRepositoryMethodRetrieve<int, TTemplate>, | ||
IRepositoryMethodRetrieveAll<int, TTemplate> | ||
where TTemplate : ITemplate | ||
{ | ||
int Count { get; } | ||
} |
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
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