From 8971ca309acc7070a1a0a5d1cdb97b57cc15924e Mon Sep 17 00:00:00 2001 From: xangelo Date: Tue, 27 Aug 2024 08:52:57 -0400 Subject: [PATCH] feat: support adding locations without them being visible to players This gives us the ability to add items to airtable without them being visible to the user --- .../20240320020618_conditional-location.ts | 16 ++++++++++++++++ seeds/cities.ts | 3 ++- src/server/api.ts | 2 +- src/server/map.ts | 4 ++-- src/server/routes/travel.ts | 4 ++-- src/shared/map.ts | 1 + 6 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 migrations/20240320020618_conditional-location.ts diff --git a/migrations/20240320020618_conditional-location.ts b/migrations/20240320020618_conditional-location.ts new file mode 100644 index 0000000..0f154ac --- /dev/null +++ b/migrations/20240320020618_conditional-location.ts @@ -0,0 +1,16 @@ +import { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { + return knex.schema.alterTable('locations', table => { + table.boolean('is_visible').defaultTo(true); + }); +} + + +export async function down(knex: Knex): Promise { + return knex.schema.alterTable('locations', table => { + table.dropColumn('is_visible'); + }) +} + diff --git a/seeds/cities.ts b/seeds/cities.ts index 866907f..b4e58d0 100644 --- a/seeds/cities.ts +++ b/seeds/cities.ts @@ -74,7 +74,8 @@ export async function createLocations(): Promise { city_id: r.fields.city_id[0], display_order: r.fields["Display Order"], event_name: r.fields['event_name'], - min_level: Math.max(parseInt(r.fields['Min Level'].toString()), 1) + min_level: Math.max(parseInt(r.fields['Min Level'].toString()), 1), + is_visible: !!(r.fields['Visible'] ?? true) } })).onConflict('id').merge(); diff --git a/src/server/api.ts b/src/server/api.ts index b63d65d..45f7992 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -209,7 +209,7 @@ app.get('/player/explore', authEndpoint, async (req: Request, res: Response) => // display the default explore view const [city, locations, paths] = await Promise.all([ getCityDetails(req.player.city_id), - getAllServices(req.player.city_id, req.player.level), + getAllServices(req.player.city_id), getAllPaths(req.player.city_id) ]); diff --git a/src/server/map.ts b/src/server/map.ts index 45b0084..6b99a6c 100644 --- a/src/server/map.ts +++ b/src/server/map.ts @@ -4,11 +4,11 @@ import type { Travel, TravelWithNames } from '../shared/travel'; import { db } from './lib/db'; import { random } from 'lodash'; -export async function getAllServices(city_id: number, min_level: number): Promise { +export async function getAllServices(city_id: number): Promise { return db.select('*') .from('locations') .where({city_id}) - .andWhere('min_level', '<=', min_level) + .andWhere('is_visible', true) .orderBy('type') .orderBy('display_order'); } diff --git a/src/server/routes/travel.ts b/src/server/routes/travel.ts index 5e84c24..8ca4597 100644 --- a/src/server/routes/travel.ts +++ b/src/server/routes/travel.ts @@ -41,7 +41,7 @@ travelRouter.post('/travel/step', authEndpoint, async (req: Request, res: Respon const [city, locations, paths] = await Promise.all([ getCityDetails(travel.destination_id), - getAllServices(travel.destination_id, req.player.level), + getAllServices(travel.destination_id), getAllPaths(travel.destination_id) ]); @@ -98,7 +98,7 @@ travelRouter.post('/travel/return-to-source', authEndpoint, async (req: Request, else { const [city, locations, paths] = await Promise.all([ getCityDetails(req.player.city_id), - getAllServices(req.player.city_id, req.player.level), + getAllServices(req.player.city_id), getAllPaths(req.player.city_id) ]); diff --git a/src/shared/map.ts b/src/shared/map.ts index b4267db..acf1f45 100644 --- a/src/shared/map.ts +++ b/src/shared/map.ts @@ -14,6 +14,7 @@ export type Location = { type: LocationType, display_order: number; event_name: string; + min_level: number; } export type LocationWithCity = Location & { -- 2.25.1