feat: polish game HUD scoring and results
This commit is contained in:
@@ -4,7 +4,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { z } from "zod";
|
||||
|
||||
const UNITY_BRIDGE_URL = (process.env.UNITY_BRIDGE_URL || "http://127.0.0.1:19744").replace(/\/$/, "");
|
||||
const EXPLICIT_UNITY_BRIDGE_URL = process.env.UNITY_BRIDGE_URL;
|
||||
let unityBridgeUrl = (EXPLICIT_UNITY_BRIDGE_URL || "http://127.0.0.1:19744").replace(/\/$/, "");
|
||||
|
||||
const server = new McpServer({
|
||||
name: "vrbeats-unity",
|
||||
@@ -24,13 +25,7 @@ function textResult(value) {
|
||||
}
|
||||
|
||||
async function callUnity(path, options = {}) {
|
||||
const response = await fetch(`${UNITY_BRIDGE_URL}${path}`, {
|
||||
method: options.method || "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||
});
|
||||
const response = await fetchUnity(path, options);
|
||||
|
||||
const rawText = await response.text();
|
||||
let parsed;
|
||||
@@ -49,6 +44,40 @@ async function callUnity(path, options = {}) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
async function fetchUnity(path, options = {}) {
|
||||
const urls = [unityBridgeUrl];
|
||||
|
||||
if (!EXPLICIT_UNITY_BRIDGE_URL) {
|
||||
for (let port = 19744; port <= 19748; port += 1) {
|
||||
const url = `http://127.0.0.1:${port}`;
|
||||
if (!urls.includes(url)) {
|
||||
urls.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let lastError;
|
||||
|
||||
for (const url of urls) {
|
||||
try {
|
||||
const response = await fetch(`${url}${path}`, {
|
||||
method: options.method || "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||
});
|
||||
|
||||
unityBridgeUrl = url;
|
||||
return response;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError;
|
||||
}
|
||||
|
||||
function queryString(params) {
|
||||
const query = new URLSearchParams();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user