forked from noxious/server
Fix for loading assets, removed debugging logics
This commit is contained in:
parent
6c30e8d277
commit
6700ff7a5d
@ -38,14 +38,8 @@ export default function setupCharacterMove(socket: TSocket, io: Server) {
|
|||||||
const start = { x: socket.character.position_x, y: socket.character.position_y };
|
const start = { x: socket.character.position_x, y: socket.character.position_y };
|
||||||
const end = { x: data.position_x, y: data.position_y };
|
const end = { x: data.position_x, y: data.position_y };
|
||||||
|
|
||||||
console.log('Starting position:', start);
|
|
||||||
console.log('Target position:', end);
|
|
||||||
console.log('Grid:', grid);
|
|
||||||
|
|
||||||
const path = AStar.findPath(start, end, grid);
|
const path = AStar.findPath(start, end, grid);
|
||||||
|
|
||||||
console.log('Calculated path:', path);
|
|
||||||
|
|
||||||
if (path.length > 0) {
|
if (path.length > 0) {
|
||||||
await moveAlongPath(socket, io, path, grid);
|
await moveAlongPath(socket, io, path, grid);
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,6 +8,7 @@ import { TAsset } from './Types'
|
|||||||
import tileRepository from '../repositories/TileRepository'
|
import tileRepository from '../repositories/TileRepository'
|
||||||
import objectRepository from '../repositories/ObjectRepository'
|
import objectRepository from '../repositories/ObjectRepository'
|
||||||
import spriteRepository from '../repositories/SpriteRepository'
|
import spriteRepository from '../repositories/SpriteRepository'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
async function addHttpRoutes(app: Application) {
|
async function addHttpRoutes(app: Application) {
|
||||||
app.get('/assets', async (req: Request, res: Response) => {
|
app.get('/assets', async (req: Request, res: Response) => {
|
||||||
@ -35,7 +36,7 @@ async function addHttpRoutes(app: Application) {
|
|||||||
sprites.forEach((sprite) => {
|
sprites.forEach((sprite) => {
|
||||||
sprite.spriteActions.forEach((spriteAction) => {
|
sprite.spriteActions.forEach((spriteAction) => {
|
||||||
assets.push({
|
assets.push({
|
||||||
key: spriteAction.id,
|
key: sprite.id + '-' + spriteAction.action,
|
||||||
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||||
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
||||||
frameWidth: spriteAction.frameWidth,
|
frameWidth: spriteAction.frameWidth,
|
||||||
@ -46,24 +47,33 @@ async function addHttpRoutes(app: Application) {
|
|||||||
|
|
||||||
res.json(assets)
|
res.json(assets)
|
||||||
})
|
})
|
||||||
app.get('/assets/:type/:file', (req: Request, res: Response) => {
|
|
||||||
const assetName = req.params.file
|
|
||||||
|
|
||||||
// if (!isValidAsset(assetName)) {
|
app.get('/assets/:type/:spriteId?/:file', (req: Request, res: Response) => {
|
||||||
// return res.status(400).send('Invalid asset name');
|
const assetType = req.params.type;
|
||||||
// }
|
const spriteId = req.params.spriteId;
|
||||||
|
const fileName = req.params.file;
|
||||||
|
|
||||||
const options = {
|
let assetPath;
|
||||||
root: path.join(process.cwd(), 'public', req.params.type)
|
if (assetType === 'sprites' && spriteId) {
|
||||||
|
assetPath = path.join(process.cwd(), 'public', assetType, spriteId, fileName);
|
||||||
|
} else {
|
||||||
|
assetPath = path.join(process.cwd(), 'public', assetType, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendFile(assetName, options, (err) => {
|
console.log(`Attempting to serve: ${assetPath}`);
|
||||||
|
|
||||||
|
if (!fs.existsSync(assetPath)) {
|
||||||
|
console.error(`File not found: ${assetPath}`);
|
||||||
|
return res.status(404).send('Asset not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
res.sendFile(assetPath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error sending file:', err)
|
console.error('Error sending file:', err);
|
||||||
res.status(500).send('Error downloading the asset')
|
res.status(500).send('Error downloading the asset');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
app.post('/login', async (req: Request, res: Response) => {
|
app.post('/login', async (req: Request, res: Response) => {
|
||||||
const { username, password } = req.body
|
const { username, password } = req.body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user