Refactor sports.js to streamline configuration handling, remove unused variables, and enhance code readability

This commit is contained in:
CodeDevMLH
2026-02-27 23:18:07 +01:00
parent 79c4f988f2
commit d0634e4487

View File

@@ -2,28 +2,30 @@ const config = window.SeasonalsPluginConfig?.Sports || {};
const sports = config.EnableSports !== undefined ? config.EnableSports : true; const sports = config.EnableSports !== undefined ? config.EnableSports : true;
const symbolCount = config.SymbolCount || 5; const symbolCount = config.SymbolCount || 5;
const useRandomSymbols = config.EnableRandomSymbols !== undefined ? config.EnableRandomSymbols : true;
const enableRandomMobile = config.EnableRandomSymbolsMobile !== undefined ? config.EnableRandomSymbolsMobile : false;
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true;
const enableTrophy = config.EnableTrophy !== undefined ? config.EnableTrophy : false; const enableTrophy = config.EnableTrophy !== undefined ? config.EnableTrophy : false;
const rawSportsBalls = config.SportsBalls || 'football,basketball,tennis,volleyball';
const turfColorHex = config.TurfColor || '#228b22';
const confettiColors = config.ConfettiColors ? config.ConfettiColors.split(',') : ['#000000', '#FF0000', '#FFCC00']; // Add Country Colored confetti
// Pre-declare and manage image assets // Pre-declare and manage image assets
// Credits: https://flaticon.com
const SPORTS_ASSETS = { const SPORTS_ASSETS = {
badminton: ['badminton_1', 'badminton_2'], badminton: ['badminton_1', 'badminton_2'],
baseball: ['baseball_1', 'baseball_2'], baseball: ['baseball_1', 'baseball_2'],
basketball: ['basketball_1', 'basketball_2'], basketball: ['basketball_1', 'basketball_2'],
billiard: Array.from({length: 14}, (_, i) => `billiard_ball_${i + 1}`), billiard: Array.from({length: 14}, (_, i) => `billiard_ball_${i + 1}`),
bowling: ['bowling_1', 'bowling_2'], bowling: ['bowling_1', 'bowling_2'],
football: Array.from({length: 5}, (_, i) => `football_${i + 1}`), football: Array.from({length: 5}, (_, i) => `football_${i + 1}`),
golf: ['golf_ball_1', 'golf_ball_2'], golf: ['golf_ball_1', 'golf_ball_2'],
rugby: ['rugby_ball_1', 'rugby_ball_2'], rugby: ['rugby_ball_1', 'rugby_ball_2'],
table_tennis: ['table_tennis_ball_1', 'table_tennis_ball_2'], table_tennis: ['table_tennis_ball_1', 'table_tennis_ball_2'],
tennis: ['tennis_ball_1', 'tennis_ball_2'], tennis: ['tennis_ball_1', 'tennis_ball_2'],
volleyball: ['volleyball_1', 'volleyball_2'], volleyball: ['volleyball_1', 'volleyball_2'],
waterball: ['waterball_1', 'waterball_2'] waterball: ['waterball_1', 'waterball_2']
}; };
const turfColorHex = config.TurfColor || '#228b22';
let msgPrinted = false; let msgPrinted = false;
@@ -67,11 +69,10 @@ function createSports() {
document.body.appendChild(container); document.body.appendChild(container);
} }
// Parse turf color config
// Create a turf/grass overlay at the bottom using the provided hex // Create a turf/grass overlay at the bottom using the provided hex
const turf = document.createElement('div'); const turf = document.createElement('div');
turf.className = 'sports-turf'; turf.className = 'sports-turf';
// Using hex with transparency (e.g., 4D = 30%, CC = 80%) // Using hex with transparency
turf.style.background = `linear-gradient(180deg, transparent 0%, ${turfColorHex}4D 30%, ${turfColorHex}CC 100%)`; turf.style.background = `linear-gradient(180deg, transparent 0%, ${turfColorHex}4D 30%, ${turfColorHex}CC 100%)`;
container.appendChild(turf); container.appendChild(turf);
@@ -85,7 +86,6 @@ function createSports() {
const useRandomDuration = enableDifferentDuration !== false; const useRandomDuration = enableDifferentDuration !== false;
// Map standard sports balls to spawn based on category configuration // Map standard sports balls to spawn based on category configuration
const rawSportsBalls = config.SportsBalls || 'football,basketball,tennis,volleyball';
const chosenCategories = rawSportsBalls.split(',').map(s => s.trim()).filter(s => s !== ''); const chosenCategories = rawSportsBalls.split(',').map(s => s.trim()).filter(s => s !== '');
const createBall = (randomItem) => { const createBall = (randomItem) => {
@@ -140,7 +140,7 @@ function createSports() {
// Create falling sports balls // Create falling sports balls
chosenCategories.forEach(category => { chosenCategories.forEach(category => {
let variants = SPORTS_ASSETS[category]; let variants = SPORTS_ASSETS[category];
if (!variants) variants = [category]; // Legacy fallback if (!variants) variants = [category];
for (let i = 0; i < ballsPerCategory; i++) { for (let i = 0; i < ballsPerCategory; i++) {
// Pick a random variant // Pick a random variant
@@ -162,7 +162,6 @@ function createSports() {
let trophyImg = document.createElement('img'); let trophyImg = document.createElement('img');
trophyImg.src = `../Seasonals/Resources/sport_assets/trophy.gif`; trophyImg.src = `../Seasonals/Resources/sport_assets/trophy.gif`;
// Randomly scale trophy slightly larger
trophyImg.style.transform = `scale(${Math.random() * 0.5 + 0.8})`; trophyImg.style.transform = `scale(${Math.random() * 0.5 + 0.8})`;
trophyImg.onerror = function() { trophyImg.onerror = function() {
this.style.display = 'none'; this.style.display = 'none';
@@ -211,8 +210,6 @@ function createSports() {
setTimeout(() => { if (document.body.contains(container)) launchTrophy(); }, Math.random() * 5000 + 2000); setTimeout(() => { if (document.body.contains(container)) launchTrophy(); }, Math.random() * 5000 + 2000);
} }
// Add Germany Colored confetti (Black, Red, Gold)
const confettiColors = ['#000000', '#FF0000', '#FFCC00'];
const confettiCount = isMobile ? 30 : 60; const confettiCount = isMobile ? 30 : 60;
for (let i = 0; i < confettiCount; i++) { for (let i = 0; i < confettiCount; i++) {
@@ -257,8 +254,6 @@ function createSports() {
} }
} }
/* Removed legacy fallback logic */
function initializeSports() { function initializeSports() {
if (!sports) return; if (!sports) return;
createSports(); createSports();