Compare commits

...
8 Commits
Author SHA1 Message Date
TrèsAbhi 010303a818 feat: camo 2025-12-24 20:30:19 -06:00
TrèsAbhi 7281b9fed0 feat: power_to_weight 2025-12-24 20:10:06 -06:00
TrèsAbhi c5785c7ae6 feat: more controllers 2025-12-24 19:57:26 -06:00
TrèsAbhi 698731cb9a feat: generalize render chars 2025-12-24 19:48:01 -06:00
TrèsAbhi 99bae8f2c5 fix: array rendering 2025-12-24 19:39:26 -06:00
TrèsAbhi 5034ec1aa0 feat: terrain hardness 2025-12-24 19:37:21 -06:00
TrèsAbhi be821c1f8b Merge branch 'ue' of https://github.com/blitzkit/blitzkit into ue 2025-12-24 19:33:04 -06:00
TrèsAbhi a364b79a9b feat: autoreloader dom 2025-12-24 19:33:01 -06:00
9 changed files with 274 additions and 112 deletions

No files matched your search

Whitespace-only changes.
@@ -147,12 +147,6 @@ function patch(stage0: StageParameters, stage1: StageParameters) {
stage0.pump_reload_times = [...stage1.pump_reload_times];
}
if (stage1.pump_reload_times.length < stage0.pump_reload_times.length) {
throw new Error(
`Pump reload times go down???? (${stage0.pump_reload_times.length} -> ${stage1.pump_reload_times.length})`
);
}
if (stage1.pitch_limits_up.length > 0 && stage0.pitch_limits_up.length > 0) {
throw new Error("Pitch limits not implemented");
}
@@ -1,3 +1,4 @@
import { TankClass } from "@blitzkit/core";
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import {
ShellUpgrageSingleChange_AttributeName,
@@ -6,9 +7,9 @@ import {
} from "@protos/blitz_static_tank_upgrade_single_stage";
import { radToDeg } from "three/src/math/MathUtils.js";
import { applyPitchYawLimits } from "./applyPitchYawLimits";
import type { TankState } from "./tankState";
import { TerrainHardness, type TankState } from "./tankState";
export type CharacteristicOutput = number | null;
export type CharacteristicOutput = number | number[] | null;
type Characteristic = (helpers: {
characteristic: (name: CharacteristicName) => CharacteristicOutput;
@@ -84,6 +85,14 @@ export const characteristics = {
);
},
reloads({ characteristic, parameters }) {
const gunType = characteristic("gun_type")!;
if (gunType !== GunType.AutoReloader) return null;
return parameters.pump_reload_times;
},
intra_clip({ characteristic, attribute }) {
const gunType = characteristic("gun_type")!;
@@ -96,30 +105,58 @@ export const characteristics = {
return 60 / clipRate;
},
optimal_shell({ characteristic }) {
const gunType = characteristic("gun_type")!;
if (gunType !== GunType.AutoReloader) return null;
const intraClip = characteristic("intra_clip") as number;
const reloads = characteristic("reloads") as number[];
let optimal: number | undefined = undefined;
for (let index = 0; index < reloads.length; index++) {
const reload = reloads[index] + (index > 0 ? intraClip : 0);
if (optimal === undefined || reload < reloads[optimal]) optimal = index;
}
if (optimal === undefined) {
throw new Error("Unable to find optimal shell");
}
return optimal;
},
dpm({ characteristic }) {
let dps: number;
const gunType = characteristic("gun_type")!;
const damage = characteristic("damage")!;
const damage = characteristic("damage") as number;
switch (gunType) {
case GunType.Regular: {
const reload = characteristic("reload")!;
const reload = characteristic("reload") as number;
dps = damage / reload;
break;
}
case GunType.AutoLoader: {
const reload = characteristic("reload")!;
const intraClip = characteristic("intra_clip")!;
const clipSize = characteristic("clip_size")!;
const reload = characteristic("reload") as number;
const intraClip = characteristic("intra_clip") as number;
const clipSize = characteristic("clip_size") as number;
dps = (damage * clipSize) / (reload + (clipSize - 1) * intraClip);
break;
}
case GunType.AutoReloader: {
return -Infinity;
const reloads = characteristic("reloads") as number[];
const optimalShell = characteristic("optimal_shell") as number;
const intraClip = characteristic("intra_clip") as number;
const reload =
reloads[optimalShell] + (optimalShell > 0 ? intraClip : 0);
dps = damage / reload;
break;
}
default:
@@ -243,37 +280,37 @@ export const characteristics = {
},
weight({ attribute }) {
return attribute(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_MASS);
},
terrain_coefficient_hard({ attribute }) {
return attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_HARD
return (
attribute(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_MASS) / 1000
);
},
terrain_coefficient_medium({ attribute }) {
return attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_MEDIUM
);
terrain_coefficient({ attribute, state }) {
let name: TankAttributeChange_AttributeName;
switch (state.terrainHardness) {
case TerrainHardness.Soft:
name =
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_SOFT;
break;
case TerrainHardness.Medium:
name =
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_MEDIUM;
break;
case TerrainHardness.Hard:
name =
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_HARD;
break;
}
return attribute(name);
},
terrain_coefficient_soft({ attribute }) {
return attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TERRAIN_RESISTANCE_SOFT
);
},
power_to_weight_hard() {
return -Infinity;
},
power_to_weight_medium() {
return -Infinity;
},
power_to_weight_soft() {
return -Infinity;
power_to_weight({ characteristic }) {
const power = characteristic("engine_power") as number;
const weight = characteristic("weight") as number;
const terrainCoefficient = characteristic("terrain_coefficient") as number;
return power / weight / terrainCoefficient;
},
turret_traverse_speed({ attribute }) {
@@ -282,15 +319,7 @@ export const characteristics = {
);
},
hull_traverse_speed_hard() {
return -Infinity;
},
hull_traverse_speed_medium() {
return -Infinity;
},
hull_traverse_speed_soft() {
hull_traverse_speed() {
return -Infinity;
},
@@ -316,33 +345,38 @@ export const characteristics = {
);
},
camouflage_still({ attribute }) {
return attribute(
class({ tank }) {
return tank.tank_class;
},
camouflage({ attribute, characteristic, attributeSafe, state }) {
const tankClass = characteristic("class");
const base = attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_STILL
);
},
camouflage_moving({ attribute }) {
return attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_MOVING
);
},
camouflage_shooting_still({ attribute }) {
return attribute(
const moving =
tankClass === TankClass.LIGHT
? 0
: attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_MOVING
);
const shooting = attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FACTOR_AT_SHOT
);
},
camouflage_shooting_moving() {
return -Infinity;
},
camouflage_on_fire({ attributeSafe }) {
return (
if (
attributeSafe(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FIRE_PENALTY
) ?? -Infinity
)
) {
throw new Error("Fire penalty implemented! Code it in!!");
}
return (
100 *
base *
(1 + moving * state.speed) *
(state.isShooting ? shooting : 1)
);
},
@@ -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" },
@@ -63,20 +66,12 @@ export const characteristicsOrder: CharacteristicsOrder = [
{ name: "speed_backward", units: "km_h" },
{ name: "engine_power", units: "bhp" },
{ name: "weight", units: "t" },
{ name: "terrain_coefficient_hard" },
{ name: "terrain_coefficient_medium" },
{ name: "terrain_coefficient_soft" },
{ name: "power_to_weight_hard", units: "bhp_t" },
{ name: "power_to_weight_medium", units: "bhp_t" },
{ name: "power_to_weight_soft", units: "bhp_t" },
{ name: "weight", decimals: 1, units: "t" },
{ name: "terrain_coefficient" },
{ name: "power_to_weight", decimals: 1, units: "bhp_t" },
{ name: "hull_traverse_speed", units: "deg_s" },
{ name: "turret_traverse_speed", units: "deg_s" },
{ name: "hull_traverse_speed_hard", units: "deg_s" },
{ name: "hull_traverse_speed_medium", units: "deg_s" },
{ name: "hull_traverse_speed_soft", units: "deg_s" },
{ toy: "traverse" },
],
@@ -90,11 +85,7 @@ export const characteristicsOrder: CharacteristicsOrder = [
{ toy: "view_range" },
{ name: "camouflage_still", units: "%" },
{ name: "camouflage_moving", units: "%" },
{ name: "camouflage_shooting_still", units: "%" },
{ name: "camouflage_shooting_moving", units: "%" },
{ name: "camouflage_on_fire", units: "%" },
{ name: "camouflage", decimals: 0, units: "%" },
{ name: "height", units: "m" },
{ name: "length", units: "m" },
@@ -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(", ");
}
@@ -1,10 +1,17 @@
export enum TerrainHardness {
Soft,
Medium,
Hard,
}
export interface TankState {
stage: number;
shell: number;
speed: number;
isHullTraversing: boolean;
isTurretTraversing: boolean;
isShooting: boolean;
isGunDamaged: boolean;
terrainHardness: TerrainHardness;
isCaughtOnFire: boolean;
}
@@ -2,13 +2,15 @@
import "@fontsource-variable/inter";
import BaseMeta from "../components/BaseMeta.astro";
import BaseStyles from "../components/BaseStyles.astro";
import Navbar from "../components/Navbar.astro";
import type { Color } from "../pages/styles/colors/[accent].css";
interface Props {
accent: Color;
noNavbar?: boolean;
}
const { accent } = Astro.props;
const { accent, noNavbar } = Astro.props;
---
<html>
@@ -18,6 +20,7 @@ const { accent } = Astro.props;
</head>
<body class="dark">
{!noNavbar && <Navbar />}
<slot />
</body>
</html>
@@ -3,6 +3,8 @@ import { Suspense, useMemo } from "react";
import { api } from "../../../core/api/dynamic";
import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder";
import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics";
import { renderCharacteristic } from "../../../core/tankopedia/renderCharacteristic";
import { TerrainHardness } from "../../../core/tankopedia/tankState";
import { useAwait } from "../../../hooks/useAwait";
import { Tankopedia } from "../../../stores/tankopedia";
@@ -29,6 +31,8 @@ function Content({ id }: { id: string }) {
<>
<h1>{id}</h1>
<br />
<div style={{ display: "flex", flexWrap: "wrap" }}>
{times(tank.upgrade_stages.length + 1, (index) => (
<button
@@ -62,33 +66,138 @@ function Content({ id }: { id: string }) {
))}
</div>
<br />
<div>
<span>speed (0 - {characteristics.speed_forward})</span>
<input
type="range"
min={0}
max={characteristics.speed_forward as number}
value={protagonist.speed}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.speed = event.target.valueAsNumber;
});
}}
/>
</div>
<br />
<div>
<span>isHullTraversing</span>
<input
type="checkbox"
value={`${protagonist.isHullTraversing}`}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.isHullTraversing = event.target.checked;
});
}}
/>
</div>
<br />
<div>
<span>isTurretTraversing</span>
<input
type="checkbox"
value={`${protagonist.isTurretTraversing}`}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.isTurretTraversing = event.target.checked;
});
}}
/>
</div>
<br />
<div>
<span>isShooting</span>
<input
type="checkbox"
value={`${protagonist.isShooting}`}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.isShooting = event.target.checked;
});
}}
/>
</div>
<br />
<div>
<span>isGunDamaged</span>
<input
type="checkbox"
value={`${protagonist.isGunDamaged}`}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.isGunDamaged = event.target.checked;
});
}}
/>
</div>
<br />
<div style={{ display: "flex", flexWrap: "wrap" }}>
{Object.values(TerrainHardness).map(
(hardness) =>
typeof hardness === "number" && (
<button
key={hardness}
onClick={() => {
Tankopedia.mutate((draft) => {
draft.protagonist.terrainHardness = hardness;
});
}}
>
{TerrainHardness[hardness]}{" "}
{hardness === protagonist.terrainHardness && "(selected)"}
</button>
)
)}
</div>
<br />
<div>
<span>isCaughtOnFire</span>
<input
type="checkbox"
value={`${protagonist.isCaughtOnFire}`}
onChange={(event) => {
Tankopedia.mutate((draft) => {
draft.protagonist.isCaughtOnFire = event.target.checked;
});
}}
/>
</div>
<br />
{characteristicsOrder.map(({ group, order }) => (
<>
<h2 key={group}>{group}</h2>
{order.map((entry) => {
if ("toy" in entry) {
return <p key={`toy-${entry.toy}`}>toy: {entry.toy}</p>;
{order.map((config) => {
if ("toy" in config) {
return <p key={`toy-${config.toy}`}>toy: {config.toy}</p>;
} else {
const characteristic = characteristics[entry.name];
const characteristic = characteristics[config.name];
if (characteristic === null) return null;
let rendered: string | number;
if (Number.isFinite(characteristic)) {
if (entry.decimals === undefined) {
rendered = characteristic;
} else {
rendered = characteristic.toFixed(entry.decimals);
}
} else {
rendered = `${Math.sign(characteristic) === 1 ? "" : "-"}∞`;
}
const rendered = renderCharacteristic(characteristic, config);
return (
<p key={`characteristic-${entry.name}`}>
{entry.name}: {rendered} {entry.units && `${entry.units}`}
<p key={`characteristic-${config.name}`}>
{config.name}: {rendered} {config.units && `${config.units}`}
</p>
);
}
+2 -1
View File
@@ -1,5 +1,5 @@
import { Varuna } from "varuna";
import type { TankState } from "../core/tankopedia/tankState";
import { TerrainHardness, type TankState } from "../core/tankopedia/tankState";
interface Tankopedia {
protagonist: TankState;
@@ -14,5 +14,6 @@ export const Tankopedia = new Varuna<Tankopedia, number>((maxStage) => ({
isShooting: false,
isTurretTraversing: false,
speed: 0,
terrainHardness: TerrainHardness.Hard,
},
}));