Refactor carnival and cherry blossom initialization to streamline object creation and enhance configuration handling
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
const config = window.SeasonalsPluginConfig?.Carnival || {};
|
const config = window.SeasonalsPluginConfig?.Carnival || {};
|
||||||
|
|
||||||
const carnival = config.EnableCarnival !== undefined ? config.EnableCarnival : true; // enable/disable carnival
|
const carnival = config.EnableCarnival !== undefined ? config.EnableCarnival : true; // enable/disable carnival
|
||||||
const randomCarnival = config.EnableRandomCarnival !== undefined ? config.EnableRandomCarnival : true; // enable random carnival
|
const carnivalCount = config.ObjectCount !== undefined ? config.ObjectCount : 120; // Number of confetti pieces to spawn
|
||||||
const randomCarnivalMobile = config.EnableRandomCarnivalMobile !== undefined ? config.EnableRandomCarnivalMobile : false; // enable random carnival on mobile
|
const carnivalCountMobile = config.ObjectCountMobile !== undefined ? config.ObjectCountMobile : 60; // Number of confetti pieces to spawn on mobile
|
||||||
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different durations
|
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different durations
|
||||||
const enableSway = config.EnableCarnivalSway !== undefined ? config.EnableCarnivalSway : true; // enable/disable carnivalsway
|
const enableSway = config.EnableCarnivalSway !== undefined ? config.EnableCarnivalSway : true; // enable/disable carnivalsway
|
||||||
const carnivalCount = config.ObjectCount !== undefined ? config.ObjectCount : 120; // Number of confetti pieces to spawn
|
|
||||||
|
|
||||||
const confettiColors = [
|
const confettiColors = [
|
||||||
'#fce18a', '#ff726d', '#b48def', '#f4306d',
|
'#fce18a', '#ff726d', '#b48def', '#f4306d',
|
||||||
@@ -148,19 +147,8 @@ function createConfettiPiece(container, isInitial = false) {
|
|||||||
container.appendChild(wrapper);
|
container.appendChild(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRandomCarnivalObjects(count) {
|
|
||||||
const carnivalContainer = document.querySelector('.carnival-container');
|
|
||||||
if (!carnivalContainer) return;
|
|
||||||
|
|
||||||
console.log('Adding random carnival confetti');
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
createConfettiPiece(carnivalContainer, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize standard carnival objects
|
// initialize standard carnival objects
|
||||||
function initCarnivalObjects() {
|
function initCarnivalObjects(count) {
|
||||||
let container = document.querySelector('.carnival-container');
|
let container = document.querySelector('.carnival-container');
|
||||||
if (!container) {
|
if (!container) {
|
||||||
container = document.createElement("div");
|
container = document.createElement("div");
|
||||||
@@ -170,7 +158,7 @@ function initCarnivalObjects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initial confetti
|
// Initial confetti
|
||||||
for (let i = 0; i < 60; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
createConfettiPiece(container, true);
|
createConfettiPiece(container, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,13 +166,12 @@ function initCarnivalObjects() {
|
|||||||
// initialize carnival
|
// initialize carnival
|
||||||
function initializeCarnival() {
|
function initializeCarnival() {
|
||||||
if (!carnival) return;
|
if (!carnival) return;
|
||||||
initCarnivalObjects();
|
|
||||||
toggleCarnival();
|
|
||||||
|
|
||||||
const screenWidth = window.innerWidth;
|
const screenWidth = window.innerWidth;
|
||||||
if (randomCarnival && (screenWidth > 768 || randomCarnivalMobile)) {
|
const count = screenWidth > 768 ? carnivalCount : carnivalCountMobile;
|
||||||
addRandomCarnivalObjects(carnivalCount);
|
|
||||||
}
|
initCarnivalObjects(count);
|
||||||
|
toggleCarnival();
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeCarnival();
|
initializeCarnival();
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ const config = window.SeasonalsPluginConfig?.CherryBlossom || {};
|
|||||||
|
|
||||||
const cherryBlossom = config.EnableCherryBlossom !== undefined ? config.EnableCherryBlossom : true; // enable/disable cherryblossom
|
const cherryBlossom = config.EnableCherryBlossom !== undefined ? config.EnableCherryBlossom : true; // enable/disable cherryblossom
|
||||||
const petalCount = config.PetalCount !== undefined ? config.PetalCount : 25; // count of petal
|
const petalCount = config.PetalCount !== undefined ? config.PetalCount : 25; // count of petal
|
||||||
const randomCherryBlossom = config.EnableRandomCherryBlossom !== undefined ? config.EnableRandomCherryBlossom : true; // enable random cherryblossom
|
const petalCountMobile = config.PetalCountMobile !== undefined ? config.PetalCountMobile : 10; // count of petal on mobile
|
||||||
const randomCherryBlossomMobile = config.EnableRandomCherryBlossomMobile !== undefined ? config.EnableRandomCherryBlossomMobile : false; // enable random cherryblossom on mobile
|
|
||||||
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different durations
|
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different durations
|
||||||
|
|
||||||
let msgPrinted = false;
|
let msgPrinted = false;
|
||||||
@@ -67,16 +66,7 @@ function createPetal(container) {
|
|||||||
container.appendChild(petal);
|
container.appendChild(petal);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRandomObjects() {
|
function initObjects(count) {
|
||||||
const container = document.querySelector('.cherryblossom-container');
|
|
||||||
if (!container) return;
|
|
||||||
|
|
||||||
for (let i = 0; i < petalCount; i++) {
|
|
||||||
createPetal(container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function initObjects() {
|
|
||||||
let container = document.querySelector('.cherryblossom-container');
|
let container = document.querySelector('.cherryblossom-container');
|
||||||
if (!container) {
|
if (!container) {
|
||||||
container = document.createElement("div");
|
container = document.createElement("div");
|
||||||
@@ -86,20 +76,19 @@ function initObjects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initial batch
|
// Initial batch
|
||||||
for (let i = 0; i < 15; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
createPetal(container);
|
createPetal(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeCherryBlossom() {
|
function initializeCherryBlossom() {
|
||||||
if (!cherryBlossom) return;
|
if (!cherryBlossom) return;
|
||||||
initObjects();
|
|
||||||
toggleCherryBlossom();
|
|
||||||
|
|
||||||
const screenWidth = window.innerWidth;
|
const screenWidth = window.innerWidth;
|
||||||
if (randomCherryBlossom && (screenWidth > 768 || randomCherryBlossomMobile)) {
|
const count = screenWidth > 768 ? petalCount : petalCountMobile;
|
||||||
addRandomObjects();
|
|
||||||
}
|
initObjects(count);
|
||||||
|
toggleCherryBlossom();
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeCherryBlossom();
|
initializeCherryBlossom();
|
||||||
|
|||||||
Reference in New Issue
Block a user