┌─────────────────────────────────────────────────────────┐
│ Application Layer │
│ (UI Framework - React/Vue/Angular - To be implemented) │
└────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Command Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ File Commands│ │Thing Commands│ │Sprite Commands│ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Worker Communication Layer │
│ (WorkerCommunicator) │
└────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Background Processing Layer │
│ (ObjectBuilderWorker) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ File Operations │ Thing Operations │ Sprites│ │
│ └──────────────────────────────────────────────────┘ │
└────────────────────┬────────────────────────────────────┘
│
┌────────────┼────────────┐
▼ ▼ ▼
┌─────────────┐ ┌──────────┐ ┌──────────┐
│ThingStorage │ │SpriteStor│ │VersionStor│
└─────────────┘ └──────────┘ └──────────┘
main.ts
- Application initialization
- Settings loading
- Worker creation
- Lifecycle management
cli.ts
- Interactive command-line interface
- Command parsing and execution
- User interaction
Command Pattern Implementation
- Base:
WorkerCommand - File Commands:
LoadFilesCommand,CreateNewFilesCommand,CompileCommand, etc. - Thing Commands:
NewThingCommand,UpdateThingCommand,ImportThingsCommand, etc. - Sprite Commands:
NewSpriteCommand,ImportSpritesCommand,ExportSpritesCommand, etc.
WorkerCommunicator
- Command routing
- Event handling
- Async callback support
- Command registration
ObjectBuilderWorker
- Main processing logic
- File operations
- Thing operations
- Sprite operations
- Optimization operations
Key Callbacks:
- File:
createNewFilesCallback,loadFilesCallback,compileAsCallback - Thing:
newThingCallback,updateThingCallback,importThingsCallback - Sprite:
newSpriteCallback,addSpritesCallback,importSpritesFromFilesCallback
ThingTypeStorage
- Manages thing types (items, outfits, effects, missiles)
- Loads from
.datfiles - Compiles to
.datfiles - Version-specific metadata handling
SpriteStorage
- Manages sprite data
- Loads from
.sprfiles - Compiles to
.sprfiles - Sprite indexing and compression
VersionStorage
- Client version information
- XML-based storage
- Version detection
SpriteDimensionStorage
- Sprite dimension configurations
- XML-based storage
1. UI/CLI sends LoadFilesCommand
↓
2. WorkerCommunicator routes to ObjectBuilderWorker
↓
3. ObjectBuilderWorker.loadFilesCallback()
↓
4. ThingTypeStorage.load(datFile)
↓
5. SpriteStorage.load(sprFile)
↓
6. Events emitted for progress/completion
↓
7. Commands sent back to UI (SetClientInfoCommand, SetThingListCommand)
1. UI/CLI sends NewThingCommand
↓
2. WorkerCommunicator routes to ObjectBuilderWorker
↓
3. ObjectBuilderWorker.newThingCallback()
↓
4. ThingType.create() - Creates new ThingType
↓
5. ThingTypeStorage.addThing(thing)
↓
6. SetThingDataCommand sent to UI
1. UI/CLI sends CompileCommand
↓
2. ObjectBuilderWorker.compileCallback()
↓
3. ThingTypeStorage.compile(datFile)
↓
4. SpriteStorage.compile(sprFile)
↓
5. OTFI file saved (if needed)
↓
6. SetClientInfoCommand sent to UI
All major classes extend EventEmitter:
ObjectBuilderWorker- Emits progress and completion eventsThingTypeStorage- Emits storage eventsSpriteStorage- Emits storage eventsClientMerger- Emits merge progressSpritesOptimizer- Emits optimization progress
ProgressEvent- Progress updatesStorageEvent- Storage operationscomplete- Operation completionerror- Error events
Version Detection:
- Reads file signature
- Determines client version
- Selects appropriate metadata reader/writer
Metadata Readers:
MetadataReader1- Client version 1MetadataReader2- Client version 2MetadataReader3-6- Client versions 3-6
Metadata Writers:
MetadataWriter1-6- Corresponding writers
Sprite Reading:
- Reads sprite count
- Reads sprite data with compression
- Indexes sprites by ID
Sprite Writing:
- Writes sprite count
- Writes sprite data with compression
- Maintains sprite indices
Encoding:
- Serializes ThingData
- Compresses with LZMA
- Writes version header
Decoding:
- Reads version header
- Decompresses with LZMA
- Deserializes ThingData
1. Application startup
↓
2. SettingsManager.getInstance()
↓
3. SettingsManager.loadSettings(ObjectBuilderSettings)
↓
4. JSON file read from ~/.objectbuilder/settings/
↓
5. ObjectBuilderSettings.unserialize(data)
↓
6. SettingsCommand sent to worker
- Format: JSON (OTML support can be added)
- Location: OS-specific app data directory
- File:
ObjectBuilderSettings.otcfg
- Uses
canvaslibrary for Node.js - Provides Flash BitmapData-like API
- Supports pixel manipulation
- Channel operations
ImageCodecclass- Supports PNG, JPEG, BMP, GIF
- JPEG quality control
- Transparent background support
Operation → Try/Catch → Error Event → UI Command → User Notification
- File I/O errors
- Format errors
- Validation errors
- Storage errors
- File I/O is async
- Image processing uses async/await
- Progress events for long operations
- Large files processed in chunks
- Bitmap data disposed after use
- Event listeners cleaned up
- Create command class extending
WorkerCommand - Register in
ObjectBuilderWorker.register() - Implement callback method
- Add CLI command (optional)
- Implement
IStorageinterface - Extend
EventEmitter - Register in application initialization
- Create reader/writer classes
- Add format detection
- Integrate with storage classes
- Path validation
- Permission checks
- File existence checks
- Type checking
- Range validation
- Format validation
- React/Vue/Angular components
- State management
- Real-time updates
- Drag-and-drop support
- Unit tests
- Integration tests
- E2E tests
- Performance tests
- Worker threads for heavy operations
- Caching strategies
- Lazy loading
- Memory optimization