Skip to content

Commit

Permalink
glcanvas for macroquad
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Oct 12, 2024
1 parent a0f925a commit 1ade555
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
41 changes: 28 additions & 13 deletions apps/api/app/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,35 @@ router.get("/game/:game_name/:game_version/iframe", async (ctx) => {
gameInfo?.viewer?.alternate?.url && ctx.query.alternate === "1" ? gameInfo?.viewer.alternate : gameInfo.viewer;
const viewerUrl = ctx.query.customViewerUrl || viewer.url;

ctx.body = `
<html>
<head>
<meta charset="UTF-8">
${viewer.dependencies.scripts.map((dep) => `<${"script"} src='${dep}'></${"script"}>`).join("\n")}
<${"script"} src='${viewerUrl}' type='text/javascript'> </${"script"}>
${viewer.dependencies.stylesheets
.map((dep) => `<link type='text/css' rel='stylesheet' href='${dep}'></link>`)
.join("\n")}
const stylesheets = viewer.dependencies.stylesheets
.map((dep) => `<link type='text/css' rel='stylesheet' href='${dep}'></link>`)
.join("\n");
const scripts = viewer.dependencies.scripts.map((dep) => `<${"script"} src='${dep}'></${"script"}>`).join("\n");
const viewerScript = `<${"script"} src='${viewerUrl}' type='text/javascript'></${"script"}>`;

const template = viewer.topLevelVariable === "clash" ? `
<head>
<meta charset="UTF-8">
${stylesheets}
</head>
<body>
<div id='app'>
</div>
</body>
<body>
<canvas id='glcanvas' style="margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; position: absolute; z-index: 0;"></canvas>
${scripts}
${viewerScript}
</body>` : `
<head>
<meta charset="UTF-8">
${scripts}
${viewerScript}
${stylesheets}
</head>
<body>
<div id='app'>
</div>
</body>`;

ctx.body = `
${template}
<${"script"} type='text/javascript'>
const gameObj = window.${viewer.topLevelVariable}.launch('#app');
window.addEventListener('message', event => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Game/StartedGame.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ ${$game.players.map((pl) => `- ${pl.name} (${pl.score} pts)`).join("\n")}`;
{#key gameId}
<iframe
bind:this={gameIframe}
allow="cross-origin-isolated"
allow="cross-origin-isolated fullscreen"
credentialless
id="game-iframe"
title="Game UX"
sandbox="allow-scripts allow-same-origin"
sandbox="allow-scripts allow-same-origin allow-orientation-lock"
class:d-none={!stateSent}
class:fullScreen={$gameInfo.viewer?.fullScreen}
{src}
Expand Down

0 comments on commit 1ade555

Please sign in to comment.