* ScreenMap Export Function * Exports screenMap data as JSON string with size information * Returns malloc'd buffer that must be freed with freeFrameData() */
| 89 | * Returns malloc'd buffer that must be freed with freeFrameData() |
| 90 | */ |
| 91 | EMSCRIPTEN_KEEPALIVE void* getScreenMapData(int* dataSize) { |
| 92 | fl::ActiveStripData& active_strips = fl::ActiveStripData::Instance(); |
| 93 | const auto& screenMaps = active_strips.getScreenMaps(); |
| 94 | |
| 95 | // Create dictionary of screenmaps (stripId → screenmap object) |
| 96 | // Same format as _jsSetCanvasSize() to match JavaScript expectations |
| 97 | fl::json root = fl::json::object(); |
| 98 | |
| 99 | // Build a separate screenmap object for each strip |
| 100 | for (const auto &[stripIndex, screenMap] : screenMaps) { |
| 101 | // Create this strip's screenmap object |
| 102 | fl::json screenMapObj = fl::json::object(); |
| 103 | |
| 104 | // Create strips object containing only this strip |
| 105 | fl::json stripsObj = fl::json::object(); |
| 106 | fl::json stripMapObj = fl::json::object(); |
| 107 | |
| 108 | fl::json mapObj = fl::json::object(); |
| 109 | fl::json xArray = fl::json::array(); |
| 110 | fl::json yArray = fl::json::array(); |
| 111 | |
| 112 | for (fl::u32 i = 0; i < screenMap.getLength(); i++) { |
| 113 | float x = screenMap[i].x; |
| 114 | float y = screenMap[i].y; |
| 115 | |
| 116 | xArray.push_back(fl::json(x)); |
| 117 | yArray.push_back(fl::json(y)); |
| 118 | } |
| 119 | |
| 120 | mapObj.set("x", xArray); |
| 121 | mapObj.set("y", yArray); |
| 122 | stripMapObj.set("map", mapObj); |
| 123 | |
| 124 | // Add diameter |
| 125 | stripMapObj.set("diameter", screenMap.getDiameter()); |
| 126 | |
| 127 | // Add this strip to the strips object |
| 128 | stripsObj.set(fl::to_string(stripIndex), stripMapObj); |
| 129 | |
| 130 | // Set strips object |
| 131 | screenMapObj.set("strips", stripsObj); |
| 132 | |
| 133 | // Add this screenmap to the root dictionary |
| 134 | root.set(fl::to_string(stripIndex), screenMapObj); |
| 135 | } |
| 136 | |
| 137 | // Serialize to JSON |
| 138 | fl::string json_str = root.to_string(); |
| 139 | |
| 140 | // Allocate and return data pointer |
| 141 | char* buffer = (char*)fl::malloc(json_str.length() + 1); |
| 142 | fl::strcpy(buffer, json_str.c_str()); |
| 143 | *dataSize = json_str.length(); |
| 144 | |
| 145 | return buffer; |
| 146 | } |
| 147 | |
| 148 | /** |
nothing calls this directly
no test coverage detected