Refactor spring.js to adjust object counts for mobile, streamline pollen and creature creation, and update code comments
This commit is contained in:
@@ -2,13 +2,13 @@ const config = window.SeasonalsPluginConfig?.Spring || {};
|
||||
|
||||
const spring = config.EnableSpring !== undefined ? config.EnableSpring : true; // Enable/disable spring
|
||||
const pollenCount = config.PollenCount || 30; // Number of pollen particles
|
||||
const sunbeamCount = config.SunbeamCount || 5; // Number of sunbeams
|
||||
const enableSunbeams = config.EnableSpringSunbeams !== undefined ? config.EnableSpringSunbeams : true; // Enable/disable sunbeams
|
||||
const sunbeamCount = config.SunbeamCount || 5; // Number of sunbeams
|
||||
const birdCount = config.BirdCount !== undefined ? config.BirdCount : 3; // Number of birds
|
||||
const butterflyCount = config.ButterflyCount !== undefined ? config.ButterflyCount : 4; // Number of butterflies
|
||||
const beeCount = config.BeeCount !== undefined ? config.BeeCount : 2; // Number of bees
|
||||
const ladybugCount = config.LadybugCount !== undefined ? config.LadybugCount : 2; // Number of ladybugs
|
||||
const randomSpring = config.EnableRandomSpring !== undefined ? config.EnableRandomSpring : true; // Enable random spring objects
|
||||
const symbolCountMobile = config.SymbolCountMobile !== undefined ? config.SymbolCountMobile : 2; // Devisor to reduce number of objects on mobile
|
||||
|
||||
// Credit: https://lottiefiles.com/free-animation/birds-flying-V7O0L8jkOg
|
||||
const birdImages = [
|
||||
@@ -23,7 +23,10 @@ const butterflyImages = [
|
||||
'../Seasonals/Resources/spring_assets/Butterfly_2.gif'
|
||||
];
|
||||
|
||||
// Credit: https://lottiefiles.com/free-animation/loading-flying-beee-WcTfIccdJZ
|
||||
const beeImage = '../Seasonals/Resources/spring_assets/Bee.gif';
|
||||
|
||||
// Credit: https://pixabay.com/gifs/ladybug-insect-nature-fly-wings-5068/
|
||||
const ladybugImage = '../Seasonals/Resources/spring_assets/ladybug.gif';
|
||||
|
||||
let msgPrinted = false;
|
||||
@@ -230,31 +233,38 @@ function initializeSpring() {
|
||||
|
||||
const container = document.querySelector('.spring-container');
|
||||
if (container) {
|
||||
if (randomSpring) {
|
||||
let isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
|
||||
let divisor = isMobile ? Math.max(1, symbolCountMobile) : 1;
|
||||
|
||||
let adjPollen = Math.floor(pollenCount / divisor);
|
||||
let adjBird = Math.floor(birdCount / divisor);
|
||||
let adjButterfly = Math.floor(butterflyCount / divisor);
|
||||
let adjBee = Math.floor(beeCount / divisor);
|
||||
let adjLadybug = Math.floor(ladybugCount / divisor);
|
||||
|
||||
// Add Pollen
|
||||
for (let i = 0; i < pollenCount; i++) {
|
||||
for (let i = 0; i < adjPollen; i++) {
|
||||
createPollen(container);
|
||||
}
|
||||
|
||||
// Add Birds
|
||||
for (let i = 0; i < birdCount; i++) {
|
||||
for (let i = 0; i < adjBird; i++) {
|
||||
setTimeout(() => createBird(container), Math.random() * 1000); // 0-1s desync
|
||||
}
|
||||
// Add Butterflies
|
||||
for (let i = 0; i < butterflyCount; i++) {
|
||||
for (let i = 0; i < adjButterfly; i++) {
|
||||
setTimeout(() => createButterfly(container), Math.random() * 1000); // 0-1s desync
|
||||
}
|
||||
// Add Bees
|
||||
for (let i = 0; i < beeCount; i++) {
|
||||
for (let i = 0; i < adjBee; i++) {
|
||||
setTimeout(() => createBee(container), Math.random() * 1000); // 0-1s desync
|
||||
}
|
||||
// Add Ladybugs
|
||||
for (let i = 0; i < ladybugCount; i++) {
|
||||
for (let i = 0; i < adjLadybug; i++) {
|
||||
setTimeout(() => createLadybugGif(container), Math.random() * 1000); // 0-1s desync
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createBird(container) {
|
||||
const wrapper = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user