Skip to content

Read card database from Arena's on-disk SQLite files#1

Open
dan-blanchard wants to merge 1 commit intomtgatool:mainfrom
dan-blanchard:feat/sqlite-card-database
Open

Read card database from Arena's on-disk SQLite files#1
dan-blanchard wants to merge 1 commit intomtgatool:mainfrom
dan-blanchard:feat/sqlite-card-database

Conversation

@dan-blanchard
Copy link
Copy Markdown

Arena ships its card database as a SQLite file (Raw_CardDatabase_*.mtga) in the game's Downloads/Raw/ directory. This PR adds a pure-JS reader that finds it and exposes all ~27K cards with English names, set codes, collector numbers, rarity, types, colors, power/toughness, and localized names for 8+ languages.

No native code, no process attachment, no elevated privileges. It just reads a file that's already on disk.

What it does

  • findCardDatabasePath() auto-discovers the .mtga file on Windows (Program Files/Wizards of the Coast/MTGA/), with fallback support for macOS and Linux Wine prefixes
  • readCardDatabase() opens it with sql.js, joins Cards with Localizations_enUS to resolve TitleId → card name, and returns a byGrpId lookup map
  • Supports an explicit arenaPath option for non-standard installs and a locale option for Japanese, Portuguese, etc.

Why

This makes it possible to resolve grpId → card name without Scryfall (which has null arena_id for ~1500 recent cards). The database is static per Arena build (same for all players), so reading it from disk is simpler and more reliable than extracting it from live process memory.

Combined with the existing readData walker or the readMtgaCards collection scanner, this gives the full pipeline: grpId → quantity + card name + set + collector number.

Testing

All 10 new tests pass (npm test). Verified on a Windows Arena install (version 2026.58.0.324, 27,189 cards):

  • Path discovery returns valid path when Arena is installed, null gracefully when not
  • Explicit nonexistent arenaPath returns null (no fallback to platform defaults)
  • Loads 27K+ cards with names
  • byGrpId.get(75452) → "Inspiring Commander" (ANB #11)
  • Japanese locale loads different names
  • Nonexistent locale gives empty names gracefully
  • Invalid path throws with descriptive error message
  • Field types are correct (numbers, booleans, strings)
  • Includes both tokens and non-tokens in expected proportions

Dependency: sql.js (pure JS SQLite, no native compilation needed)

🤖 Generated with Claude Code

Arena ships its card database as a SQLite file (Raw_CardDatabase_*.mtga)
in Downloads/Raw/. New pure-JS reader auto-discovers and reads it:
~27K cards with names, set codes, collector numbers, localization for
8+ languages. No native code, no process attachment, no sudo.

Dependency: sql.js (pure JS SQLite)
10 tests included.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant