Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePotatoArchivist committed May 31, 2024
1 parent d35a262 commit 227689b
Show file tree
Hide file tree
Showing 33 changed files with 716 additions and 517 deletions.
84 changes: 42 additions & 42 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
name: Deploy Vite to Github Pages

on:
push:
branches: [ "main" ]
push:
branches: ['main']

workflow_dispatch:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: 'npm'
- run: npm ci
- name: Build app
run: npm run build
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
# Path of the directory containing the static assets.
path: dist
deploy:
runs-on: ubuntu-latest
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
cache: 'npm'

- run: npm ci

- name: Build app
run: npm run build

- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
# Path of the directory containing the static assets.
path: dist

deploy:
runs-on: ubuntu-latest
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 1 addition & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
"singleAttributePerLine": false,
"semi": false,
"plugins": ["prettier-plugin-svelte", "prettier-plugin-organize-imports"],
"overrides": [
{ "files": "*.svelte", "options": { "parser": "svelte" } }
]
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["svelte.svelte-vscode"]
"recommendations": ["svelte.svelte-vscode"]
}
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/super-ttt.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Super Tic Tac Toe</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/super-ttt.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Super Tic Tac Toe</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
93 changes: 60 additions & 33 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,63 +1,85 @@
<script lang="ts">
import { fade } from 'svelte/transition';
import Game from './Game.svelte';
import IdDialog from './IdDialog.svelte';
import NetworkGame from './NetworkGame.svelte';
import { highContrast, themeSetting, themeState } from './lib/theme';
import Sidebar from './Sidebar.svelte';
import ConnectionButton from './ConnectionButton.svelte';
import { fade } from 'svelte/transition'
import Game from './Game.svelte'
import IdDialog from './IdDialog.svelte'
import NetworkGame from './NetworkGame.svelte'
import { highContrast, themeSetting, themeState } from './lib/theme'
import Sidebar from './Sidebar.svelte'
import ConnectionButton from './ConnectionButton.svelte'
const joinId = new URLSearchParams(window.location.search).get('join')
let gameType: 'single' | 'host' | 'client' | undefined = joinId ? 'client' : undefined;
let id = joinId || '';
let inviteDialog: ConnectionButton | undefined;
let idDialog: IdDialog | undefined;
let connected: boolean = false;
let gameType: 'single' | 'host' | 'client' | undefined = joinId
? 'client'
: undefined
let id = joinId || ''
let inviteDialog: ConnectionButton | undefined
let idDialog: IdDialog | undefined
let connected: boolean = false
function genBaseId() {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return [...new Array(4).keys()].map(() => letters[Math.floor(letters.length * Math.random())]).join('')
return [...new Array(4).keys()]
.map(() => letters[Math.floor(letters.length * Math.random())])
.join('')
}
function createLink(id: string) {
return `${window.location.origin}${window.location.pathname}?join=${id}`
}
function host() {
gameType = 'host'
id = genBaseId()
}
function exit() {
gameType = undefined;
id = '';
connected = false;
window.history.replaceState({}, '', `${window.location.origin}${window.location.pathname}`)
gameType = undefined
id = ''
connected = false
window.history.replaceState(
{},
'',
`${window.location.origin}${window.location.pathname}`
)
}
$: document.body.classList.toggle('light', $themeState === 'light')
$: document.body.classList.toggle('high-contrast', $highContrast)
</script>

<main>
{#if gameType === 'client' && !id}
<section class="screen" in:fade={{delay: 401}} out:fade on:introend={() => idDialog?.focus()}>
<IdDialog on:submit={event => id = event.detail} on:cancel={() => gameType = undefined} bind:this={idDialog} />
<section
class="screen"
in:fade={{ delay: 401 }}
out:fade
on:introend={() => idDialog?.focus()}>
<IdDialog
on:submit={event => (id = event.detail)}
on:cancel={() => (gameType = undefined)}
bind:this={idDialog} />
</section>
{:else if gameType === undefined}
<section class="screen menu" in:fade={{delay: 401}} out:fade>
<section class="screen menu" in:fade={{ delay: 401 }} out:fade>
<h1>Super Tic Tac Toe</h1>
<h2>Start Game</h2>
<button on:click={() => gameType = 'single'}>Single Device</button>
<button on:click={() => (gameType = 'single')}
>Single Device</button>
<button on:click={host}>Host</button>
<button on:click={() => gameType = 'client'}>Join</button>
<button on:click={() => (gameType = 'client')}>Join</button>

<Sidebar noExit />
</section>
{:else}
<section class="screen" in:fade={{delay: 401}} out:fade on:introend={() => {if (gameType === 'host') inviteDialog?.open()}}>
<section
class="screen"
in:fade={{ delay: 401 }}
out:fade
on:introend={() => {
if (gameType === 'host') inviteDialog?.open()
}}>
{#if gameType === 'single'}
<Game />
{:else if gameType === 'host'}
Expand All @@ -67,7 +89,12 @@
{/if}
<Sidebar on:exit={exit}>
{#if gameType !== 'single'}
<ConnectionButton {id} link={createLink(id)} {connected} host={gameType === 'host'} bind:this={inviteDialog} />
<ConnectionButton
{id}
link={createLink(id)}
{connected}
host={gameType === 'host'}
bind:this={inviteDialog} />
{/if}
</Sidebar>
</section>
Expand All @@ -85,17 +112,17 @@
grid-auto-flow: row;
gap: 1em;
}
button {
justify-content: center;
font-size: 1.5em;
}
h2 {
font-size: 2em;
margin: 0.5em 0;
}
h1 {
font-size: 2.5em;
margin: 0.5em 0;
Expand Down
Loading

0 comments on commit 227689b

Please sign in to comment.