Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/input/input_builders.py
9903 views
1
"""Functions used to generate source files during build time"""
2
3
from collections import OrderedDict
4
5
import methods
6
7
8
def make_default_controller_mappings(target, source, env):
9
with methods.generated_wrapper(str(target[0])) as file:
10
file.write("""\
11
#include "core/input/default_controller_mappings.h"
12
13
#include "core/typedefs.h"
14
15
""")
16
17
# ensure mappings have a consistent order
18
platform_mappings = OrderedDict()
19
for src_path in map(str, source):
20
with open(src_path, "r", encoding="utf-8") as f:
21
# read mapping file and skip header
22
mapping_file_lines = f.readlines()[2:]
23
24
current_platform = None
25
for line in mapping_file_lines:
26
if not line:
27
continue
28
line = line.strip()
29
if len(line) == 0:
30
continue
31
if line[0] == "#":
32
current_platform = line[1:].strip()
33
if current_platform not in platform_mappings:
34
platform_mappings[current_platform] = {}
35
elif current_platform:
36
line_parts = line.split(",")
37
guid = line_parts[0]
38
if guid in platform_mappings[current_platform]:
39
file.write(
40
"// WARNING: DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(
41
src_path, current_platform, platform_mappings[current_platform][guid]
42
)
43
)
44
platform_mappings[current_platform][guid] = line
45
46
PLATFORM_VARIABLES = {
47
"Linux": "LINUXBSD",
48
"Windows": "WINDOWS",
49
"Mac OS X": "MACOS",
50
"Android": "ANDROID",
51
"iOS": "APPLE_EMBEDDED",
52
"Web": "WEB",
53
}
54
55
file.write("const char *DefaultControllerMappings::mappings[] = {\n")
56
for platform, mappings in platform_mappings.items():
57
variable = PLATFORM_VARIABLES[platform]
58
file.write(f"#ifdef {variable}_ENABLED\n")
59
for mapping in mappings.values():
60
file.write(f'\t"{mapping}",\n')
61
file.write(f"#endif // {variable}_ENABLED\n")
62
63
file.write("\tnullptr\n};\n")
64
65