-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmourVariationManager.cs
More file actions
46 lines (41 loc) · 1.78 KB
/
ArmourVariationManager.cs
File metadata and controls
46 lines (41 loc) · 1.78 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using TaleWorlds.Library;
using TaleWorlds.ModuleManager;
using TaleWorlds.MountAndBlade;
namespace ArmourVariationManager
{
public class ArmourVariationManager
{
//If you integrate the code to your own mod, change this path to where your xml is
private readonly string _xmlFilePath = ModuleHelper.GetModuleFullPath("ArmourVariationManager") + "ModuleData/" + "armourvariations.xml";
private ArmourVariations _armourVariationList { get; set; } = new ArmourVariations();
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public static ArmourVariationManager Instance { get; private set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public MBReadOnlyList<ArmourVariation> ArmourVariations => new MBReadOnlyList<ArmourVariation>(_armourVariationList);
public ArmourVariationManager()
{
Instance = this;
LoadXml();
}
private void LoadXml()
{
XmlSerializer ser = new XmlSerializer(typeof(ArmourVariations));
if (File.Exists(_xmlFilePath))
{
var result = ser.Deserialize(File.OpenRead(_xmlFilePath)) as ArmourVariations;
if (result != null) _armourVariationList = result;
}
}
public ArmourVariation GetVariationData(string id)
{
return ArmourVariations.Where(x => x.VariationId == id).FirstOrDefault();
}
}
}