MistWarp GUI Internals
This section provides comprehensive documentation of MistWarp's GUI architecture, internal systems, and component structure. Whether you're contributing to MistWarp, building addons, or creating custom modifications, this guide will give you deep insight into how everything works.
Architecture Overview
MistWarp's GUI follows a modern React-based architecture with several key layers:
┌─────────────────────────────────────────────┐
│ React App │
├─────────────────────────────────────────────┤
│ Redux Store │
│ (State Management) │
├─────────────────────────────────────────────┤
│ HOCs & Containers │
│ (Data Flow & Side Effects) │
├─────────────────────────────────────────────┤
│ React Components │
│ (UI & Presentation) │
├─────────────────────────────────────────────┤
│ Addon System │
│ (Extension & Customization) │
├─────────────────────────────────────────────┤
│ Theme Engine │
│ (Styling & Theming) │
└─────────────────────────────────────────────┘
Core Packages
Primary Repositories
- scratch-gui - Main GUI implementation
- scratch-vm - Virtual machine and runtime
- scratch-render - Rendering engine
- scratch-blocks - Visual block editor
- scratch-paint - Costume/backdrop editor
Package Dependencies
graph TD
A[scratch-gui] --> B[scratch-vm]
A --> C[scratch-render]
A --> D[scratch-blocks]
A --> E[scratch-paint]
A --> F[scratch-audio]
B --> C
B --> G[scratch-parser]
D --> H[scratch-svg-renderer]
File Structure
scratch-gui/
├── src/
│ ├── components/ # React UI components
│ ├── containers/ # Redux-connected containers
│ ├── lib/ # Utility libraries
│ ├── reducers/ # Redux reducers
│ ├── addons/ # Addon system
│ ├── css/ # Global styles
│ └── index.js # Entry point
├── static/ # Static assets
├── test/ # Test files
└── webpack.config.js # Build configuration
Key Concepts
Component Hierarchy
The GUI follows a clear component hierarchy:
- App Container - Root application wrapper
- GUI Component - Main interface layout
- Feature Containers - Blocks, Stage, Sprites, etc.
- UI Components - Buttons, modals, menus, etc.
- Addon Components - Enhanced functionality
State Management
MistWarp uses Redux for centralized state management:
- Project State - Current project, loading status
- Editor State - Active tab, selected sprite
- UI State - Modal visibility, settings
- VM State - Runtime information
- Addon State - Addon configurations
Data Flow
User Action → Component → Container → Action → Reducer → Store → Component
Event System
Components communicate through:
- Redux Actions - State changes
- VM Events - Runtime events
- Addon Hooks - Extension points
- DOM Events - User interactions
Major Systems
Core Components
The fundamental UI building blocks including the main GUI component, blocks editor, stage, and sprite management.
Containers & HOCs
Redux-connected containers and Higher-Order Components that manage data flow and side effects.
State Management
Comprehensive Redux store setup, reducers, actions, and middleware for managing application state.
Addon System
Powerful extension system allowing custom functionality, UI modifications, and behavior changes.
Theming & Styling
Dynamic theming system with CSS variables, custom themes, and appearance customization.
Performance & Optimization
Performance monitoring, optimization techniques, and debugging tools.
Development Patterns
Component Design
MistWarp components follow these patterns:
// Functional component with hooks
const MyComponent = ({ prop1, prop2 }) => {
const [state, setState] = useState(initialState);
useEffect(() => {
// Side effects
}, [dependencies]);
return (
<div className={styles.container}>
{/* JSX content */}
</div>
);
};
// Connected container
const MyContainer = connect(
mapStateToProps,
mapDispatchToProps
)(MyComponent);
State Management Patterns
// Action creator
const updateSetting = (key, value) => ({
type: 'UPDATE_SETTING',
key,
value
});
// Reducer
const settingsReducer = (state = initialState, action) => {
switch (action.type) {
case 'UPDATE_SETTING':
return {
...state,
[action.key]: action.value
};
default:
return state;
}
};
Addon Integration
// Addon API usage
export default class MyAddon {
onEnable() {
this.addButton();
this.addCSS();
}
addButton() {
const button = document.createElement('button');
this.addon.tab.appendToSharedSpace({
space: 'stageHeader',
element: button,
order: 1
});
}
}
Build System
Webpack Configuration
MistWarp uses a sophisticated Webpack setup:
- Development Server - Hot reloading, source maps
- Production Build - Minification, optimization
- Addon Processing - Dynamic addon loading
- Asset Management - Images, fonts, CSS
Key Build Features
- Code Splitting - Reduced bundle sizes
- Tree Shaking - Dead code elimination
- Hot Module Replacement - Fast development
- CSS Processing - PostCSS, autoprefixing
- SVG Optimization - Compressed vector graphics
Testing Strategy
Test Types
- Unit Tests - Individual component testing
- Integration Tests - Component interaction testing
- E2E Tests - Full user workflow testing
- Performance Tests - Render and runtime performance
Testing Tools
- Jest - Test runner and assertions
- React Testing Library - Component testing
- Puppeteer - E2E testing
- Lighthouse - Performance auditing
Debugging Tools
Built-in Debugging
- Redux DevTools - State inspection
- React DevTools - Component tree inspection
- Performance Profiler - Runtime performance analysis
- Addon Developer Tools - Addon debugging utilities
Development Helpers
// Debug utilities
window.vm // Access to VM instance
window.reduxStore // Access to Redux store
window.scratchGui // GUI utilities
window.addons // Addon system access
Contributing Guidelines
Code Standards
- ESLint - Code quality enforcement
- Prettier - Code formatting
- JSDoc - Documentation comments
- PropTypes - Component prop validation
Git Workflow
- Fork repository
- Create feature branch
- Make changes with tests
- Submit pull request
- Pass CI checks
- Code review process
Getting Started with Internals
For Addon Developers
Start with Addon System Overview to understand how to extend MistWarp's functionality.
For Contributors
Begin with Architecture Guide to understand the overall system design.
For Theme Developers
Explore Theming System to learn about customizing MistWarp's appearance.
For Performance Engineers
Learn optimization techniques and monitoring tools for improving MistWarp performance.
This documentation is continuously updated as MistWarp evolves. For the latest information, always refer to the source code and Git history.