Skip to content

Commit

Permalink
Merge pull request #981 from hackclub/kognise/deprecated-file-player
Browse files Browse the repository at this point in the history
Add file player to fix khrj's workflow
  • Loading branch information
grymmy committed Mar 28, 2023
2 parents bbc4331 + 0e9bdaf commit 9918994
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/pages/deprecated-file-player.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
import '../global.css'
import StandardHead from '../components/standard-head.astro'
const file = Astro.url.searchParams.get('file') ?? ''
const codeRes = await fetch(file)
const code = await codeRes.text()
---

<html lang='en'>
<head>
<StandardHead title='(Deprecated) File Player' />
<style>
#screen-container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

#screen {
max-width: 100%;
max-height: 100%;
background: black;
}
</style>
</head>
<body>
<div id='screen-container'>
<canvas id='screen' width='1000' height='800' tabindex='-1' />
</div>

<script define:vars={{ code }}>
window.__sprig_intitial_code__ = code
</script>
<script>
import { runGame } from '../lib/engine/3-editor'

const screen = document.getElementById('screen') as HTMLCanvasElement
const { __sprig_intitial_code__ } = window as unknown as { __sprig_intitial_code__: string }

let runRes = runGame(__sprig_intitial_code__, screen, (_) => {})
if (runRes.error) console.error(runRes.error.raw)

const params = new URLSearchParams(window.location.search)
if (params.has('watch')) {
let oldCode = __sprig_intitial_code__
setInterval(async () => {
const codeRes = await fetch(params.get('file') || '')
const code = await codeRes.text()

if (oldCode !== code) {
oldCode = code
runRes.cleanup()
runRes = runGame(code, screen, (_) => {})
if (runRes.error) console.error(runRes.error.raw)
}
}, Number(params.get('watch') || 1000))
}
</script>
</body>
</html>

1 comment on commit 9918994

@vercel
Copy link

@vercel vercel bot commented on 9918994 Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sprig – ./

sprig-gamer.vercel.app
sprig.vercel.app
sprig-git-main-gamer.vercel.app

Please sign in to comment.