From 150b8d03ce60e69968bf0770b4ea87a45bf326cd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 10:18:29 +0000 Subject: [PATCH 1/6] Add saved gear profiles for rifles, optics and cartridges Named profiles stored in localStorage (bc-gear-v1) with a picker per kind, Save / Save as / Delete, and a 'modified' indicator. Loading a profile writes its fields and toggles back and recalculates. Stored data is sanitised on load. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Dh8dzr6LAKa4Fptz8uf6ZM --- README.md | 26 ++++++- index.html | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test.js | 39 ++++++++++ 3 files changed, 269 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5d92de..4497432 100644 --- a/README.md +++ b/README.md @@ -78,12 +78,34 @@ windage clicks with the direction to dial, time of flight and remaining velocity Targets are kept in the order you entered them, and any distance the bullet can't reach is reported as *no solution* rather than silently estimated. +## Saved gear + +The **Saved gear** card at the top stores named profiles for three kinds of +equipment, so you can switch setups without retyping: + +| Kind | What it stores | +| --- | --- | +| **Rifle** | barrel twist, twist direction, sight height over bore, zero distance | +| **Optic** | click value, clicks per mark, marks per turn, MRAD/MOA output units | +| **Cartridge** | caliber, weight, muzzle velocity, BC + G1/G7 model, bullet length | + +Pick a profile from the dropdown to load it. The calculators and any tables +already on screen recalculate straight away. **Save as…** stores the current +values under a new name, **Save** overwrites the selected profile, and +**Delete** removes it. If you edit a field after loading a profile, the card +shows *Modified* until you save. Profiles are mixed and matched freely (any +rifle + any optic + any cartridge). A cartridge's BC is restored together with +its drag model, so it is never re-converted. + +Profiles live in the browser's `localStorage` (`bc-gear-v1`). They stay on this +device and browser and are separate from the autosaved form state. + ## Tests -`test.js` extracts the app's ` diff --git a/test.js b/test.js index 237fdff..605ee94 100644 --- a/test.js +++ b/test.js @@ -233,6 +233,45 @@ test('crosswind target drifts to the correct side', () => { const s = solveShots({ ...CTX, p: { ...P, windZ: -4 }, sg: null }, [500], TURRET)[0]; assert(s.windCm < 0 && s.side === 'L' && s.wClk > 0); }); + +console.log('saved gear:'); +test('empty / garbage storage gives an empty store for every kind', () => { + for (const raw of [null, 'x', 42, [], { rifle: 'nope' }]) { + const g = sanitizeGear(raw); + assert.deepStrictEqual(Object.keys(g).sort(), ['cartridge', 'optic', 'rifle']); + for (const k of Object.keys(g)) assert.deepStrictEqual(g[k], { items: [], active: null }); + } +}); +test('well-formed profiles survive, malformed ones are dropped', () => { + const g = sanitizeGear({ + cartridge: { + active: 'a', + items: [ + { id: 'a', name: ' 175 SMK ', data: { tBc: '0.243', dragModel: 'G7', tMv: 800, evil: { x: 1 } } }, + { id: 'a', name: 'dup id', data: {} }, + { id: 'b', name: '', data: {} }, + { id: 'c', name: 'no data' }, + null + ] + } + }); + assert.strictEqual(g.cartridge.items.length, 1); + assert.strictEqual(g.cartridge.items[0].name, '175 SMK'); + assert.deepStrictEqual(g.cartridge.items[0].data, { tBc: '0.243', dragModel: 'G7', tMv: '800' }); + assert.strictEqual(g.cartridge.active, 'a'); +}); +test('active id pointing at a missing profile is cleared', () => + assert.strictEqual(sanitizeGear({ optic: { active: 'gone', items: [] } }).optic.active, null)); +test('each kind snapshots its own fields and toggle', () => { + assert.deepStrictEqual(Object.keys(gearSnapshot('rifle')).sort(), ['tSight', 'tTwist', 'tZero', 'twistDir']); + assert.deepStrictEqual(Object.keys(gearSnapshot('optic')).sort(), ['clickCm', 'clicksPerMark', 'marksPerTurn', 'trajUnit']); + assert.deepStrictEqual(Object.keys(gearSnapshot('cartridge')).sort(), + ['dragModel', 'tBc', 'tCaliber', 'tLength', 'tMv', 'tWeight']); +}); +test('no input field belongs to two kinds', () => { + const all = Object.values(GEAR_KINDS).flatMap(k => k.inputs); + assert.strictEqual(new Set(all).size, all.length); +}); `; eval(src + suite); From f54d7fbd6879830ffa0e268a55349c1f086c54bd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 10:25:09 +0000 Subject: [PATCH 2/6] Make the third gear kind an ammo load; allow bullet weight in grams The load profile now holds just bullet weight, muzzle velocity and BC (with its G1/G7 model) under a free-text name. Caliber moves to the rifle profile and the form's Rifle section. Bullet weight gets a gr/g toggle that converts in place; the solver always works in grains internally. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Dh8dzr6LAKa4Fptz8uf6ZM --- README.md | 21 +++++++------ index.html | 90 ++++++++++++++++++++++++++++++++++++++---------------- test.js | 22 +++++++------ 3 files changed, 88 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 4497432..7b9d21c 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ A second section computes the whole trajectory from first principles instead of single known drop. It's a 3-DOF point-mass solver using the standard **G1/G7** drag models: -- **Bullet:** caliber, weight (grains), length (mm), muzzle velocity (m/s), - ballistic coefficient (G1 or G7) -- **Rifle/scope:** zero distance, sight height over bore, barrel twist & +- **Load:** bullet weight (grains or grams; the toggle converts in place), + muzzle velocity (m/s), ballistic coefficient (G1 or G7), bullet length (mm) +- **Rifle/scope:** caliber, zero distance, sight height over bore, barrel twist & twist direction (drives gyroscopic stability + spin drift) - **Atmosphere:** temperature, pressure, humidity (used for real air density) - **Wind:** speed + direction as a clock hour (12 = headwind, 3 = from the right) @@ -85,27 +85,30 @@ equipment, so you can switch setups without retyping: | Kind | What it stores | | --- | --- | -| **Rifle** | barrel twist, twist direction, sight height over bore, zero distance | +| **Rifle** | caliber, barrel twist, twist direction, sight height over bore, zero distance | | **Optic** | click value, clicks per mark, marks per turn, MRAD/MOA output units | -| **Cartridge** | caliber, weight, muzzle velocity, BC + G1/G7 model, bullet length | +| **Load** | bullet weight (grains or grams), muzzle velocity, BC + G1/G7 model | Pick a profile from the dropdown to load it. The calculators and any tables already on screen recalculate straight away. **Save as…** stores the current values under a new name, **Save** overwrites the selected profile, and **Delete** removes it. If you edit a field after loading a profile, the card shows *Modified* until you save. Profiles are mixed and matched freely (any -rifle + any optic + any cartridge). A cartridge's BC is restored together with -its drag model, so it is never re-converted. +rifle + any optic + any load). A load is an ammo load, so its name is free text: +the cartridge, bullet, lot number or anything else that identifies it. Its +weight and BC are restored together with their unit and drag model, so they are +never re-converted. Profiles live in the browser's `localStorage` (`bc-gear-v1`). They stay on this device and browser and are separate from the autosaved form state. ## Tests -`test.js` extracts the app's `