Example integration of WasmDropHandler with EditorManager.
This file demonstrates how to integrate the drag & drop ROM loading functionality into the main yaze application when building for WASM.
INTEGRATION STEPS:
- In your Controller or EditorManager initialization:
#ifdef __EMSCRIPTEN__
absl::Status InitializeWasmFeatures() {
auto& drop_handler = yaze::platform::WasmDropHandler::GetInstance();
return drop_handler.Initialize(
"",
[this](const std::string& filename, const std::vector<uint8_t>& data) {
HandleDroppedRom(filename, data);
},
[](const std::string& error) {
}
);
}
#define LOG_ERROR(category, format,...)
- Implement the ROM loading handler:
void HandleDroppedRom(const std::string& filename,
const std::vector<uint8_t>& data) {
auto rom = std::make_unique<Rom>();
auto status = rom->LoadFromData(data);
if (!status.ok()) {
toast_manager_.Show("Failed to load ROM: " + status.ToString(),
ToastType::kError);
return;
}
rom->set_filename(filename);
auto session_id = session_coordinator_->FindEmptySession();
if (session_id == -1) {
session_id = session_coordinator_->CreateNewSession();
}
session_coordinator_->SetSessionRom(session_id, std::move(rom));
session_coordinator_->SetCurrentSession(session_id);
LoadAssets();
ui_coordinator_->SetWelcomeScreenVisible(false);
ui_coordinator_->SetEditorSelectionVisible(true);
toast_manager_.Show("ROM loaded via drag & drop: " + filename,
ToastType::kSuccess);
}
- Optional: Customize the drop zone appearance:
drop_handler.SetOverlayText("Drop your A Link to the Past ROM here!");
- Optional: Enable/disable drop zone based on application state:
drop_handler.SetEnabled(false);
PerformRomOperation();
drop_handler.SetEnabled(true);
HTML INTEGRATION:
Include the CSS in your HTML file:
<link rel="stylesheet" href="drop_zone.css">
The JavaScript is automatically initialized when the Module is ready. You can also manually initialize it:
<script src="drop_zone.js"></script>
<script>
// Optional: Custom initialization after Module is ready
Module.onRuntimeInitialized = function() {
YazeDropZone.init({
config: {
maxFileSize: 8 * 1024 * 1024, // 8MB max
messages: {
dropHere: 'Drop SNES ROM here',
loading: 'Loading ROM...'
}
}
});
};
</script>
TESTING:
To test the drag & drop functionality:
- Build with Emscripten: cmake –preset wasm-dbg && cmake –build build_wasm
- Serve the files: python3 -m http.server 8000 -d build_wasm
- Open browser: http://localhost:8000/yaze.html
- Drag a .sfc/.smc ROM file onto the page
- The overlay should appear and the ROM should load
TROUBLESHOOTING:
- If overlay doesn't appear: Check browser console for errors
- If ROM doesn't load: Verify Rom::LoadFromData() implementation
- If styles are missing: Ensure drop_zone.css is included
- For debugging: Check Module._yazeHandleDroppedFile in console
Definition in file wasm_drop_integration_example.h.