mirror of
https://github.com/github/awesome-copilot.git
synced 2026-08-01 23:12:29 +00:00
c46b4a919a
* Add flight-map-canvas extension A canvas port of the Flight Map VSCode extension: a first-person satellite terrain map flown with flight simulator controls, for session breaks while an agent works. The simulator under game/ is copied verbatim from the source extension's media/ folder. That page already reached its host through one seam - an acquireVsCodeApi() object and a placeholder in its head - so extension.mjs fills that seam for the canvas: a loopback server that injects a policy, the render configuration, and a shim translating Server-Sent Events into the messages the page already handles. Two agent actions: fly_to sends the flight to a capital, a geocoded city, or a raw lat/lng, and picks a random capital when called with no input; report_job shows the current job step under the HUD. Adds the vendored three.min.js to the codespell skip list, matching the existing entry for arcade-canvas's phaser.min.js. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Apply suggestions from code review --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
/************************************************************************
|
|
* HostBridge - Thin abstraction over the VS Code webview messaging API. *
|
|
* *
|
|
* The simulator runs in two places: inside a VS Code webview panel and *
|
|
* as a plain page in a browser. Everything that needs the extension *
|
|
* host (config injection, saving renderMap.json) goes through here so *
|
|
* the rest of the code stays identical in both environments. *
|
|
* *
|
|
* In the browser the API is absent and every call degrades to a no-op, *
|
|
* leaving the original web behavior in place. *
|
|
***********************************************************************/
|
|
var HostBridge = (function () {
|
|
|
|
var api = null;
|
|
var handlers = {};
|
|
|
|
// acquireVsCodeApi exists only inside a webview, and may be called
|
|
// exactly once per page load
|
|
if (typeof acquireVsCodeApi === 'function') {
|
|
try {
|
|
api = acquireVsCodeApi();
|
|
} catch (e) {
|
|
api = null;
|
|
}
|
|
}
|
|
|
|
if (api) {
|
|
window.addEventListener('message', function (event) {
|
|
var message = event.data;
|
|
if (!message || !message.command) return;
|
|
var fn = handlers[message.command];
|
|
if (fn) fn(message);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* True when running inside the VS Code webview panel.
|
|
*/
|
|
function isHosted() {
|
|
return api !== null;
|
|
}
|
|
|
|
/**
|
|
* Send a message to the extension host. No-op in the browser.
|
|
*/
|
|
function post(message) {
|
|
if (api) api.postMessage(message);
|
|
}
|
|
|
|
/**
|
|
* Register a handler for a command sent by the extension host.
|
|
*/
|
|
function on(command, fn) {
|
|
handlers[command] = fn;
|
|
}
|
|
|
|
/**
|
|
* Render configuration injected by the extension host, or null when
|
|
* running as a standalone page.
|
|
*/
|
|
function getInjectedConfig() {
|
|
return (window.__flightMapConfig && typeof window.__flightMapConfig === 'object')
|
|
? window.__flightMapConfig
|
|
: null;
|
|
}
|
|
|
|
return {
|
|
isHosted: isHosted,
|
|
post: post,
|
|
on: on,
|
|
getInjectedConfig: getInjectedConfig
|
|
};
|
|
})();
|