mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 13:16:11 +01:00
feat: generalize render chars
This commit is contained in:
1 parent
99bae8f2c5
commit
698731cb9a
4 files changed
+41
-36
No files matched your search
@@ -84,7 +84,7 @@ export const characteristics = {
|
||||
);
|
||||
},
|
||||
|
||||
reloads({ characteristic, attribute, parameters }) {
|
||||
reloads({ characteristic, parameters }) {
|
||||
const gunType = characteristic("gun_type")!;
|
||||
|
||||
if (gunType !== GunType.AutoReloader) return null;
|
||||
|
||||
@@ -5,14 +5,16 @@ export enum BetterDirection {
|
||||
Lower,
|
||||
}
|
||||
|
||||
export interface CharacteristicRenderConfig {
|
||||
name: CharacteristicName;
|
||||
decimals?: number;
|
||||
units?: string;
|
||||
}
|
||||
|
||||
type CharacteristicsOrder = {
|
||||
group: string;
|
||||
order: (
|
||||
| {
|
||||
name: CharacteristicName;
|
||||
decimals?: number;
|
||||
units?: string;
|
||||
}
|
||||
| CharacteristicRenderConfig
|
||||
| {
|
||||
toy: string;
|
||||
}
|
||||
@@ -25,11 +27,12 @@ export const characteristicsOrder: CharacteristicsOrder = [
|
||||
order: [
|
||||
{ name: "gun_type" },
|
||||
{ name: "dpm", decimals: 0, units: "hp_min" },
|
||||
{ name: "reload", decimals: 2, units: "s" },
|
||||
{ name: "reloads", decimals: 2, units: "s" },
|
||||
{ name: "damage", units: "hp" },
|
||||
{ name: "module_damage", units: "hp" },
|
||||
{ name: "penetration", units: "mm" },
|
||||
{ name: "clip_size" },
|
||||
{ name: "reload", decimals: 2, units: "s" },
|
||||
{ name: "intra_clip", decimals: 2, units: "s" },
|
||||
|
||||
{ toy: "reload" },
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { CharacteristicOutput } from "./characteristics";
|
||||
import type { CharacteristicRenderConfig } from "./characteristicsOrder";
|
||||
|
||||
export function renderCharacteristic(
|
||||
characteristic: CharacteristicOutput,
|
||||
config: CharacteristicRenderConfig
|
||||
): string | null {
|
||||
if (characteristic === null) return null;
|
||||
|
||||
if (typeof characteristic === "number") {
|
||||
if (Number.isFinite(characteristic)) {
|
||||
if (config.decimals === undefined) {
|
||||
return characteristic.toString();
|
||||
}
|
||||
|
||||
return characteristic.toFixed(config.decimals);
|
||||
}
|
||||
|
||||
return `${characteristic < 0 ? "-" : ""}∞`;
|
||||
}
|
||||
|
||||
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
|
||||
}
|
||||
Reference in new issue
Block a user