Skip to content

About

JS/TS/ES Web Interface for AsyncTI4

Resources

Stars

16 stars

Watchers

8 watching

Forks

Repository files navigation

TI4 Web

A Twilight Imperium 4 companion application for AsyncTI4 games, built with React, Vite, and TypeScript. Game state comes from the bot API and websocket; static catalogs supply definitions for systems, planets, cards, technologies, and leaders.

Versioning

The app version (MAJOR.MINOR.PATCH) lives in package.json and is shown in the bottom-left corner of every page (site footer and game map). Bump it with every change that ships: MAJOR for breaking changes or redesigns, MINOR for new features, PATCH for fixes and tweaks (npm version patch --no-git-tag-version).

Clicking the version copies a human-readable debug report to the clipboard: build, browser and login info, and on a game page the full game state (players, strategy cards, objectives, laws, every map system with its units, tokens and planets, decks) plus the logged-in player's action cards, secret objectives and promissory notes.

Tech Stack

  • React 19 with the React Compiler
  • Vite and TypeScript
  • Base UI through the local design system in src/ds/
  • TanStack Query for server state and Zustand for application settings
  • React Router for routing
  • Remotion for the music video
  • ESLint with type-aware TypeScript rules

Development

Use Node.js 22.12+ and Yarn. Run commands from the repository root.

# Install dependencies and start the development server
yarn install
yarn dev

# Check both TypeScript projects explicitly
yarn tsc -p tsconfig.app.json --noEmit
yarn tsc -p tsconfig.node.json --noEmit

# Lint, build, and preview the production output
yarn lint
yarn build
yarn preview

The root tsconfig.json contains project references rather than source files; explicit project checks above cover application and build-tool code.

API endpoints are centralized in src/config.ts. The development server proxies /bot to https://bot.asyncti4.com, /proxy to https://asyncti4.com, and /auth to a local service on port 8000. Game data and websocket updates use the remote bot in development as well as production.

Game Data Catalogs

Live game data contains IDs that must resolve through the static TypeScript catalogs in src/entities/data/. A missing catalog entry can hide a tile, planet, leader, relic, promissory note, or technology even when the bot reports it in the game state.

The production deployment and test deployment replace generated catalogs from s3://bot-images-asyncti4.com/web_data/ before building. The local development server and ordinary local builds use the files already in the checkout. This can make local games differ from production when those files are stale.

Published catalogs are available at https://images.asyncti4.com/web_data/<catalog>.ts. To refresh the map, leader, relic, promissory-note, and technology catalogs:

for catalog in systems planets leaders relics promissoryNotes tech; do
  curl --fail --silent --show-error \
    "https://images.asyncti4.com/web_data/${catalog}.ts" \
    --output "src/entities/data/${catalog}.ts" || break
done

Keep generated catalogs as published. Review their diffs and update the explicit metadata types in src/entities/data/types.ts if upstream adds fields, then run the checks above. Refresh generated data files individually rather than replacing hand-maintained helpers such as catalogs.ts, leaderPortraits.ts, or uiImages.ts.

src/entities/data/catalogs.ts merges the generated system, planet, and leader catalogs with local supplements. Generated entries take precedence; supplements only fill IDs absent from the base catalogs.

Images and Icons

Faction Icons

Use FactionIcon or useFactionImageUrl() when an icon represents a player in a game. They resolve custom emoji and Discord images from game context or explicit overrides. Neighbors, player-area column headers, PDS coverage, and promissory-note chips use this approach. Artwork representing a specific faction's technology or unit keeps that faction's fixed symbol.

getFactionImage() also handles the bot's alternate CDN paths and filename casing for franken19 through franken26. Callers do not need to construct those paths.

Leader Portraits

getLeaderPortraitUrl() resolves portraits for every source, including the music video. It checks an ID's own artwork, then the bot's emoji aliases, then homebrewReplacesID from the leader catalog. IDs are matched without regard to case, replacement chains are followed, and cycles or unknown IDs return no URL. Portrait visibility depends on resolved artwork rather than a source allowlist.

Paths and aliases live in src/entities/data/leaderPortraits.ts, matching the bot's LeaderEmojis mappings and existing portrait files. Preserve CDN filename casing. LeaderPortraitImage uses a transparent fallback when artwork is unknown or fails to load, including locked and exhausted leaders.

Shared Game Images

Reference existing bot assets through cdnImage(). The helper selects the WebP files generated by the bot's image-upload workflow from its PNG/JPEG sources. Leader portraits, system tiles, planet-card tile backgrounds, and default faction icons use these CDN assets.

Common technology, unit-upgrade, resource, and action-card images are centralized in src/entities/data/uiImages.ts. Single planet-trait icons also use the CDN; CSS backgrounds use the corresponding CDN URLs. Reuse those assets instead of adding local copies or duplicate converted images to either repository.

Remaining music-video image assets and their preload behavior are maintained separately in src/music-video/.

Map Coverage

The map supports Fracture positions frac1 through frac25. When all original seven positions are present, the layout reserves 400 pixels of vertical space; any expanded position (frac8–frac25) adds another 600 pixels, matching the bot layout for tiles and player-stat areas.

Unknown bot map positions are omitted from drawing and listed in a “Map incomplete” warning. Their raw tile data and planet lookups are retained so other game views remain usable. Add verified coordinates in src/entities/data/tileCoordinates.ts to render those positions. This also applies to player-stat positions and map previews.

Repository Structure

ti4_web_new/
├── public/                   # Remaining static assets and fonts
├── src/
│   ├── main.tsx              # Application entry point and routes
│   ├── config.ts             # Environment-specific API endpoints
│   ├── pages/                # Route-level pages
│   ├── layout/               # Shared site chrome
│   ├── domains/              # Game shell, map, players, cards, auth, and other features
│   ├── ds/                   # Design tokens and Base UI-backed primitives
│   ├── shared/               # Shared UI, accessibility helpers, and types
│   ├── hooks/                # Shared React hooks
│   ├── state/                # Settings stores and game context
│   ├── api/                  # Data fetching and websocket updates
│   ├── entities/
│   │   ├── data/             # Static catalogs, data types, and asset mappings
│   │   ├── lookup/           # Entity and image lookup helpers
│   │   ├── game/             # Game models and context construction
│   │   ├── geometry/         # Hex and tile geometry
│   │   ├── positioning/      # Unit placement
│   │   └── replay/           # Map replay planning
│   ├── music-video/          # Remotion composition, assets, and player
│   ├── styles/               # Global styles and themes
│   └── utils/                # General utilities
├── dist/                     # Generated Vite build output
├── .github/workflows/        # Build and deployment workflows
├── eslint.config.js          # Type-aware TypeScript lint configuration
├── tsconfig.json             # Project references
├── tsconfig.app.json         # Application TypeScript configuration
├── tsconfig.node.json        # Build-tool TypeScript configuration
├── vite.config.ts            # Vite configuration
└── package.json              # Dependencies and scripts

The game-shell domain composes the game views; cards supplies details panels used across those views. Imports use the @/ alias for src/. Game model types live in src/entities/game/types.ts; catalog types live in src/entities/data/types.ts. Keep component-specific types near their components.

About

JS/TS/ES Web Interface for AsyncTI4

Resources

Stars

16 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages