mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
unit rendering
This commit is contained in:
1 parent
3714c74394
commit
bb0b932d26
5 files changed
+21
-8
No files matched your search
@@ -82,7 +82,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"units": {
|
"units": {
|
||||||
"hp_min": "{value}hp/min",
|
|
||||||
"s": "{value}s",
|
"s": "{value}s",
|
||||||
"hp": "{value}hp",
|
"hp": "{value}hp",
|
||||||
"mm": "{value}mm",
|
"mm": "{value}mm",
|
||||||
|
|||||||
@@ -79,6 +79,12 @@
|
|||||||
.value {
|
.value {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.units {
|
||||||
|
display: flex;
|
||||||
|
align-items: end;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ranking {
|
.ranking {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ interface ItemProps {
|
|||||||
function Item({ config, value }: ItemProps) {
|
function Item({ config, value }: ItemProps) {
|
||||||
const strings = useStrings();
|
const strings = useStrings();
|
||||||
const renderCharacteristic = useCharacteristicRenderer();
|
const renderCharacteristic = useCharacteristicRenderer();
|
||||||
|
const hasUnits = config.units !== undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={styles.item}>
|
<span className={styles.item}>
|
||||||
@@ -106,7 +107,12 @@ function Item({ config, value }: ItemProps) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
</Text>
|
</Text>
|
||||||
<Text>{renderCharacteristic(value, config)}</Text>
|
|
||||||
|
<Text lowContrast={hasUnits} size={hasUnits ? "minor" : undefined}>
|
||||||
|
<div className={styles.units}>
|
||||||
|
{renderCharacteristic(value, config)}
|
||||||
|
</div>
|
||||||
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.ranking}>
|
<div className={styles.ranking}>
|
||||||
|
|||||||
+7
-5
@@ -1,13 +1,14 @@
|
|||||||
|
import { literalsArray } from "@blitzkit/i18n";
|
||||||
import { useMemo, type ReactNode } from "react";
|
import { useMemo, type ReactNode } from "react";
|
||||||
|
import { Text } from "../components/Text";
|
||||||
import type { CharacteristicOutput } from "../tankopedia/characteristics";
|
import type { CharacteristicOutput } from "../tankopedia/characteristics";
|
||||||
import {
|
import {
|
||||||
characteristicsOrder,
|
characteristicsOrder,
|
||||||
type CharacteristicRenderConfig,
|
type CharacteristicRenderConfig,
|
||||||
} from "../tankopedia/characteristicsOrder";
|
} from "../tankopedia/characteristicsOrder";
|
||||||
import { useGameStrings } from "./useGameStrings";
|
import { useGameStrings } from "./useGameStrings";
|
||||||
import { useStrings } from "./useStrings";
|
|
||||||
import { useLocale } from "./useLocale";
|
import { useLocale } from "./useLocale";
|
||||||
import { literals } from "@blitzkit/i18n";
|
import { useStrings } from "./useStrings";
|
||||||
|
|
||||||
export function useCharacteristicRenderer() {
|
export function useCharacteristicRenderer() {
|
||||||
const groups = useMemo(() => {
|
const groups = useMemo(() => {
|
||||||
@@ -39,7 +40,7 @@ export function useCharacteristicRenderer() {
|
|||||||
|
|
||||||
if (typeof characteristic === "number") {
|
if (typeof characteristic === "number") {
|
||||||
if (Number.isFinite(characteristic)) {
|
if (Number.isFinite(characteristic)) {
|
||||||
let value: string | number = characteristic;
|
let value: ReactNode = characteristic;
|
||||||
|
|
||||||
if (config.decimals !== undefined) {
|
if (config.decimals !== undefined) {
|
||||||
value *= 10 ** config.decimals;
|
value *= 10 ** config.decimals;
|
||||||
@@ -54,8 +55,9 @@ export function useCharacteristicRenderer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.units !== undefined) {
|
if (config.units !== undefined) {
|
||||||
// TODO: render units with lowContrast Text
|
value = literalsArray(strings.units[config.units], {
|
||||||
value = literals(strings.units[config.units], { value });
|
value: <Text>{value}</Text>,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@@ -110,7 +110,7 @@ export const characteristicsOrder: CharacteristicsGroup[] = [
|
|||||||
return GunType[output as GunType];
|
return GunType[output as GunType];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ name: "dpm", decimals: 0, units: "hp_min", localize: true },
|
{ name: "dpm", decimals: 0, units: "hp", localize: true },
|
||||||
{ name: "damage", units: "hp", localize: true },
|
{ name: "damage", units: "hp", localize: true },
|
||||||
{ name: "module_damage", units: "hp", localize: true },
|
{ name: "module_damage", units: "hp", localize: true },
|
||||||
{ name: "reload", decimals: 1, units: "s" },
|
{ name: "reload", decimals: 1, units: "s" },
|
||||||
|
|||||||
Reference in new issue
Block a user