From 62e61194204e17d229b80026a6b65d2f9c2e03e2 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Fri, 24 May 2024 20:14:10 -0300 Subject: [PATCH 01/10] Update championship.js --- scripts/championship.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/championship.js b/scripts/championship.js index 7fd1e2c..2357664 100644 --- a/scripts/championship.js +++ b/scripts/championship.js @@ -932,6 +932,20 @@ export class Championship { title: "GP "+raceName, html: `
+
+ + + + + +
+
From 95652369e822b6f4ff2ad90fd9216e2ae86f8bba Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:13:13 -0300 Subject: [PATCH 02/10] feat - Audio system Fully functional audio system --- scripts/audio.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/scripts/audio.js b/scripts/audio.js index a805a38..c168883 100644 --- a/scripts/audio.js +++ b/scripts/audio.js @@ -5,6 +5,7 @@ export let audio = new Audio(); const NUMBER_OF_SONGS = 7; const stylesNotSelected = []; +let lastPlayedSong = ""; const songs = { "Soundtrack": [ "Stronger - Savfk" @@ -25,15 +26,44 @@ export function SoundStart(){ window.setTimeout(soundtrack, rand(1500,5000)); } +function selectSong(){ + const SONGS_PATH = "../audio/songs/"; + const SONGS_EXT = ".mp3"; + let song_name; + + if(stylesNotSelected.length == Object.keys(songs).length) + return; //All music styles were deselected + + let themeID; + let theme; + do { + themeID = rand(0, Object.keys(songs).length); + theme = Object.keys(songs)[themeID]; + + } while (stylesNotSelected.includes(theme)); + + + let songID; + do { //Not repeat song + songID = rand(0, songs[theme].length); + song_name = songs[theme][songID]; + + } while (songs[theme].length > 1 && song_name == lastPlayedSong); + + console.log(SONGS_PATH+song_name+SONGS_EXT) + lastPlayedSong = song_name; + audio = new Audio(SONGS_PATH+song_name+SONGS_EXT); +} + export function soundtrack(){ if(audio.paused){ const SongID = rand(0,NUMBER_OF_SONGS); - //audio = new Audio("../audio/songs/"+SongID+".mp3"); + + selectSong(); + audio.volume = game.settings.volume; const tryToPlay = setInterval(() => { - console.log(SongID) - audio.play() .then(() => { clearInterval(tryToPlay); From ed8570a542bb7e12863cea920cb340cfeb894879 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:15:36 -0300 Subject: [PATCH 03/10] feat - Language Localization Base system for language localization --- localization/base_PT.json | 4 ++++ scripts/translation.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 localization/base_PT.json create mode 100644 scripts/translation.js diff --git a/localization/base_PT.json b/localization/base_PT.json new file mode 100644 index 0000000..7ea7ee9 --- /dev/null +++ b/localization/base_PT.json @@ -0,0 +1,4 @@ +{ + "gender_male_PT": "Homem", + "gender_female_PT": "Mulher" +} \ No newline at end of file diff --git a/scripts/translation.js b/scripts/translation.js new file mode 100644 index 0000000..ef9dc9f --- /dev/null +++ b/scripts/translation.js @@ -0,0 +1,28 @@ +import { game } from "./game.js"; + +let dict = {}; + +export function LOC(key){ + key = key.toLowerCase(); + + console.log(key+"_"+game.game_language) + + try { + return dict[key+"_"+game.game_language]; + + } catch (error) { + console.error(`Failed translation of "${key}" in Game Language: ${game.game_language}`); + return key; + } +} + +function dictAppend(filename){ + const request = new XMLHttpRequest(); + request.open("GET", `../localization/${filename}.json`, false); + request.send(null) + const json = JSON.parse(request.responseText); + + dict = Object.assign(dict, json); +} + +dictAppend("base_PT"); From dcf96d3c0578199a4d6137172b56f15660d80c5c Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:17:01 -0300 Subject: [PATCH 04/10] refactor - Championship --- scripts/championship.js | 431 +++++++++++++++++++--------------------- scripts/game.js | 6 +- ui/start-load-save.js | 2 +- 3 files changed, 211 insertions(+), 228 deletions(-) diff --git a/scripts/championship.js b/scripts/championship.js index e9673b8..bbce9b0 100644 --- a/scripts/championship.js +++ b/scripts/championship.js @@ -10,82 +10,61 @@ import { simulateOthersSeries } from "./othersSeries.js"; const SIMULATION_TICKS = 3; -export class Championship { - constructor(LoadedChampionship) { - this.loaded = LoadedChampionship; - - if(this.loaded){ - this.teams = this.loaded.teams; - this.tracks = this.loaded.tracks; - this.results = this.loaded.results; - this.standings = this.loaded.standings; - this.teamStandings = this.loaded.teamStandings; - this.actualRound = this.loaded.actualRound; - this.pointsSystem = this.loaded.pointsSystem; - this.budgetCap = this.loaded.budgetCap; - this.historic = this.loaded.historic; - this.drivers = this.loaded.drivers; - this.teams = this.loaded.teams; - this.race = this.loaded.race; +export const Championship = { + teams: ["Red Bull","Mercedes","Ferrari","Aston Martin","AlphaTauri","Alfa Romeo","Alpine","Haas","Williams","McLaren"], + tracks: ["Bahrein","Arábia Saudita","Austrália","Azerbaijão","Miami","Emília-Romanha","Mônaco","Espanha","Canadá","Áustria","Grã-Bretanha","Hungria","Bélgica","Países Baixos","Itália","Singapura","Japão","Catar","Estados Unidos","Cidade do México","São Paulo","Las Vegas","Abu Dhabi"], + drivers: [], + + results: {}, + standings: [], + teamStandings: [], + actualRound: 1, + + pointsSystem: [25,18,15,12,10,8,6,4,2,1], + budgetCap: 145000, //in Thousands + race: { + grid: {}, + qSection: "Q1", + qDrivers: [], + + raceDrivers: [], + finalResult: [], + positions: [], + condition: "", + safetyCarLaps: 0, + + retires: [], + rain: 0, + lap: 0, + simTick: 0, + log: [], + }, + + historic: [ + { + year: 2022, + driverChampion: "Max Verstappen", + driverCountry: "NL", + driverTeam: "Red Bull", + driverEngine: "Red Bull PowerTrains", + + constructorChampion: "Red Bull", + constructorCountry: "AT", + constructorEngine: "Red Bull PowerTrains", } - else{ - this.teams = ["Red Bull","Mercedes","Ferrari","Aston Martin","AlphaTauri","Alfa Romeo","Alpine","Haas","Williams","McLaren"]; - this.tracks = ["Bahrein","Arábia Saudita","Austrália","Azerbaijão","Miami","Emília-Romanha","Mônaco","Espanha","Canadá","Áustria","Grã-Bretanha","Hungria","Bélgica","Países Baixos","Itália","Singapura","Japão","Catar","Estados Unidos","Cidade do México","São Paulo","Las Vegas","Abu Dhabi"]; - //this.tracks = ["Bahrein"]; - - this.results = {}; - this.standings = []; - this.teamStandings = []; - this.actualRound = 1; - this.pointsSystem = [25,18,15,12,10,8,6,4,2,1]; - this.budgetCap = 145000; - - this.historic = [ - { - year: 2022, - driverChampion: "Max Verstappen", - driverCountry: "NL", - driverTeam: "Red Bull", - driverEngine: "Red Bull PowerTrains", - - constructorChampion: "Red Bull", - constructorCountry: "AT", - constructorEngine: "Red Bull PowerTrains", - } - ]; - - this.drivers = []; - - this.teams.forEach(t => { - const team = teamsData[t]; - - this.drivers.push(driversData[team.driver1].name); - this.drivers.push(driversData[team.driver2].name); - }); - - this.race = { - grid: {}, - qSection: "Q1", - qDrivers: [], - - raceDrivers: [], - finalResult: [], - positions: [], - condition: "", - safetyCarLaps: 0, + ], - retires: [], - rain: 0, - lap: 0, - simTick: 0, - log: [], - } - } + init: () => { + + Championship.teams.forEach(t => { + const team = teamsData[t]; - delete this.loaded; - } + Championship.drivers.push(driversData[team.driver1].name); + Championship.drivers.push(driversData[team.driver2].name); + }); + }, - EndSeason(){ + EndSeason: () => { let html = `

Mundial de Pilotos

@@ -99,24 +78,24 @@ export class Championship { 1º - - ${this.standings[0][0]} - ${game.drivers[this.standings[0][0]].team} - ${this.standings[0][1]} + + ${Championship.standings[0][0]} + ${game.drivers[Championship.standings[0][0]].team} + ${Championship.standings[0][1]} 2º - - ${this.standings[1][0]} - ${game.drivers[this.standings[1][0]].team} - ${this.standings[1][1]} + + ${Championship.standings[1][0]} + ${game.drivers[Championship.standings[1][0]].team} + ${Championship.standings[1][1]} 3º - - ${this.standings[2][0]} - ${game.drivers[this.standings[2][0]].team} - ${this.standings[2][1]} + + ${Championship.standings[2][0]} + ${game.drivers[Championship.standings[2][0]].team} + ${Championship.standings[2][1]} @@ -133,24 +112,24 @@ export class Championship { 1º - - ${this.teamStandings[0][0]} - ${game.teams[this.teamStandings[0][0]].engine} - ${this.teamStandings[0][1]} + + ${Championship.teamStandings[0][0]} + ${game.teams[Championship.teamStandings[0][0]].engine} + ${Championship.teamStandings[0][1]} 2º - - ${this.teamStandings[1][0]} - ${game.teams[this.teamStandings[1][0]].engine} - ${this.teamStandings[1][1]} + + ${Championship.teamStandings[1][0]} + ${game.teams[Championship.teamStandings[1][0]].engine} + ${Championship.teamStandings[1][1]} 3º - - ${this.teamStandings[2][0]} - ${game.teams[this.teamStandings[2][0]].engine} - ${this.teamStandings[2][1]} + + ${Championship.teamStandings[2][0]} + ${game.teams[Championship.teamStandings[2][0]].engine} + ${Championship.teamStandings[2][1]}
` @@ -165,35 +144,35 @@ export class Championship { }).then(() => { YearUpdate(); }); - } + }, - QualifySection(){ + QualifySection: () => { let grid = {}; - const oldGrid = this.race.grid; + const oldGrid = Championship.race.grid; - const raceName = this.tracks[this.actualRound-1]; + const raceName = Championship.tracks[Championship.actualRound-1]; let poleTime = 0; let poleName = ""; - if(this.race.qSection == "Q2" && this.race.qDrivers.length == 0){ + if(Championship.race.qSection == "Q2" && Championship.race.qDrivers.length == 0){ for(let i = 0; i < 15; i++) { - this.race.qDrivers.push(oldGrid[i].name); + Championship.race.qDrivers.push(oldGrid[i].name); oldGrid[i].time = 999; } } - if(this.race.qSection == "Q3" && this.race.qDrivers.length == 15){ - this.race.qDrivers = []; + if(Championship.race.qSection == "Q3" && Championship.race.qDrivers.length == 15){ + Championship.race.qDrivers = []; for(let i = 0; i < 10; i++) { - this.race.qDrivers.push(oldGrid[i].name); + Championship.race.qDrivers.push(oldGrid[i].name); oldGrid[i].time = 999; } } - for(const d in this.drivers){ - const driverName = this.drivers[d]; + for(const d in Championship.drivers){ + const driverName = Championship.drivers[d]; - if(this.race.qSection != "Q1" && !this.race.qDrivers.includes(driverName)){ + if(Championship.race.qSection != "Q1" && !Championship.race.qDrivers.includes(driverName)){ grid[driverName] = { name: driverName, time: -1, @@ -218,9 +197,9 @@ export class Championship { let divider; - if(this.race.qSection == "Q1") divider = 59; - if(this.race.qSection == "Q2") divider = 59.5; - if(this.race.qSection == "Q3") divider = 60; + if(Championship.race.qSection == "Q1") divider = 59; + if(Championship.race.qSection == "Q2") divider = 59.5; + if(Championship.race.qSection == "Q3") divider = 60; let lapTime = base/divider + ((base*driverF*cornersF*straightF) / (base*Math.pow(0.8,3))); @@ -275,20 +254,20 @@ export class Championship { grid = Object.values(grid).sort((a, b) => a.time - b.time); grid = grid.sort((a, b) => b.qSection - a.qSection); - this.race.grid = grid; - } + Championship.race.grid = grid; + }, - RaceSection(status){ - const raceDrivers = this.race.raceDrivers; - const retires = this.race.retires; - const meanLaptime = this.race.meanLaptime; - const lap = this.race.lap; - const rain = this.race.rain; + RaceSection: (status) => { + const raceDrivers = Championship.race.raceDrivers; + const retires = Championship.race.retires; + const meanLaptime = Championship.race.meanLaptime; + const lap = Championship.race.lap; + const rain = Championship.race.rain; - const raceName = this.tracks[this.actualRound-1]; + const raceName = Championship.tracks[Championship.actualRound-1]; if(status == "start"){ - let grid = this.race.grid; + let grid = Championship.race.grid; let aux = {}; for (let i = 0; i < grid.length; i++) { @@ -297,7 +276,7 @@ export class Championship { grid = aux; if(Math.floor(Math.random() * 100) < circuitsData[raceName].rainChance) - this.race.rain = true; + Championship.race.rain = true; let i = 0; for(const k in grid) { @@ -312,7 +291,7 @@ export class Championship { tireStrategy: "", }); - if(!this.race.rain){ + if(!Championship.race.rain){ const strategy = Math.floor(Math.random() * 100); if(strategy > 50) raceDrivers[i-1].tire = "S"; @@ -334,7 +313,7 @@ export class Championship { if(!raceDrivers[d].racing) continue; const base = circuitsData[raceName].baseLapTime; - const driverName = this.drivers[d]; + const driverName = Championship.drivers[d]; const team = game.drivers[driverName].team; const car = game.teams[team].car; @@ -384,7 +363,7 @@ export class Championship { if(Math.random() * 100 == 1){ pitVar *= Math.floor(Math.random() * 5)+1; - this.race.log.push(raceDrivers[d].name+" teve problemas no pit"); + Championship.race.log.push(raceDrivers[d].name+" teve problemas no pit"); } lapTime += 0.33 + pitVar; @@ -427,7 +406,7 @@ export class Championship { const tireStrategy = raceDrivers[d].tireStrategy; - if(this.race.condition == "sc" && tireLap > 10*SIMULATION_TICKS){ + if(Championship.race.condition == "sc" && tireLap > 10*SIMULATION_TICKS){ changeTire(); } if((lapsRemaining <= 15) && tireStrategy[0] != "W" && Array.from(tireStrategy).every(char => char === tireStrategy[0])){ @@ -492,7 +471,7 @@ export class Championship { if(Math.floor(Math.random() * 100) < 30){ newRaceCondition = "vsc"; - this.race.safetyCarLaps = rollDice("2d4+0"); + Championship.race.safetyCarLaps = rollDice("2d4+0"); } retires.unshift({ @@ -516,7 +495,7 @@ export class Championship { if(rain) crashChance *= 3; - if(this.race.condition == "sc") + if(Championship.race.condition == "sc") crashChance = -1; if(retires.length < (raceDrivers.length-3) && crashChanceRoll <= crashChance && crashRoll >= driverEscape){ @@ -524,8 +503,8 @@ export class Championship { if(Math.floor(Math.random() * 100) < 100){ newRaceCondition = "sc"; - this.race.safetyCarLaps = rollDice("3d4+0"); - this.race.log.push(raceDrivers[d]+" se acidentou e gerou "+this.race.safetyCarLaps+" voltas de safety car"); + Championship.race.safetyCarLaps = rollDice("3d4+0"); + Championship.race.log.push(raceDrivers[d]+" se acidentou e gerou "+Championship.race.safetyCarLaps+" voltas de safety car"); } retires.unshift({ @@ -536,7 +515,7 @@ export class Championship { continue; } - if(this.race.condition == "vsc" || this.race.condition == "sc"){ + if(Championship.race.condition == "vsc" || Championship.race.condition == "sc"){ lapTime = raceDrivers[0].lapTime; } @@ -544,10 +523,10 @@ export class Championship { raceDrivers[d].totalTime += lapTime; raceDrivers[d].actualLap++; - if(this.race.condition != "sc" && this.race.condition != "vsc") + if(Championship.race.condition != "sc" && Championship.race.condition != "vsc") raceDrivers[d].tireLap++; - if(this.race.condition == "sc"){ + if(Championship.race.condition == "sc"){ raceDrivers[d].totalTime = raceDrivers[0].totalTime+(d/60); } } @@ -557,37 +536,37 @@ export class Championship { let finalResult = raceDrivers.sort((a, b) => a.totalTime - b.totalTime); const aux = []; - this.race.positions = []; + Championship.race.positions = []; for (let i = 0; i < finalResult.length; i++) { if(finalResult[i].racing){ - this.race.positions.push(finalResult[i].name); + Championship.race.positions.push(finalResult[i].name); aux.push(finalResult[i]); } } finalResult = aux; - this.race.finalResult = finalResult; + Championship.race.finalResult = finalResult; - this.race.simTick++; + Championship.race.simTick++; if(newRaceCondition != ""){ - this.race.condition = newRaceCondition; + Championship.race.condition = newRaceCondition; } - if(this.race.simTick >= SIMULATION_TICKS){ - this.race.lap++; - this.race.simTick = 0; - this.race.safetyCarLaps--; + if(Championship.race.simTick >= SIMULATION_TICKS){ + Championship.race.lap++; + Championship.race.simTick = 0; + Championship.race.safetyCarLaps--; - if(this.race.condition == "sc" && this.race.safetyCarLaps <= 0){ - this.race.condition = ""; + if(Championship.race.condition == "sc" && Championship.race.safetyCarLaps <= 0){ + Championship.race.condition = ""; } - if(this.race.condition == "vsc" && this.race.safetyCarLaps <= 0){ - this.race.condition = ""; + if(Championship.race.condition == "vsc" && Championship.race.safetyCarLaps <= 0){ + Championship.race.condition = ""; } } - } - - timeConvert(minutes) { + }, + + timeConvert: (minutes) => { const minutesInt = Math.floor(minutes); const seconds = Math.floor((minutes - minutesInt) * 60); const milliseconds = Math.floor(((minutes - minutesInt) * 60 - seconds) * 1000); @@ -598,13 +577,13 @@ export class Championship { return secondsStr + ':' + millisecondsStr; if(minutesInt > 0) return minutesInt + ':' + secondsStr + ':' + millisecondsStr; - } + }, genGridTableHTML(status){ if(status != "end") - this.QualifySection(); + Championship.QualifySection(); - const grid = this.race.grid; + const grid = Championship.race.grid; let TimeTableHTML = ` @@ -620,10 +599,10 @@ export class Championship { for(const k in grid) { i++; - if(i == 11 && this.race.qSection == "Q2"){ + if(i == 11 && Championship.race.qSection == "Q2"){ TimeTableHTML += "" } - if(i == 16 && this.race.qSection == "Q1"){ + if(i == 16 && Championship.race.qSection == "Q1"){ TimeTableHTML += "" } @@ -648,7 +627,7 @@ export class Championship { time = ""; } else{ - time = this.timeConvert(time); + time = Championship.timeConvert(time); } TimeTableHTML += ` @@ -660,30 +639,30 @@ export class Championship { if(k == 0) TimeTableHTML += `` else - TimeTableHTML += `` + TimeTableHTML += `` if(k != 0) - TimeTableHTML += `` + TimeTableHTML += `` TimeTableHTML += `` } TimeTableHTML += "
Pole Position+${this.timeConvert(Number(grid[k].time) - Number(grid[k-1].time))}+${Championship.timeConvert(Number(grid[k].time) - Number(grid[k-1].time))}+${this.timeConvert(Number(grid[k].time) - Number(grid[0].time))}+${Championship.timeConvert(Number(grid[k].time) - Number(grid[0].time))}
"; return TimeTableHTML; - } + }, - genRaceTableHTML(status){ - if(this.race.finalResult.length == 0) - this.RaceSection("start"); + genRaceTableHTML: (status) => { + if(Championship.race.finalResult.length == 0) + Championship.RaceSection("start"); else if(status != "podium" && status != "end") - this.RaceSection(); + Championship.RaceSection(); - const finalResult = this.race.finalResult; - const retires = this.race.retires; - const rain = this.race.rain; - const lap = this.race.lap; + const finalResult = Championship.race.finalResult; + const retires = Championship.race.retires; + const rain = Championship.race.rain; + const lap = Championship.race.lap; - const raceName = this.tracks[this.actualRound-1]; + const raceName = Championship.tracks[Championship.actualRound-1]; let TimeTableHTML = ` @@ -717,10 +696,10 @@ export class Championship { else classPos = "non-scorer-position"; if(status == "podium"){ - TimeTableHTML += `` + TimeTableHTML += `` } else{ - TimeTableHTML += `` + TimeTableHTML += `` } } @@ -741,17 +720,17 @@ export class Championship { if(status == "podium"){ TimeTableHTML = ` - - - + + + ` } return TimeTableHTML; - } + }, - carsHTML(status){ + carsHTML: (status) => { const isVisualRaceSimDisabled = !game.settings["visual-race-simulation"]; if(isVisualRaceSimDisabled){ @@ -761,8 +740,8 @@ export class Championship { return; } - const finalResult = this.race.finalResult; - const grid = this.race.grid; + const finalResult = Championship.race.finalResult; + const grid = Championship.race.grid; const raceCarsContainer = document.querySelector("#race-cars"); const raceStatusImage = document.querySelector("#race-status"); @@ -788,7 +767,7 @@ export class Championship {

${nameCode}

+ onerror="Championship.onerror=null;Championship.src='img/car.png'; Championship.style='background-color:${bgColor}'">
`; }); @@ -821,17 +800,17 @@ export class Championship { if(i != finalResult.length){ const max = document.querySelector("#race-cars").offsetHeight - 155; - const totalLaps = circuitsData[this.tracks[this.actualRound - 1]].laps; + const totalLaps = circuitsData[Championship.tracks[Championship.actualRound - 1]].laps; const diff = (finalResult[i].totalTime - finalResult[0].totalTime)*100; - const lapMove = max * ((this.race.lap / totalLaps)); + const lapMove = max * ((Championship.race.lap / totalLaps)); if(!el.classList.contains("car-transition") && game.settings["race-simulation-speed"] >= 150) el.classList.add("car-transition"); el.style.left = `${(max - (max - (lapMove) + diff)) + 40}px`; el.style.top = `${25 + (i*20)}px`; - el.style.zIndex = `${(i*10) + this.race.lap}`; + el.style.zIndex = `${(i*10) + Championship.race.lap}`; let tire = ""; @@ -864,18 +843,18 @@ export class Championship { } }); - const raceStatus = this.race.condition; + const raceStatus = Championship.race.condition; raceStatusImage.style.display = "block"; if (raceStatus === "vsc") raceStatusImage.src = "img/vsc_flag.webp"; else if (raceStatus === "sc") raceStatusImage.src = "img/sc_flag.webp"; - else if (raceStatus === "" && this.race.safetyCarLaps >= -5) raceStatusImage.src = "img/green_flag.webp"; + else if (raceStatus === "" && Championship.race.safetyCarLaps >= -5) raceStatusImage.src = "img/green_flag.webp"; else raceStatusImage.style.display = "none"; } - } + }, - RunRaceSimulation(){ - if(this.actualRound > this.tracks.length){ + RunRaceSimulation: () => { + if(Championship.actualRound > Championship.tracks.length){ seasonOverviewUI("end"); simulateOthersSeries(); return; @@ -883,9 +862,9 @@ export class Championship { BeforeRaceUpdateTeamsStats(); - const raceName = this.tracks[this.actualRound-1]; + const raceName = Championship.tracks[Championship.actualRound-1]; - let TimeTableHTML = this.genGridTableHTML(); + let TimeTableHTML = Championship.genGridTableHTML(); let timerInterval; const qualifyUI = { @@ -905,22 +884,22 @@ export class Championship { timerInterval = setInterval(() => { i++; - TimeTableHTML = this.genGridTableHTML(); + TimeTableHTML = Championship.genGridTableHTML(); timeTable.innerHTML = TimeTableHTML; - if(i == 10 && this.race.qSection == "Q1"){ - this.race.qSection = "Q2"; + if(i == 10 && Championship.race.qSection == "Q1"){ + Championship.race.qSection = "Q2"; i = 0; } - if(i == 10 && this.race.qSection == "Q2"){ - this.race.qSection = "Q3"; + if(i == 10 && Championship.race.qSection == "Q2"){ + Championship.race.qSection = "Q3"; i = 0; } - if(i == 10 && this.race.qSection == "Q3"){ + if(i == 10 && Championship.race.qSection == "Q3"){ clearInterval(timerInterval); - TimeTableHTML = this.genGridTableHTML("end"); + TimeTableHTML = Championship.genGridTableHTML("end"); timeTable.innerHTML = TimeTableHTML; Swal.enableButtons(); } @@ -962,7 +941,7 @@ export class Championship { const cars = Swal.getHtmlContainer().querySelector("#race-cars"); const podium = Swal.getHtmlContainer().querySelector("#podium"); - cars.innerHTML = this.carsHTML("start"); + cars.innerHTML = Championship.carsHTML("start"); let tickRate = game.settings["race-simulation-speed"]; @@ -970,10 +949,10 @@ export class Championship { tickRate /= 4; timerInterval = setInterval(e => { - timeTable.innerHTML = this.genRaceTableHTML(); - this.carsHTML(); + timeTable.innerHTML = Championship.genRaceTableHTML(); + Championship.carsHTML(); - if(this.race.lap == circuitsData[raceName].laps){ + if(Championship.race.lap == circuitsData[raceName].laps){ clearInterval(timerInterval); Swal.enableButtons(); } @@ -1000,20 +979,20 @@ export class Championship { const timeTable = Swal.getHtmlContainer().querySelector("#time-table"); const podium = Swal.getHtmlContainer().querySelector("#podium"); - timeTable.innerHTML = this.genRaceTableHTML("end"); - podium.innerHTML = this.genRaceTableHTML("podium"); + timeTable.innerHTML = Championship.genRaceTableHTML("end"); + podium.innerHTML = Championship.genRaceTableHTML("podium"); }, })). then(e => { //############################################################## // UPDATE STATS - const grid = this.race.grid; + const grid = Championship.race.grid; grid.forEach(e => { game.drivers[e.name].gps++; }); - const finalResult = this.race.finalResult; + const finalResult = Championship.race.finalResult; game.drivers[grid[0].name].poles++; game.drivers[finalResult[0].name].wins++; @@ -1023,13 +1002,13 @@ export class Championship { //############################################################## - this.results[raceName] = this.race.positions; - this.actualRound++; + Championship.results[raceName] = Championship.race.positions; + Championship.actualRound++; UpdateTeamAfterRace(); genTeamHTML(); - this.race = { + Championship.race = { grid: {}, qSection: "Q1", qDrivers: [], @@ -1047,13 +1026,13 @@ export class Championship { log: [], } }); - } + }, - createStandings(){ + createStandings: () => { const driverRanking = {}; - for (const d in this.drivers) { - const driver = game.drivers[this.drivers[d]]; + for (const d in Championship.drivers) { + const driver = game.drivers[Championship.drivers[d]]; driverRanking[driver.name] = { pts: 0, @@ -1062,8 +1041,8 @@ export class Championship { }; } - for (const r in this.results) { - const raceResult = this.results[r]; + for (const r in Championship.results) { + const raceResult = Championship.results[r]; for (let pos = 0; pos < raceResult.length; pos++) { const driver = driverRanking[raceResult[pos]]; @@ -1072,8 +1051,8 @@ export class Championship { driver.wins++; } - if(pos < this.pointsSystem.length) - driver.pts += this.pointsSystem[pos]; + if(pos < Championship.pointsSystem.length) + driver.pts += Championship.pointsSystem[pos]; if(driver.bestFinish > pos+1){ driver.bestFinish = pos+1; @@ -1081,18 +1060,18 @@ export class Championship { } } - this.standings = []; + Championship.standings = []; for (const k in driverRanking) { - this.standings.push([k, driverRanking[k].pts, driverRanking[k].wins, driverRanking[k].bestFinish]); + Championship.standings.push([k, driverRanking[k].pts, driverRanking[k].wins, driverRanking[k].bestFinish]); } - this.standings.sort((a, b) => a[3] - b[3]); - this.standings.sort((a, b) => b[1] - a[1]); + Championship.standings.sort((a, b) => a[3] - b[3]); + Championship.standings.sort((a, b) => b[1] - a[1]); //Team Standings const teamRanking = {}; - for (const t of this.teams) { + for (const t of Championship.teams) { const team = game.teams[t]; teamRanking[team.name] = { @@ -1103,8 +1082,8 @@ export class Championship { }; } - for (const r in this.results) { - const raceResult = this.results[r]; + for (const r in Championship.results) { + const raceResult = Championship.results[r]; for (let pos = 0; pos < raceResult.length; pos++) { const driver = game.drivers[raceResult[pos]]; @@ -1117,8 +1096,8 @@ export class Championship { team.podiums++; } - if(pos < this.pointsSystem.length) - team.pts += this.pointsSystem[pos]; + if(pos < Championship.pointsSystem.length) + team.pts += Championship.pointsSystem[pos]; if(team.bestFinish > pos+1){ team.bestFinish = pos+1; @@ -1126,9 +1105,9 @@ export class Championship { } } - this.teamStandings = []; + Championship.teamStandings = []; for (const k in teamRanking) { - this.teamStandings.push([ + Championship.teamStandings.push([ k, teamRanking[k].pts, teamRanking[k].wins, @@ -1136,7 +1115,7 @@ export class Championship { teamRanking[k].bestFinish]); } - this.teamStandings.sort((a, b) => a[4] - b[4]); - this.teamStandings.sort((a, b) => b[1] - a[1]); + Championship.teamStandings.sort((a, b) => a[4] - b[4]); + Championship.teamStandings.sort((a, b) => b[1] - a[1]); } } \ No newline at end of file diff --git a/scripts/game.js b/scripts/game.js index fff06c6..540434d 100644 --- a/scripts/game.js +++ b/scripts/game.js @@ -17,7 +17,7 @@ export const game = { uiTeamColors: true, team: "Red Bull", year: 2023, - championship: new Championship(), + championship: Championship, othersSeries: {}, drivers: {}, teams: {}, @@ -25,6 +25,7 @@ export const game = { engineers: {}, contractsFailed: [], news: [], + game_language: "PT", } function gameBootstrap(){ @@ -33,9 +34,12 @@ function gameBootstrap(){ game.settings = loadGameSettings(); SoundStart(); + console.log(game.championship) + } gameBootstrap(); export function startNewGame(){ + game.championship.init(); game.drivers = driversData; game.teams = teamsData; game.engines = enginesData; diff --git a/ui/start-load-save.js b/ui/start-load-save.js index 3f09034..acfce42 100644 --- a/ui/start-load-save.js +++ b/ui/start-load-save.js @@ -220,7 +220,7 @@ export function loadGameScreen(){ game.team = newGame.team, game.year = newGame.year, - game.championship = new Championship(newGame.championship), + game.championship = newGame.championship, game.othersSeries = newGame.othersSeries, game.drivers = newGame.drivers, game.teams = newGame.teams, From 0b7e1edbfe2b827007e0abdb363dfc78572e8ff9 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:20:05 -0300 Subject: [PATCH 05/10] fix - Correct male driver gender --- scripts/drivers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/drivers.js b/scripts/drivers.js index 3191ad5..1fcee52 100644 --- a/scripts/drivers.js +++ b/scripts/drivers.js @@ -74,7 +74,7 @@ export function startDriversStats(){ const driver = game.drivers[d]; driver.contractInterest = []; - if(!driver.gender) driver.gender = "M"; + if(!driver.gender) driver.gender = "Male"; if(!driver.image) driver.image = driver.name; if(!driver.newTeam) driver.newTeam = ""; if(!driver.newStatus) driver.newStatus = ""; From b41fb030079017a34ea19b208124c8861a4879e1 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:23:05 -0300 Subject: [PATCH 06/10] fix - Style tweak Reduced height size of the Season Overview screen, avoiding unwanted scrollbars --- styles/ui.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/ui.css b/styles/ui.css index d6161ad..6d1c59a 100644 --- a/styles/ui.css +++ b/styles/ui.css @@ -51,7 +51,7 @@ #season-overview{ overflow-y: scroll; - height: 550px; + height: 500px; } #season-overview table{ color: #202122; From 6053198dd4fa46c0e884cb5031983275c03c5775 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:25:19 -0300 Subject: [PATCH 07/10] feat - Driver gender in ViewDriver Screen Using LOC, being the first use of the Language Localization System --- ui/viewDriver.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/viewDriver.js b/ui/viewDriver.js index ba8ae89..ac2cf92 100644 --- a/ui/viewDriver.js +++ b/ui/viewDriver.js @@ -5,6 +5,7 @@ import { market } from "./market.js"; import { getSalary } from "../scripts/drivers.js"; import { genTeamHTML } from "../scripts/main.js"; import { publishNews } from "./news.js"; +import { LOC } from "../scripts/translation.js"; export function viewDriver(name, returnToMarket, scrollPos){ let html = ""; @@ -15,6 +16,9 @@ export function viewDriver(name, returnToMarket, scrollPos){
+${this.timeConvert(Number(finalResult[k].totalTime) - Number(finalResult[0].totalTime))}+${Championship.timeConvert(Number(finalResult[k].totalTime) - Number(finalResult[0].totalTime))}+${this.timeConvert(Number(finalResult[k].totalTime) - Number(finalResult[k-1].totalTime))}+${Championship.timeConvert(Number(finalResult[k].totalTime) - Number(finalResult[k-1].totalTime))}
+ + + + ` + + /* + + */ + + html += `
Dados Pessoais
${LOC("gender_"+driver.gender)}
País: From 5b8a982e72674794603767c60f00bb20d7ff9d45 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 19:28:57 -0300 Subject: [PATCH 08/10] fix - Hiding engineers personality Hiding the visualization of the engineers' personality, as this system does not yet have a functional implementation --- ui/viewEng.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ui/viewEng.js b/ui/viewEng.js index d2155d6..ed44c5a 100644 --- a/ui/viewEng.js +++ b/ui/viewEng.js @@ -35,10 +35,17 @@ export function viewEng(name, returnToMarket, scrollPos){
${eng.gender}
Personalidade: ${eng.personality}
País: From ac4a2db5a16bd109db4a85616b98d9c45c39aff5 Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sat, 25 May 2024 21:20:46 -0300 Subject: [PATCH 09/10] docs - version name --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 92de9ee..a2dec58 100644 --- a/index.html +++ b/index.html @@ -88,7 +88,7 @@

GP Tycoon

- Copyright © JGSS - v0.12 + Copyright © JGSS - version 0.14 (Nakajima)
From d13b00153811bd424317a2ee4fbdbfc71bc053fa Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Sun, 26 May 2024 09:54:20 -0300 Subject: [PATCH 10/10] style - minor style tweak --- styles/race.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/race.css b/styles/race.css index fa04b96..739ac9e 100644 --- a/styles/race.css +++ b/styles/race.css @@ -48,7 +48,7 @@ } #time-table .tire-strategy { letter-spacing: 2px; - width: 50px; + width: max-content; } #podium {