From: xangelo Date: Mon, 19 Jun 2023 09:34:08 +0000 (-0400) Subject: refresh-cities and refresh-shops commands added to chat X-Git-Tag: v0.0.1~30 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=73c31c6043e9c33ba52bf63101c9e49a5e9d506c;p=risinglegends.git refresh-cities and refresh-shops commands added to chat --- diff --git a/seeds/cities.ts b/seeds/cities.ts index 9e5020f..37201c8 100644 --- a/seeds/cities.ts +++ b/seeds/cities.ts @@ -83,12 +83,18 @@ export async function createLocations(): Promise { }); } -createCities().then(createPaths).then(createLocations).then(() => { - console.log(`${stats.cityCount} Cities created`); - console.log(`${stats.paths} paths created`); - console.log('Complete'); - process.exit(0); -}).catch(e => { - console.log(e); - process.exit(1); -}); +export async function createAllCitiesAndLocations() { + return createCities().then(createPaths).then(createLocations); +} + +if(!module.parent) { + createCities().then(createPaths).then(createLocations).then(() => { + console.log(`${stats.cityCount} Cities created`); + console.log(`${stats.paths} paths created`); + console.log('Complete'); + process.exit(0); + }).catch(e => { + console.log(e); + process.exit(1); + }); +} diff --git a/seeds/shop_items.ts b/seeds/shop_items.ts index 2679614..49caa28 100644 --- a/seeds/shop_items.ts +++ b/seeds/shop_items.ts @@ -47,10 +47,12 @@ export async function createShopItems(): Promise { }); } -createShopItems().then(() => { - console.log('Complete'); - process.exit(0); -}).catch(e => { - console.log(e); - process.exit(1); -}) +if(!module.parent) { + createShopItems().then(() => { + console.log('Complete'); + process.exit(0); + }).catch(e => { + console.log(e); + process.exit(1); + }); +} diff --git a/src/server/api.ts b/src/server/api.ts index 96c665a..20808e3 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -26,6 +26,8 @@ import * as EventList from '../events/server'; // TEMP! import { createMonsters } from '../../seeds/monsters'; +import { createAllCitiesAndLocations } from '../../seeds/cities'; +import { createShopItems } from '../../seeds/shop_items'; dotenv(); @@ -117,17 +119,30 @@ io.on('connection', async socket => { await createMonsters(); message = broadcastMessage('server', 'Monster refresh!'); } + else if(msg === '/server lmnop refresh-cities') { + await createAllCitiesAndLocations(); + message = broadcastMessage('server', 'Cities, Locations, and Paths refreshed!'); + } + else if(msg === '/server lmnop refresh-shops') { + await createShopItems(); + message = broadcastMessage('server', 'Refresh shop items'); + } else { - message = broadcastMessage('server', msg.split('/server lmnop ')[1]); + const str = msg.split('/server lmnop ')[1]; + if(str) { + message = broadcastMessage('server', str); + } } } else { message = broadcastMessage(player.username, msg); } - chatHistory.push(message); - chatHistory.slice(-10); - io.emit('chat', message); + if(message) { + chatHistory.push(message); + chatHistory.slice(-10); + io.emit('chat', message); + } } });