-
Notifications
You must be signed in to change notification settings - Fork 3
feat(types): align terrain and furniture pry handling with BN data #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4abc49c
feat(types): add support for prying mechanics in terrain and furnitur…
ushkinaz 020692d
fix(types): update label from "Result" to "Becomes" for clarity in UI
ushkinaz e672bc3
fix(tests): improve assertions for furniture details with stricter DO…
ushkinaz fac322f
fix(ThingLink.svelte): remove redundant condition around count format…
ushkinaz 9cbc270
fix(Terrain): simplify prying item handling and improve count display…
ushkinaz 5b8e7c7
fix(types): update pry details display and reorganize break item logi…
ushkinaz 640ef07
fix(tests): remove percentage check and simplify break items structur…
ushkinaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,55 @@ | ||
| <script lang="ts"> | ||
| import { t } from "@transifex/native"; | ||
| import type { CBNData } from "src/data"; | ||
| import type { ActivityDataCommon } from "src/types"; | ||
| import { getContext } from "svelte"; | ||
| import ThingLink from "./ThingLink.svelte"; | ||
| import { untrack } from "svelte"; | ||
|
|
||
| interface Props { | ||
| act: ActivityDataCommon & { result?: string }; | ||
| act: ActivityDataCommon; | ||
| resultType: "terrain" | "furniture"; | ||
| } | ||
|
|
||
| let { act, resultType }: Props = $props(); | ||
|
|
||
| const data = getContext<CBNData>("data"); | ||
| function visibleResult( | ||
| value: ActivityDataCommon, | ||
| resultType: "terrain" | "furniture", | ||
| ): string | undefined { | ||
| if (value.result === (resultType === "terrain" ? "t_null" : "f_null")) { | ||
| return undefined; | ||
| } | ||
| return value.result; | ||
| } | ||
|
|
||
| const activity = untrack(() => act); | ||
| const result = untrack(() => visibleResult(act, resultType)); | ||
|
|
||
| const _context = "Terrain / Furniture"; | ||
| const _comment = "activity (prying, hacksawing, etc.)"; | ||
| const _comment = "activity (oxytorch, hacksaw, boltcut, etc.)"; | ||
| </script> | ||
|
|
||
| <ul class="comma-separated"> | ||
| {#each act.byproducts ?? [] as { item: i, count }} | ||
| <li> | ||
| <ThingLink | ||
| id={i} | ||
| type="item" | ||
| showIcon={false} />{#if typeof count === "number"} ({count}){:else if Array.isArray(count)} ({count[0]}–{count[1]}){/if} | ||
| </li> | ||
| {/each} | ||
| </ul> | ||
| <dl> | ||
| <dt>{t("Duration", { _context, _comment })}</dt> | ||
| <dd>{act.duration ?? "1 s"}</dd> | ||
| {#if act.prying_data} | ||
| <dt>{t("Difficulty", { _context, _comment })}</dt> | ||
| <dd>{act.prying_data.difficulty ?? 0}</dd> | ||
| <dt>{t("Requires", { _context, _comment })}</dt> | ||
| <dd>{activity.duration ?? "1 s"}</dd> | ||
| {#if result} | ||
| <dt>{t("Becomes", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ThingLink id="PRY" type="tool_quality" showIcon={false} /> | ||
| {act.prying_data.prying_level ?? 0}{#if act.prying_data.prying_nails}, <ThingLink | ||
| id="PRYING_NAIL" | ||
| type="tool_quality" | ||
| showIcon={false} /> 1{/if} | ||
| <ThingLink id={result} type={resultType} showIcon={false} /> | ||
| </dd> | ||
| <dt>{t("Noisy", { _context, _comment })}</dt> | ||
| <dd>{act.prying_data.noisy ? t("Yes") : t("No")}</dd> | ||
| <dt>{t("Alarm", { _context, _comment })}</dt> | ||
| <dd>{act.prying_data.alarm ? t("Yes") : t("No")}</dd> | ||
| <dt>{t("Breakable", { _context, _comment })}</dt> | ||
| <dd>{act.prying_data.breakable ? t("Yes") : t("No")}</dd> | ||
| {/if} | ||
| {#if act.result && act.result !== "t_null"} | ||
| <dt>{t("Result", { _context, _comment })}</dt> | ||
| {#if activity.byproducts} | ||
| <dt>{t("Byproducts", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ThingLink id={act.result} type={resultType} /> | ||
| <ul class="comma-separated"> | ||
| {#each activity.byproducts ?? [] as { item: i, count }} | ||
| <li> | ||
| <ThingLink | ||
| id={i} | ||
| type="item" | ||
| showIcon={false} />{#if typeof count === "number"} ({count}){:else if Array.isArray(count)} ({count[0]}–{count[1]}){/if} | ||
| </li> | ||
| {/each} | ||
| </ul> | ||
| </dd> | ||
| {/if} | ||
| </dl> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <script lang="ts"> | ||
| import { t } from "@transifex/native"; | ||
| import { formatPercent } from "../data"; | ||
| import type { | ||
| FurniturePryData, | ||
| ItemGroupEntry, | ||
| TerrainPryData, | ||
| } from "src/types"; | ||
| import { untrack } from "svelte"; | ||
| import ThingLink from "./ThingLink.svelte"; | ||
|
|
||
| type PryData = TerrainPryData | FurniturePryData; | ||
| type PryItemEntry = ItemGroupEntry & { item: string }; | ||
|
|
||
| interface Props { | ||
| act: PryData; | ||
| resultType: "terrain" | "furniture"; | ||
| } | ||
|
|
||
| let { act, resultType }: Props = $props(); | ||
|
|
||
| const pry = untrack(() => act); | ||
| const result = untrack(() => visibleResult(act, resultType)); | ||
| const pryItems = untrack(() => (act.pry_items ?? []).filter(isItemEntry)); | ||
| const breakItems = untrack(() => (act.break_items ?? []).filter(isItemEntry)); | ||
|
|
||
| function isItemEntry(entry: ItemGroupEntry): entry is PryItemEntry { | ||
| return "item" in entry; | ||
| } | ||
|
ushkinaz marked this conversation as resolved.
Outdated
|
||
|
|
||
| function formatAmount( | ||
| value?: number | [number, number], | ||
| hideOne = false, | ||
| ): string | undefined { | ||
| if (value == null) { | ||
| return undefined; | ||
| } | ||
| if (typeof value === "number") { | ||
| return hideOne && value === 1 ? undefined : String(value); | ||
| } | ||
| if (value[0] === value[1]) { | ||
| return hideOne && value[0] === 1 ? undefined : String(value[0]); | ||
| } | ||
| return `${value[0]}–${value[1]}`; | ||
| } | ||
|
|
||
| function formatProbability(prob?: number): string | undefined { | ||
| if (prob == null || prob === 1) { | ||
| return undefined; | ||
| } | ||
| return prob > 1 ? `${prob}%` : formatPercent(prob); | ||
| } | ||
|
ushkinaz marked this conversation as resolved.
Outdated
|
||
|
|
||
| function visibleResult( | ||
| value: PryData, | ||
| resultType: "terrain" | "furniture", | ||
| ): string | undefined { | ||
| let result = undefined; | ||
| if (resultType === "terrain") { | ||
| result = "new_ter_type" in value ? value.new_ter_type : undefined; | ||
| } else if (resultType === "furniture") { | ||
| result = "new_furn_type" in value ? value.new_furn_type : undefined; | ||
| } | ||
| if (result === (resultType === "terrain" ? "t_null" : "f_null")) { | ||
| return undefined; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| const _context = "Terrain / Furniture"; | ||
| const _comment = "prying"; | ||
| </script> | ||
|
|
||
| <dl> | ||
| <dt>{t("Difficulty", { _context, _comment })}</dt> | ||
| <dd>{pry.difficulty ?? 1}</dd> | ||
| <dt>{t("Requires", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ThingLink id="PRY" type="tool_quality" showIcon={false} /> | ||
| {pry.pry_quality ?? 0} | ||
| </dd> | ||
| <dt>{t("Noisy", { _context, _comment })}</dt> | ||
| <dd>{(pry.noise ?? 0) > 0 ? t("Yes") : t("No")}</dd> | ||
|
ushkinaz marked this conversation as resolved.
Outdated
|
||
| <dt>{t("Alarm", { _context, _comment })}</dt> | ||
| <dd>{pry.alarm ? t("Yes") : t("No")}</dd> | ||
| <dt>{t("Breakable", { _context, _comment })}</dt> | ||
| <dd>{pry.breakable ? t("Yes") : t("No")}</dd> | ||
|
ushkinaz marked this conversation as resolved.
|
||
| {#if result} | ||
| <dt>{t("Becomes", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ThingLink id={result} type={resultType} showIcon={false} /> | ||
| </dd> | ||
| {/if} | ||
|
ushkinaz marked this conversation as resolved.
|
||
| {#if pryItems.length} | ||
| <dt>{t("Pry Items", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ul class="comma-separated"> | ||
| {#each pryItems as entry} | ||
| {@const amount = | ||
| formatAmount(entry.count, true) ?? formatAmount(entry.charges)} | ||
| {@const probability = formatProbability(entry.prob)} | ||
| <li> | ||
| <ThingLink | ||
| id={entry.item} | ||
| type="item" | ||
| showIcon={false} />{#if amount} ({amount}){/if}{#if probability} ({probability}){/if} | ||
| </li> | ||
| {/each} | ||
| </ul> | ||
| </dd> | ||
| {/if} | ||
| {#if breakItems.length} | ||
| <dt>{t("Break Items", { _context, _comment })}</dt> | ||
| <dd> | ||
| <ul class="comma-separated"> | ||
| {#each breakItems as entry} | ||
| {@const amount = | ||
| formatAmount(entry.count, true) ?? formatAmount(entry.charges)} | ||
| {@const probability = formatProbability(entry.prob)} | ||
| <li> | ||
| <ThingLink | ||
| id={entry.item} | ||
| type="item" | ||
| showIcon={false} />{#if amount} ({amount}){/if}{#if probability} ({probability}){/if} | ||
| </li> | ||
| {/each} | ||
| </ul> | ||
| </dd> | ||
| {/if} | ||
|
ushkinaz marked this conversation as resolved.
|
||
| </dl> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.