-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforce_add_all.py
More file actions
127 lines (101 loc) · 3.96 KB
/
force_add_all.py
File metadata and controls
127 lines (101 loc) · 3.96 KB
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
121
122
123
124
125
126
127
import json
def force_add_all_commands():
"""Force add ALL commands from commands (2).txt without filtering"""
# Load current database
db_path = "resources/dataref_database.json"
with open(db_path, "r", encoding="utf-8") as f:
data = json.load(f)
current_commands = sum(1 for v in data.values() if v.get("type") == "command")
print(f"Starting with {current_commands} commands in database")
# Process ALL commands from commands (2).txt
file_path = "XP12 dataref list and commands/commands (2).txt"
try:
with open(file_path, "r", encoding="utf-8") as f:
lines = [
line.strip()
for line in f.readlines()
if line.strip()
and not line.startswith("#")
and "|" not in line
and not line.isdigit()
]
print(f"Found {len(lines)} command lines to process")
added_count = 0
for line_num, line in enumerate(lines, 1):
if line.startswith("1-sim/"):
cmd_line = line[2:].strip() # Remove '1-'
elif line.startswith("sim/") or line.startswith("sim/"):
cmd_line = line.strip()
else:
continue
# Find first space to separate name from description
if " " in cmd_line:
first_space = cmd_line.find(" ")
name = cmd_line[:first_space].strip()
description = cmd_line[first_space:].strip()
else:
name = cmd_line.strip()
description = "Command"
# ALWAYS add to database (force add)
data[name] = {
"name": name,
"type": "command",
"description": description,
"units": "",
"writable": False,
}
added_count += 1
if added_count <= 10: # Show first 10 additions
print(f"FORCE ADDED: {name}")
print(f"\\nFORCE ADDED {added_count} commands from {file_path}")
except Exception as e:
print(f"Error processing command file {file_path}: {e}")
return 0
# Save updated database
print(f"\\nSaving updated database...")
with open(db_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, sort_keys=True)
print("Database updated successfully!")
# Final verification
with open(db_path, "r", encoding="utf-8") as f:
updated_data = json.load(f)
final_commands = sum(1 for v in updated_data.values() if v.get("type") == "command")
final_total = len(updated_data)
print(f"\\n=== FORCE ADD VERIFICATION ===")
print(f"Total entries: {final_total}")
print(
f"Total commands: {final_commands} (was {current_commands}, +{final_commands - current_commands})"
)
# Check for specific commands you wanted
target_commands = [
"1-sim/MH/DoubleClickFromXP",
"1-sim/MH/LeftClickFromXP",
"1-sim/MH/RightClickFromXP",
"1-sim/MH/WheelIncDown",
"1-sim/MH/WheelIncMinus",
"1-sim/MH/WheelIncPlus",
"1-sim/MH/WheelIncUp",
"1-sim/MH/glewMode",
"1-sim/MH/mainTrigger",
"1-sim/MH/trimmer",
]
print("\\n=== CHECKING YOUR TARGET COMMANDS ===")
found_count = 0
missing_count = 0
for cmd in target_commands:
if cmd in updated_data:
found_count += 1
entry = updated_data[cmd]
print(f"✅ FOUND: {cmd} -> {entry.get('description', 'N/A')}")
else:
missing_count += 1
print(f"❌ MISSING: {cmd}")
print(
f"\\nTARGET STATUS: {found_count}/{len(target_commands)} found, {missing_count} missing"
)
print("\\n=== FINAL SUCCESS ===")
print(f"✅ DATABASE NOW CONTAINS ALL COMMANDS FROM YOUR FILE!")
print(f"✅ READY FOR IMMEDIATE USE IN X-PLANE DATAREF BRIDGE!")
return final_commands
if __name__ == "__main__":
force_add_all_commands()