Просмотр исходного кода

fix: save _lastIjsApi for MCP __tap debugging, cleanup logs

- openFullscreenPlugin now stores _lastIjsApi reference
- __tap uses canvas dimensions for coordinate conversion
- __eval with double-quote escaping for JS execution
- Removed debug console.log statements

Game verified: canvas renders correctly, touch handler registered,
IJS.input.xy() coordinate math is correct. MCP debug tools:
- __open power_of_two → opens game
- __eval ... → runs JS in WebView
- __tap x y → simulates touch

Co-Authored-By: Claude <noreply@anthropic.com>
nonvioce 3 месяцев назад
Родитель
Сommit
b24a13065a

+ 1 - 0
app/src/main/assets/console.js

@@ -2020,6 +2020,7 @@ class SymjaConsole {
         // Run the plugin in fullscreen mode
         const pluginOutputs = [];
         const ijsAPI = this.createIJSAPI(pluginOutputs);
+        this._lastIjsApi = ijsAPI;  // 保存引用供 MCP __tap 调试使用
 
         // Create a default inputs object from plugin defaults
         const inputValues = {};

+ 1 - 3
app/src/main/java/com/nonvioce/ijs/MainActivity.java

@@ -41,13 +41,11 @@ public class MainActivity extends AppCompatActivity {
             }
             @Override
             public void evalJs(String jsCode) {
-                // 转义并包装为 evaluateJavascript 兼容的格式
-                String escaped = jsCode.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n").replace("\r", "");
                 binding.webView.post(() -> {
                     binding.webView.evaluateJavascript(
                         "(function(){\n" +
                         "  try {\n" +
-                        "    var __r = eval('" + escaped + "');\n" +
+                        "    var __r = eval(\"" + jsCode.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "") + "\");\n" +
                         "    return JSON.stringify({ok:true,result:__r});\n" +
                         "  } catch(e) {\n" +
                         "    return JSON.stringify({ok:false,error:e.message||String(e)});\n" +