How hir-247-30/splatoon-weapon-randomization works
Main Components
• Environment/Configuration: The .env file (derived from .env.example) holds the players’ names and the Discord webhook URL.
• Main Application Entry Point: src/main.ts is the starting point that orchestrates the process.
• Services:
• Player Service (src/services/playerService.ts): Likely responsible for handling player-specific logic, such as reading player names from the environment.
• Report Service (src/services/reportService.ts): Manages the logic around generating and sending notifications to the specified Discord channel.
• Business Logic / Utility Functions:
• Choice Logic (src/lib/choice.ts): Contains the logic for randomly picking a weapon based on the number of players and the selection rules outlined in the README.
• Shared Components:
• Common Functions and Types (src/common/functions.ts and src/common/types.ts): These provide utility functions and type definitions that are potentially used throughout the application.
• Constants:
• Weapons Constants (src/const/weapons.ts): This file likely contains the data defining different Splatoon weapons, their categories (e.g., short, medium, long range) and roles (e.g., ink, balance, kill).
Relationships and Interactions
• The Main entry point (src/main.ts) initializes the application by loading configurations from the environment.
• It then calls into the services (playerService and reportService) which in turn use the choice logic from src/lib/choice.ts to process the appropriate weapon selection based on the player count.
• The services may also reference the constants (from src/const/weapons.ts) and any shared types/functions (from src/common) to maintain consistency.
• After processing, the reportService sends a notification via the configured Discord webhook URL.
Architectural Patterns and Design Principles
• Modularity: The code is separated by concerns into distinct directories (common, lib, const, and services), which promotes a clear separation of responsibilities.
• Environment-based Configuration: Using .env for configuration ensures that sensitive data (e.g., Discord webhook) and player information are not hard-coded.
• Entrypoint Delegation: The main file (src/main.ts) delegates specialized tasks to separate, easily testable service modules.
• Clear Dependency Flow: Core business logic (in choice.ts and services) depends on shared constants and types, following a predictable and maintainable flow.
Relevant Technologies and Frameworks
• Node.js and TypeScript as the base runtime environment and language.
• npm for dependency management (as indicated by package.json, package-lock.json, and npm commands in the README).
• ESLint for code quality assurance (eslint.config.js).
Essential Elements
• Clear labels for each component: Environment (config), Main (Orchestrator), Services (Player & Report), Business Logic (Choice Logic), Shared Utilities (Common Types/Functions), and Constants (Weapons).