feat: add initial ammo chart, update dbs, and update docs.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to OnlyScavs will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.4.0] - 2026-04-06
|
||||
|
||||
### Added
|
||||
- Ammo Chart page (`/ammo`) — scatter plot of damage vs. armor penetration, colored by caliber, with clickable legend, live search/filter, and sortable stats table
|
||||
- `import_ammo.py` — imports all ammo rounds from tarkov.dev GraphQL API into local `ammo` table
|
||||
|
||||
## [0.3.0] - 2026-03-29
|
||||
|
||||
### Added
|
||||
- Barter Calculator page (`/barters`) — shows all trader barters with true rouble cost breakdown
|
||||
- Carry Efficiency metric for rigs and backpacks (capacity per kg)
|
||||
- Landing page hero image and updated card grid
|
||||
|
||||
### Changed
|
||||
- Keys page redesigned with grouped display by map and inline editing for ratings/notes
|
||||
|
||||
### Fixed
|
||||
- Gear database refreshed from tarkov.dev API pull
|
||||
|
||||
## [0.2.0] - 2026-03-01
|
||||
|
||||
### Added
|
||||
- Loadout Planner (`/loadout`) — browse guns, armor, helmets, rigs, and backpacks; save builds
|
||||
- Quest Trees (`/quests`) — visualize quest chains and trader dependencies
|
||||
- Armor plate support with open slot system (`armor_open_slots`, `armor_slot_plates` tables)
|
||||
- Injectors page (`/meds`) — compare stim/stimulator effects, skills, and side effects
|
||||
- `import_gear.py` — imports weapons, armor, helmets, rigs, and mod attachments
|
||||
- `migrations_v2.sql` — unified `gear_items` schema with weapon slots and armor plate slots
|
||||
|
||||
### Fixed
|
||||
- Quest tree display cleaned up
|
||||
- Key ratings not saving correctly
|
||||
|
||||
## [0.1.1] - 2026-02-21
|
||||
|
||||
### Added
|
||||
- Collector checklist (`/collector`) — track Kappa container quest progress with recursive prerequisite tree via SQL CTE
|
||||
- `import_quests.py` — imports all tasks and quest dependencies from tarkov.dev
|
||||
- `TARKOV_DEV_API.md` — full tarkov.dev GraphQL API reference for all queries used in the project
|
||||
- `.gitignore` and project docs
|
||||
|
||||
## [0.1.0] - 2026-01-25
|
||||
|
||||
### Added
|
||||
- Initial release — key ratings tool (`/keys`)
|
||||
- `import_keys.py` — fetches all key items from tarkov.dev GraphQL API
|
||||
- SQLite database with `keys`, `key_ratings`, and `maps` tables
|
||||
- Sorting and filtering on key ratings view
|
||||
- `migrations_v1.sql` — maps tagging and `used_in_quest` flag
|
||||
|
||||
[Unreleased]: https://github.com/serversdwn/onlyscavs/compare/v0.3.0...HEAD
|
||||
[0.3.0]: https://github.com/serversdwn/onlyscavs/compare/v0.2.0...v0.3.0
|
||||
[0.2.0]: https://github.com/serversdwn/onlyscavs/compare/v0.1.1...v0.2.0
|
||||
[0.1.1]: https://github.com/serversdwn/onlyscavs/compare/v0.1.0...v0.1.1
|
||||
[0.1.0]: https://github.com/serversdwn/onlyscavs/releases/tag/v0.1.0
|
||||
@@ -454,5 +454,6 @@ craftUnlock[] – craft objects
|
||||
|---|---|---|
|
||||
| [import_keys.py](import_keys.py) | `items(types: [keys])` | Fetches all key items into `keys` table |
|
||||
| [import_quests.py](import_quests.py) | `tasks { id name wikiLink trader taskRequirements }` | Fetches all tasks and their dependencies into `quests` + `quest_deps` tables |
|
||||
| [import_ammo.py](import_ammo.py) | `ammo { item { id name } caliber damage penetrationPower ... }` | Fetches all ammo rounds into `ammo` table |
|
||||
|
||||
The Collector prerequisite tree is computed from `quest_deps` using a recursive SQL CTE in [app.py](app.py) at `/collector`.
|
||||
|
||||
@@ -1102,5 +1102,40 @@ def barters():
|
||||
return render_template("barters.html", barters=barter_list)
|
||||
|
||||
|
||||
@app.route("/ammo")
|
||||
def ammo():
|
||||
caliber_filter = request.args.get("caliber", "").strip()
|
||||
search = request.args.get("q", "").strip().lower()
|
||||
|
||||
conn = get_db()
|
||||
try:
|
||||
exists = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='ammo'"
|
||||
).fetchone()
|
||||
if not exists:
|
||||
return render_template("ammo.html", rounds=[], calibers=[], caliber=caliber_filter, q=search)
|
||||
|
||||
calibers = [r["caliber"] for r in conn.execute(
|
||||
"SELECT DISTINCT caliber FROM ammo WHERE caliber IS NOT NULL ORDER BY caliber"
|
||||
).fetchall()]
|
||||
|
||||
query = "SELECT * FROM ammo WHERE 1=1"
|
||||
params = []
|
||||
if caliber_filter:
|
||||
query += " AND caliber = ?"
|
||||
params.append(caliber_filter)
|
||||
if search:
|
||||
query += " AND (LOWER(name) LIKE ? OR LOWER(short_name) LIKE ?)"
|
||||
params.extend([f"%{search}%", f"%{search}%"])
|
||||
query += " ORDER BY caliber, penetration_power DESC"
|
||||
|
||||
rows = conn.execute(query, params).fetchall()
|
||||
rounds = [dict(r) for r in rows]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
return render_template("ammo.html", rounds=rounds, calibers=calibers, caliber=caliber_filter, q=search)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
import requests
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
DB_PATH = "tarkov.db"
|
||||
API_URL = "https://api.tarkov.dev/graphql"
|
||||
|
||||
GRAPHQL_QUERY = """
|
||||
{
|
||||
ammo {
|
||||
item {
|
||||
id
|
||||
name
|
||||
shortName
|
||||
gridImageLink
|
||||
wikiLink
|
||||
}
|
||||
caliber
|
||||
damage
|
||||
armorDamage
|
||||
penetrationPower
|
||||
penetrationChance
|
||||
fragmentationChance
|
||||
ricochetChance
|
||||
initialSpeed
|
||||
lightBleedModifier
|
||||
heavyBleedModifier
|
||||
projectileCount
|
||||
tracer
|
||||
tracerColor
|
||||
ammoType
|
||||
accuracyModifier
|
||||
recoilModifier
|
||||
staminaBurnPerDamage
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def fetch_ammo():
|
||||
response = requests.post(
|
||||
API_URL,
|
||||
json={"query": GRAPHQL_QUERY},
|
||||
timeout=30
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
if "errors" in data:
|
||||
raise RuntimeError(data["errors"])
|
||||
|
||||
return data["data"]["ammo"]
|
||||
|
||||
|
||||
def ensure_schema(conn):
|
||||
conn.executescript("""
|
||||
CREATE TABLE IF NOT EXISTS ammo (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
short_name TEXT,
|
||||
caliber TEXT,
|
||||
damage INTEGER,
|
||||
armor_damage INTEGER,
|
||||
penetration_power INTEGER,
|
||||
penetration_chance REAL,
|
||||
fragmentation_chance REAL,
|
||||
ricochet_chance REAL,
|
||||
initial_speed REAL,
|
||||
light_bleed_modifier REAL,
|
||||
heavy_bleed_modifier REAL,
|
||||
projectile_count INTEGER DEFAULT 1,
|
||||
tracer INTEGER DEFAULT 0,
|
||||
tracer_color TEXT,
|
||||
ammo_type TEXT,
|
||||
accuracy_modifier REAL,
|
||||
recoil_modifier REAL,
|
||||
stamina_burn_per_damage REAL,
|
||||
grid_image_url TEXT,
|
||||
wiki_url TEXT,
|
||||
imported_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ammo_caliber ON ammo(caliber);
|
||||
CREATE INDEX IF NOT EXISTS idx_ammo_damage ON ammo(damage);
|
||||
CREATE INDEX IF NOT EXISTS idx_ammo_pen ON ammo(penetration_power);
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
|
||||
def upsert_ammo(conn, rounds):
|
||||
inserted = 0
|
||||
updated = 0
|
||||
skipped = 0
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
for r in rounds:
|
||||
item = r.get("item") or {}
|
||||
api_id = item.get("id")
|
||||
name = item.get("name")
|
||||
|
||||
if not api_id or not name:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
row_data = (
|
||||
name,
|
||||
item.get("shortName"),
|
||||
r.get("caliber"),
|
||||
r.get("damage"),
|
||||
r.get("armorDamage"),
|
||||
r.get("penetrationPower"),
|
||||
r.get("penetrationChance"),
|
||||
r.get("fragmentationChance"),
|
||||
r.get("ricochetChance"),
|
||||
r.get("initialSpeed"),
|
||||
r.get("lightBleedModifier"),
|
||||
r.get("heavyBleedModifier"),
|
||||
r.get("projectileCount") or 1,
|
||||
1 if r.get("tracer") else 0,
|
||||
r.get("tracerColor"),
|
||||
r.get("ammoType"),
|
||||
r.get("accuracyModifier"),
|
||||
r.get("recoilModifier"),
|
||||
r.get("staminaBurnPerDamage"),
|
||||
item.get("gridImageLink"),
|
||||
item.get("wikiLink"),
|
||||
)
|
||||
|
||||
cursor.execute("SELECT id FROM ammo WHERE id = ?", (api_id,))
|
||||
exists = cursor.fetchone()
|
||||
|
||||
if exists:
|
||||
cursor.execute("""
|
||||
UPDATE ammo SET
|
||||
name = ?, short_name = ?, caliber = ?,
|
||||
damage = ?, armor_damage = ?, penetration_power = ?,
|
||||
penetration_chance = ?, fragmentation_chance = ?, ricochet_chance = ?,
|
||||
initial_speed = ?, light_bleed_modifier = ?, heavy_bleed_modifier = ?,
|
||||
projectile_count = ?, tracer = ?, tracer_color = ?, ammo_type = ?,
|
||||
accuracy_modifier = ?, recoil_modifier = ?, stamina_burn_per_damage = ?,
|
||||
grid_image_url = ?, wiki_url = ?,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
""", (*row_data, api_id))
|
||||
updated += 1
|
||||
else:
|
||||
cursor.execute("""
|
||||
INSERT INTO ammo (
|
||||
id, name, short_name, caliber,
|
||||
damage, armor_damage, penetration_power,
|
||||
penetration_chance, fragmentation_chance, ricochet_chance,
|
||||
initial_speed, light_bleed_modifier, heavy_bleed_modifier,
|
||||
projectile_count, tracer, tracer_color, ammo_type,
|
||||
accuracy_modifier, recoil_modifier, stamina_burn_per_damage,
|
||||
grid_image_url, wiki_url
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (api_id, *row_data))
|
||||
inserted += 1
|
||||
|
||||
conn.commit()
|
||||
return inserted, updated, skipped
|
||||
|
||||
|
||||
def main():
|
||||
print("Fetching ammo data from tarkov.dev...")
|
||||
rounds = fetch_ammo()
|
||||
print(f" Got {len(rounds)} rounds")
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
try:
|
||||
ensure_schema(conn)
|
||||
inserted, updated, skipped = upsert_ammo(conn, rounds)
|
||||
print(f" Inserted: {inserted} Updated: {updated} Skipped: {skipped}")
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
print("Done.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,587 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ammo Chart — OnlyScavs</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0e0e0e;
|
||||
--panel: #161616;
|
||||
--panel2: #1c1c1c;
|
||||
--text: #e8e8e8;
|
||||
--muted: #777;
|
||||
--muted2: #555;
|
||||
--border: #262626;
|
||||
--accent: #9ccfff;
|
||||
--accent2: #ffd580;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ── NAV ─────────────────────────────────────────────────── */
|
||||
.site-nav {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 32px;
|
||||
height: 52px;
|
||||
background: rgba(14,14,14,0.88);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
border-bottom: 1px solid rgba(255,255,255,0.06);
|
||||
}
|
||||
.nav-brand {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
.nav-links { display: flex; gap: 4px; }
|
||||
.nav-links a {
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
font-size: 0.82rem;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
transition: color 0.15s, background 0.15s;
|
||||
}
|
||||
.nav-links a:hover, .nav-links a.active {
|
||||
color: var(--text);
|
||||
background: rgba(255,255,255,0.06);
|
||||
}
|
||||
|
||||
/* ── LAYOUT ───────────────────────────────────────────────── */
|
||||
.page {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 80px 32px 60px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.page-header h1 {
|
||||
font-size: 1.6rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.01em;
|
||||
color: #fff;
|
||||
}
|
||||
.page-header p {
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* ── CONTROLS ─────────────────────────────────────────────── */
|
||||
.controls {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 20px;
|
||||
align-items: center;
|
||||
}
|
||||
.controls input, .controls select {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 7px 12px;
|
||||
border-radius: 7px;
|
||||
font-size: 0.83rem;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.controls input:focus, .controls select:focus {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.controls input { width: 200px; }
|
||||
.controls select { cursor: pointer; }
|
||||
.controls label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.controls label input[type=checkbox] {
|
||||
width: auto;
|
||||
padding: 0;
|
||||
accent-color: var(--accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
.count-badge {
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted2);
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
/* ── CHART ────────────────────────────────────────────────── */
|
||||
.chart-wrap {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
position: relative;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.chart-wrap canvas {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* ── LEGEND ───────────────────────────────────────────────── */
|
||||
.legend-wrap {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.legend-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
padding: 4px 10px;
|
||||
border-radius: 20px;
|
||||
border: 1px solid var(--border);
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, color 0.15s, opacity 0.15s;
|
||||
}
|
||||
.legend-chip:hover { border-color: #444; color: var(--text); }
|
||||
.legend-chip.hidden { opacity: 0.35; }
|
||||
.legend-dot {
|
||||
width: 9px; height: 9px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ── TABLE ────────────────────────────────────────────────── */
|
||||
.table-wrap {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
overflow: auto;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
thead th {
|
||||
background: var(--panel2);
|
||||
color: var(--muted);
|
||||
font-weight: 600;
|
||||
font-size: 0.72rem;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
padding: 10px 14px;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
thead th:hover { color: var(--text); }
|
||||
thead th.sort-asc::after { content: " ↑"; color: var(--accent); }
|
||||
thead th.sort-desc::after { content: " ↓"; color: var(--accent); }
|
||||
tbody tr {
|
||||
border-top: 1px solid var(--border);
|
||||
transition: background 0.1s;
|
||||
}
|
||||
tbody tr:hover { background: var(--panel2); }
|
||||
tbody td { padding: 9px 14px; vertical-align: middle; white-space: nowrap; }
|
||||
td.num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
|
||||
.tier-bar {
|
||||
display: inline-block;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
min-width: 2px;
|
||||
vertical-align: middle;
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
background: rgba(156,207,255,0.12);
|
||||
color: var(--accent);
|
||||
}
|
||||
.tag.tracer {
|
||||
background: rgba(255,213,128,0.12);
|
||||
color: var(--accent2);
|
||||
}
|
||||
|
||||
/* ── EMPTY ────────────────────────────────────────────────── */
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 80px 20px;
|
||||
color: var(--muted2);
|
||||
}
|
||||
.empty strong { display: block; font-size: 1.1rem; margin-bottom: 8px; color: var(--muted); }
|
||||
|
||||
/* ── TOOLTIP OVERRIDE ─────────────────────────────────────── */
|
||||
#chartjs-tooltip {
|
||||
background: #1a1a1a;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
color: var(--text);
|
||||
font-size: 0.78rem;
|
||||
pointer-events: none;
|
||||
position: fixed;
|
||||
transition: opacity 0.15s;
|
||||
max-width: 220px;
|
||||
line-height: 1.6;
|
||||
z-index: 9999;
|
||||
}
|
||||
#chartjs-tooltip .tt-name { font-weight: 700; margin-bottom: 4px; color: #fff; }
|
||||
#chartjs-tooltip .tt-row { color: var(--muted); }
|
||||
#chartjs-tooltip .tt-row span { color: var(--text); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="site-nav">
|
||||
<a class="nav-brand" href="/">OnlyScavs</a>
|
||||
<div class="nav-links">
|
||||
<a href="/keys">Keys</a>
|
||||
<a href="/collector">Collector</a>
|
||||
<a href="/quests">Quests</a>
|
||||
<a href="/loadout">Loadout</a>
|
||||
<a href="/meds">Injectors</a>
|
||||
<a href="/barters">Barters</a>
|
||||
<a href="/ammo" class="active">Ammo</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="page">
|
||||
<div class="page-header">
|
||||
<h1>Ammo Chart</h1>
|
||||
<p>Damage vs. Armor Penetration — scatter plot by caliber</p>
|
||||
</div>
|
||||
|
||||
{% if not rounds %}
|
||||
<div class="empty">
|
||||
<strong>No ammo data yet.</strong>
|
||||
Run <code>python import_ammo.py</code> to import from tarkov.dev.
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<div class="controls">
|
||||
<input type="text" id="search" placeholder="Search ammo…" value="{{ q }}">
|
||||
<select id="caliberFilter">
|
||||
<option value="">All calibers</option>
|
||||
{% for c in calibers %}
|
||||
<option value="{{ c }}" {% if c == caliber %}selected{% endif %}>{{ c }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<label>
|
||||
<input type="checkbox" id="tracerOnly"> Tracer only
|
||||
</label>
|
||||
<span class="count-badge" id="countBadge"></span>
|
||||
</div>
|
||||
|
||||
<div class="chart-wrap">
|
||||
<canvas id="ammoChart" height="460"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="legend-wrap" id="legendWrap"></div>
|
||||
|
||||
<div class="table-wrap">
|
||||
<table id="ammoTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-col="name">Name</th>
|
||||
<th data-col="caliber">Caliber</th>
|
||||
<th data-col="damage" class="sort-desc">Damage</th>
|
||||
<th data-col="penetration_power">Pen</th>
|
||||
<th data-col="armor_damage">Armor Dmg</th>
|
||||
<th data-col="fragmentation_chance">Frag %</th>
|
||||
<th data-col="initial_speed">Velocity</th>
|
||||
<th data-col="projectile_count">Pellets</th>
|
||||
<th data-col="tracer">Tracer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="chartjs-tooltip" style="opacity:0;"></div>
|
||||
|
||||
<script>
|
||||
const ALL_ROUNDS = {{ rounds | tojson }};
|
||||
|
||||
// ── Color palette per caliber ──────────────────────────────────────────────
|
||||
const PALETTE = [
|
||||
"#9ccfff","#ffd580","#7ee8a2","#ff9eb5","#c9b1ff",
|
||||
"#ffb347","#80deea","#f48fb1","#a5d6a7","#ffe082",
|
||||
"#90caf9","#ef9a9a","#ce93d8","#80cbc4","#ffcc02",
|
||||
"#ff7043","#66bb6a","#ab47bc","#26c6da","#d4e157",
|
||||
];
|
||||
|
||||
function caliberColor(caliber, idx) {
|
||||
return PALETTE[idx % PALETTE.length];
|
||||
}
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
let sortCol = "damage";
|
||||
let sortAsc = false;
|
||||
let hiddenCalibers = new Set();
|
||||
|
||||
// ── Filter rounds ──────────────────────────────────────────────────────────
|
||||
function filteredRounds() {
|
||||
const q = document.getElementById("search").value.trim().toLowerCase();
|
||||
const cal = document.getElementById("caliberFilter").value;
|
||||
const tracer = document.getElementById("tracerOnly").checked;
|
||||
|
||||
return ALL_ROUNDS.filter(r => {
|
||||
if (cal && r.caliber !== cal) return false;
|
||||
if (tracer && !r.tracer) return false;
|
||||
if (q && !r.name.toLowerCase().includes(q) &&
|
||||
!(r.short_name || "").toLowerCase().includes(q)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// ── Caliber list ───────────────────────────────────────────────────────────
|
||||
function getCalibers(rounds) {
|
||||
const seen = new Map();
|
||||
rounds.forEach(r => { if (r.caliber && !seen.has(r.caliber)) seen.set(r.caliber, seen.size); });
|
||||
return seen;
|
||||
}
|
||||
|
||||
// ── Chart ──────────────────────────────────────────────────────────────────
|
||||
const ctx = document.getElementById("ammoChart");
|
||||
let chart = null;
|
||||
|
||||
function buildDatasets(rounds) {
|
||||
const calibers = getCalibers(rounds);
|
||||
const groups = {};
|
||||
calibers.forEach((_, cal) => { groups[cal] = []; });
|
||||
|
||||
rounds.forEach(r => {
|
||||
if (r.damage == null || r.penetration_power == null) return;
|
||||
if (hiddenCalibers.has(r.caliber)) return;
|
||||
const key = r.caliber || "Unknown";
|
||||
if (!groups[key]) groups[key] = [];
|
||||
groups[key].push({ x: r.damage, y: r.penetration_power, r: r });
|
||||
});
|
||||
|
||||
const caliberList = [...calibers.keys()];
|
||||
return caliberList.map((cal, idx) => ({
|
||||
label: cal,
|
||||
data: (groups[cal] || []).map(p => ({ x: p.x, y: p.y, r: p.r })),
|
||||
backgroundColor: caliberColor(cal, idx) + "cc",
|
||||
borderColor: caliberColor(cal, idx),
|
||||
borderWidth: 1,
|
||||
pointRadius: 6,
|
||||
pointHoverRadius: 9,
|
||||
_calIdx: idx,
|
||||
}));
|
||||
}
|
||||
|
||||
function renderChart(rounds) {
|
||||
const datasets = buildDatasets(rounds);
|
||||
|
||||
if (chart) {
|
||||
chart.data.datasets = datasets;
|
||||
chart.update("none");
|
||||
return;
|
||||
}
|
||||
|
||||
const tooltip = document.getElementById("chartjs-tooltip");
|
||||
|
||||
chart = new Chart(ctx, {
|
||||
type: "scatter",
|
||||
data: { datasets },
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
animation: { duration: 200 },
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
enabled: false,
|
||||
external(context) {
|
||||
const { chart, tooltip: tt } = context;
|
||||
if (tt.opacity === 0) { tooltip.style.opacity = 0; return; }
|
||||
|
||||
const point = tt.dataPoints?.[0];
|
||||
if (!point) return;
|
||||
const r = point.raw.r;
|
||||
|
||||
tooltip.innerHTML = `
|
||||
<div class="tt-name">${r.name}</div>
|
||||
<div class="tt-row">Caliber: <span>${r.caliber || "—"}</span></div>
|
||||
<div class="tt-row">Damage: <span>${r.damage ?? "—"}</span></div>
|
||||
<div class="tt-row">Pen: <span>${r.penetration_power ?? "—"}</span></div>
|
||||
<div class="tt-row">Armor Dmg: <span>${r.armor_damage ?? "—"}</span></div>
|
||||
<div class="tt-row">Frag: <span>${r.fragmentation_chance != null ? (r.fragmentation_chance * 100).toFixed(0) + "%" : "—"}</span></div>
|
||||
${r.tracer ? '<div class="tt-row"><span style="color:var(--accent2)">Tracer</span></div>' : ""}
|
||||
`;
|
||||
|
||||
const pos = chart.canvas.getBoundingClientRect();
|
||||
const x = pos.left + tt.caretX + 12;
|
||||
const y = pos.top + tt.caretY - 10;
|
||||
tooltip.style.left = x + "px";
|
||||
tooltip.style.top = y + "px";
|
||||
tooltip.style.opacity = 1;
|
||||
}
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
title: { display: true, text: "Damage", color: "#777", font: { size: 12 } },
|
||||
grid: { color: "rgba(255,255,255,0.05)" },
|
||||
ticks: { color: "#666" },
|
||||
min: 0,
|
||||
},
|
||||
y: {
|
||||
title: { display: true, text: "Armor Penetration", color: "#777", font: { size: 12 } },
|
||||
grid: { color: "rgba(255,255,255,0.05)" },
|
||||
ticks: { color: "#666" },
|
||||
min: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ── Legend ─────────────────────────────────────────────────────────────────
|
||||
function renderLegend(rounds) {
|
||||
const calibers = getCalibers(ALL_ROUNDS); // always all calibers in legend
|
||||
const wrap = document.getElementById("legendWrap");
|
||||
wrap.innerHTML = "";
|
||||
calibers.forEach((idx, cal) => {
|
||||
const chip = document.createElement("div");
|
||||
chip.className = "legend-chip" + (hiddenCalibers.has(cal) ? " hidden" : "");
|
||||
chip.innerHTML = `<span class="legend-dot" style="background:${caliberColor(cal, idx)}"></span>${cal}`;
|
||||
chip.addEventListener("click", () => {
|
||||
if (hiddenCalibers.has(cal)) hiddenCalibers.delete(cal);
|
||||
else hiddenCalibers.add(cal);
|
||||
refresh();
|
||||
});
|
||||
wrap.appendChild(chip);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Table ──────────────────────────────────────────────────────────────────
|
||||
const caliberColorMap = new Map();
|
||||
|
||||
function calForRound(r) {
|
||||
if (!caliberColorMap.has(r.caliber)) {
|
||||
const idx = caliberColorMap.size;
|
||||
caliberColorMap.set(r.caliber, PALETTE[idx % PALETTE.length]);
|
||||
}
|
||||
return caliberColorMap.get(r.caliber);
|
||||
}
|
||||
|
||||
// Pre-populate color map from all rounds so it's stable
|
||||
(function() {
|
||||
const seen = new Set();
|
||||
ALL_ROUNDS.forEach(r => {
|
||||
if (r.caliber && !seen.has(r.caliber)) {
|
||||
seen.add(r.caliber);
|
||||
caliberColorMap.set(r.caliber, PALETTE[caliberColorMap.size % PALETTE.length]);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
function renderTable(rounds) {
|
||||
const sorted = [...rounds].sort((a, b) => {
|
||||
const va = a[sortCol] ?? (typeof a[sortCol] === "number" ? -Infinity : "");
|
||||
const vb = b[sortCol] ?? (typeof b[sortCol] === "number" ? -Infinity : "");
|
||||
if (va < vb) return sortAsc ? -1 : 1;
|
||||
if (va > vb) return sortAsc ? 1 : -1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
const maxPen = Math.max(...ALL_ROUNDS.map(r => r.penetration_power || 0), 1);
|
||||
const tbody = document.getElementById("tableBody");
|
||||
tbody.innerHTML = "";
|
||||
|
||||
sorted.forEach(r => {
|
||||
const color = calForRound(r);
|
||||
const penPct = Math.round(((r.penetration_power || 0) / maxPen) * 100);
|
||||
const fragPct = r.fragmentation_chance != null
|
||||
? (r.fragmentation_chance * 100).toFixed(0) + "%" : "—";
|
||||
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td>${r.name}</td>
|
||||
<td><span class="tag">${r.caliber || "—"}</span></td>
|
||||
<td class="num">${r.damage ?? "—"}</td>
|
||||
<td class="num">
|
||||
<span class="tier-bar" style="width:${penPct}%;background:${color}"></span>${r.penetration_power ?? "—"}
|
||||
</td>
|
||||
<td class="num">${r.armor_damage ?? "—"}</td>
|
||||
<td class="num">${fragPct}</td>
|
||||
<td class="num">${r.initial_speed != null ? Math.round(r.initial_speed) + " m/s" : "—"}</td>
|
||||
<td class="num">${r.projectile_count && r.projectile_count > 1 ? r.projectile_count : "—"}</td>
|
||||
<td>${r.tracer ? '<span class="tag tracer">T</span>' : ""}</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
|
||||
document.getElementById("countBadge").textContent = `${sorted.length} rounds`;
|
||||
|
||||
// Update sort header indicators
|
||||
document.querySelectorAll("thead th[data-col]").forEach(th => {
|
||||
th.classList.remove("sort-asc", "sort-desc");
|
||||
if (th.dataset.col === sortCol) {
|
||||
th.classList.add(sortAsc ? "sort-asc" : "sort-desc");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ── Sort clicks ────────────────────────────────────────────────────────────
|
||||
document.querySelectorAll("thead th[data-col]").forEach(th => {
|
||||
th.addEventListener("click", () => {
|
||||
if (sortCol === th.dataset.col) sortAsc = !sortAsc;
|
||||
else { sortCol = th.dataset.col; sortAsc = false; }
|
||||
renderTable(filteredRounds());
|
||||
});
|
||||
});
|
||||
|
||||
// ── Refresh ────────────────────────────────────────────────────────────────
|
||||
function refresh() {
|
||||
const rounds = filteredRounds();
|
||||
renderChart(rounds);
|
||||
renderLegend(rounds);
|
||||
renderTable(rounds);
|
||||
}
|
||||
|
||||
// ── Init ───────────────────────────────────────────────────────────────────
|
||||
document.getElementById("search").addEventListener("input", refresh);
|
||||
document.getElementById("caliberFilter").addEventListener("change", refresh);
|
||||
document.getElementById("tracerOnly").addEventListener("change", refresh);
|
||||
|
||||
// Set chart container height explicitly for Chart.js
|
||||
ctx.style.height = "460px";
|
||||
|
||||
refresh();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -233,6 +233,7 @@
|
||||
<a href="/loadout">Loadout</a>
|
||||
<a href="/meds">Injectors</a>
|
||||
<a href="/barters">Barters</a>
|
||||
<a href="/ammo">Ammo</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -284,6 +285,12 @@
|
||||
<div class="card-desc">Calculate the true rouble cost of any barter deal.</div>
|
||||
<div class="card-arrow">Open →</div>
|
||||
</a>
|
||||
<a class="card" href="/ammo">
|
||||
<div class="card-icon">◎</div>
|
||||
<div class="card-title">Ammo Chart</div>
|
||||
<div class="card-desc">Scatter plot of damage vs. armor penetration for every caliber.</div>
|
||||
<div class="card-arrow">Open →</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user