erArk CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
erArk is an R18 adult game focused on Arknights characters, developed in Python. The game is a text-based simulation with character interactions, events, and various gameplay systems.
Core Development Commands
Running the Game
python game.py
Building Game Data
Before running the game, you need to build the configuration data:
python buildconfig.py # Build CSV configurations and JSON data
python buildpo.py # Build localization PO files
python buildmo.py # Build MO files from PO files
Dependencies Installation
pip install -r requirements.txt
Testing Individual Components
The game uses a debug mode (configured in config.ini) for testing. Set debug = 1 to enable debug features.
High-Level Architecture
Core Game Flow
- Entry Point:
game.py- Initializes the game, loads configurations, and starts either GUI or Web mode - Game Initialization:
Script/Core/game_init.py- Sets up the game environment, styles, and main flow - Main Frame Loop:
Script/Design/start_flow.py- Contains UI handling and panel management - Main Behavior Loop:
Script/Design/character_behavior.py- The actual game simulation loop
Key Systems
Configuration System
- CSV Data: Game data is stored in CSV files under
data/csv/ - Build Process:
buildconfig.pyreads CSVs and generates:- JSON data files (
data/*.json) - Python config definitions (
Script/Config/config_def.py) - Localization PO files (
data/po/)
- JSON data files (
Character System
- Character Templates: Stored in
data/character/as CSV files - Character Management:
Script/Design/character.pyandcharacter_handle.py - Character Behaviors:
Script/Design/character_behavior.py - AI System:
Script/Design/handle_npc_ai.pyandhandle_npc_ai_in_h.py
Event System
- Event Data: JSON files in
data/event/ - Event Processing:
Script/Design/event.py - Talk System: CSV files in
data/talk/for character dialogues
UI System
- Flow Management:
Script/Core/flow_handle.py(GUI) andflow_handle_web.py(Web) - Drawing System:
Script/UI/Moudle/draw.pywith web adapters inScript/UI/web_draw_adapter.py - Panels: Various UI panels in
Script/UI/Panel/
Save System
- Save Management:
Script/Core/save_handle.py - Cache Control:
Script/Core/cache_control.pymanages game state
Web Mode
The game supports a web-based interface:
- Set
web_draw = 1inconfig.inito enable - Web server implementation in
Script/Core/web_server.py - Web IO adapter in
Script/Core/io_web.py
Code Guidelines
- Comments: All comments should be in Chinese
- Function Documentation: Every function must have Chinese comments describing:
- Input parameters and types
- Return values and types
- Function purpose
- Code Sections: Each code section should have comments explaining its purpose
- Code Style: Use Black formatter with line width 200
Key Configuration Files
config.ini: Main game configurationdata/data.json: Compiled game data from CSVsdata/Character.json: Character template datadata/Character_Talk.json: Character dialogue datadata/Character_Event.json: Character event data
Development Workflow
- Edit CSV files in
data/csv/,data/talk/, ordata/character/ - Run
python buildconfig.pyto rebuild game data - Run
python game.pyto test changes - For localization changes, run
python buildpo.pyandpython buildmo.py
Important Notes
- The game is in alpha stage with some features not yet implemented
- The game requires Sarasa Mono SC font for proper display
- Only Windows is officially supported
- Memory requirement: ~1GB peak usage, ensure 2GB free memory
Main Behavior Loop (character_behavior.init_character_behavior())
This is the core game loop that manages character behaviors and time progression:
1. Player Phase
- Player selects an action (instruction) through UI panels
- Action sets behavior ID, duration, and start time on player character
- Loop processes player behavior until completion (
0 not in cache.over_behavior_character) - Special handling for time stop mode - time is rolled back after player action
2. NPC Phase
- After player action completes, all NPCs in
cache.npc_id_gotare processed - Each NPC's behavior is calculated based on:
- Current state (tired, following, in H-mode, unconscious, etc.)
- AI decision making (
handle_npc_ai.find_character_target()) - Available actions and targets in their location
- NPCs continue their behaviors until all complete
3. Time Management
- Time progresses based on behavior durations
- Each character has
behavior.start_timeandbehavior.duration - When behavior completes, character enters idle state (
SHARE_BLANKLY) - New day triggers at midnight with
past_day_settle.update_new_day() - Player sleep triggers auto-save through
sleep_settle.update_save()
4. Behavior Processing (character_behavior())
For each character:
- Pre-behavior checks: tired/sleep, movement restrictions, assistant mode, follow mode, H-state
- Status settlement:
judge_character_status()handles events and numerical changes - Real-time updates:
realtime_settle.character_aotu_change_value()applies time-based changes - State persistence: Updates ongoing states and conditions
- Completion check:
judge_character_status_time_over()determines if behavior is finished - Talent acquisition: Automatic talent gains based on actions
5. Settlement System
- Behavior effects:
settle_behavior.handle_settle_behavior()calculates numerical changes - Event system: Events can trigger before or after instructions
- Change accumulation: All changes are tracked in
CharacterStatusChangeobjects - Display to player: Changes are formatted and shown after player actions
- Special handling: Group activities, hidden actions, and complex interactions
6. Key Variables
cache.over_behavior_character: Set of characters who completed their current behaviorcache.game_time: Current game timepl_start_time: Player's behavior start time (reference for NPC timing)cache.time_stop_mode: Special mode where time doesn't advance
7. Loop Exit Conditions
- All characters (player + NPCs) have completed their behaviors
- Time stop mode is active (only player acts, then loop breaks)
- Special events or state changes that interrupt normal flow
Drawing System - Two Rendering Modes
The game supports two rendering modes: Normal (Tkinter) and Web. The mode is determined by web_draw in config.ini.
Normal Drawing Mode (Tkinter)
When web_draw = 0, the game uses Tkinter for GUI rendering:
-
Drawing Classes (
Script/UI/Moudle/draw.py):NormalDraw: Basic text drawing with width constraintsCenterDraw: Center-aligned textRightDraw: Right-aligned textButton: Interactive button elementsFullDraw: Draw text without truncationWaitDraw: Draw text and wait for player inputLineFeedWaitDraw: Wait on each line break
-
IO Operations (
Script/Core/io_init.py):- Uses
main_framefrom Tkinter for display - Commands are handled through event queues
- Direct rendering to Tkinter text widgets
- Uses
-
Flow Control (
Script/Core/flow_handle.py):askfor_all(): Wait for player to select from optionsaskfor_wait(): Simple wait for player input- Direct event handling through Tkinter bindings
Web Drawing Mode
When web_draw = 1, the game runs as a web server:
-
Web Drawing Classes (
Script/UI/web_draw.py):WebDrawBase: Base class for web elementsWebNormalDraw: Text elements as HTMLWebButton: Interactive buttons as HTML- All drawing objects generate HTML element dictionaries
-
Drawing Adaptation (
Script/UI/web_draw_adapter.py):WebDrawAdapter: Converts Tkinter draw objects to web elements- Adapts all drawing types (normal, center, right, buttons, etc.)
- Elements stored in
cache.current_draw_elements
-
Web IO Operations (
Script/Core/io_web.py):era_print(): Converts text to HTML elementsclear_screen(): Clears element cache and updates web state- Commands handled through web API requests
- No direct rendering, all output buffered as HTML elements
-
Web Flow Control (
Script/Core/flow_handle_web.py):askfor_all(): Polls for web API responses- Updates game state through
update_game_state() - Asynchronous command handling via HTTP requests
Key Differences
-
Output Handling:
- Normal: Direct write to Tkinter widgets
- Web: Buffer HTML elements in
cache.current_draw_elements
-
Input Handling:
- Normal: Tkinter event bindings and queues
- Web: HTTP API polling and response handling
-
State Management:
- Normal: Immediate UI updates
- Web: Batch updates sent to client via
update_game_state()
-
Command Processing:
- Normal: Synchronous event handling
- Web: Asynchronous request/response cycle
Development Considerations
- All UI components should use the abstract drawing classes
- Avoid direct Tkinter or HTML manipulation
- Use
io_init.era_print()for all text output - Test both modes when making UI changes
- Web mode requires the web server running on port 5000
Data Processing Workflow Documentation
The .github/prompts/数据处理工作流 directory contains 47 detailed system documentation files. These documents explain the relationships between different systems and code components. When working on related features, refer to these documents for understanding system interconnections, dependencies, and data flow.
🏗️ Core System Architecture Documents
- 角色行为系统 - Core behavior loop, time management, status changes
- 结算系统 - Behavior settlement, numerical calculations, status updates
- 前提系统 - Condition verification for behaviors and events
- 口上系统 - Text and dialogue system
- 事件系统 - Story events and special trigger mechanisms
🔧 Technical & Tool Systems
- CSV数据加载机制说明 - CSV data loading and processing
- AI文本生成系统 - AI text generation functionality
- 存档系统 - Save system and cross-version compatibility
- 通用结算函数函数 - Universal calculation functions
- 多周目结算与继承系统 - Multi-playthrough data inheritance
- ArkEditor编辑器系统说明 - Built-in editor system
🎮 User Interface Systems
- 主场景互动界面 - Main scene interaction interface
- 指令面板系统 - Player instruction panels
- 通用NPC选择面板 - Universal NPC selection panels
- 系统设置系统 - System configuration interface
- 全干员位置面板 - All character position panel
- PRTS系统 - PRTS communication system
🗺️ Scene & Map Systems
👥 Character Creation & Growth
👗 Appearance & Decoration Systems
- 服装系统说明 - Clothing system details
- 衣柜检查功能 - Wardrobe inspection features
- 收藏品系统 - Collectible management
- 角色图片系统 - Character image resources
👨⚕️ Body Status Systems
- 身体信息面板系统 - Body information display
- 射精面板系统 - Ejaculation status panels
- 妊娠系统 - Pregnancy state management
🎯 Rhodes Island Department Systems
- 管理罗德岛系统 - Rhodes Island base management
- 助理系统 - Assistant character functions
- 基建系统 - Construction and building management
- 农业生产系统 - Agricultural production
- 工业生产系统 - Industrial production
- 资源交易系统 - Resource trading and markets
- 招募系统 - Character recruitment mechanisms
- 外勤委托系统 - External mission commissioning
- 邀请访客系统 - Visitor invitation system
- 势力外交系统 - Faction diplomacy
- 载具管理系统 - Vehicle management
- 读书系统 - Reading and learning functionality
- 身体检查与管理系统 - Body examination and health management
🛍️ Items & Equipment Systems
- 道具背包系统 - Item inventory management
- 礼物系统 - Gift giving and receiving
- 食物系统 - Food preparation and consumption
🌟 Originium Arts Systems
- 源石技艺系统 - Originium arts learning and management
- 时间停止系统 - Time stop special functionality
- 催眠系统 - Hypnosis functionality and mechanisms
🎭 Special H-Mode Systems
- 群交系统 - Group interaction functionality
- 监禁调教系统 - Confinement and training
- 睡眠系统 - Sleep state management
- 隐奸系统 - Hidden behavior system
Usage Guidelines
- Browse by Category: Select the appropriate category based on the system type you're working on
- System Dependencies: Many systems are interconnected - refer to related system documentation
- Document Structure: Each document typically contains system overview, core components, data structures, workflow explanations, configuration details, technical implementation, and extension guides