| 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 |
PLATFORM_VARIABLES = { |
| 18 |
"Linux": "LINUXBSD", |
| 19 |
"Windows": "WINDOWS", |
| 20 |
"Mac OS X": "MACOS", |
| 21 |
"Android": "ANDROID", |
| 22 |
"iOS": "APPLE_EMBEDDED", |
| 23 |
"Web": "WEB", |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
platform_mappings = OrderedDict() |
| 28 |
for src_path in map(str, source): |
| 29 |
with open(src_path, "r", encoding="utf-8") as f: |
| 30 |
mapping_file_lines = f.readlines() |
| 31 |
|
| 32 |
current_platform = None |
| 33 |
for line in mapping_file_lines: |
| 34 |
if not line: |
| 35 |
continue |
| 36 |
line = line.strip() |
| 37 |
if len(line) == 0: |
| 38 |
continue |
| 39 |
if line[0] == "#": |
| 40 |
platform_or_header = line[1:].strip() |
| 41 |
if platform_or_header not in PLATFORM_VARIABLES: |
| 42 |
continue |
| 43 |
current_platform = platform_or_header |
| 44 |
if current_platform not in platform_mappings: |
| 45 |
platform_mappings[current_platform] = {} |
| 46 |
elif current_platform: |
| 47 |
line_parts = line.split(",") |
| 48 |
guid = line_parts[0] |
| 49 |
if guid in platform_mappings[current_platform]: |
| 50 |
file.write( |
| 51 |
"// WARNING: DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format( |
| 52 |
src_path, current_platform, platform_mappings[current_platform][guid] |
| 53 |
) |
| 54 |
) |
| 55 |
platform_mappings[current_platform][guid] = line |
| 56 |
|
| 57 |
file.write("const char *DefaultControllerMappings::mappings[] = {\n") |
| 58 |
for platform, mappings in platform_mappings.items(): |
| 59 |
variable = PLATFORM_VARIABLES[platform] |
| 60 |
file.write(f"#ifdef {variable}_ENABLED\n") |
| 61 |
for mapping in mappings.values(): |
| 62 |
file.write(f'\t"{mapping}",\n') |
| 63 |
file.write(f"#endif // {variable}_ENABLED\n") |
| 64 |
|
| 65 |
file.write("\tnullptr\n};\n") |