File size: 2,955 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class BillboardSetHandler
{
	protected bool 							m_BillboardSetIndex 	= -1;
	protected ref array<ref BillboardSet> 	m_BillboardSets;
	protected static const string 			ROOT_CLASS = "BillboardPresets";
	protected static int 					m_SetIndexCached = -1;//once we resolve the name into an index, we cache it(this disallows dynamic index swapping during mission's runtime)
	
	string GetTextureByType(string type)
	{
		if (m_BillboardSetIndex == -1)
			return "";
		BillboardSet bbset = m_BillboardSets.Get(m_BillboardSetIndex);
		return bbset.GetTextureByType(type);
	}

	void OnRPCIndex(int index)
	{
		if (!m_BillboardSets)
			LoadBillboardConfigs();
						
		if (m_BillboardSets && m_BillboardSets.IsValidIndex(index))
		{
			m_BillboardSetIndex = index;
		}
	}
	
	protected bool LoadBillboardConfigs()
	{
		m_BillboardSets = new array<ref BillboardSet>();
		
		int setCount = g_Game.ConfigGetChildrenCount(ROOT_CLASS);

		for (int setIndex = 0; setIndex < setCount; setIndex++)
		{
			string setName;
			GetGame().ConfigGetChildName(ROOT_CLASS, setIndex, setName);
			string path = ROOT_CLASS + " " + setName;
			m_BillboardSets.Insert(new BillboardSet(path));
		}
		
		return true; 
	}
	
	static bool ActivateBillboardSet(string setClassName, PlayerIdentity identity)
	{
		if (!g_Game)
			return false;
		
		if (m_SetIndexCached == -1)
		{
			int setCount = g_Game.ConfigGetChildrenCount(ROOT_CLASS);
			for (int setIndex = 0; setIndex < setCount; setIndex++)
			{
				string setName;
				GetGame().ConfigGetChildName(ROOT_CLASS, setIndex, setName);
				
				if (setName == setClassName)
				{
					m_SetIndexCached = setIndex;
					break
				}
			}
		}
		
		if (m_SetIndexCached != -1)
		{
			auto param = new Param1<int>(m_SetIndexCached);
			GetGame().RPCSingleParam( identity.GetPlayer(), ERPCs.RPC_SET_BILLBOARDS, param, true, identity );
			return true;
		}
		return false;
	}
}


class BillboardSet
{
	protected ref map<string, string> m_TypeTextureMapping = new map<string, string>();
	
	void BillboardSet(string path)
	{
		LoadConfig(path);
	}
	
	string GetTextureByType(string type)
	{
		return m_TypeTextureMapping.Get(type);
	}

	protected void LoadConfig(string path)
	{
		int count = g_Game.ConfigGetChildrenCount(path);
		for ( int i = 0; i < count; i++ )
		{
			string itemName;
			GetGame().ConfigGetChildName(path, i, itemName);
			
			string typesPath = path + " " + itemName + " types";
			string texturePath = path + " " + itemName + " texture";
			
			if (GetGame().ConfigIsExisting(typesPath) && GetGame().ConfigIsExisting(texturePath))
			{
				TStringArray types = new TStringArray();
				string texture;
				GetGame().ConfigGetText(texturePath, texture);
				GetGame().ConfigGetTextArray(typesPath, types);
				
				foreach (string s: types)
				{
					m_TypeTextureMapping.Insert(s,texture);
				}
			}
			else
			{
				ErrorEx("Billboard set incorrect configuration, type or texture param missing: " + path);
			}
			
		}
	}
}