Skip to content

Commit

Permalink
Merge pull request #387 from IUrreta/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
IUrreta authored Oct 17, 2024
2 parents be5dfc4 + 7f8ecfd commit 8401f8f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 26 deletions.
8 changes: 8 additions & 0 deletions back/commands/customEngines.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def __init__(self, message, client):
async def execute(self):
engine_list = self.message["enginesData"]
self.process_engine_list(engine_list)
engines = await self.dbutils.get_custom_engines_list(self.message["saveSelected"])
engines_list = ["Custom Engines fetched", engines]
data_json_engines = json.dumps(engines_list)
await self.send_message_to_client(data_json_engines)
info = ["Custom engines saved"]
data_json_info = json.dumps(info)
await self.send_message_to_client(data_json_info)



def process_engine_list(self, engine_list):
Expand Down
13 changes: 2 additions & 11 deletions back/commands/saveSelected.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def execute(self):
cars = ["Cars fetched", cars, att]
data_json_cars = json.dumps(cars)
await self.send_message_to_client(data_json_cars)
engines = await self.get_custom_engines_list(save)
engines = await self.dbutils.get_custom_engines_list(save)
engines_list = ["Custom Engines fetched", engines]
data_json_engines = json.dumps(engines_list)
await self.send_message_to_client(data_json_engines)
Expand Down Expand Up @@ -150,15 +150,6 @@ async def overwrite_config_file(self, difficulty, disabledList, refurbish, froze
with open(file_path, "w") as json_file:
json.dump(data, json_file, indent=4)


async def get_custom_engines_list(self, saveName):
config_file_path = f"./../configs/{saveName.split('.')[0]}_config.json"
if os.path.exists(config_file_path):
with open(config_file_path, "r") as json_file:
data = json.load(json_file)

custom_engines = data.get("engines", {})
return custom_engines

async def check_engine_allocations(self, save):
config_file_path = f"./../configs/{save.split('.')[0]}_config.json"
Expand All @@ -176,7 +167,7 @@ async def check_engine_allocations(self, save):

def create_config_file(self, saveName, game_year):
folder = "./../configs"
file = f"{saveName.split(".")[0]}_config.json"
file = f'{saveName.split(".")[0]}_config.json'
file_path = os.path.join(folder, file)
if not os.path.exists(folder):
os.makedirs(folder)
Expand Down
2 changes: 1 addition & 1 deletion back/scripts/edit_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fetch_teamData(teamID, save):
pit_dict[stat[0]] = round(stat[1], 2)


config_file_path = f"../configs/{save.split(".")[0]}_config.json"
config_file_path = f'../configs/{save.split(".")[0]}_config.json'
with open(config_file_path, "r") as file:
config = json.load(file)

Expand Down
24 changes: 20 additions & 4 deletions back/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
from scripts.countries import countries_dict
import sqlite3
import os
import json

difficulty_dict = {
0:{
Expand Down Expand Up @@ -671,6 +673,15 @@ def remove_number(self, cadena):
cadena = cadena[:-1]
return cadena

async def get_custom_engines_list(self, saveName):
config_file_path = f"./../configs/{saveName.split('.')[0]}_config.json"
if os.path.exists(config_file_path):
with open(config_file_path, "r") as json_file:
data = json.load(json_file)

custom_engines = data.get("engines", {})
return custom_engines

def manage_weight_trigger(self, type, cursor, disabled):
cursor.execute("DROP TRIGGER IF EXISTS reduced_weight_normal")
cursor.execute("DROP TRIGGER IF EXISTS reduced_weight_extreme")
Expand Down Expand Up @@ -764,7 +775,7 @@ def manage_difficulty_triggers(self, type, disabledList):
cursor.execute("DROP TRIGGER IF EXISTS designTime_impossible")

if type >= 2 and disabledList["statDif"] == 0:
trigger_name = f"difficulty_{difficulty_dict[type]["name"]}"
trigger_name = f'difficulty_{difficulty_dict[type]["name"]}'
increase_perc = difficulty_dict[type]["perc"]
increase_7and8 = difficulty_dict[type]["7and8"]
increase_9 = difficulty_dict[type]["9"]
Expand Down Expand Up @@ -821,7 +832,7 @@ def manage_difficulty_triggers(self, type, disabledList):


if type >= 2 and disabledList["designTimeDif"] == 0:
trigger_name = f"designTime_{difficulty_dict[type]["name"]}"
trigger_name = f'designTime_{difficulty_dict[type]["name"]}'
trigger_sql = f"""
CREATE TRIGGER {trigger_name}
AFTER INSERT ON Parts_Designs_StatValues
Expand All @@ -845,7 +856,6 @@ def manage_difficulty_triggers(self, type, disabledList):
cursor.execute(trigger_sql)



self.manage_weight_trigger(type, cursor, disabledList["lightDif"])
self.manage__instant_build_triggers(type, cursor, disabledList["buildDif"])
self.manage_research_triggers(type, cursor, disabledList["researchDif"])
Expand Down Expand Up @@ -1022,7 +1032,7 @@ def fetch_existing_trigers(self):
"lightDif": 1,
"researchDif": 1,
"buildDif": 1,
"factoryDif": 1,
"factoryDif": 0,
"statDif": 1,
"designTimeDif": 1
}
Expand All @@ -1031,6 +1041,7 @@ def fetch_existing_trigers(self):
conn = sqlite3.connect("../result/main.db")
cursor = conn.cursor()
triggers = cursor.execute("SELECT name FROM sqlite_master WHERE type='trigger';").fetchall()
factory_levels = cursor.execute("SELECT BuildingID FROM Buildings_HQ WHERE BuildingType = 3 AND TeamID != (SELECT TeamID FROM Player)").fetchall()
conn.close()
if triggers:
for trigger in triggers:
Expand All @@ -1055,6 +1066,11 @@ def fetch_existing_trigers(self):
if dif_level > highest_difficulty:
highest_difficulty = dif_level

#if all factorylevels are 34 or 35 factoryDif is 0
for level in factory_levels:
if level[0] < 34:
disabled["factoryDif"] = 1
break

return highest_difficulty, disabled, refurbish, frozenMentality

12 changes: 6 additions & 6 deletions front/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ let inverted_dict = { 'ferrari': 1, 'mclaren': 2, 'redbull': 3, 'merc': 4, 'alpi
const difficultyConfig = {
"default": {
visible: ["defaultDif"],
lightDif: { className: "", text: "" },
researchDif: { className: "", text: "" },
statDif: { className: "", text: "" },
designTimeDif: { className: "", text: "" },
factoryDif: { className: "", text: "" },
buildDif: { className: "", text: "" }
lightDif: { className: "dif-warning", text: "" },
researchDif: { className: "dif-warning", text: "" },
statDif: { className: "dif-warning", text: "" },
designTimeDif: { className: "dif-warning", text: "" },
factoryDif: { className: "dif-warning", text: "" },
buildDif: { className: "dif-warning", text: "" }
},
"reduced weight": {
visible: ["lightDif"],
Expand Down
1 change: 1 addition & 0 deletions front/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ document.addEventListener('DOMContentLoaded',function () {
let difficultyValue = parseInt(difficultySlider.value)
let disabledList = {}
document.querySelectorAll(".dif-warning:not(.default)").forEach(function (elem) {
console.log(elem)
let id = elem.id
if (elem.classList.contains("disabled")) {
disabledList[id] = 1
Expand Down
2 changes: 1 addition & 1 deletion launcher/version.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.3.1
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Database Editor F1 Manager",
"version": "2.3.0",
"version": "2.3.1",
"description": "A tool that will let you edit your save file from F1 Manager games",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 8401f8f

Please sign in to comment.