forked from noxious/client
moving stuff yes
This commit is contained in:
parent
778c10a9ce
commit
910a9fa2cf
@ -15,12 +15,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { Container, Image, RoundRectangle, Sprite, Text, useScene } from 'phavuer'
|
import { Container, Image, refObj, refTo, RoundRectangle, Sprite, Text, useScene } from 'phavuer'
|
||||||
import { type ExtendedCharacter as CharacterT } from '@/types'
|
import { type ExtendedCharacter as CharacterT } from '@/types'
|
||||||
import { calculateIsometricDepth, tileToWorldX, tileToWorldY } from '@/composables/zoneComposable'
|
import { calculateIsometricDepth, tileToWorldX, tileToWorldY } from '@/composables/zoneComposable'
|
||||||
import { watch, computed, ref, onMounted, onUnmounted } from 'vue'
|
import { watch, computed, ref, onMounted, onUnmounted } from 'vue'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
|
import { useZoneStore } from '@/stores/zoneStore'
|
||||||
|
|
||||||
enum Direction {
|
enum Direction {
|
||||||
POSITIVE,
|
POSITIVE,
|
||||||
@ -28,7 +29,7 @@ enum Direction {
|
|||||||
NOCHANGE
|
NOCHANGE
|
||||||
}
|
}
|
||||||
|
|
||||||
const charContainer = ref<Phaser.GameObjects.Container | null>(null)
|
const charContainer = refObj();
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
layer: Phaser.Tilemaps.TilemapLayer
|
layer: Phaser.Tilemaps.TilemapLayer
|
||||||
@ -40,6 +41,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
|
const zoneStore = useZoneStore()
|
||||||
const scene = useScene()
|
const scene = useScene()
|
||||||
|
|
||||||
const isometricDepth = ref(calculateIsometricDepth(props.character!.positionX, props.character!.positionY, 28, 94, true))
|
const isometricDepth = ref(calculateIsometricDepth(props.character!.positionX, props.character!.positionY, 28, 94, true))
|
||||||
@ -167,7 +169,8 @@ onMounted(() => {
|
|||||||
*/
|
*/
|
||||||
// Check if player is this character, then lock with camera
|
// Check if player is this character, then lock with camera
|
||||||
if (props.character && props.character.id === gameStore.character?.id) {
|
if (props.character && props.character.id === gameStore.character?.id) {
|
||||||
scene.cameras.main.startFollow(charContainer.value as Phaser.GameObjects.Container)
|
charContainer.value?.setName(props.character.name)
|
||||||
|
zoneStore.characterLoaded = true;
|
||||||
}
|
}
|
||||||
if (props.character) {
|
if (props.character) {
|
||||||
updatePosition(props.character.positionX, props.character.positionY, Direction.POSITIVE)
|
updatePosition(props.character.positionX, props.character.positionY, Direction.POSITIVE)
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
|
import { useScene } from 'phavuer'
|
||||||
|
import { watch } from 'vue'
|
||||||
|
import { useZoneStore } from '@/stores/zoneStore'
|
||||||
|
|
||||||
export function useCameraControls(scene: Phaser.Scene): any {
|
export function useCameraControls(scene: Phaser.Scene): any {
|
||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
|
const zoneStore = useZoneStore()
|
||||||
const camera = scene.cameras.main
|
const camera = scene.cameras.main
|
||||||
|
|
||||||
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
||||||
@ -14,6 +18,15 @@ export function useCameraControls(scene: Phaser.Scene): any {
|
|||||||
gameStore.setPlayerDraggingCamera(false)
|
gameStore.setPlayerDraggingCamera(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => zoneStore.characterLoaded,
|
||||||
|
(characterLoaded) => {
|
||||||
|
if(characterLoaded) {
|
||||||
|
scene.cameras.main.startFollow(scene.children.getByName(gameStore.character.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
||||||
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerUp)
|
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerUp)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { io, Socket } from 'socket.io-client'
|
|||||||
import type { Asset, Character, Notification, User } from '@/types'
|
import type { Asset, Character, Notification, User } from '@/types'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import { useCookies } from '@vueuse/integrations/useCookies'
|
import { useCookies } from '@vueuse/integrations/useCookies'
|
||||||
|
import { BehaviorSubject } from 'rxjs'
|
||||||
|
|
||||||
export const useGameStore = defineStore('game', {
|
export const useGameStore = defineStore('game', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
@ -4,7 +4,8 @@ import type { ExtendedCharacter, Zone } from '@/types'
|
|||||||
export const useZoneStore = defineStore('zone', {
|
export const useZoneStore = defineStore('zone', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
zone: null as Zone | null,
|
zone: null as Zone | null,
|
||||||
characters: [] as ExtendedCharacter[]
|
characters: [] as ExtendedCharacter[],
|
||||||
|
characterLoaded: false,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getCharacterById: (state) => {
|
getCharacterById: (state) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user