From b5185d916fff5422880ddaaf817ec4068c22879d Mon Sep 17 00:00:00 2001 From: xangelo Date: Mon, 18 Dec 2023 01:11:13 -0500 Subject: [PATCH] fix: migrate existing routers to new router folder There were some existing routers for dungeons, healers, recruiters, and repair systems that were in their own folder. They've since been folded into the main router configuration. --- src/server/api.ts | 8 ----- src/server/routes/index.ts | 6 +++- src/server/{ => routes}/locations/dungeon.ts | 32 +++++++++---------- src/server/{ => routes}/locations/healer.ts | 22 ++++++------- .../{ => routes}/locations/recruiter.ts | 27 ++++++++-------- src/server/{ => routes}/locations/repair.ts | 28 ++++++++-------- src/server/routes/{ => locations}/stores.ts | 20 ++++++------ src/shared/constants.ts | 2 ++ 8 files changed, 71 insertions(+), 74 deletions(-) rename src/server/{ => routes}/locations/dungeon.ts (85%) rename src/server/{ => routes}/locations/healer.ts (88%) rename src/server/{ => routes}/locations/recruiter.ts (81%) rename src/server/{ => routes}/locations/repair.ts (68%) rename src/server/routes/{ => locations}/stores.ts (88%) diff --git a/src/server/api.ts b/src/server/api.ts index 75134f5..b63d65d 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -25,10 +25,6 @@ import { getPlayerSkills} from './skills'; import { fightRound } from './fight'; -import { router as healerRouter } from './locations/healer'; -import { router as professionRouter } from './locations/recruiter'; -import { router as repairRouter } from './locations/repair'; -import { router as dungeonRouter } from './locations/dungeon'; import * as Routers from './routes'; import * as Alert from './views/alert'; @@ -152,10 +148,6 @@ io.on('connection', async socket => { }); -app.use(healerRouter); -app.use(professionRouter); -app.use(repairRouter); -app.use(dungeonRouter); each(Routers, router => { app.use(router); }); diff --git a/src/server/routes/index.ts b/src/server/routes/index.ts index b08846f..07fe33d 100644 --- a/src/server/routes/index.ts +++ b/src/server/routes/index.ts @@ -2,4 +2,8 @@ export { chatRouter } from './chat'; export { inventoryRouter } from './inventory'; export { profileRouter } from './profile'; export { travelRouter } from './travel'; -export { storeRouter } from './stores'; +export { storeRouter } from './locations/stores'; +export { dungeonRouter } from './locations/dungeon'; +export { healerRouter } from './locations/healer'; +export { recruiterRouter } from './locations/recruiter'; +export { repairRouter } from './locations/repair'; diff --git a/src/server/locations/dungeon.ts b/src/server/routes/locations/dungeon.ts similarity index 85% rename from src/server/locations/dungeon.ts rename to src/server/routes/locations/dungeon.ts index 2b45096..9355656 100644 --- a/src/server/locations/dungeon.ts +++ b/src/server/routes/locations/dungeon.ts @@ -1,21 +1,21 @@ import { Router } from "express"; -import { authEndpoint } from '../auth'; -import { logger } from "../lib/logger"; -import { getDungeon, getService } from '../map'; -import { completeDungeon, getActiveDungeon, getRoomVists, getUniqueFights, loadDungeon, loadRoom, movePlayerToRoomInDungeon, putPlayerInDungeon, updatePlayerDungeonState } from '../dungeon'; -import { Dungeon, DungeonRewards } from "../../shared/dungeon"; -import { dungeonRewards, renderDungeon } from '../views/dungeons/room'; -import * as Alert from '../views/alert'; -import { createFight, loadMonster } from "../monster"; -import { renderFightPreRoundDungeon } from "../views/fight"; +import { authEndpoint } from '../../auth'; +import { logger } from "../../lib/logger"; +import { getDungeon, getService } from '../../map'; +import { completeDungeon, getActiveDungeon, getRoomVists, getUniqueFights, loadDungeon, loadRoom, movePlayerToRoomInDungeon, putPlayerInDungeon, updatePlayerDungeonState } from '../../dungeon'; +import { Dungeon, DungeonRewards } from "../../../shared/dungeon"; +import { dungeonRewards, renderDungeon } from '../../views/dungeons/room'; +import * as Alert from '../../views/alert'; +import { createFight, loadMonster } from "../../monster"; +import { renderFightPreRoundDungeon } from "../../views/fight"; import { has, max, each } from 'lodash'; -import { expToLevel, maxHp, maxVigor } from "../../shared/player"; -import { updatePlayer } from "../player"; -import { getEventHistoryToday } from "../events"; +import { expToLevel, maxHp, maxVigor } from "../../../shared/player"; +import { updatePlayer } from "../../player"; +import { getEventHistoryToday } from "../../events"; -export const router = Router(); +export const dungeonRouter = Router(); -router.get('/city/dungeon/:dungeon_id/:location_id', authEndpoint, async (req, res) => { +dungeonRouter.get('/city/dungeon/:dungeon_id/:location_id', authEndpoint, async (req, res) => { let dungeon: Dungeon; let activeDungeon = await getActiveDungeon(req.player.id); // because of how we treat locations + dungeons, the "event_name" of a location @@ -48,7 +48,7 @@ router.get('/city/dungeon/:dungeon_id/:location_id', authEndpoint, async (req, r res.send(renderDungeon(service.city_name, service.name, room, visits)); }); -router.post('/city/dungeon/step/:target_room_id', authEndpoint, async (req, res) => { +dungeonRouter.post('/city/dungeon/step/:target_room_id', authEndpoint, async (req, res) => { const activeDungeon = await getActiveDungeon(req.player.id); if(!activeDungeon) { logger.log(`Not in a dungeon`); @@ -124,7 +124,7 @@ router.post('/city/dungeon/step/:target_room_id', authEndpoint, async (req, res) res.send(renderDungeon(service.city_name, service.name, nextRoom, visits)); }); -router.post('/city/dungeon/:dungeon_id/complete', authEndpoint, async (req, res) => { +dungeonRouter.post('/city/dungeon/:dungeon_id/complete', authEndpoint, async (req, res) => { const activeDungeon = await getActiveDungeon(req.player.id); if(!activeDungeon) { logger.log(`Not in a dungeon`); diff --git a/src/server/locations/healer.ts b/src/server/routes/locations/healer.ts similarity index 88% rename from src/server/locations/healer.ts rename to src/server/routes/locations/healer.ts index 3d7374b..7c20c6e 100644 --- a/src/server/locations/healer.ts +++ b/src/server/routes/locations/healer.ts @@ -1,15 +1,15 @@ import { Request, Response, Router } from "express"; -import { maxHp, maxVigor } from "../../shared/player"; -import { authEndpoint } from '../auth'; -import { logger } from "../lib/logger"; -import { updatePlayer } from "../player"; -import { getCityDetails, getService } from '../map'; +import { maxHp, maxVigor } from "../../../shared/player"; +import { authEndpoint } from '../../auth'; +import { logger } from "../../lib/logger"; +import { updatePlayer } from "../../player"; +import { getCityDetails, getService } from '../../map'; import { sample } from 'lodash'; -import { City, Location } from "../../shared/map"; -import { renderPlayerBar } from "../views/player-bar"; -import { BackToTown } from "../views/components/button"; +import { City, Location } from "../../../shared/map"; +import { renderPlayerBar } from "../../views/player-bar"; +import { BackToTown } from "../../views/components/button"; -export const router = Router(); +export const healerRouter = Router(); type TextSegment = 'intro' | 'insufficient_money' | 'heal_successful'; @@ -91,7 +91,7 @@ function getText(type: TextSegment, location: Location, city: City): string { } -router.get('/city/services/healer/:location_id', authEndpoint, async (req: Request, res: Response) => { +healerRouter.get('/city/services/healer/:location_id', authEndpoint, async (req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); const city = await getCityDetails(service.city_id); @@ -134,7 +134,7 @@ ${BackToTown()} -router.post('/city/services/healer/heal/:location_id', authEndpoint, async (req: Request, res: Response) => { +healerRouter.post('/city/services/healer/heal/:location_id', authEndpoint, async (req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); const city = await getCityDetails(service.city_id); diff --git a/src/server/locations/recruiter.ts b/src/server/routes/locations/recruiter.ts similarity index 81% rename from src/server/locations/recruiter.ts rename to src/server/routes/locations/recruiter.ts index fa46860..73a3c1a 100644 --- a/src/server/locations/recruiter.ts +++ b/src/server/routes/locations/recruiter.ts @@ -1,21 +1,20 @@ import { Request, Response, Router } from "express"; -import { getService } from "../map"; -import { authEndpoint } from '../auth'; -import { logger } from "../lib/logger"; -import * as Alert from "../views/alert"; -import { changeProfession } from "../player"; -import { renderPlayerBar } from "../views/player-bar"; -import { BackToTown } from "../views/components/button"; +import { getService } from "../../map"; +import { authEndpoint } from '../../auth'; +import { logger } from "../../lib/logger"; +import * as Alert from "../../views/alert"; +import { changeProfession } from "../../player"; +import { renderPlayerBar } from "../../views/player-bar"; +import { BackToTown } from "../../views/components/button"; +import { MIN_LEVEL_TO_CHANGE_PROFESSIONS } from "../../../shared/constants"; function p(str: string) { return `

${str}

`; } -export const router = Router(); +export const recruiterRouter = Router(); -const MIN_LEVEL = 25; - -router.get('/city/services/profession_recruitor/:location_id', authEndpoint, async(req: Request, res: Response) => { +recruiterRouter.get('/city/services/profession_recruitor/:location_id', authEndpoint, async(req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); if(!service || service.city_id !== req.player.city_id) { @@ -31,8 +30,8 @@ router.get('/city/services/profession_recruitor/:location_id', authEndpoint, asy html.push(`

You could become a powerful Mage! Casting spells to rain fire upon our enemies.

`); html.push(`

You could become a lithe Rogue! Attacking our enemies swiftly when they least expect!

`); - if(req.player.level < MIN_LEVEL) { - html.push(p(`Unfortunately you have to be at least level ${MIN_LEVEL} to take part in our training...`)); + if(req.player.level < MIN_LEVEL_TO_CHANGE_PROFESSIONS) { + html.push(p(`Unfortunately you have to be at least level ${MIN_LEVEL_TO_CHANGE_PROFESSIONS} to take part in our training...`)); } else { html.push(p(`Be Careful! Once you change your profession, you'll never be a Wanderer again...`)); @@ -80,7 +79,7 @@ router.get('/city/services/profession_recruitor/:location_id', authEndpoint, asy `); }); -router.post('/city/services/profession_change/:location_id', authEndpoint, async(req: Request, res: Response) => { +recruiterRouter.post('/city/services/profession_change/:location_id', authEndpoint, async(req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); if(!service || service.city_id !== req.player.city_id) { diff --git a/src/server/locations/repair.ts b/src/server/routes/locations/repair.ts similarity index 68% rename from src/server/locations/repair.ts rename to src/server/routes/locations/repair.ts index 19d382c..d457f5f 100644 --- a/src/server/locations/repair.ts +++ b/src/server/routes/locations/repair.ts @@ -1,17 +1,17 @@ import { Request, Response, Router } from "express"; -import { authEndpoint } from '../auth'; -import { logger } from "../lib/logger"; -import { getService } from "../map"; -import { getInventory, getInventoryItem, repair } from '../inventory'; -import { renderRepairService } from '../views/repair'; -import { repairCost } from "../../shared/inventory"; -import * as Alert from "../views/alert"; -import { updatePlayer } from "../player"; -import { renderPlayerBar } from "../views/player-bar"; - -export const router = Router(); - -router.get('/city/services/repair/:location_id', authEndpoint, async(req: Request, res: Response) => { +import { authEndpoint } from '../../auth'; +import { logger } from "../../lib/logger"; +import { getService } from "../../map"; +import { getInventory, getInventoryItem, repair } from '../../inventory'; +import { renderRepairService } from '../../views/repair'; +import { repairCost } from "../../../shared/inventory"; +import * as Alert from "../../views/alert"; +import { updatePlayer } from "../../player"; +import { renderPlayerBar } from "../../views/player-bar"; + +export const repairRouter = Router(); + +repairRouter.get('/city/services/repair/:location_id', authEndpoint, async(req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); if(!service || service.city_id !== req.player.city_id) { @@ -28,7 +28,7 @@ router.get('/city/services/repair/:location_id', authEndpoint, async(req: Reques res.send(renderRepairService(damaged, req.player, service)); }); -router.post('/city/services/:location_id/repair/:item_id', authEndpoint, async (req: Request, res: Response) => { +repairRouter.post('/city/services/:location_id/repair/:item_id', authEndpoint, async (req: Request, res: Response) => { const service = await getService(parseInt(req.params.location_id)); if(!service || service.city_id !== req.player.city_id) { diff --git a/src/server/routes/stores.ts b/src/server/routes/locations/stores.ts similarity index 88% rename from src/server/routes/stores.ts rename to src/server/routes/locations/stores.ts index b126fa8..9dd1a80 100644 --- a/src/server/routes/stores.ts +++ b/src/server/routes/locations/stores.ts @@ -1,14 +1,14 @@ import { Request, Response, Router } from 'express'; -import { logger } from '../lib/logger'; -import { authEndpoint } from '../auth'; -import { getShopEquipment, listShopItems } from '../shopEquipment'; -import { updatePlayer } from '../player'; -import { getService } from '../map'; -import { getItemFromShop, getShopItems, givePlayerItem } from '../items'; -import { Item, ShopItem } from '../../shared/items'; -import { renderPlayerBar } from '../views/player-bar'; -import * as Alert from '../views/alert'; -import { renderEquipmentDetails, renderStore } from '../views/stores'; +import { logger } from '../../lib/logger'; +import { authEndpoint } from '../../auth'; +import { getShopEquipment, listShopItems } from '../../shopEquipment'; +import { updatePlayer } from '../../player'; +import { getService } from '../../map'; +import { getItemFromShop, getShopItems, givePlayerItem } from '../../items'; +import { Item, ShopItem } from '../../../shared/items'; +import { renderPlayerBar } from '../../views/player-bar'; +import * as Alert from '../../views/alert'; +import { renderEquipmentDetails, renderStore } from '../../views/stores'; export const storeRouter = Router(); // used to purchase items from a particular shop diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 2ca98e8..352c019 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -8,3 +8,5 @@ export const DUNGEON_TRAVEL_BLOCK = 3000; export const EVENT_FLUSH_INTERVAL = 10000; export const EVENT_SECOND_BUCKET = 2; + +export const MIN_LEVEL_TO_CHANGE_PROFESSIONS = 25; -- 2.25.1