mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
some units
This commit is contained in:
1 parent
595db8709b
commit
666f44d9e6
4 files changed
+46
-22
No files matched your search
@@ -37,7 +37,9 @@ interface GroupProps {
|
|||||||
function Group({ group, characteristics }: GroupProps) {
|
function Group({ group, characteristics }: GroupProps) {
|
||||||
const strings = useStrings();
|
const strings = useStrings();
|
||||||
const toys = group.order.filter((item) => "toy" in item).length;
|
const toys = group.order.filter((item) => "toy" in item).length;
|
||||||
const items = group.order.filter((item) => "name" in item).length;
|
const items = group.order.filter(
|
||||||
|
(item) => "name" in item && characteristics[item.name] !== null,
|
||||||
|
).length;
|
||||||
const groupSpan = `calc(${toys} * var(--group-span) + ${items} + 2)`;
|
const groupSpan = `calc(${toys} * var(--group-span) + ${items} + 2)`;
|
||||||
const contentSpan = `calc(${toys} * var(--group-span) + ${items})`;
|
const contentSpan = `calc(${toys} * var(--group-span) + ${items})`;
|
||||||
|
|
||||||
@@ -70,13 +72,14 @@ function Group({ group, characteristics }: GroupProps) {
|
|||||||
gridRow: `span ${contentSpan}`,
|
gridRow: `span ${contentSpan}`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{group.order.map((item) =>
|
{group.order.map((item) => (
|
||||||
"toy" in item ? (
|
<>
|
||||||
<Toy {...item} />
|
{"toy" in item && <Toy {...item} />}
|
||||||
) : (
|
{"name" in item && characteristics[item.name] !== null && (
|
||||||
<Item config={item} value={characteristics[item.name]} />
|
<Item config={item} value={characteristics[item.name]} />
|
||||||
),
|
)}
|
||||||
)}
|
</>
|
||||||
|
))}
|
||||||
|
|
||||||
<div className={styles.dead} />
|
<div className={styles.dead} />
|
||||||
</div>
|
</div>
|
||||||
@@ -107,7 +110,7 @@ function Item({ config, value }: ItemProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.ranking}>
|
<div className={styles.ranking}>
|
||||||
<Bar value={Math.random()} />
|
<Bar value={0.5} />
|
||||||
|
|
||||||
<Text lowContrast size="minor" className={styles.number}>
|
<Text lowContrast size="minor" className={styles.number}>
|
||||||
1 / 132
|
1 / 132
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
} from "../tankopedia/characteristicsOrder";
|
} from "../tankopedia/characteristicsOrder";
|
||||||
import { useGameStrings } from "./useGameStrings";
|
import { useGameStrings } from "./useGameStrings";
|
||||||
import { useStrings } from "./useStrings";
|
import { useStrings } from "./useStrings";
|
||||||
|
import { useLocale } from "./useLocale";
|
||||||
|
import { literals } from "@blitzkit/i18n";
|
||||||
|
|
||||||
export function useCharacteristicRenderer() {
|
export function useCharacteristicRenderer() {
|
||||||
const groups = useMemo(() => {
|
const groups = useMemo(() => {
|
||||||
@@ -22,6 +24,7 @@ export function useCharacteristicRenderer() {
|
|||||||
return groups;
|
return groups;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const locale = useLocale();
|
||||||
const strings = useStrings();
|
const strings = useStrings();
|
||||||
const gameStrings = useGameStrings(groups);
|
const gameStrings = useGameStrings(groups);
|
||||||
|
|
||||||
@@ -36,11 +39,26 @@ export function useCharacteristicRenderer() {
|
|||||||
|
|
||||||
if (typeof characteristic === "number") {
|
if (typeof characteristic === "number") {
|
||||||
if (Number.isFinite(characteristic)) {
|
if (Number.isFinite(characteristic)) {
|
||||||
if (config.decimals === undefined) {
|
let value: string | number = characteristic;
|
||||||
return characteristic.toString();
|
|
||||||
|
if (config.decimals !== undefined) {
|
||||||
|
value *= 10 ** config.decimals;
|
||||||
|
value = Math.round(value);
|
||||||
|
value /= 10 ** config.decimals;
|
||||||
}
|
}
|
||||||
|
|
||||||
return characteristic.toFixed(config.decimals);
|
if (config.localize) {
|
||||||
|
value = value.toLocaleString(locale);
|
||||||
|
} else {
|
||||||
|
value = value.toFixed(config.decimals);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.units !== undefined) {
|
||||||
|
// TODO: render units with lowContrast Text
|
||||||
|
value = literals(strings.units[config.units], { value });
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${characteristic < 0 ? "-" : ""}∞`;
|
return `${characteristic < 0 ? "-" : ""}∞`;
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ export const characteristics = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
camouflage({ attribute, characteristic, attributeSafe, state, tank }) {
|
camouflage({ attribute, attributeSafe, state, tank }) {
|
||||||
const base = attribute(
|
const base = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_STILL,
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_STILL,
|
||||||
);
|
);
|
||||||
@@ -399,8 +399,10 @@ export const characteristics = {
|
|||||||
return -Infinity;
|
return -Infinity;
|
||||||
},
|
},
|
||||||
|
|
||||||
dispersion_angle() {
|
dispersion_angle({ characteristic }) {
|
||||||
return -Infinity;
|
const dispersion = characteristic("dispersion") as number;
|
||||||
|
const angle = Math.atan2(dispersion / 2, 100) * (180 / Math.PI);
|
||||||
|
return angle;
|
||||||
},
|
},
|
||||||
|
|
||||||
azimuth_left() {
|
azimuth_left() {
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export enum BetterDirection {
|
|||||||
export interface CharacteristicRenderConfig {
|
export interface CharacteristicRenderConfig {
|
||||||
name: CharacteristicName;
|
name: CharacteristicName;
|
||||||
decimals?: number;
|
decimals?: number;
|
||||||
units?: string;
|
units?: keyof Strings["units"];
|
||||||
|
localize?: boolean;
|
||||||
strings?: string;
|
strings?: string;
|
||||||
render?: (data: {
|
render?: (data: {
|
||||||
output: CharacteristicOutput;
|
output: CharacteristicOutput;
|
||||||
@@ -109,11 +110,11 @@ export const characteristicsOrder: CharacteristicsGroup[] = [
|
|||||||
return GunType[output as GunType];
|
return GunType[output as GunType];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ name: "dpm", decimals: 0, units: "hp_min" },
|
{ name: "dpm", decimals: 0, units: "hp_min", localize: true },
|
||||||
{ name: "damage", units: "hp" },
|
{ name: "damage", units: "hp", localize: true },
|
||||||
{ name: "module_damage", units: "hp" },
|
{ name: "module_damage", units: "hp", localize: true },
|
||||||
{ name: "reload", decimals: 2, units: "s" },
|
{ name: "reload", decimals: 1, units: "s" },
|
||||||
{ name: "reloads", decimals: 2, units: "s" },
|
{ name: "reloads", decimals: 1, units: "s" },
|
||||||
|
|
||||||
{ toy: "reload" },
|
{ toy: "reload" },
|
||||||
],
|
],
|
||||||
@@ -160,7 +161,7 @@ export const characteristicsOrder: CharacteristicsGroup[] = [
|
|||||||
order: [
|
order: [
|
||||||
{ name: "aim_time", decimals: 1, units: "s" },
|
{ name: "aim_time", decimals: 1, units: "s" },
|
||||||
{ name: "dispersion", decimals: 3, units: "m" },
|
{ name: "dispersion", decimals: 3, units: "m" },
|
||||||
{ name: "dispersion_angle", decimals: 3, units: "m" },
|
{ name: "dispersion_angle", decimals: 3, units: "deg" },
|
||||||
{ toy: "aim_time" },
|
{ toy: "aim_time" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user