A complete rewrite of the Haven & Hearth Base Planner using React, TypeScript, and Object-Oriented principles.
The application follows SOLID principles with a clean separation of concerns:
- BuildableItem: Represents buildable items with image preloading
- PlacedItem: Represents items placed on the grid with collision detection
- GridManager: Manages the grid state and item placement logic
- PavingManager: Handles paving tiles and shape drawing (line, rectangle, circle)
- MeasurementTool: Provides measurement functionality
- CanvasRenderer: Encapsulates all canvas drawing operations
- types.ts: TypeScript type definitions
- DataService: Loads and filters buildable items and paving types
- ImageLoaderService: Handles asynchronous image preloading
- PersistenceService: Manages save/load and PNG export functionality
- App: Main application component
- Header: Top navigation with controls
- BuildablesSidebar: Searchable/filterable list of buildable items
- PavingSidebar: Paving selection and tools
- PlannerCanvas: Interactive canvas component
- InfoPanel: Displays selection info and action buttons
- useCanvas: Manages canvas rendering and managers
- useSelection: Handles selection state for buildables, placed items, and paving
cd react-app
npm installnpm run devThe app will open at http://localhost:5173
npm run build- ✅ Object-Oriented Design: Clean separation with classes for domain logic
- ✅ TypeScript: Full type safety across the application
- ✅ React Hooks: Custom hooks for state management
- ✅ Service Layer: Business logic separated from UI
- ✅ Canvas Rendering: Dedicated renderer class
- ✅ Image Preloading: Async loading with service
- ✅ Save/Load: JSON-based persistence
- ✅ PNG Export: Export canvas as image
- ✅ Measurement Tool: Measure distances on grid
- ✅ Paving Tools: Line, rectangle, and circle paving modes
- ✅ Drag & Place: Interactive item placement
- ✅ Rotation: Rotate placed items
- ✅ Collision Detection: Prevent overlapping items
- ✅ Search & Filter: Find items quickly by name or category
- Singleton Pattern: Services (DataService, PersistenceService, ImageLoaderService)
- Strategy Pattern: Shape drawing in PavingManager
- Observer Pattern: React's state management
- Factory Pattern: BuildableItem.createPlacedItem()
- Repository Pattern: DataService for data access
- Maintains grid size and placed items
- Validates item placement (bounds, collisions)
- Provides item manipulation methods (add, remove, move, rotate)
- Manages paving grid (Map-based storage)
- Implements shape algorithms (Bresenham's line, circle, rectangle)
- Handles paving placement and removal
- Encapsulates all canvas drawing operations
- Draws grid, paving, items, and measurements
- Converts mouse coordinates to grid coordinates
- Manages measurement state
- Calculates Euclidean and Manhattan distances
- Provides delta X/Y values
- Testability: Each class can be unit tested independently
- Maintainability: Clear responsibilities make changes easier
- Reusability: Models and services can be reused in other projects
- Type Safety: TypeScript prevents many runtime errors
- Separation of Concerns: UI logic separated from business logic
- Scalability: Easy to add new features without breaking existing code
The original vanilla JS implementation has been completely refactored:
- Global variables → Class-based state management
- Procedural code → Object-oriented classes
- Inline logic → Service layer
- Direct DOM manipulation → React components
- No types → Full TypeScript
src/data/buildables.json: 313 buildable itemssrc/data/paving.json: 90 paving types
Both files are imported and instantiated as proper class instances at runtime.