forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpellsModule.cs
58 lines (51 loc) · 2.54 KB
/
SpellsModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Threading.Tasks;
using Prism.Events;
using Prism.Ioc;
using WDE.Common;
using WDE.Common.Database;
using WDE.Common.Events;
using WDE.Common.Parameters;
using WDE.Common.Services;
using WDE.Common.Utils;
using WDE.Module;
using WDE.MVVM.Observable;
using WDE.Spells.Parameters;
namespace WDE.Spells
{
public class SpellsModule : ModuleBase
{
private IContainerProvider containerProvider = null!;
public override void OnInitialized(IContainerProvider containerProvider)
{
this.containerProvider = containerProvider;
containerProvider.Resolve<IEventAggregator>()
.GetEvent<AllModulesLoaded>()
.Subscribe(() =>
{
var factory = containerProvider.Resolve<IParameterFactory>();
var spellPicker = this.containerProvider.Resolve<ISpellEntryProviderService>();
void RegisterSpellParameter(string key, string? customCounterTable = null) =>
factory.RegisterCombined(key, "DbcSpellParameter", "DatabaseSpellParameter", (dbc, db) => new SpellParameter(spellPicker, dbc, db, customCounterTable), QuickAccessMode.Limited);
RegisterSpellParameter("SpellParameter");
RegisterSpellParameter("Spell(spell_override)Parameter", "spell_override");
factory.RegisterDepending("MultiSpellParameter", "SpellParameter", spells => new MultiSpellParameter(spells));
factory.RegisterDepending("SpellAreaSpellParameter", "SpellParameter", spells => new SpellAreaSpellParameter(spells));
factory.RegisterDepending("SpellOrRankedSpellParameter", "SpellParameter", spells => new SpellOrRankedSpellParameter(spells));
},
ThreadOption.PublisherThread,
true);
containerProvider.Resolve<ILoadingEventAggregator>()
.OnEvent<DatabaseLoadedEvent>()
.SubscribeAction(_ =>
{
LoadDatabaseSpellsAsync().ListenErrors();
});
}
private async Task LoadDatabaseSpellsAsync()
{
var factory = containerProvider.Resolve<IParameterFactory>();
var database = containerProvider.Resolve<IDatabaseProvider>();
factory.Register("DatabaseSpellParameter", new DatabaseSpellParameter(await database.GetSpellDbcAsync()));
}
}
}