-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseManager.cs
43 lines (41 loc) · 1.31 KB
/
DatabaseManager.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
using GameEntitySystem;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using TemplatesDatabase;
namespace Game
{
public static class DatabaseManager
{
static GameDatabase m_gameDatabase;
static Dictionary<string, ValuesDictionary> m_valueDictionaries = new Dictionary<string, ValuesDictionary>();
public static GameDatabase GameDatabase
{
get
{
if (m_gameDatabase != null)
return m_gameDatabase;
throw new InvalidOperationException("Database not loaded.");
}
}
// Replace DatabaseManager.Initialize
public static void Initialize()
{
if (m_gameDatabase == null)
{
var node = ContentManager.Get<XElement>("Database");
ContentManager.Dispose("Database");
ContentManager.CombineXml(node, ModsManager.GetEntries(".xdb"), "Guid", "Name");
m_gameDatabase = new GameDatabase(XmlDatabaseSerializer.LoadDatabase(node));
foreach (DatabaseObject explicitNestingChild in GameDatabase.Database.Root.GetExplicitNestingChildren(GameDatabase.EntityTemplateType, false))
{
var valuesDictionary = new ValuesDictionary();
valuesDictionary.PopulateFromDatabaseObject(explicitNestingChild);
m_valueDictionaries[explicitNestingChild.Name] = valuesDictionary;
}
return;
}
throw new InvalidOperationException("Database already loaded.");
}
}
}