Re-applied changes

This commit is contained in:
Dennis Postma 2025-01-25 15:38:20 +01:00
parent 18db005bc1
commit 967cb1893d

View File

@ -106,26 +106,22 @@ const updateScene = () => {
{} {}
) as { [key: string]: number } ) as { [key: string]: number }
const finalEffects = {...mapEffects, const finalEffects = { ...mapEffects, light: timeBasedLight, rain: weatherState.value.rainPercentage, fog: weatherState.value.fogDensity }
light: timeBasedLight,
rain: weatherState.value.rainPercentage,
fog: weatherState.value.fogDensity }
applyEffects(finalEffects) applyEffects(finalEffects)
} }
const applyEffects = (effectValues: any) => { const applyEffects = (effectValues: any) => {
if (effects.light.value) { if (effects.light.value) {
const darkness = 1 - (effectValues.light) / 100 const darkness = 1 - effectValues.light / 100
effects.light.value.clear().fillStyle(0x000000, darkness).fillRect(0, 0, window.innerWidth, window.innerHeight) effects.light.value.clear().fillStyle(0x000000, darkness).fillRect(0, 0, window.innerWidth, window.innerHeight)
} }
if (effects.rain.value) { if (effects.rain.value) {
if (effectValues.rain.value) if (effectValues.rain.value) effects.rain.value.start().setQuantity(effectValues.rain / 10)
effects.rain.value.start().setQuantity(effectValues.rain / 10)
else effects.rain.value.stop() else effects.rain.value.stop()
} }
if (effectValues.fog.value && effects.fog.value) effects.fog.value.setAlpha(effectValues.fog/100); if (effectValues.fog.value && effects.fog.value) effects.fog.value.setAlpha(effectValues.fog / 100)
} }
// Linear Interpolation // Linear Interpolation
@ -133,7 +129,7 @@ const applyEffects = (effectValues: any) => {
// a = 0 return x // a = 0 return x
// a = 0.5 return (x+y)/2 // a = 0.5 return (x+y)/2
// a = 1 return y // a = 1 return y
const lerp = (x:number,y:number,a:number) => x * (1-a) + y * a const lerp = (x: number, y: number, a: number) => x * (1 - a) + y * a
const calculateLightStrength = (time: Date): number => { const calculateLightStrength = (time: Date): number => {
const hour = time.getHours() const hour = time.getHours()
@ -142,19 +138,11 @@ const calculateLightStrength = (time: Date): number => {
const totalMinutes = (hour - (LIGHT_CONFIG.SUNSET_HOUR - 2)) * 60 + minute const totalMinutes = (hour - (LIGHT_CONFIG.SUNSET_HOUR - 2)) * 60 + minute
//Transition from daylight to night //Transition from daylight to night
if (hour >= LIGHT_CONFIG.SUNSET_HOUR - LIGHT_CONFIG.TRANSITION_HOURS && hour < LIGHT_CONFIG.SUNSET_HOUR) if (hour >= LIGHT_CONFIG.SUNSET_HOUR - LIGHT_CONFIG.TRANSITION_HOURS && hour < LIGHT_CONFIG.SUNSET_HOUR) return lerp(LIGHT_CONFIG.DAY_STRENGTH, LIGHT_CONFIG.NIGHT_STRENGTH, (hour + minute / 60 - (LIGHT_CONFIG.SUNSET_HOUR - LIGHT_CONFIG.TRANSITION_HOURS)) / LIGHT_CONFIG.TRANSITION_HOURS)
return lerp(LIGHT_CONFIG.DAY_STRENGTH, LIGHT_CONFIG.NIGHT_STRENGTH,
(hour+(minute/60)-(LIGHT_CONFIG.SUNSET_HOUR-LIGHT_CONFIG.TRANSITION_HOURS))/LIGHT_CONFIG.TRANSITION_HOURS)
//Transition from sunrise to morning //Transition from sunrise to morning
else if (hour >= LIGHT_CONFIG.SUNRISE_HOUR && hour < LIGHT_CONFIG.SUNRISE_HOUR + LIGHT_CONFIG.TRANSITION_HOURS) else if (hour >= LIGHT_CONFIG.SUNRISE_HOUR && hour < LIGHT_CONFIG.SUNRISE_HOUR + LIGHT_CONFIG.TRANSITION_HOURS) return lerp(LIGHT_CONFIG.NIGHT_STRENGTH, LIGHT_CONFIG.DAY_STRENGTH, (hour + minute / 60 - LIGHT_CONFIG.SUNRISE_HOUR) / LIGHT_CONFIG.TRANSITION_HOURS)
return lerp(LIGHT_CONFIG.NIGHT_STRENGTH, LIGHT_CONFIG.DAY_STRENGTH, else if (hour > LIGHT_CONFIG.SUNRISE_HOUR && hour < LIGHT_CONFIG.SUNSET_HOUR) return LIGHT_CONFIG.DAY_STRENGTH
(hour+(minute/60)-LIGHT_CONFIG.SUNRISE_HOUR)/LIGHT_CONFIG.TRANSITION_HOURS) else return LIGHT_CONFIG.NIGHT_STRENGTH
else if (hour > LIGHT_CONFIG.SUNRISE_HOUR && hour < LIGHT_CONFIG.SUNSET_HOUR)
return LIGHT_CONFIG.DAY_STRENGTH
else
return LIGHT_CONFIG.NIGHT_STRENGTH
} }
// Socket and window handlers // Socket and window handlers
@ -178,9 +166,12 @@ const handleResize = () => {
} }
// Lifecycle // Lifecycle
watch(() => mapObject.value, () => { watch(
() => mapObject.value,
() => {
updateScene() updateScene()
}) }
)
onMounted(() => window.addEventListener('resize', handleResize)) onMounted(() => window.addEventListener('resize', handleResize))