-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecruiterSubModule.cs
72 lines (66 loc) · 2.03 KB
/
RecruiterSubModule.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using TaleWorlds.MountAndBlade;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
namespace Recruiter
{
public class RecruiterSubModule : MBSubModuleBase
{
private static readonly string ConfigFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.json");
private static readonly List<Action> ActionsToExecuteNextTick = new List<Action>();
public static Config Config { get; private set; }
public static void ExecuteActionOnNextTick(Action action)
{
if (action == null)
{
return;
}
ActionsToExecuteNextTick.Add(action);
}
protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();
LoadConfig();
}
protected override void OnApplicationTick(float dt)
{
base.OnApplicationTick(dt);
foreach (var action in ActionsToExecuteNextTick)
{
action();
}
ActionsToExecuteNextTick.Clear();
}
protected override void OnGameStart(Game game, IGameStarter gameStarter)
{
base.OnGameStart(game, gameStarter);
var campaign = game.GameType as Campaign;
if (campaign == null)
{
return;
}
var campaignGameStarter = gameStarter as CampaignGameStarter;
campaignGameStarter?.AddBehavior(new RecruiterCampaignBehavior());
}
private static void LoadConfig()
{
if (!File.Exists(ConfigFilePath))
{
return;
}
try
{
Config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigFilePath));
}
catch
{
}
}
}
}