forked from noxious/client
Half working effects
Command triggered effects still brokey
This commit is contained in:
parent
93baa10acf
commit
b86d9dd4ce
@ -3,8 +3,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { WeatherState } from '@/application/types'
|
import type { Map, WeatherState } from '@/application/types'
|
||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
|
import { MapStorage } from '@/storage/storages'
|
||||||
import { useMapStore } from '@/stores/mapStore'
|
import { useMapStore } from '@/stores/mapStore'
|
||||||
import { Scene } from 'phavuer'
|
import { Scene } from 'phavuer'
|
||||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||||
@ -20,8 +21,10 @@ const LIGHT_CONFIG = {
|
|||||||
// Stores and refs
|
// Stores and refs
|
||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
const mapStore = useMapStore()
|
const mapStore = useMapStore()
|
||||||
|
const mapStorage = new MapStorage()
|
||||||
const sceneRef = ref<Phaser.Scene | null>(null)
|
const sceneRef = ref<Phaser.Scene | null>(null)
|
||||||
const mapEffectsReady = ref(false)
|
const mapEffectsReady = ref(false)
|
||||||
|
const mapObject = ref<Map | null>(null)
|
||||||
|
|
||||||
// Effect objects
|
// Effect objects
|
||||||
const effects = {
|
const effects = {
|
||||||
@ -50,6 +53,25 @@ const createScene = (scene: Phaser.Scene) => {
|
|||||||
setupSocketListeners()
|
setupSocketListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadMap = async () => {
|
||||||
|
if (!mapStore.mapId) return
|
||||||
|
const loadedMap = await mapStorage.get(mapStore.mapId)
|
||||||
|
mapObject.value = loadedMap
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watch for mapId changes and load map when it's available
|
||||||
|
watch(
|
||||||
|
() => mapStore.mapId,
|
||||||
|
async (newMapId) => {
|
||||||
|
if (newMapId) {
|
||||||
|
mapEffectsReady.value = false
|
||||||
|
await loadMap()
|
||||||
|
updateScene()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
const initializeEffects = (scene: Phaser.Scene) => {
|
const initializeEffects = (scene: Phaser.Scene) => {
|
||||||
// Light
|
// Light
|
||||||
effects.light.value = scene.add.graphics().setDepth(1000)
|
effects.light.value = scene.add.graphics().setDepth(1000)
|
||||||
@ -80,7 +102,7 @@ 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 mapEffects = mapStore.map?.mapEffects?.reduce(
|
const mapEffects = mapObject.value?.mapEffects?.reduce(
|
||||||
(acc, curr) => ({
|
(acc, curr) => ({
|
||||||
...acc,
|
...acc,
|
||||||
[curr.effect]: curr.strength
|
[curr.effect]: curr.strength
|
||||||
@ -105,7 +127,6 @@ const updateScene = () => {
|
|||||||
rain: weatherState.value.isRainEnabled ? weatherState.value.rainPercentage : 0,
|
rain: weatherState.value.isRainEnabled ? weatherState.value.rainPercentage : 0,
|
||||||
fog: weatherState.value.isFogEnabled ? weatherState.value.fogDensity * 100 : 0
|
fog: weatherState.value.isFogEnabled ? weatherState.value.fogDensity * 100 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
applyEffects(finalEffects)
|
applyEffects(finalEffects)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +182,7 @@ const handleResize = () => {
|
|||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
watch(
|
watch(
|
||||||
() => mapStore.map,
|
() => mapObject.value,
|
||||||
() => {
|
() => {
|
||||||
mapEffectsReady.value = false
|
mapEffectsReady.value = false
|
||||||
updateScene()
|
updateScene()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user