1
0
forked from noxious/client

Merge remote-tracking branch 'origin/main' into feature/map-refactor

# Conflicts:
#	src/components/game/map/Effects.vue
This commit is contained in:
Dennis Postma 2025-01-25 14:47:00 +01:00
commit b5e84c133a

View File

@ -106,21 +106,27 @@ const updateScene = () => {
{} {}
) as { [key: string]: number } ) as { [key: string]: number }
const finalEffects = { ...mapEffects, light: timeBasedLight, rain: weatherState.value.rainPercentage, fog: weatherState.value.fogDensity } const finalEffects = {...mapEffects,
light: timeBasedLight,
rain: weatherState.value.rainPercentage,
fog: weatherState.value.fogDensity }
console.log(finalEffects) console.log(finalEffects)
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) effects.rain.value.start().setQuantity(effectValues.rain / 10) if (effects.rain.value) {
if (effectValues.rain.value)
effects.rain.value.start().setQuantity(effectValues.rain / 10)
else effects.rain.value.stop() else effects.rain.value.stop()
}
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
@ -128,7 +134,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, y, a) => 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()
@ -137,11 +143,19 @@ 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) 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) 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)
//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) return lerp(LIGHT_CONFIG.NIGHT_STRENGTH, LIGHT_CONFIG.DAY_STRENGTH, (hour + minute / 60 - LIGHT_CONFIG.SUNRISE_HOUR) / LIGHT_CONFIG.TRANSITION_HOURS) 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.SUNSET_HOUR) return LIGHT_CONFIG.DAY_STRENGTH return lerp(LIGHT_CONFIG.NIGHT_STRENGTH, LIGHT_CONFIG.DAY_STRENGTH,
else return LIGHT_CONFIG.NIGHT_STRENGTH (hour+(minute/60)-LIGHT_CONFIG.SUNRISE_HOUR)/LIGHT_CONFIG.TRANSITION_HOURS)
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
@ -165,12 +179,9 @@ const handleResize = () => {
} }
// Lifecycle // Lifecycle
watch( watch(() => mapObject.value, () => {
() => mapObject.value,
() => {
updateScene() updateScene()
} })
)
onMounted(() => window.addEventListener('resize', handleResize)) onMounted(() => window.addEventListener('resize', handleResize))