UI update for map with sector selector
[browser-rts.git] / src / api.ts
index 5f48de443d383b76ec6375fd80d9ef63f0088a08..aba677b1f72ad8c1e6f6dc59a2ca8471481441e5 100644 (file)
@@ -11,7 +11,7 @@ import { construction } from './tasks/construction';
 import { unitTraining } from './tasks/unit-training';
 import { fight } from './tasks/fight';
 import { renderUnitTraining } from './render/unit-training';
-import { launchOffensive, listOperations, renderOverworldMap } from './render/fight';
+import { launchOffensive, listOperations, renderOverworldMap } from './render/map';
 import { createBullBoard } from '@bull-board/api';
 import { BullAdapter } from '@bull-board/api/bullAdapter';
 import _ from 'lodash';
@@ -117,11 +117,23 @@ server.get<{}, string>('/poll/unit-training', async req => {
        return renderUnitTraining(city, units, unitTrainingQueues);
 });
 
-server.get<{}, string>('/poll/map', async req => {
+server.post<{body: {sector: string}}, string>('/poll/map', async req => {
        const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
        const city = await cityRepo.getUsersCity(account.id);
 
-       return renderOverworldMap(await cityRepo.findAllInSector(city.sector_id), city);
+  let sector = city.sector_id;
+  if(req.body.sector) {
+    try {
+      sector = parseInt(req.body.sector);
+    }
+    catch(e) {
+      sector = city.sector_id;
+    }
+  }
+
+  console.log('Checking cities in sector', sector);
+
+       return renderOverworldMap(await cityRepo.findAllInSector(sector), city, sector);
 });
 
 server.get<{}, string>('/poll/mailroom', async req => {
@@ -285,4 +297,4 @@ server.get<void, string>('/attacks/outgoing', async req => {
 });
 
 
-server.start();
\ No newline at end of file
+server.start();