121 lines
3.4 KiB
Vue
121 lines
3.4 KiB
Vue
<template>
|
|
<div class="flex justify-center items-center h-dvh relative">
|
|
<Game :config="gameConfig" @create="createGame">
|
|
<Scene name="main" @preload="preloadScene" @create="createScene">
|
|
<Menu />
|
|
<Hud />
|
|
<Hotkeys />
|
|
<Minimap />
|
|
<Zone />
|
|
<Chat />
|
|
<ExpBar />
|
|
|
|
<CharacterProfile />
|
|
<Effects />
|
|
</Scene>
|
|
</Game>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import config from '@/config'
|
|
import 'phaser'
|
|
import { Game, Scene } from 'phavuer'
|
|
import { useGameStore } from '@/stores/gameStore'
|
|
import Menu from '@/components/gui/Menu.vue'
|
|
import ExpBar from '@/components/gui/ExpBar.vue'
|
|
import Hud from '@/components/gui/Hud.vue'
|
|
import Zone from '@/components/zone/Zone.vue'
|
|
import Hotkeys from '@/components/gui/Hotkeys.vue'
|
|
import Chat from '@/components/gui/Chat.vue'
|
|
import CharacterProfile from '@/components/gui/CharacterProfile.vue'
|
|
import Effects from '@/components/Effects.vue'
|
|
import Minimap from '@/components/gui/Minimap.vue'
|
|
import AwaitLoaderPlugin from 'phaser3-rex-plugins/plugins/awaitloader-plugin'
|
|
|
|
const gameStore = useGameStore()
|
|
|
|
const gameConfig = {
|
|
name: config.name,
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
type: Phaser.AUTO, // AUTO, CANVAS, WEBGL, HEADLESS
|
|
resolution: 5,
|
|
plugins: {
|
|
global: [
|
|
{
|
|
key: 'rexAwaitLoader',
|
|
plugin: AwaitLoaderPlugin,
|
|
start: true
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
const createGame = (game: Phaser.Game) => {
|
|
/**
|
|
* Resize the game when the window is resized
|
|
*/
|
|
addEventListener('resize', () => {
|
|
game.scale.resize(window.innerWidth, window.innerHeight)
|
|
})
|
|
|
|
// We don't support canvas mode, only WebGL
|
|
if (game.renderer.type === Phaser.CANVAS) {
|
|
gameStore.addNotification({
|
|
title: 'Warning',
|
|
message: 'Your browser does not support WebGL. Please use a modern browser like Chrome, Firefox, or Edge.'
|
|
})
|
|
gameStore.disconnectSocket()
|
|
}
|
|
}
|
|
|
|
function preloadScene(scene: Phaser.Scene) {
|
|
/**
|
|
* Load the base assets into the Phaser scene
|
|
*/
|
|
scene.load.image('blank_tile', '/assets/zone/blank_tile.png')
|
|
scene.load.image('waypoint', '/assets/waypoint.png')
|
|
|
|
/**
|
|
* We're using rex-await-loader to load assets asynchronously
|
|
* Phaser does not support this out of the box, so we're using this plugin
|
|
*/
|
|
// scene.load.rexAwait(async function (successCallback) {
|
|
// await assetManager.getAssetsByGroup('tiles').then((assets) => {
|
|
// assets.forEach((asset) => {
|
|
// if (scene.load.textureManager.exists(asset.key)) return
|
|
// scene.textures.addBase64(asset.key, asset.data)
|
|
// })
|
|
// })
|
|
//
|
|
// // Load objects
|
|
// await assetManager.getAssetsByGroup('objects').then((assets) => {
|
|
// assets.forEach((asset) => {
|
|
// if (scene.load.textureManager.exists(asset.key)) return
|
|
// scene.textures.addBase64(asset.key, asset.data)
|
|
// })
|
|
// })
|
|
//
|
|
// successCallback()
|
|
// })
|
|
}
|
|
|
|
function createScene(scene: Phaser.Scene) {
|
|
/**
|
|
* Create sprite animations
|
|
* This is done here because phaser forces us to
|
|
*/
|
|
// assetManager.getAssetsByGroup('sprite_animations').then((assets) => {
|
|
// assets.forEach((asset) => {
|
|
// scene.anims.create({
|
|
// key: asset.key,
|
|
// frameRate: 7,
|
|
// frames: scene.anims.generateFrameNumbers(asset.key, { start: 0, end: asset.frameCount! - 1 }),
|
|
// repeat: -1
|
|
// })
|
|
// })
|
|
// })
|
|
}
|
|
</script>
|