|
| 1 | +# Contributing to BalatroBot |
| 2 | + |
| 3 | +Welcome to BalatroBot! We're excited that you're interested in contributing to this Python framework and Lua mod for creating automated bots to play Balatro. |
| 4 | + |
| 5 | +BalatroBot uses a unique dual-architecture approach with a Python framework that communicates with a Lua mod running inside Balatro via TCP sockets. This allows for real-time bot automation and game state analysis. |
| 6 | + |
| 7 | +## Project Status & Priorities |
| 8 | + |
| 9 | +We track all development work using the [BalatroBot GitHub Project](https://github.com/users/S1M0N38/projects/7). This is the best place to see current priorities, ongoing work, and opportunities for contribution. |
| 10 | + |
| 11 | +**Current Focus**: We're heavily refactoring the Python framework while focusing development efforts on the Lua API (`src/lua/api.lua`). The existing Python code serves as reference but will be drastically simplified in future versions. |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +Before contributing, ensure you have: |
| 18 | + |
| 19 | +- **Balatro**: Version 1.0.1o-FULL |
| 20 | +- **SMODS (Steamodded)**: Version 1.0.0-beta-0711a or newer |
| 21 | +- **Python**: 3.13+ (managed via uv) |
| 22 | +- **uv**: Python package manager ([Installation Guide](https://docs.astral.sh/uv/)) |
| 23 | + |
| 24 | +### Recommended Tools |
| 25 | + |
| 26 | +- **[DebugPlus](https://github.com/WilsontheWolf/DebugPlus)**: Essential for Lua API development and debugging |
| 27 | + |
| 28 | +### Development Environment Setup |
| 29 | + |
| 30 | +1. **Fork and Clone** |
| 31 | + |
| 32 | + ```bash |
| 33 | + git clone https://github.com/YOUR_USERNAME/balatrobot.git |
| 34 | + cd balatrobot |
| 35 | + ``` |
| 36 | + |
| 37 | +2. **Install Dependencies** |
| 38 | + |
| 39 | + ```bash |
| 40 | + uv sync --all-extras |
| 41 | + ``` |
| 42 | + |
| 43 | +3. **Set Up Balatro with Mods** |
| 44 | + |
| 45 | + **macOS** (currently supported): |
| 46 | + |
| 47 | + ```bash |
| 48 | + ./balatro.sh > balatro.log 2>&1 & sleep 10 && echo 'Balatro started and ready' |
| 49 | + ``` |
| 50 | + |
| 51 | + - **Linux**: We need a robust cross-platform script! Feel free to [open an issue](https://github.com/S1M0N38/balatrobot/issues/new) and contribute a Linux-compatible version. |
| 52 | + |
| 53 | + - **Windows**: Development on Windows is not currently supported. |
| 54 | + |
| 55 | +!!! Tip |
| 56 | + |
| 57 | + Right now I'm using this [`balatro.sh`](https://gist.github.com/S1M0N38/4653c532bf048474100df3a270822bb4) script to start balatro with mods. |
| 58 | +
|
| 59 | +4. **Verify Game Setup** |
| 60 | +
|
| 61 | + ```bash |
| 62 | + # Check if Balatro is running |
| 63 | + ps aux | grep -E "(Balatro\.app|balatro\.sh)" | grep -v grep |
| 64 | +
|
| 65 | + # Monitor startup logs |
| 66 | + tail -n 100 balatro.log |
| 67 | + ``` |
| 68 | +
|
| 69 | + Look for these success indicators: |
| 70 | +
|
| 71 | + - "BalatrobotAPI initialized" |
| 72 | + - "BalatroBot loaded - version X.X.X" |
| 73 | + - "TCP socket created on port 12346" |
| 74 | +
|
| 75 | +
|
| 76 | +## How to Contribute |
| 77 | +
|
| 78 | +### Types of Contributions Welcome |
| 79 | +
|
| 80 | +- **Bug Fixes**: Issues tracked in our GitHub project |
| 81 | +- **Feature Development**: New bot strategies, API enhancements |
| 82 | +- **Performance Improvements**: Optimization of TCP communication or game interaction |
| 83 | +- **Documentation**: Improvements to guides, API documentation, or examples |
| 84 | +- **Testing**: Additional test coverage, edge case handling |
| 85 | +
|
| 86 | +### Contribution Workflow |
| 87 | +
|
| 88 | +1. **Check Issues First** (Highly Encouraged) |
| 89 | +
|
| 90 | + - Browse the [BalatroBot GitHub Project](https://github.com/users/S1M0N38/projects/7) |
| 91 | + - Comment on issues you'd like to work on |
| 92 | + - Create new issues for bugs or feature requests |
| 93 | + |
| 94 | +2. **Fork & Branch** |
| 95 | + |
| 96 | + ```bash |
| 97 | + git checkout -b feature/your-feature-name |
| 98 | + # or |
| 99 | + git checkout -b fix/issue-description |
| 100 | + ``` |
| 101 | + |
| 102 | +3. **Make Changes** |
| 103 | + |
| 104 | + - Follow our code style guidelines (see below) |
| 105 | + - Add tests for new functionality |
| 106 | + - Update documentation as needed |
| 107 | + |
| 108 | +4. **Create Pull Request** |
| 109 | + |
| 110 | + - **Important**: Enable "Allow edits from maintainers" when creating your PR |
| 111 | + - Link to related issues |
| 112 | + - Provide clear description of changes |
| 113 | + - Include testing instructions |
| 114 | + |
| 115 | +### Commit Messages |
| 116 | + |
| 117 | +We highly encourage following [Conventional Commits](https://www.conventionalcommits.org/) format: |
| 118 | + |
| 119 | +``` |
| 120 | +feat(api): add new game state detection |
| 121 | +fix(tcp): resolve connection timeout issues |
| 122 | +docs(readme): update setup instructions |
| 123 | +test(api): add shop booster validation tests |
| 124 | +``` |
| 125 | +
|
| 126 | +## Development & Testing |
| 127 | +
|
| 128 | +### Code Quality Tools |
| 129 | +
|
| 130 | +```bash |
| 131 | +# Python linting and formatting |
| 132 | +ruff check . |
| 133 | +ruff check --select I --fix . |
| 134 | +ruff format . |
| 135 | +
|
| 136 | +# Markdown formatting (docs and specific files) |
| 137 | +mdformat --number docs/index.md docs/installation.md docs/developing-bots.md docs/protocol-api.md CONTRIBUTING.md README.md |
| 138 | +
|
| 139 | +# Type checking |
| 140 | +basedpyright |
| 141 | +``` |
| 142 | + |
| 143 | +### Testing Requirements |
| 144 | + |
| 145 | +**⚠️ Important**: All tests require Balatro to be running in the background. |
| 146 | + |
| 147 | +```bash |
| 148 | +# Start Balatro first |
| 149 | +./balatro.sh > balatro.log 2>&1 & sleep 10 |
| 150 | + |
| 151 | +# Run all tests (stops on first failure) |
| 152 | +pytest -x |
| 153 | + |
| 154 | +# Run specific test file |
| 155 | +pytest -x tests/test_api_functions.py |
| 156 | + |
| 157 | +# Run with verbose output |
| 158 | +pytest -vx |
| 159 | +``` |
| 160 | + |
| 161 | +**Test Suite Overview**: |
| 162 | + |
| 163 | +- 55 tests covering API functions and TCP communication |
| 164 | +- ~160 seconds execution time |
| 165 | +- Tests game state transitions, socket communication, error handling |
| 166 | + |
| 167 | +**Troubleshooting Test Failures**: |
| 168 | + |
| 169 | +- **Connection timeouts**: Ensure TCP port 12346 is available |
| 170 | +- **Game state errors**: Verify game is responsive and hasn't crashed |
| 171 | +- **Invalid responses**: Check mod loaded correctly in `balatro.log` |
| 172 | +- **Balatro crashes**: Stop testing immediately, investigate crash logs, restart game before retrying |
| 173 | + |
| 174 | +### Documentation |
| 175 | + |
| 176 | +```bash |
| 177 | +# Serve documentation locally |
| 178 | +mkdocs serve |
| 179 | + |
| 180 | +# Build documentation |
| 181 | +mkdocs build |
| 182 | +``` |
| 183 | + |
| 184 | +## Technical Guidelines |
| 185 | + |
| 186 | +### Python Development |
| 187 | + |
| 188 | +- **Style**: Follow modern Python 3.12+ patterns |
| 189 | +- **Type Hints**: Use pipe operator for unions (`str | int | None`) |
| 190 | +- **Type Aliases**: Use `type` statement |
| 191 | +- **Docstrings**: Google-style without type information (types in annotations) |
| 192 | +- **Generics**: Modern syntax (`class Container[T]:`) |
| 193 | + |
| 194 | +### Lua Development |
| 195 | + |
| 196 | +- **Focus Area**: Primary development is on `src/lua/api.lua` |
| 197 | +- **Communication**: TCP protocol on port 12346 |
| 198 | +- **Protocol**: Bot sends "HELLO" → Game responds with JSON state → Bot sends actions |
| 199 | +- **Debugging**: Use DebugPlus mod for enhanced debugging capabilities |
| 200 | + |
| 201 | +### Architecture Context |
| 202 | + |
| 203 | +The project consists of: |
| 204 | + |
| 205 | +- **Lua API** (`src/lua/api.lua`): Game-side mod handling socket communication |
| 206 | +- **Python Framework** (`src/balatrobot/`): Bot development framework (being refactored) |
| 207 | +- **TCP Communication**: Real-time bidirectional communication |
| 208 | +- **Testing Suite**: Comprehensive API and integration tests |
| 209 | + |
| 210 | +## Communication & Community |
| 211 | + |
| 212 | +### Preferred Channels |
| 213 | + |
| 214 | +- **GitHub Issues**: Primary communication for bugs, features, and project coordination |
| 215 | +- **Discord**: Join us at the [Balatro Discord](https://discord.com/channels/1116389027176787968/1391371948629426316) for real-time discussions |
| 216 | + |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +## Questions? |
| 221 | + |
| 222 | +- Check the [GitHub Project](https://github.com/users/S1M0N38/projects/7) for current priorities |
| 223 | +- [Open an issue](https://github.com/S1M0N38/balatrobot/issues/new) for bugs or questions |
| 224 | +- Join the [Discord discussion](https://discord.com/channels/1116389027176787968/1391371948629426316) |
| 225 | + |
| 226 | +Happy contributing! |
| 227 | + |
0 commit comments