forked from noxious/server
asset mngr stuff
This commit is contained in:
@ -14,6 +14,11 @@ interface IPayload {
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:tile:list', async (data: any, callback: (response: string[]) => void) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
console.log(`---Character #${socket.character?.id} is not a game master.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// get root path
|
||||
const folder = path.join(process.cwd(), 'public', 'tiles');
|
||||
|
||||
|
39
src/app/events/gm/GmTileRemove.ts
Normal file
39
src/app/events/gm/GmTileRemove.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Server } from "socket.io";
|
||||
import {TSocket} from "../../utilities/Types";
|
||||
import {writeFile} from "node:fs";
|
||||
import {randomUUID} from "node:crypto";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
interface IPayload {
|
||||
tile: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle game master remove tile event
|
||||
* @param socket
|
||||
* @param io
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:tile:remove', async (data: IPayload, callback: (response: boolean) => void) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
return;
|
||||
}
|
||||
|
||||
// get root path
|
||||
const public_folder = path.join(process.cwd(), 'public', 'tiles');
|
||||
|
||||
// remove the tile from the disk
|
||||
const finalFilePath = path.join(public_folder, data.tile);
|
||||
fs.unlink(finalFilePath, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(true);
|
||||
});
|
||||
});
|
||||
}
|
@ -17,7 +17,9 @@ interface IPayload {
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:tile:upload', async (data: any, callback: (response: boolean) => void) => {
|
||||
|
||||
// @TODO : check if socket is gm
|
||||
if (socket.character?.role !== 'gm') {
|
||||
return;
|
||||
}
|
||||
|
||||
// get root path
|
||||
const public_folder = path.join(process.cwd(), 'public', 'tiles');
|
||||
@ -28,13 +30,18 @@ export default function (socket: TSocket, io: Server) {
|
||||
}
|
||||
|
||||
for (const key in data) {
|
||||
const filename = randomUUID();
|
||||
// the files in the folder are named 0.png, 1.png, 2.png etc... check the last file name and add 1
|
||||
const files = fs.readdirSync(public_folder);
|
||||
const lastFile = files[files.length - 1];
|
||||
const lastFileName = lastFile?.split('.')[0];
|
||||
const filename = `${parseInt(lastFileName ?? 0) + 1}.png`;
|
||||
const finalFilePath = path.join(public_folder, filename);
|
||||
const tile = data[key];
|
||||
|
||||
// save the tile to the disk, for example
|
||||
writeFile(finalFilePath, tile, (err) => {});
|
||||
|
||||
// return true to the client
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
|
@ -15,6 +15,11 @@ interface IPayload {
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:zone_editor:zone:request', async (data: IPayload) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`---GM ${socket.character?.id} has requested zone via zone editor.`);
|
||||
|
||||
if (!data.zoneId) {
|
||||
|
@ -20,6 +20,12 @@ interface IPayload {
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:zone_editor:zone:save', async (data: IPayload) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
console.log(`---Character #${socket.character?.id} is not a game master.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`---GM ${socket.character?.id} has saved zone via zone editor.`);
|
||||
|
||||
console.log(data);
|
||||
|
@ -49,6 +49,7 @@ class CharacterRepository {
|
||||
data: {
|
||||
userId,
|
||||
name,
|
||||
role: 'gm',
|
||||
position_x: 0,
|
||||
position_y: 0,
|
||||
rotation: 0,
|
||||
|
10
src/app/services/AssetService.ts
Normal file
10
src/app/services/AssetService.ts
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
class AssetService
|
||||
{
|
||||
static generateTileset() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default AssetService;
|
Reference in New Issue
Block a user