How freezingmoon/ancientbeast works
Project type and purpose
• This is a browser-based, single-page turn-based strategy game (Ancient Beast).
• It’s built with TypeScript/JavaScript and Phaser for rendering, packaged via Webpack, and played online (PWA support via service worker).
• There is client-side logic only; multiplayer relies on external servers (WebSocket/API).
File structure
• Top-level build & config: Dockerfile, .env.example, webpack.config.js, tsconfig.json, Babel, ESLint, Prettier, Husky.
• Source code (“src/”):
• Core game modules: game.ts, creature.ts, effect.ts, drop.ts, damage.ts, etc.
• Abilities under “src/abilities/”, data under “src/data/”.
• UI under “src/ui/”: buttons, chat, interface, progress bars, etc.
• Multiplayer under “src/multiplayer/”: authentication, connection, gameplay, session management.
• Sound under “src/sound/”: buffer loader, music player, sound system, pre-match audio.
• Templates in “src/templates/” for analytics snippet, service worker registration.
• Utility under “src/utility/”: math, pathfinding, grid utilities, versioning, constants.
• Styles under “src/style/”: LESS/CSS for cards, grids, skin, avatars.
• Testing: Jest tests in “src/__tests__/”.
• Static PWA support: “static/worker.js”, “static/manifest.json”, “static/analytics.js”.
Insights from README
• Describes game features, online multiplayer, PWA optimizations, lightweight design.
• No server code in repo – multiplayer endpoints are external.
a. Main components
• Client (Browser)
• Game Engine (Phaser) & Core Logic
• UI Layer (DOM/Canvas controls, menu, chat)
• Asset Loader (images, audio, sprites)
• Sound System
• Service Worker (caching & offline support)
• Webpack Bundle (runtime code)
• Build System
• Webpack/Babel for bundling/transpiling
• npm scripts, Dockerfile for containerization
• Static Hosting
• CDN or web server serving HTML/CJS, assets, worker.js
• External Services
• Multiplayer Server (WebSocket/API for matches & session)
• Analytics (Google Analytics, custom analytics.js)
• Optional Auth (OAuth/JWT endpoint)
b. Relationships & interactions
• Developer runs build: webpack → bundles static files → Docker container or static host.
• Browser loads index.ejs → main.js → initializes Phaser game & UI modules.
• Asset Loader fetches assets from “assets/” path.
• Service Worker intercepts requests, caches bundles & assets, enabling offline play.
• Multiplayer module opens WebSocket to external server → handshake (authenticate.ts) → gameplay messages (connect.ts, gameplay.ts).
• UI events update game state; game logic produces commands → sent over WebSocket or consumed locally.
• Analytics snippet loads “static/analytics.js” → sends events to analytics backend.
c. Architectural patterns & design principles
• Modular separation: domain logic (game, creature), UI, utilities, multiplayer, sound.
• Single responsibility for each module folder.
• Separation of build vs. runtime: webpack config, Dockerfile distinct from src code.
• PWA pattern: service worker + manifest for caching and offline.
d. Key technologies/frameworks
• Phaser for rendering & game loop
• Webpack + Babel + TypeScript for build & transpile
• Jest for unit tests
• Service Worker API for offline
• WebSockets / REST for multiplayer
• LESS/CSS for theming
Elements
• Labels: e.g., “Game Engine”, “UI Layer”, “Service Worker”, “Build System”, “External WS Server”.
• Build → Host
• Browser → Asset Server
• Browser ↔ WebSocket Server
• Browser → Analytics API
• Browser ↔ Cache (Service Worker)
• Green for build/deploy (Webpack, Docker)
• Orange for external services (Multiplayer, Analytics)
Final recommendations
• Break the client into sub-components matching the “src/” folders to illustrate modularity.
• Static hosting layer as the boundary between build artifacts and runtime.
• Asynchronous flows (asset loading, WebSocket messaging).