From efa3706a8e803826a346a2fe1b47dfea847feb8b Mon Sep 17 00:00:00 2001 From: Mitsunee <19474909+Mitsunee@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:09:22 +0200 Subject: [PATCH] add: implement warnings in monster search script --- src/search-monster.ts | 10 +++++++++- src/utils/describe-monster.ts | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/search-monster.ts b/src/search-monster.ts index 1854c3b..6964c0f 100644 --- a/src/search-monster.ts +++ b/src/search-monster.ts @@ -19,6 +19,8 @@ options: --hide-lv Disables showing monster levels --show-rank Enables showing monster ranks --hide-rank Disables showing monster ranks + --show-warn Enables showing monster warnings + --hide-warn Disables showing monster warnings Options can be entered at any point and in any order. All arguments starting with a - (dash) are parsed as an argument, all other arguments are parsed as search queries. @@ -58,6 +60,12 @@ async function main() { case "--hide-rank": opts.showRank = false; continue; + case "--show-warn": + opts.showWarnings = true; + continue; + case "--hide-warn": + opts.showWarnings = false; + continue; } // handle unknown arg @@ -76,7 +84,7 @@ async function main() { const results = await searchMonsterByName(list, query); for (const result of results) { console.log( - `- ${describeMonster(result.data, { ...opts, lang: result.lang })}` + `- ${await describeMonster(result.data, { ...opts, lang: result.lang })}` ); } console.log(""); // force newline diff --git a/src/utils/describe-monster.ts b/src/utils/describe-monster.ts index 9f509a1..8e7b20d 100644 --- a/src/utils/describe-monster.ts +++ b/src/utils/describe-monster.ts @@ -1,3 +1,5 @@ +import { getMonsterWarnings } from "./get-monster-warnings"; + type LangOpt = "always" | "never" | "not en only"; export interface DescribeMonsterOpts { @@ -6,17 +8,22 @@ export interface DescribeMonsterOpts { showLevel?: boolean; lang?: GameLanguage; showLang?: LangOpt; + showWarnings?: boolean; } /** * Describes a monster in text * @param data MonsterData Object */ -export function describeMonster(data: MonsterData, opts?: DescribeMonsterOpts) { +export async function describeMonster( + data: MonsterData, + opts?: DescribeMonsterOpts +) { const showLevel = opts?.showLevel ?? true; const showRank = opts?.showRank ?? false; const lang: GameLanguage = opts?.lang ?? "en"; const showLang = opts?.showLang ?? "not en only"; + const showWarnings = opts?.showWarnings ?? false; let description = ""; // Handle showing ID @@ -46,5 +53,13 @@ export function describeMonster(data: MonsterData, opts?: DescribeMonsterOpts) { description += ` (${lang})`; } + // Handle warnings + if (showWarnings) { + const warnings = await getMonsterWarnings(data); + if (warnings.length > 0) { + description += ` (WARN: ${warnings.join(", ")})`; + } + } + return description; }