add files

This commit is contained in:
SemvdH
2025-11-17 23:08:01 +01:00
parent e8c8a60edf
commit ac6bcbb58a
2 changed files with 115 additions and 0 deletions

37
ac_cars.py Normal file
View File

@@ -0,0 +1,37 @@
import os
CONFIG_FILE = "server_cfg.ini"
#CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
#CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
CONTENT_FOLDER = "./content"
CONFIG_PATH = "./cfg"
CARS_FOLDER = os.path.join(CONTENT_FOLDER, "cars")
def get_all_cars():
cars_folders = sorted([x.name for x in os.scandir(CARS_FOLDER) if x.is_dir()])
all_cars = []
for i in range(len(cars_folders)):
skins = get_car_skins(cars_folders[i])
skins_data = []
for j in range(len(skins)):
skin_data = {
"name": skins[j],
"image": f"/img/car/{cars_folders[i]}/{skins[j]}"
}
skins_data.append(skin_data)
car_data = {
"name": cars_folders[i],
"skins": skins_data
}
all_cars.append(car_data)
print(f"added data " + str(car_data))
return all_cars
def get_car_skins(car: str) -> list[str]:
car_path = os.path.join(CARS_FOLDER, car);
skin_path = os.path.join(car_path, "skins")
skindirs = [x.path.replace(skin_path + "/","") for x in os.scandir(skin_path) if x.is_dir()]
return skindirs

78
ac_maps.py Normal file
View File

@@ -0,0 +1,78 @@
import os
CONFIG_FILE = "server_cfg.ini"
# CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
# CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
CONTENT_FOLDER = "./content"
CONFIG_PATH = "./cfg"
TRACKS_FOLDER = os.path.join(CONTENT_FOLDER, "tracks")
def get_all_tracks():
return sorted([x.name for x in os.scandir(TRACKS_FOLDER) if x.is_dir()])
def get_preview_image(track: str, config: str = ""):
return get_path_image("preview", track, config)
def get_outline_image(track: str, config: str = ""):
return get_path_image("outline", track, config)
def get_path_image(image_name, track: str, config: str = ""):
img_path = os.path.join(TRACKS_FOLDER, track, "ui", config)
for name in os.listdir(img_path):
lower = name.lower()
if image_name in lower and lower.endswith(".png") or lower.endswith(".jpg"):
return os.path.join(img_path, name)
img_path = os.path.join(TRACKS_FOLDER, track, config)
for name in os.listdir(img_path):
lower = name.lower()
if image_name in lower and lower.endswith(".png") or lower.endswith(".jpg"):
return os.path.join(img_path, name)
return ""
def get_configs(track) -> list[str]:
track_path = os.path.join(TRACKS_FOLDER, track);
configdirs = [x.path.replace(track_path + "/","") for x in os.scandir(track_path) if x.is_dir()]
configdirs.sort()
standard_folders = {'ai', 'ui', 'extension', 'data', 'skins','texture', 'sfx'}
for s in standard_folders:
if s in configdirs:
configdirs.remove(s)
if (len(configdirs) == 0):
print("===== The map you entered does not have a config! =====")
config = ""
return configdirs
def change_track(newname, config=""):
print(f"handling track change for {newname} with config {config}")
if newname not in get_all_tracks():
return False, f"Track '{newname}' does not exist!"
new_content = ""
config_file = os.path.join(CONFIG_PATH, CONFIG_FILE)
with open(config_file,'r') as file:
for line in file:
line = line.strip()
if line.startswith("TRACK="):
new_content += "TRACK=" + str(newname)
print("changing line " + line + " to " + "TRACK=" + str(newname))
elif line.startswith("CONFIG_TRACK="):
if (len(config) > 1):
new_content +="CONFIG_TRACK=" + str(config)
print("changing line " + line + " to " + "CONFIG_TRACK=" + str(config))
else:
new_content += "CONFIG_TRACK="
print("no config entered, setting config line to CONFIG_TRACK=")
else:
new_content += line
new_content += "\n"
with open(config_file,'w') as newfile:
newfile.write(new_content)
return True, f"Changed track to: {newname}"