From 87f2dc8bd3e75cde8c7edeaee71bfc4d28c55276 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Thu, 29 Oct 2026 10:15:36 +0100 Subject: [PATCH] feat: quest book with quest lines, level rewards and a hint to the next click; opens by itself when a quest is done Co-Authored-By: Claude Opus 5.5 (1M context) --- CLAUDE.md | 2 +- app/components/game/VillageBar.vue | 17 ++ app/components/game/VillageFrame.vue | 20 +++ app/components/icon/Ui.vue | 5 + app/components/quest/Book.vue | 238 +++++++++++++++++++++++++++ app/composables/useQuests.ts | 57 +++++++ app/mock/server.ts | 67 ++++++++ app/types/game.ts | 59 +++++++ i18n/locales/en.ts | 1 + i18n/messageloader.ts | 3 +- i18n/pages/quests.ts | 143 ++++++++++++++++ 11 files changed, 610 insertions(+), 2 deletions(-) create mode 100644 app/components/quest/Book.vue create mode 100644 app/composables/useQuests.ts create mode 100644 i18n/pages/quests.ts diff --git a/CLAUDE.md b/CLAUDE.md index a5c39c7..dd17010 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,7 +10,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars. - **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 14 px base, square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `app/components/icon/`, colours in `app/utils/palette.ts`. No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo, and nothing copied from Die Stämme. - **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals. - **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`). -- **One game shell, like Die Stämme.** Everything sits in one centred column (1100 px). Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. +- **One game shell, like Die Stämme.** Everything sits in one centred column (1100 px). Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=` marking that row. - All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string. ## Mock server diff --git a/app/components/game/VillageBar.vue b/app/components/game/VillageBar.vue index 4c1a1c4..4b87d52 100644 --- a/app/components/game/VillageBar.vue +++ b/app/components/game/VillageBar.vue @@ -12,6 +12,10 @@ const nextAttack = computed(() => attacks.value[0] ?? null) const support = computed(() => incoming.value.length - attacks.value.length) const isActive = (path: string) => route.path === `${base.value}${path}` +const questBook = useQuestBookOpen() +/** Quests to claim plus level rewards to collect. */ +const questsWaiting = computed(() => props.village.quests.claimable + props.village.quests.rewards) + /** The new name while the village is being renamed. */ const renaming = ref(null) async function rename() { @@ -42,6 +46,19 @@ async function rename() {
+ + +
diff --git a/app/components/game/VillageFrame.vue b/app/components/game/VillageFrame.vue index 5434b66..d1ecf83 100644 --- a/app/components/game/VillageFrame.vue +++ b/app/components/game/VillageFrame.vue @@ -12,6 +12,25 @@ watch(v.village, (state) => { if (state) enter(state.world_id, state.id) }) +// The quest book opens by itself when a quest is newly complete, like Die Stämme's. +// What the player has already seen is kept per world, so a reload doesn't reopen it. +const questBook = useQuestBookOpen() +watch( + () => v.village.value && { world: v.village.value.world_id, claimable: v.village.value.quests.claimable }, + (now) => { + if (!now) return + const key = `vp.quests.${now.world}` + let seen = 0 + try { + seen = Number(localStorage.getItem(key) ?? 0) + localStorage.setItem(key, String(now.claimable)) + } catch { + return + } + if (now.claimable > seen) questBook.value = true + }, +) + // One key per screen of the world, as the menu and quick bar titles show. useShortcuts(() => { const base = `/village/${props.villageId}` @@ -48,5 +67,6 @@ useShortcuts(() => {
+
diff --git a/app/components/icon/Ui.vue b/app/components/icon/Ui.vue index c1e7400..47dabaf 100644 --- a/app/components/icon/Ui.vue +++ b/app/components/icon/Ui.vue @@ -17,6 +17,7 @@ export type UiIconName = | 'eye' | 'edit' | 'home' + | 'book' defineProps<{ name: UiIconName }>() @@ -78,6 +79,10 @@ defineProps<{ name: UiIconName }>() + + + + diff --git a/app/components/quest/Book.vue b/app/components/quest/Book.vue new file mode 100644 index 0000000..50f12e0 --- /dev/null +++ b/app/components/quest/Book.vue @@ -0,0 +1,238 @@ + + + + + + diff --git a/app/composables/useQuests.ts b/app/composables/useQuests.ts new file mode 100644 index 0000000..6a4295b --- /dev/null +++ b/app/composables/useQuests.ts @@ -0,0 +1,57 @@ +import type { QuestBookState, QuestClaimed } from '~/types/game' + +/** Whether the quest book is open; one book for the whole game shell. */ +export const useQuestBookOpen = () => useState('quest-book-open', () => false) + +/** + * The quest book of the village in the header. Claims answer with the fresh village, + * which goes straight into the shared village state so the stock updates at once. + */ +export function useQuests() { + const v = useVillageContext() + const book = ref(null) + const error = ref(null) + const busy = ref(false) + const errorText = useErrorText() + + const villageId = () => v.village.value?.id + + async function load() { + const id = villageId() + if (!id) return + error.value = null + try { + book.value = await ws.send('quest.index', { village_id: id }) + } catch (e) { + error.value = errorText(e) + } + } + + async function run(event: string, data: object) { + const id = villageId() + if (!id) return false + busy.value = true + error.value = null + try { + const res = await ws.send(event, { village_id: id, ...data }) + book.value = res.book + v.village.value = res.village + return true + } catch (e) { + error.value = errorText(e) + return false + } finally { + busy.value = false + } + } + + return { + book, + error, + busy, + load, + claim: (quest: string) => run('quest.claim', { quest }), + /** Collect the given level rewards, or all of them. */ + collect: (ids?: number[]) => run('quest.collect', ids ? { ids } : {}), + } +} diff --git a/app/mock/server.ts b/app/mock/server.ts index 3b87aba..16e8270 100644 --- a/app/mock/server.ts +++ b/app/mock/server.ts @@ -6,6 +6,10 @@ import { onUnmounted, ref } from 'vue' import type { AuthResult, + QuestBookState, + QuestClaimed, + QuestGoal, + QuestLine, AuthUser, BattleReport, BuildOption, @@ -145,6 +149,8 @@ interface MockState { /** Missing in states stored before the rally point existed. */ movements?: MockMovement[] reports?: MockReport[] + /** Claimed quests per `user:world`. */ + quests?: Record } const STORAGE_KEY = 'vp.mock.v4' @@ -553,6 +559,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState { movements: movements(state, v, now), support: support(state, v), rally: rallyInfo(v), + quests: { claimable: questBook(state, v).lines.filter((l) => l.quest?.complete).length, rewards: 0 }, unread_reports: (state.reports ?? []).filter((r) => r.user_id === v.user_id && r.world_id === v.world_id && !r.read).length, builders: BUILDERS, buildings: v.buildings.map( @@ -967,6 +974,48 @@ function createVillage(state: MockState, user: AuthUser, worldId: number, now: n // WS intents. +// A short copy of the quest lines with building goals only; the backend has the real book. +const MOCK_QUESTS: Record> = { + construction: { + hq_2: { goals: [['headquarters', 2]], reward: { wood: 120, clay: 120, iron: 100 } }, + storage_farm_2: { goals: [['storage', 2], ['farm', 2]], reward: { wood: 150, clay: 150, iron: 150 } }, + resource_camps: { goals: [['timber_camp', 1], ['clay_pit', 1], ['iron_mine', 1]], reward: { wood: 200, clay: 200, iron: 150 } }, + }, + army: { + barracks: { goals: [['barracks', 1]], reward: { wood: 250, clay: 220, iron: 120 } }, + rally_point: { goals: [['rally_point', 1]], reward: { wood: 100, clay: 100, iron: 100 } }, + }, + village: { + hiding_place: { goals: [['hiding_place', 1]], reward: { wood: 120, clay: 120, iron: 120 } }, + }, +} + +function questBook(state: MockState, v: MockVillage): QuestBookState { + const claimed = state.quests?.[`${v.user_id}:${v.world_id}`] ?? [] + const levels = new Map() + for (const own of state.villages.filter((o) => o.user_id === v.user_id && o.world_id === v.world_id)) { + for (const b of own.buildings) levels.set(b.type, Math.max(levels.get(b.type) ?? 0, b.level)) + } + const lines = (Object.keys(MOCK_QUESTS) as QuestLine['line'][]).map((line): QuestLine => { + const quests = MOCK_QUESTS[line] + const key = Object.keys(quests).find((k) => !claimed.includes(k)) + const goals = key + ? quests[key]!.goals.map(([type, need]): QuestGoal => { + const have = levels.get(type) ?? 0 + return { kind: 'building', subject: type, have: Math.min(have, need), need, met: have >= need, hint: type } + }) + : [] + return { + line, + done: Object.keys(quests).filter((k) => claimed.includes(k)).length, + total: Object.keys(quests).length, + quest: key ? { key, goals, reward: quests[key]!.reward, complete: goals.every((g) => g.met) } : null, + quests: Object.keys(quests).map((k) => ({ key: k, claimed: claimed.includes(k) })), + } + }) + return { lines, rewards: [], upcoming: [], share: 0.2 } +} + type Handler = (state: MockState, user: AuthUser, data: any, now: number) => unknown function ownVillage(state: MockState, user: AuthUser, id: unknown, now: number) { @@ -1219,6 +1268,24 @@ const handlers: Record = { return view(state, v, now) }, + 'quest.index': (state, user, data, now): QuestBookState => questBook(state, ownVillage(state, user, data.village_id, now)), + + 'quest.claim': (state, user, data, now): QuestClaimed => { + const v = ownVillage(state, user, data.village_id, now) + const line = questBook(state, v).lines.find((l) => l.quest?.key === data.quest) + if (!line?.quest?.complete) fail('quest_open') + const key = `${v.user_id}:${v.world_id}` + state.quests = { ...state.quests, [key]: [...(state.quests?.[key] ?? []), line.quest.key] } + refund(v, line.quest.reward as Cost) + return { book: questBook(state, v), village: view(state, v, now) } + }, + + // The mock pays no level rewards. + 'quest.collect': (state, user, data, now): QuestClaimed => { + const v = ownVillage(state, user, data.village_id, now) + return { book: questBook(state, v), village: view(state, v, now) } + }, + 'report.index': (state, user, data): ReportPage => reportPage(state, user, Number(data.world_id), Number(data.page) || 1, data.type || null), // Opening a report marks it read. diff --git a/app/types/game.ts b/app/types/game.ts index 0564827..3d58896 100644 --- a/app/types/game.ts +++ b/app/types/game.ts @@ -103,6 +103,8 @@ export interface VillageState { rally: RallyInfo /** The player's unread reports on this world. */ unread_reports: number + /** Quest book badge: lines with a completed quest to claim, level rewards to collect. */ + quests: { claimable: number; rewards: number } builders: number buildings: Building[] queue: BuildOrder[] @@ -362,3 +364,60 @@ export interface GameError { message: string code?: string } + +/** A screen a quest goal points at that is not a building's row on the headquarters screen. */ +export type QuestScreen = 'overview' | 'recruit' | 'rally' | 'workforce' | 'map' | 'reports' + +export interface QuestGoal { + /** building: a type at a level in any village; instances: that many of a type in one village; counter: an action done that often. */ + kind: 'building' | 'instances' | 'counter' + /** A building type, or a counter key such as `recruited.spear`. */ + subject: string + have: number + need: number + met: boolean + /** Where to go: a building type (its headquarters row) or a screen. */ + hint: BuildingType | QuestScreen +} + +export interface Quest { + key: string + goals: QuestGoal[] + reward: Partial + complete: boolean +} + +export interface QuestLine { + line: 'construction' | 'army' | 'village' + done: number + total: number + /** The first unclaimed quest; null once the line is finished. */ + quest: Quest | null + quests: { key: string; claimed: boolean }[] +} + +/** A building level reached for the first time pays back part of its cost. */ +export interface LevelReward { + id: number + type: BuildingType + level: number + reward: Partial + /** Where it was reached; it is collected into the current village. */ + village: { id: number; name: string | null } +} + +/** `quest.index`. */ +export interface QuestBookState { + lines: QuestLine[] + rewards: LevelReward[] + /** What the next level of each building type in this village would pay back. */ + upcoming: { type: BuildingType; level: number; reward: Partial }[] + /** Share of a level's cost paid back, 0..1. */ + share: number +} + +/** `quest.claim` and `quest.collect`. */ +export interface QuestClaimed { + book: QuestBookState + village: VillageState +} diff --git a/i18n/locales/en.ts b/i18n/locales/en.ts index 187c7ac..f250400 100644 --- a/i18n/locales/en.ts +++ b/i18n/locales/en.ts @@ -86,5 +86,6 @@ export default { direction: 'Pick a start direction.', name: 'A village name has 1 to 32 characters.', world_full: 'This world is full.', + quest_open: 'This quest is not complete yet.', }, } diff --git a/i18n/messageloader.ts b/i18n/messageloader.ts index e500ea9..d02bdf4 100644 --- a/i18n/messageloader.ts +++ b/i18n/messageloader.ts @@ -3,12 +3,13 @@ import networking from '@blax-software/networking/i18n' import en from './locales/en' import auth from './pages/auth' import map from './pages/map' +import quests from './pages/quests' import reports from './pages/reports' import village from './pages/village' import worlds from './pages/worlds' // Explicit imports instead of import.meta.glob: @nuxtjs/i18n also loads this file in the // Nitro build, where glob imports don't exist. Add new page files here, in path order. -export default mergeMessages({ en }, [auth, map, reports, village, worlds], { packages: [networking] }) as { +export default mergeMessages({ en }, [auth, map, quests, reports, village, worlds], { packages: [networking] }) as { en: Record } diff --git a/i18n/pages/quests.ts b/i18n/pages/quests.ts new file mode 100644 index 0000000..0cfb655 --- /dev/null +++ b/i18n/pages/quests.ts @@ -0,0 +1,143 @@ +import type { TranslationFile } from '@blax-software/i18n' + +export default { + en: { + quests: { + title: 'Quest book', + open: 'Quest book', + close: 'Close', + tab_quests: 'Quests', + tab_rewards: 'Rewards', + lines_label: 'Quest lines', + line: { construction: 'Construction', army: 'Army', village: 'Village life' }, + step: 'Quest {n} of {total}', + goals: 'Goal', + progress: 'Progress', + reward: 'Reward', + claim: 'Complete quest', + go: 'Show me', + overflow: 'Your storage is too small: whatever does not fit is lost.', + line_done: 'You have finished every quest in this line.', + goal: { + building: '{building} at level {level}', + instances: '{count} × {building} in one village', + }, + counter: { + recruited_spear: 'Train {count} spearmen', + attacks_barbarian: 'Attack a barbarian village', + scouts_sent: 'Send scouts to a village', + village_renamed: 'Give your village a name', + priority_set: 'Change the priority of a building', + map_viewed: 'Look at the world map', + reports_read: 'Read a report', + levy_called: 'Call up the levy', + }, + rewards_about: 'Every building level you reach for the first time pays back {share}% of what it cost. Collect it into the village you are in.', + building: 'Building', + reached_in: 'Reached in', + level_of: '{building} level {level}', + collect: 'Collect', + collect_all: 'Collect all', + no_rewards: 'Nothing to collect. Finish a building level you have not had before.', + upcoming: 'Next rewards in this village', + q: { + hq_2: { + title: 'A roof over the council', + text: 'The headquarters is a tent for now. Raise it to level 2: your builders work faster and the village gains building space.', + }, + storage_farm_2: { + title: 'Stores and fields', + text: 'Everything you make waits in the storage, and the farm feeds the people who make it. Bring both to level 2.', + }, + resource_camps: { + title: 'Wood, clay and iron', + text: 'The village only trickles resources on its own. Build a timber camp, a clay pit and an iron mine.', + }, + camps_3: { + title: 'Keep the carts rolling', + text: 'More production means faster growth. Raise all three resource sites to level 3.', + }, + hq_3: { + title: 'Room to grow', + text: 'Every headquarters level adds building space. Reach level 3 before the village runs out of room.', + }, + storage_farm_5: { + title: 'Granaries and barns', + text: 'Bigger buildings cost more than a small storage holds, and soldiers eat. Bring storage and farm to level 5.', + }, + hq_5: { + title: 'A proper hall', + text: 'A headquarters at level 5 opens the advanced buildings and gives your builders a real workshop.', + }, + camps_8: { + title: 'A busy valley', + text: 'Timber camp and clay pit at level 8, the iron mine at 6: enough to feed a growing army and a growing village.', + }, + barracks: { + title: 'Men at arms', + text: 'A village without soldiers is a gift to its neighbours. Build a barracks.', + }, + first_spears: { + title: 'Spears for the gate', + text: 'Spearmen are cheap and hold well against horsemen. Train five of them; each one leaves his work for good.', + }, + rally_point: { + title: 'A place to gather', + text: 'Troops leave from the rally point. Build one before you send anyone anywhere.', + }, + first_raid: { + title: 'Loot from the woods', + text: 'Barbarian villages around you keep resources and few defenders. Send an attack to one of them.', + }, + wall_3: { + title: 'Stakes and timber', + text: 'A wall multiplies every defender. Raise it to level 3.', + }, + barracks_3: { + title: 'Drill yard', + text: 'A bigger barracks trains faster and opens the archers. Bring it to level 3.', + }, + stable: { + title: 'Horses', + text: 'Cavalry is fast and carries more loot. Build a stable.', + }, + first_scouts: { + title: 'Eyes on the road', + text: 'Scouts tell you what waits behind a wall before you attack it. Send some to a village.', + }, + rename: { + title: 'A name of your own', + text: 'Your village deserves a better name than the one it got. Rename it with the pencil next to its name.', + }, + priority: { + title: 'Who works where', + text: 'Villagers staff buildings by priority, and an understaffed building makes far less. Change a building\'s priority on the workforce screen.', + }, + look_around: { + title: 'Know your neighbours', + text: 'Open the world map and see who lives around you.', + }, + hiding_place: { + title: 'Something put aside', + text: 'Raiders don\'t find what lies in the hiding place. Build one.', + }, + second_camp: { + title: 'Two of a kind', + text: 'Here a village can have more than one of a building. Build a second timber camp and see your wood climb.', + }, + read_report: { + title: 'News from the field', + text: 'Every battle and every arriving support leaves a report. Read one.', + }, + levy: { + title: 'Call the levy', + text: 'When an attack comes, villagers can take up arms as militia. They stop working while they guard the village. Call up the levy once.', + }, + second_farm: { + title: 'More mouths, more fields', + text: 'A big army needs food. Build a second farm and decide what this village is for.', + }, + }, + }, + }, +} satisfies TranslationFile