1
0
forked from noxious/client

#258 - Put update effects in the timeout corner until zoneEffects is ready

Reverted latest changes due to zoneEffects needing to fully overwrite
This commit is contained in:
Colin Kallemein 2024-12-25 00:40:56 +01:00
parent c54d2a2da8
commit 680661f07c

View File

@ -21,6 +21,7 @@ const LIGHT_CONFIG = {
const gameStore = useGameStore() const gameStore = useGameStore()
const zoneStore = useZoneStore() const zoneStore = useZoneStore()
const sceneRef = ref<Phaser.Scene | null>(null) const sceneRef = ref<Phaser.Scene | null>(null)
const zoneEffectsReady = ref(false)
// Effect objects // Effect objects
const effects = { const effects = {
@ -76,21 +77,29 @@ const initializeEffects = (scene: Phaser.Scene) => {
// Effect updates // Effect updates
const updateScene = () => { const updateScene = () => {
const timeBasedLight = calculateLightStrength(gameStore.world.date) const timeBasedLight = calculateLightStrength(gameStore.world.date)
const defaultEffects = {
light: timeBasedLight,
rain: weatherState.value.isRainEnabled ? weatherState.value.rainPercentage : 0,
fog: weatherState.value.isFogEnabled ? weatherState.value.fogDensity * 100 : 0
}
const zoneEffects = zoneStore.zone?.zoneEffects?.reduce((acc, curr) => ({ const zoneEffects = zoneStore.zone?.zoneEffects?.reduce((acc, curr) => ({
...acc, ...acc,
[curr.effect]: curr.strength [curr.effect]: curr.strength
}), {}) as { [key: string]: number } }), {}) as { [key: string]: number }
applyEffects({ // Only update effects once zoneEffects are loaded
...defaultEffects, if (!zoneEffectsReady.value) {
...(zoneEffects || {}) if (zoneEffects && Object.keys(zoneEffects).length) {
}) zoneEffectsReady.value = true
} else {
return
}
}
const finalEffects = zoneEffects && Object.keys(zoneEffects).length
? zoneEffects
: {
light: timeBasedLight,
rain: weatherState.value.isRainEnabled ? weatherState.value.rainPercentage : 0,
fog: weatherState.value.isFogEnabled ? weatherState.value.fogDensity * 100 : 0
}
applyEffects(finalEffects)
} }
const applyEffects = (effectValues: any) => { const applyEffects = (effectValues: any) => {
@ -155,7 +164,10 @@ const handleResize = () => {
} }
// Lifecycle // Lifecycle
watch(() => zoneStore.zone?.zoneEffects, updateScene, { deep: true }) watch(() => zoneStore.zone, () => {
zoneEffectsReady.value = false
updateScene()
}, { deep: true })
onMounted(() => window.addEventListener('resize', handleResize)) onMounted(() => window.addEventListener('resize', handleResize))