refresh-cities and refresh-shops commands added to chat
authorxangelo <git@xangelo.ca>
Mon, 19 Jun 2023 09:34:08 +0000 (05:34 -0400)
committerxangelo <git@xangelo.ca>
Mon, 19 Jun 2023 09:34:08 +0000 (05:34 -0400)
seeds/cities.ts
seeds/shop_items.ts
src/server/api.ts

index 9e5020f685c2e31df85407c3ecf1020f717860bc..37201c8c933c545f1f84b77af83498fb7fd90ede 100644 (file)
@@ -83,12 +83,18 @@ export async function createLocations(): Promise<void> {
   });
 }
 
-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);
+  });
+}
index 26796146e68da804b7416a0dd9d72d23e33e2cee..49caa2874871e8db38aaec4074fa3c72c47ffc5b 100644 (file)
@@ -47,10 +47,12 @@ export async function createShopItems(): Promise<void> {
   });
 }
 
-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);
+  });
+}
index 96c665adbc5e01e17784c1f2ac153a66fccf80b5..20808e3b567a780bce0f8a27f1dd03053fd102f8 100644 (file)
@@ -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);
+      }
     }
   });