-
Notifications
You must be signed in to change notification settings - Fork 32
/
KethaneController.cs
62 lines (56 loc) · 2.11 KB
/
KethaneController.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using UnityEngine;
namespace Kethane
{
public class KethaneController
{
private static IEnumerable<ResourceDefinition> resourceDefinitions = null;
public static IEnumerable<ResourceDefinition> ResourceDefinitions
{
get
{
if (resourceDefinitions == null)
{
resourceDefinitions = loadResourceDefinitions();
}
return resourceDefinitions;
}
}
private static IEnumerable<ResourceDefinition> loadResourceDefinitions()
{
var defs = new SortedDictionary<String, ResourceDefinition>();
foreach (var definition in GameDatabase.Instance.GetConfigNodes("KethaneResource").Select(TryLoadResourceDefinition).Where(d => d != null))
{
if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(definition.Resource))
{
Debug.LogWarning(String.Format("[Kethane] {0} is an unknown resource, ignoring", definition.Resource));
}
else if (defs.ContainsKey(definition.Resource))
{
Debug.LogWarning(String.Format("[Kethane] Duplicate definition for {0}, ignoring", definition.Resource));
}
else
{
defs[definition.Resource] = definition;
}
}
Debug.Log(String.Format("[Kethane] Loaded {0} resource definitions", defs.Count));
return new ReadOnlyCollection<ResourceDefinition>(defs.Values.ToArray());
}
private static ResourceDefinition TryLoadResourceDefinition(ConfigNode node)
{
try
{
return new ResourceDefinition(node);
}
catch (Exception e)
{
Debug.LogError(String.Format("[Kethane] Error loading resource definition:\n\n{0}", e));
return null;
}
}
}
}