This document outlines the recommended folder structure and code organization for the ScheduleLua framework, aligned with the game's architecture.
ScheduleLua/
├── API/ # API modules
│ ├── Core/ # Core game systems
│ │ ├── GameManagerAPI.cs # Game state and management
│ │ ├── TimeAPI.cs # Time and scheduling
│ │ └── SaveAPI.cs # Save/load functionality
│ ├── Player/ # Player-related systems
│ │ ├── PlayerAPI.cs # Player state and actions
│ │ ├── InventoryAPI.cs # Player inventory
│ │ └── MovementAPI.cs # Player movement
│ ├── NPC/ # NPC-related systems
│ │ ├── NPCAPI.cs # NPC state and actions
│ │ ├── ScheduleAPI.cs # NPC scheduling
│ │ └── RelationshipAPI.cs # NPC relationships
│ ├── World/ # World-related systems
│ │ ├── MapAPI.cs # Map and locations
│ │ ├── BuildingAPI.cs # Buildings and interiors
│ │ └── WeatherAPI.cs # Weather and environment
│ ├── Economy/ # Economy-related systems
│ │ ├── MoneyAPI.cs # Money and transactions
│ │ ├── ShopAPI.cs # Shops and trading
│ │ └── ProductAPI.cs # Products and items
│ └── UI/ # UI-related systems
│ ├── UIManagerAPI.cs # UI management
│ ├── MenuAPI.cs # Menu interactions
│ └── HUDAPI.cs # HUD elements
├── Core/ # Core framework components
│ ├── LuaManager.cs # Core script loader and manager
│ ├── EventManager.cs # Event handling system
│ ├── ConfigManager.cs # Configuration management
│ └── CommandHandler.cs # Command processing
├── Utils/ # Utility classes
│ ├── Extensions.cs # Extension methods
│ ├── LuaConverter.cs # Conversion between C# and Lua types
│ └── PerformanceMonitor.cs # Performance tracking
├── Scripting/ # Scripting infrastructure
│ ├── LuaScript.cs # Script representation
│ ├── LuaEnvironment.cs # Lua environment setup
│ └── HotReload.cs # Hot reload functionality
├── Resources/ # Embedded resources
│ ├── DefaultScripts/ # Default script templates
│ └── Documentation/ # Embedded documentation
└── Examples/ # Example scripts and implementations
├── BasicExample.cs # Simple example of usage
└── AdvancedExample.cs # More complex example
The API layer is organized to match the game's subsystems:
-
Core Systems
- Game state management
- Time and scheduling
- Save/load functionality
-
Player Systems
- Player state and actions
- Inventory management
- Movement and interaction
-
NPC Systems
- NPC state and behavior
- Scheduling and routines
- Relationship management
-
World Systems
- Map and location data
- Building management
- Weather and environment
-
Economy Systems
- Money and transactions
- Shop and trading
- Product management
-
UI Systems
- UI management
- Menu interactions
- HUD elements
- LuaManager: Central manager for script loading, unloading, and management
- EventManager: Handles event registration, triggering, and clean-up
- ConfigManager: Manages configuration settings via MelonPreferences
- CommandHandler: Processes in-game commands and routes them to scripts
- LuaScript: Represents a loaded Lua script with lifecycle methods
- LuaEnvironment: Sets up the Lua environment with sandboxing and protection
- HotReload: Handles file watching and script reloading
- Namespace Organization: Each API module should use the same namespace structure as the game
- Singleton Access: Use the game's singleton pattern for accessing managers
- Event Integration: Hook into the game's event system for notifications
- Error Handling: Implement comprehensive error handling and logging
- Performance: Optimize for performance, especially in frequently called methods
To migrate from the current implementation to this structure:
- Create the new folder structure
- Split LuaAPI.cs into the respective API modules
- Update references throughout the codebase
- Implement new functionality in the appropriate modules
- Update documentation
When adding a new API area:
- Create a new file in the appropriate API folder
- Follow the existing naming and method patterns
- Register the new methods in LuaManager
- Document the new methods in the API reference
- Add examples demonstrating the new functionality