A factory automation programming game where you write Python code to control robots and optimize production chains.
ReFactory is an idle programming game that teaches Python through interactive gameplay. Instead of traditional farming mechanics, you're programming a swarm of robots to automate an ever-expanding factory floor. Your code runs in real-time using Pyodide (Python in the browser), and you can see your functions execute as robots carry out your instructions.
- 🐍 Python Programming - Write real Python code that executes in your browser
- 📚 Interactive Tutorial - Learn through hands-on coding challenges with immediate feedback
- ⚡ Energy System - Optimize your code for efficiency - wasteful code drains power!
- 🤖 Real-time Execution - Watch your robots execute your code live on the factory floor
- 🎨 Isometric Factory View - Beautiful canvas-rendered factory with robots, resources, and machines
- 💾 Auto-save - Your progress is automatically saved to local storage
- 🎯 Progressive Gameplay - Start simple, unlock complex production chains and departments
Not looking to contribute? Just want to play and optimize to the top of the leaderboard? https://refactory-swart.vercel.app/
- Node.js (v18 or higher)
- npm or pnpm
# Clone the repository
git clone <repository-url>
cd refactory
# Install dependencies
npm install
# Start the development server
npm run devVisit http://localhost:5173 to start playing!
When you first launch the game, you'll go through an interactive tutorial that teaches you:
- Moving Robots - Use
robot.move_to(x, y)to position your robots - Finding Resources - Scan for nearby resources with
robot.get_nearby_resources(radius) - Collecting Resources - Pick up resources with
robot.pickup(resource) - Automation - Build loops and conditionals to automate production
Each robot has access to these functions:
# Movement
robot.move_to(x, y) # Move to coordinates (x, y)
robot.get_position() # Get current position
# Resources
robot.get_nearby_resources(radius) # Find resources within radius
robot.pickup(resource) # Pick up a resource
robot.get_inventory() # Check what you're carrying
# Machines
robot.get_nearby_machines(radius) # Find machines within radius
robot.dropoff(machine) # Drop resources at a machine
# Status
robot.get_status() # Returns: 'idle', 'moving', 'working', or 'error'
robot.get_energy() # Get robot's energy levelHere's a basic automation script:
# Get robot status
status = robot.get_status()
# Only act when idle
if status == "idle":
# Find nearby resources
resources = robot.get_nearby_resources(200)
# Check inventory
inventory = robot.get_inventory()
# If we found resources and aren't carrying anything
if len(resources) > 0 and inventory["type"] is None:
# Get the first resource
resource = resources[0]
# Move to it
robot.move_to(resource["position"]["x"], resource["position"]["y"])
# Pick it up
robot.pickup(resource)- Frontend: SvelteKit 5 (Runes mode)
- Python Runtime: Pyodide (Python in WebAssembly)
- Rendering: HTML5 Canvas
- State Management: Svelte 5 reactive stores
- Styling: Scoped CSS
refactory/
├── src/
│ ├── lib/
│ │ ├── components/ # Svelte components
│ │ │ ├── CodeEditor.svelte
│ │ │ ├── FactoryCanvas.svelte
│ │ │ ├── GameHUD.svelte
│ │ │ ├── GameControls.svelte
│ │ │ └── InteractiveTutorial.svelte
│ │ ├── engine/ # Game logic
│ │ │ ├── gameLoop.svelte.ts
│ │ │ ├── pythonExecutor.ts
│ │ │ ├── robotController.ts
│ │ │ └── machineController.ts
│ │ ├── stores/ # State management
│ │ │ └── gameState.svelte.ts
│ │ └── types/ # TypeScript types
│ │ └── game.ts
│ └── routes/ # SvelteKit routes
│ └── +page.svelte
├── static/ # Static assets
└── package.json
Every action costs energy:
- Function calls: 0.01 energy
- Movement: 0.1 energy per move command
- Picking up resources: 0.5 energy
- Dropping off resources: 0.5 energy
Energy regenerates slowly over time. Write efficient code to maximize productivity!
- Iron Ore ⚙️ - Basic metal resource
- Copper Ore 🟠 - Electrical component resource
- Circuit Boards 💾 - Advanced manufactured goods
idle- Ready for new commandsmoving- Traveling to target positionworking- Executing a taskerror- Something went wrong (check error message)
npm run buildnpm run previewnpm run checkFuture features planned:
- ✅ Python programming interface
- ✅ Interactive tutorial system
- ⬜ Multiple robot support
- ⬜ Machine crafting system
- ⬜ Department unlocks (Electronics, Textiles, Food Processing)
- ⬜ Profiler/heat map for code optimization
- ⬜ Multiplayer leaderboards
- ⬜ Code sharing via URL
- ⬜ Version control features (git-like)
- ⬜ Worker threads for parallel processing
- ⬜ PWA support for offline play
MIT
Contributions welcome! Please feel free to submit a Pull Request.
Built with ❤️ using SvelteKit and Python