mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: game strings in characteristics
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
249f62759e
commit
e3db886923
7 files changed
+105
-37
No files matched your search
@@ -18,6 +18,7 @@ export interface CharacteristicRenderConfig {
|
||||
name: CharacteristicName;
|
||||
decimals?: number;
|
||||
units?: string;
|
||||
strings?: string;
|
||||
render?: (output: CharacteristicOutput) => string;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ export const characteristicsOrder: CharacteristicsOrder = [
|
||||
{
|
||||
group: "meta",
|
||||
order: [
|
||||
{ name: "name" },
|
||||
{ name: "name", strings: "TankEntity" },
|
||||
{ name: "tier" },
|
||||
{
|
||||
name: "nation",
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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 (config.render) return config.render(characteristic);
|
||||
|
||||
if (typeof characteristic === "number") {
|
||||
if (Number.isFinite(characteristic)) {
|
||||
if (config.decimals === undefined) {
|
||||
return characteristic.toString();
|
||||
}
|
||||
|
||||
return characteristic.toFixed(config.decimals);
|
||||
}
|
||||
|
||||
return `${characteristic < 0 ? "-" : ""}∞`;
|
||||
}
|
||||
|
||||
if (typeof characteristic === "string") {
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
|
||||
}
|
||||
Reference in new issue
Block a user