Repository navigation
Example 01 browse game data
github-actions[bot] edited this page Nov 21, 2026
·
1 revision
Generated from the thetowersdk repository. Edits made here are overwritten on the next push — change the source file instead.
/**
* Example 1 — Use the game data with no save file at all.
*
* The simplest thing the SDK does: it hands you the game's own tables as typed
* arrays. Useful for cost calculators, planners, wikis, or anything that needs
* to know what the game contains.
*
* Run it:
* pnpm exec tsx examples/01-browse-game-data.ts
*/
import { LAB_CATALOG, type LabCatalogRecord } from '@beardedunicorn/thetowersdk/data'
console.log(`The game has ${LAB_CATALOG.length} labs.\n`)
// Each record is { name, category, base, value, levels }, and every entry in
// `levels` is { level, duration, cost }. `duration` is research time as
// "HH:MM:SS"; `cost` is a plain number of coins.
const [firstLab] = LAB_CATALOG
console.log(`Example record: ${firstLab.name} (${firstLab.category ?? 'uncategorized'})`)
console.log(` ${firstLab.levels?.length ?? 0} levels`)
console.log(` level 1 -> cost ${firstLab.levels?.[0]?.cost}, duration ${firstLab.levels?.[0]?.duration}`)
console.log()
// A real question: what does it cost to max each lab? Sum its level costs.
// Costs are coins throughout, so they add up without conversion.
const totalCostToMax = (lab: LabCatalogRecord): number =>
(lab.levels ?? []).reduce((sum, level) => sum + (level.cost ?? 0), 0)
const ranked = LAB_CATALOG
.map(lab => ({ name: lab.name, category: lab.category ?? '-', total: totalCostToMax(lab) }))
.filter(lab => lab.total > 0)
.sort((a, b) => b.total - a.total)
console.log('10 most expensive labs to max (sum of all level costs):')
for (const lab of ranked.slice(0, 10)) {
console.log(` ${lab.name.padEnd(32)} ${lab.category.padEnd(12)} ${lab.total.toExponential(3)}`)
}
console.log()
// Group by category, the way a planner UI would.
const byCategory = new Map<string, number>()
for (const lab of LAB_CATALOG) {
const category = lab.category ?? 'Uncategorized'
byCategory.set(category, (byCategory.get(category) ?? 0) + 1)
}
console.log('Labs per category:')
for (const [category, count] of [...byCategory].sort((a, b) => b[1] - a[1])) {
console.log(` ${category.padEnd(20)} ${count}`)
}Generated from TheTowerSDK — do not edit here. Docs and live demos: https://beardedunicorn.github.io/TheTowerSDK/
- Workshop
- Workshop Enhancements
- Labs
- Cards
- Modules
- Module Rarities and Merging
- Module Substats
- Module Upgrade Costs
- Ultimate Weapons
- Ultimate Weapon Plus
- Bots
- Guardian
- Relics
- Themes
- Tiers
- Battle Conditions
- Enemies
- Perks
- Tournaments
- Milestones
- The Vault
- Daily Missions
- Guild
- Currencies
- Reference Tables
- Glossary
- Irreversible Upgrades
- Game Patch Notes
- Game Version History
SDK
- Quick Start
- Entry Points
- How It Fits Together
- Getting an Official Game Export
- Reading a Save
- Reading The Community Wiki
- Game 29.1 Data
- Formulas
- Builders
- Charts
- Effective Paths
- Examples
- Templates
- Building a Bot On This
- Google Sheets
- Desktop and Mobile
- Optional Add-ons
- Using It With An AI Agent
- Using Your Own Artwork
- Names And Acronyms
- Patch Notes
- Accuracy
- Versioning
- Where the Docs Live
- Contributing
- Credits
- License
Guides
Examples
- 01-browse-game-data.ts
- 02-read-a-save-file.ts
- 03-plan-upgrades-from-a-save.ts
- 04-generate-a-chart.ts
- 05-generate-a-cost-table.ts
- 06-read-the-community-wiki.ts
- 07-format-like-the-game.ts
- 08-build-a-calculator.ts
- 09-build-a-bot.ts
- 10-read-a-sheet.ts
- 11-build-a-knowledge-base.ts
- 12-show-module-and-card-art.ts
Templates