Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
KeyCompatibleGroupsManager.cs
浏览该文件的文档.
1namespace Game {
2 public static class KeyCompatibleGroupsManager {
3 public class KeyCompatibleGroup(string groupId) {
4 public string GroupId { get; } = groupId;
5 readonly HashSet<string> keys = [];
6
7 public void AddKey(string key) => keys.Add(key);
8
9 public void AddKeys(params string[] keys1) {
10 foreach (string key in keys1) {
11 AddKey(key);
12 }
13 }
14
15 public bool ContainsKey(string key) => keys.Contains(key);
16 public bool ContainsAll(IEnumerable<string> keyList) => keyList.All(k => keys.Contains(k));
17 public IReadOnlyCollection<string> Keys => keys;
18 }
19
20 public static readonly Dictionary<string, KeyCompatibleGroup> m_compatibleGroups = [];
21
22 public static void Initialize() {
23 m_compatibleGroups.Clear();
25 "InitKeyCompatibleGroups",
26 loader => {
27 loader.InitKeyCompatibleGroups();
28 return false;
29 }
30 );
31 }
32
39 public static void AddKeyToCompatibleGroup(string groupId, params string[] keys) {
40 if (!m_compatibleGroups.TryGetValue(groupId, out KeyCompatibleGroup group)) {
41 group = new KeyCompatibleGroup(groupId);
42 }
43 group.AddKeys(keys);
44 m_compatibleGroups[groupId] = group;
45 }
46
52 public static KeyCompatibleGroup GetCompatibleGroup(string groupId) =>
53 m_compatibleGroups.TryGetValue(groupId, out KeyCompatibleGroup group) ? group : null;
54
60 public static bool HasConflict(List<string> list) {
61 if (list.Count <= 1) {
62 return false;
63 }
64 foreach (KeyCompatibleGroup group in m_compatibleGroups.Values) { // 检查是否存在包含所有键的兼容组
65 if (group.ContainsAll(list)) {
66 return false;
67 }
68 }
69 return true;
70 }
71
78 public static bool HasConflict(List<string> list, out List<string> conflictKeys) {
79 conflictKeys = [];
80 if (list.Count <= 1) {
81 return false;
82 }
83 foreach (string key in list) {
84 bool hasCompatibleGroup = false;
85 foreach (KeyCompatibleGroup group in m_compatibleGroups.Values) {
86 if (group.ContainsAll(list)) {
87 hasCompatibleGroup = true;
88 break;
89 }
90 }
91 if (!hasCompatibleGroup
92 && !conflictKeys.Contains(key)) {
93 conflictKeys.Add(key);
94 }
95 }
96 return conflictKeys.Count > 0;
97 }
98 }
99}
static bool HasConflict(List< string > list)
输入按键名称列表,检查是否存在冲突
static KeyCompatibleGroup GetCompatibleGroup(string groupId)
获取兼容组信息
static readonly Dictionary< string, KeyCompatibleGroup > m_compatibleGroups
static bool HasConflict(List< string > list, out List< string > conflictKeys)
输入按键名称列表,检查是否存在冲突,并输出冲突的按键列表
static void AddKeyToCompatibleGroup(string groupId, params string[] keys)
添加按键到兼容组
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook