mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Loadouts changes and spawn menu update
This commit is contained in:
@@ -890,6 +890,16 @@ function Olympus.setMissionData(arg, time)
|
||||
["date"] = env.mission.date
|
||||
}
|
||||
|
||||
mission.coalitions = {
|
||||
["red"] = {},
|
||||
["blue"] = {},
|
||||
["neutral"] = {}
|
||||
}
|
||||
for countryName, countryId in pairs(country["id"]) do
|
||||
local coalitionName = Olympus.getCoalitionByCoalitionID(coalition.getCountryCoalition(countryId))
|
||||
mission.coalitions[coalitionName][#mission.coalitions[coalitionName] + 1] = countryName
|
||||
end
|
||||
|
||||
-- Assemble table
|
||||
Olympus.missionData["bullseyes"] = bullseyes
|
||||
Olympus.missionData["airbases"] = airbases
|
||||
|
||||
17
scripts/python/.vscode/launch.json
vendored
Normal file
17
scripts/python/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"args": ["C:\\Users\\Davide Passoni\\Documents\\DCSOlympus\\client\\public\\databases\\units\\aircraftdatabase.json"]
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
scripts/python/__pycache__/weapons_data.cpython-37.pyc
Normal file
BIN
scripts/python/__pycache__/weapons_data.cpython-37.pyc
Normal file
Binary file not shown.
133
scripts/python/addPayloadsAndLiveries.py
Normal file
133
scripts/python/addPayloadsAndLiveries.py
Normal file
@@ -0,0 +1,133 @@
|
||||
import sys
|
||||
import json
|
||||
import inspect
|
||||
import difflib
|
||||
from slpp import slpp as lua
|
||||
|
||||
SEARCH_FOLDER = "D:\\Eagle Dynamics\\DCS World OpenBeta"
|
||||
|
||||
sys.path.append("..\..\..\dcs-master\dcs-master")
|
||||
|
||||
from dcs.weapons_data import Weapons
|
||||
from dcs.planes import *
|
||||
from dcs.helicopters import *
|
||||
from dcs.liveries.liveryscanner import LiveryScanner
|
||||
|
||||
livery_scanner = LiveryScanner()
|
||||
livery_scanner.scan_dcs_installation(SEARCH_FOLDER)
|
||||
|
||||
#print("Liveries found for units:")
|
||||
#[print(key) for key in livery_scanner.map.keys()]
|
||||
|
||||
# Known id mismatches (because reasons, ask ED)
|
||||
mismatched_ids = {
|
||||
"A-10CII": "A-10C_2"
|
||||
}
|
||||
|
||||
# Get the weapons ids from pydcs
|
||||
weapon_ids = [a for a in dir(Weapons) if not a.startswith('__') and not callable(getattr(Weapons, a))]
|
||||
|
||||
# This function get the human readable name of a weapon from its CLSID
|
||||
def find_weapon_name(clsid):
|
||||
for weapon_id in weapon_ids:
|
||||
if getattr(Weapons, weapon_id)["clsid"] == clsid:
|
||||
return getattr(Weapons, weapon_id)["name"]
|
||||
|
||||
# The database file on which to operate is the first standard argument of the call
|
||||
if len(sys.argv) > 1:
|
||||
# Loads the database
|
||||
with open(sys.argv[1]) as f:
|
||||
database = json.load(f)
|
||||
for unit_name in database:
|
||||
database[unit_name]["enabled"] = True
|
||||
|
||||
# Loads the loadout names
|
||||
with open('../unitPayloads.lua') as f:
|
||||
lines = f.readlines()
|
||||
unit_payloads = lua.decode("".join(lines).replace("Olympus.unitPayloads = ", "").replace("\n", ""))
|
||||
|
||||
# Loads the loadout roles
|
||||
with open('payloadRoles.json') as f:
|
||||
payloads_roles = json.load(f)
|
||||
|
||||
# Loop on all the units in the database
|
||||
for unit_name in database:
|
||||
try:
|
||||
# Get the pydcs Python class for the unit
|
||||
cls = getattr(sys.modules[__name__], unit_name.replace("-", "_").replace(" ", "_"))
|
||||
|
||||
# Add the liveries
|
||||
liveries = []
|
||||
if unit_name in livery_scanner.map:
|
||||
liveries = livery_scanner.map[unit_name]
|
||||
else:
|
||||
if (unit_name in mismatched_ids):
|
||||
found_name = mismatched_ids[unit_name]
|
||||
else:
|
||||
lowercase_keys = [key.lower() for key in livery_scanner.map.keys()]
|
||||
res = difflib.get_close_matches(unit_name.lower(), lowercase_keys)
|
||||
found_name = list(livery_scanner.map.keys())[lowercase_keys.index(res[0])]
|
||||
print(f"Warning, could not find {unit_name} in liveries list. Best match is {found_name}. Manual check required!")
|
||||
liveries = livery_scanner.map[found_name]
|
||||
|
||||
database[unit_name]["liveries"] = {}
|
||||
for livery in liveries:
|
||||
database[unit_name]["liveries"][livery.id] = livery.name
|
||||
|
||||
# Create the loadouts table and add the empty loadout for the default task
|
||||
database[unit_name]["loadouts"] = []
|
||||
empty_loadout = {
|
||||
"items": [],
|
||||
"enabled": True,
|
||||
"code": "",
|
||||
"name": "Empty loadout",
|
||||
"roles": [cls.task_default.name]
|
||||
}
|
||||
database[unit_name]["loadouts"].append(empty_loadout)
|
||||
|
||||
# Loop on all the loadouts for that unit
|
||||
for payload_name in unit_payloads[unit_name]:
|
||||
payload_weapons = {}
|
||||
# Get the names of all the weapons in the loadout and count how many there are for each
|
||||
for payload_idx in unit_payloads[unit_name][payload_name]:
|
||||
payload_clsid = unit_payloads[unit_name][payload_name][payload_idx]["CLSID"]
|
||||
weapon_name = find_weapon_name(payload_clsid)
|
||||
if weapon_name in payload_weapons:
|
||||
payload_weapons[weapon_name] += 1
|
||||
else:
|
||||
payload_weapons[weapon_name] = 1
|
||||
|
||||
# Get the roles of this loadout. Some are numeric, some are string. Convert them to be all string
|
||||
payload_roles = []
|
||||
for role in payloads_roles[unit_name][payload_name].values():
|
||||
if isinstance(role, int):
|
||||
for name, obj in inspect.getmembers(task):
|
||||
if inspect.isclass(obj) and issubclass(obj, task.MainTask):
|
||||
if (obj.id == role):
|
||||
payload_roles.append(obj.name)
|
||||
else:
|
||||
for name, obj in inspect.getmembers(task):
|
||||
if inspect.isclass(obj) and issubclass(obj, task.MainTask):
|
||||
if (name == role):
|
||||
payload_roles.append(obj.name)
|
||||
|
||||
# Create the loadout structure and append it to the table
|
||||
new_payload = {
|
||||
"items": [{"name": weapon_name, "quantity": payload_weapons[weapon_name]} for weapon_name in payload_weapons],
|
||||
"enabled": True,
|
||||
"code": payload_name,
|
||||
"name": payload_name,
|
||||
"roles": payload_roles
|
||||
}
|
||||
database[unit_name]["loadouts"].append(new_payload)
|
||||
except Exception as e:
|
||||
print(f"Could not find data for aircraft of type {unit_name}: {e}, skipping...")
|
||||
|
||||
# Dump everything in the database
|
||||
with open(sys.argv[1], "w") as f:
|
||||
json.dump(database, f, indent=2)
|
||||
|
||||
# Done!
|
||||
print("Done!")
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
from slpp import slpp as lua
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
sys.path.append("..\..\..\dcs-master\dcs-master")
|
||||
|
||||
SEARCH_FOLDER = "D:\\Eagle Dynamics\\DCS World OpenBeta"
|
||||
|
||||
def dump_lua(data):
|
||||
@@ -39,6 +42,7 @@ for filename in list(filenames):
|
||||
|
||||
names = {}
|
||||
payloads = {}
|
||||
roles = {}
|
||||
for filename in filenames:
|
||||
with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
|
||||
try:
|
||||
@@ -53,9 +57,11 @@ for filename in filenames:
|
||||
src = tmp['payloads']
|
||||
|
||||
names[tmp['unitType']] = []
|
||||
roles[tmp['unitType']] = {}
|
||||
payloads[tmp['unitType']] = {}
|
||||
for payload in src:
|
||||
names[tmp['unitType']].append(payload['name'])
|
||||
roles[tmp['unitType']][payload['name']] = payload['tasks']
|
||||
if type(payload['pylons']) == dict:
|
||||
payloads[tmp['unitType']][payload['name']] = {payload['pylons'][key]['num']: {"CLSID" : payload['pylons'][key]['CLSID']} for key in payload['pylons']}
|
||||
else:
|
||||
@@ -63,11 +69,10 @@ for filename in filenames:
|
||||
except:
|
||||
pass
|
||||
|
||||
with open('payloadNames.js', 'w') as f:
|
||||
f.write("payloadNames = ")
|
||||
json.dump(names, f, ensure_ascii = False)
|
||||
with open('payloadRoles.json', 'w') as f:
|
||||
json.dump(roles, f, ensure_ascii = False, indent = 2)
|
||||
|
||||
with open('unitPayloads.lua', 'w') as f:
|
||||
with open('../unitPayloads.lua', 'w') as f:
|
||||
f.write("Olympus.unitPayloads = " + dump_lua(payloads))
|
||||
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import pandas as pd
|
||||
import json
|
||||
|
||||
# Load data from an Excel file
|
||||
df = pd.read_excel('data.xlsx')
|
||||
|
||||
# Group by 'Name', 'Fuel', 'Loadout Name', 'Role', and 'Code' and aggregate 'Items - Name' and 'Items - Quantity'
|
||||
grouped = df.groupby(['Name', 'Fuel', 'Loadout Name', 'Role', 'Code'])['Items - Name', 'Items - Quantity'].agg(lambda x: list(x)).reset_index()
|
||||
|
||||
# Convert the grouped data into the desired format
|
||||
result = {}
|
||||
for index, row in grouped.iterrows():
|
||||
name = row['Name']
|
||||
if name not in result:
|
||||
result[name] = {
|
||||
"name": row['Name'],
|
||||
"label": row['Name'],
|
||||
"loadouts": [
|
||||
{
|
||||
"fuel": row['Fuel'],
|
||||
"items": [
|
||||
{
|
||||
"name": item,
|
||||
"quantity": quantity
|
||||
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
|
||||
],
|
||||
"roles": [row['Role']],
|
||||
"code": row['Code'],
|
||||
"loadout_name": row['Loadout Name']
|
||||
}
|
||||
]
|
||||
}
|
||||
else:
|
||||
found = False
|
||||
for loadout in result[name]["loadouts"]:
|
||||
if loadout["fuel"] == row['Fuel'] and loadout["code"] == row['Code'] and loadout["loadout_name"] == row['Loadout Name']:
|
||||
loadout["items"].extend([
|
||||
{
|
||||
"name": item,
|
||||
"quantity": quantity
|
||||
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
|
||||
])
|
||||
loadout["roles"].append(row['Role'])
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
result[name]["loadouts"].append({
|
||||
"fuel": row['Fuel'],
|
||||
"items": [
|
||||
{
|
||||
"name": item,
|
||||
"quantity": quantity
|
||||
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
|
||||
],
|
||||
"roles": [row['Role']],
|
||||
"code": row['Code'],
|
||||
"loadout_name": row['Loadout Name']
|
||||
})
|
||||
|
||||
# Print the result with the correct indents
|
||||
print(json.dumps(result, indent=2))
|
||||
1
scripts/python/payloadNames.js
Normal file
1
scripts/python/payloadNames.js
Normal file
File diff suppressed because one or more lines are too long
7322
scripts/python/payloadRoles.json
Normal file
7322
scripts/python/payloadRoles.json
Normal file
File diff suppressed because it is too large
Load Diff
28678
scripts/python/planes.py
Normal file
28678
scripts/python/planes.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user