From 736e19871fb2b0482ae516e7867b590ee4ae16d3 Mon Sep 17 00:00:00 2001 From: TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 12 Oct 2022 18:01:27 -0400 Subject: [PATCH 1/2] holiday effects v2 - Rude config change, `holidayEffects` is now an array of objects instead of an object with bool properties - name (does nothing other than label in config): string - enabled: boolean - images: string[] - css: 'snow' | 'fireworks' - startDay: int - startMonth: int - endDay: int - startDay: int - Enables any amount of images to be put into the effects as well as any amount of custom holiday effects --- package.json | 2 +- server/src/configs/default.json | 65 +++++++++++++++++++-- server/src/services/config.js | 12 +++- src/components/Config.jsx | 4 +- src/components/HolidayEffects.jsx | 95 +++++++++++++------------------ src/services/HolidayAnimations.js | 15 +++-- 6 files changed, 120 insertions(+), 73 deletions(-) diff --git a/package.json b/package.json index 962719e78..48989731a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reactmap", - "version": "1.5.1", + "version": "1.6.0", "description": "React based frontend map.", "main": "ReactMap.js", "author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>", diff --git a/server/src/configs/default.json b/server/src/configs/default.json index d302980a8..adac5d4e3 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -137,12 +137,65 @@ "rolesLinkName": "Role Upgrading Info", "rolesLink": "" }, - "holidayEffects": { - "christmasSnow": true, - "newYearsFireworks": true, - "valentinesDay": true, - "internationalWomensDay": true - }, + "holidayEffects": [ + { + "name": "Valentine's Day", + "enabled": true, + "images": [ + "https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/A_perfect_SVG_heart.svg/20px-A_perfect_SVG_heart.svg.png" + ], + "imageScale": 1.5, + "startMonth": 1, + "startDay": 14, + "endMonth": 1, + "endDay": 14 + }, + { + "name": "International Women's Day", + "enabled": true, + "images": [ + "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Emoji_u1f338.svg/20px-Emoji_u1f338.svg.png" + ], + "imageScale": 1, + "startDay": 8, + "startMonth": 3, + "endDay": 8, + "endMonth": 3 + }, + { + "name": "Halloween", + "enabled": true, + "images": [ + "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dc/Fluent_Emoji_flat_1f383.svg/640px-Fluent_Emoji_flat_1f383.svg.png", + "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Ghost.svg/640px-Ghost.svg.png" + ], + "imageScale": 2, + "startDay": 29, + "startMonth": 10, + "endDay": 31, + "endMonth": 10 + }, + { + "name": "Christmas", + "enabled": true, + "images": [], + "css": "snow", + "startDay": 25, + "startMonth": 12, + "endDay": 26, + "endMonth": 12 + }, + { + "name": "New Years", + "enabled": true, + "images": [], + "css": "fireworks", + "startDay": 31, + "startMonth": 12, + "endDay": 1, + "endMonth": 1 + } + ], "misc": { "enableMapJsFilter": true, "fetchLatestInvasions": true, diff --git a/server/src/services/config.js b/server/src/services/config.js index 934c72277..3cf103c4f 100644 --- a/server/src/services/config.js +++ b/server/src/services/config.js @@ -156,13 +156,22 @@ const mergeMapConfig = (obj) => { } }) + if ( + obj?.holidayEffects && + !Array.isArray(obj?.holidayEffects) && + typeof obj?.holidayEffects === 'object' + ) { + console.warn( + '[CONFIG] holidayEffects has been changed to an array, please update your config. Check out `server/src/configs/default.json` for an example.', + ) + obj.holidayEffects = [] + } return { localeSelection: obj.localeSelection, ...obj, ...obj.general, ...obj.customRoutes, ...obj.links, - ...obj.holidayEffects, ...obj.misc, messageOfTheDay: { ...obj.messageOfTheDay, @@ -179,7 +188,6 @@ const mergeMapConfig = (obj) => { general: undefined, customRoutes: undefined, links: undefined, - holidayEffects: undefined, misc: undefined, } } diff --git a/src/components/Config.jsx b/src/components/Config.jsx index cb99e0d98..98bdf7fb0 100644 --- a/src/components/Config.jsx +++ b/src/components/Config.jsx @@ -66,9 +66,7 @@ export default function Config() { getServerSettings={getServerSettings} /> ) diff --git a/src/components/HolidayEffects.jsx b/src/components/HolidayEffects.jsx index 826b72f3f..bd50cc7df 100644 --- a/src/components/HolidayEffects.jsx +++ b/src/components/HolidayEffects.jsx @@ -1,61 +1,46 @@ import React from 'react' import HolidayAnimations from '@services/HolidayAnimations' -export default function HolidayEffects({ mapSettings }) { +export default function HolidayEffects({ holidayEffects }) { const date = new Date() - - if ( - mapSettings.valentinesDay && - date.getMonth() === 1 && - date.getDate() === 14 - ) { - const heart = new HolidayAnimations( - 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/A_perfect_SVG_heart.svg/20px-A_perfect_SVG_heart.svg.png', - ) - heart.initialize() - - return null - } - if ( - mapSettings.internationalWomensDay && - date.getMonth() === 2 && - date.getDate() === 8 - ) { - const flower = new HolidayAnimations( - 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Emoji_u1f338.svg/20px-Emoji_u1f338.svg.png', - ) - flower.initialize() - + return holidayEffects.map((holiday) => { + if ( + holiday.enabled && + date.getMonth() >= holiday.startMonth - 1 && + date.getMonth() <= holiday.endMonth - 1 && + date.getDate() >= holiday.startDay && + date.getDate() <= holiday.endDay + ) { + switch (holiday.css) { + case 'snow': + return ( +
+
+
+
+
+
+
+
+ ) + case 'fireworks': + return ( +
+
+
+
+ ) + default: { + if (holiday.images?.length) { + const animation = new HolidayAnimations( + holiday.images, + holiday.imageScale, + ) + animation.initialize() + } + } + } + } return null - } - if ( - mapSettings.christmasSnow && - date.getMonth() === 11 && - date.getDate() >= 24 && - date.getDate() <= 30 - ) { - return ( -
-
-
-
-
-
-
-
- ) - } - if ( - mapSettings.newYearsFireworks && - ((date.getMonth() === 11 && date.getDate() === 31) || - (date.getMonth() === 0 && date.getDate() === 1)) - ) { - return ( -
-
-
-
- ) - } - return null + }) } diff --git a/src/services/HolidayAnimations.js b/src/services/HolidayAnimations.js index 45c49d612..6f621ae54 100644 --- a/src/services/HolidayAnimations.js +++ b/src/services/HolidayAnimations.js @@ -1,9 +1,9 @@ export default class HolidayAnimations { - constructor(image) { - this.imageHeight = 15 - this.imageWidth = 15 + constructor(images, scale = 1) { + this.imageHeight = 15 * scale + this.imageWidth = 15 * scale + this.baseImages = images this.images = [] - this.image = image this.minScale = 0.3 this.canvas = document.getElementById('holiday-canvas') this.ctx = this.canvas ? this.canvas.getContext('2d') : null @@ -33,7 +33,7 @@ export default class HolidayAnimations { this.images.forEach((item) => { item.image = new Image() item.image.style.height = item.height - item.image.src = this.image + item.image.src = item.src this.ctx.globalAlpha = item.opacity this.ctx.drawImage(item.image, item.x, item.y, item.width, item.height) }) @@ -54,7 +54,10 @@ export default class HolidayAnimations { ys: Math.random() + 1, height: scale * this.imageHeight, width: scale * this.imageWidth, - opacity: scale, + opacity: Math.max(Math.random(), 0.25), + src: this.baseImages[ + Math.floor(Math.random() * this.baseImages.length) + ], }) } setInterval(this.draw.bind(this), 30) From af57093e936297361a71fdd39d8970f1cc5f9548 Mon Sep 17 00:00:00 2001 From: TurtIeSocks Date: Wed, 12 Oct 2022 22:01:53 +0000 Subject: [PATCH 2/2] Synced docker env vars with latest config Files changed:\nM server/src/configs/custom-environment-variables.json --- .../configs/custom-environment-variables.json | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/server/src/configs/custom-environment-variables.json b/server/src/configs/custom-environment-variables.json index 620aa3411..e47e3fabf 100644 --- a/server/src/configs/custom-environment-variables.json +++ b/server/src/configs/custom-environment-variables.json @@ -305,22 +305,8 @@ "rolesLink": "MAP_LINKS_ROLES_LINK" }, "holidayEffects": { - "christmasSnow": { - "__name": "MAP_HOLIDAY_EFFECTS_CHRISTMAS_SNOW", - "__format": "boolean" - }, - "newYearsFireworks": { - "__name": "MAP_HOLIDAY_EFFECTS_NEW_YEARS_FIREWORKS", - "__format": "boolean" - }, - "valentinesDay": { - "__name": "MAP_HOLIDAY_EFFECTS_VALENTINES_DAY", - "__format": "boolean" - }, - "internationalWomensDay": { - "__name": "MAP_HOLIDAY_EFFECTS_INTERNATIONAL_WOMENS_DAY", - "__format": "boolean" - } + "__name": "MAP_HOLIDAY_EFFECTS", + "__format": "json" }, "misc": { "enableMapJsFilter": {