File size: 1,342 Bytes
00437a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
using Photon.Deterministic;
using System;
using System.Collections.Generic;

namespace Quantum
{
	public unsafe partial class AIBlackboard
	{
		public AIBlackboardEntry[] Entries;

		[NonSerialized] public Dictionary<String, Int32> Map;

		public override void Loaded(IResourceManager resourceManager, Native.Allocator allocator)
		{
			base.Loaded(resourceManager, allocator);

			Map = new Dictionary<string, Int32>();

			for (Int32 i = 0; i < Entries.Length; i++)
			{
				Map.Add(Entries[i].Key.Key, i);
			}
		}

		public Int32 GetEntryID(string key)
		{
			Assert.Check(string.IsNullOrEmpty(key) == false, "The Key cannot be empty or null.");
			Assert.Check(Map.ContainsKey(key) == true, $"Key {0} not present in the Blackboard", key);

			return Map[key];
		}

		public bool TryGetEntryID(string key, out Int32 id)
		{
			return Map.TryGetValue(key, out id);
		}

		public string GetEntryName(Int32 id)
		{
			return Entries[id].Key.Key;
		}

		public bool HasEntry(string key)
		{
			for (int i = 0; i < Entries.Length; i++)
			{
				if (Entries[i].Key.Key == key)
				{
					return true;
				}
			}

			return false;
		}

		public AIBlackboardEntry GetEntry(string key)
		{
			for (int i = 0; i < Entries.Length; i++)
			{
				if (Entries[i].Key.Key == key)
				{
					return Entries[i];
				}
			}

			return default;
		}
	}
}