initial commit

This commit is contained in:
Jose Conde 2024-06-29 16:40:11 +02:00
commit 2ac728fe02
108 changed files with 7630 additions and 0 deletions

15
.eslintrc.cjs Normal file
View File

@ -0,0 +1,15 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}

31
.gitignore vendored Normal file
View File

@ -0,0 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo
.history

8
.prettierrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}

45
README.md Normal file
View File

@ -0,0 +1,45 @@
# domino-client
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Type Support for `.vue` Imports in TS
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Type-Check, Compile and Minify for Production
```sh
npm run build
```
### Run Unit Tests with [Vitest](https://vitest.dev/)
```sh
npm run test:unit
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```

1
env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

19
index.html Normal file
View File

@ -0,0 +1,19 @@
<!doctype html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.grey.min.css"
/>
<title>XXX App</title>
</head>
<body>
<main class="container">
<div id="app"></div>
</main>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

5700
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

45
package.json Normal file
View File

@ -0,0 +1,45 @@
{
"name": "domino-client",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"test:unit": "vitest",
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"pinia": "^2.1.7",
"pixi.js": "^8.2.1",
"socket.io-client": "^4.7.5",
"vue": "^3.4.29",
"vue-router": "^4.3.3",
"vue3-pixi": "^0.9.3"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.8.0",
"@tsconfig/node20": "^20.1.4",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.14.5",
"@vitejs/plugin-vue": "^5.0.5",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.5.1",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.23.0",
"jsdom": "^24.1.0",
"npm-run-all2": "^6.2.0",
"prettier": "^3.2.5",
"sass": "^1.77.6",
"typescript": "~5.4.0",
"vite": "^5.3.1",
"vitest": "^1.6.0",
"vue-tsc": "^2.0.21"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
public/images/tiles/0-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
public/images/tiles/1-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
public/images/tiles/1-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
public/images/tiles/2-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
public/images/tiles/2-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
public/images/tiles/2-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
public/images/tiles/3-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
public/images/tiles/3-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
public/images/tiles/3-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
public/images/tiles/3-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
public/images/tiles/4-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
public/images/tiles/4-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
public/images/tiles/4-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
public/images/tiles/4-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
public/images/tiles/4-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
public/images/tiles/5-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
public/images/tiles/5-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
public/images/tiles/5-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
public/images/tiles/5-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
public/images/tiles/5-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
public/images/tiles/5-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
public/images/tiles/6-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
public/images/tiles/6-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
public/images/tiles/6-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
public/images/tiles/6-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
public/images/tiles/6-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
public/images/tiles/6-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
public/images/tiles/6-6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

9
src/App.vue Normal file
View File

@ -0,0 +1,9 @@
<script setup lang="ts">
import { RouterView } from 'vue-router'
</script>
<template>
<RouterView />
</template>
<style scoped></style>

86
src/assets/base.css Normal file
View File

@ -0,0 +1,86 @@
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white: #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;
--vt-c-black: #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;
--vt-c-indigo: #2c3e50;
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1: var(--vt-c-white);
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
}
/* semantic color variables for this project */
:root {
--color-background: var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);
--color-border: var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);
--color-heading: var(--vt-c-text-light-1);
--color-text: var(--vt-c-text-light-1);
--section-gap: 160px;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);
--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);
--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
font-weight: normal;
}
body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition:
color 0.5s,
background-color 0.5s;
line-height: 1.6;
font-family:
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
'Helvetica Neue',
sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

1
src/assets/logo.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>

After

Width:  |  Height:  |  Size: 276 B

33
src/assets/main.css Normal file
View File

@ -0,0 +1,33 @@
/* @import './base.css';
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
font-weight: normal;
}
a,
.green {
text-decoration: none;
color: hsla(160, 100%, 37%, 1);
transition: 0.4s;
padding: 3px;
}
@media (hover: hover) {
a:hover {
background-color: hsla(160, 100%, 37%, 0.2);
}
}
@media (min-width: 1024px) {
body {
display: flex;
place-items: center;
}
#app {
padding: 0 2rem;
}
} */

View File

@ -0,0 +1,121 @@
<script setup lang="ts">
import type { GameState, PlayerState } from '@/utilities/interfaces'
import { onMounted, ref, type PropType } from 'vue'
import { assets } from '@/utilities/assets'
import { Assets, Application as PixiApplication, Container, Sprite, Texture } from 'pixi.js'
import { Scale } from '@/utilities/scale'
import Hand from '@/utilities/Hand'
import { playerState as mockPS } from '@/utilities/mocks'
import { Board } from '@/utilities/Board'
const emit = defineEmits(['tileClick', 'passClick', 'leftClick', 'rightClick'])
defineProps({
gameState: Object as PropType<GameState>,
playerState: Object as PropType<PlayerState>
})
// console.log('d1 :>> ', d1)
// console.log('t1 :>> ', t1)
// const tile = new Sprite(t1)
let appEl = ref<HTMLElement | null>(null)
const app: PixiApplication = new PixiApplication()
let hand: Hand
let board: Board
const scaleX = Scale([-16, 16], [0, 800])
const scaleY = Scale([-12, 12], [0, 600])
onMounted(async () => {
await setup()
await preload()
await start()
// console.log('appEl :>> ', appEl.value)
// console.log('mounted')
// if (appEl.value === null) return
// console.log('App initialized')
// console.log('loading assets')
// const t1 = await Assets.load([d1])
// console.log(`${d1} loaded`)
// console.log('assets loaded')
// const tile = new Sprite(t1)
// tile.anchor.set(0.5)
// tile.width = 50
// tile.height = 100
// tile.x = app.screen.width / 2
// tile.y = app.screen.height / 2
// app.stage.addChild(tile)
})
async function start() {
console.log('start')
console.log('scaleX(0) :>> ', scaleX(0))
console.log('scaleY(0) :>> ', scaleY(0))
const boardContainer: Container = new Container()
const handContainer: Container = new Container()
app.stage.addChild(boardContainer)
app.stage.addChild(handContainer)
hand = new Hand(handContainer, app.canvas)
board = new Board(boardContainer, app.canvas)
hand.setTiles(mockPS as PlayerState)
hand.on('tileClick', (tile) => {
emit('tileClick', tile)
})
hand.on('passClick', () => {
emit('passClick')
})
hand.on('leftClick', () => {
emit('tileClick')
})
hand.on('rightClick', () => {
emit('rightClick')
})
app.ticker.add((time) => {
// hand.update(time)
// board.update(time)
})
}
async function setup() {
await app.init({ width: 800, height: 600 })
if (appEl.value === null) return
appEl.value.appendChild(app.canvas)
}
async function preload() {
console.log('loading assets')
await Assets.load(assets)
console.log('assets loaded')
}
</script>
<template>
<div ref="appEl" class="game-container"></div>
<!-- <Application :width="800" :height="600">
<Loader :resources="resources">
<template #fallback="{ progress }">
<text :x="120" :y="120" :anchor="0.5">
{{ `Loading... ${progress}` }}
</text>
</template>
<template #default="{}"> </template>
</Loader>
</Application> -->
</template>
<style scoped>
.game-container {
position: relative;
z-index: 10;
}
</style>

View File

@ -0,0 +1,41 @@
<script setup lang="ts">
defineProps<{
msg: string
}>()
</script>
<template>
<div class="greetings">
<h1 class="green">{{ msg }}</h1>
<h3>
Youve successfully created a project with
<a href="https://vitejs.dev/" target="_blank" rel="noopener">Vite</a> +
<a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>. What's next?
</h3>
</div>
</template>
<style scoped>
h1 {
font-weight: 500;
font-size: 2.6rem;
position: relative;
top: -10px;
}
h3 {
font-size: 1.2rem;
}
.greetings h1,
.greetings h3 {
text-align: center;
}
@media (min-width: 1024px) {
.greetings h1,
.greetings h3 {
text-align: left;
}
}
</style>

View File

@ -0,0 +1,88 @@
<script setup lang="ts">
import WelcomeItem from './WelcomeItem.vue'
import DocumentationIcon from './icons/IconDocumentation.vue'
import ToolingIcon from './icons/IconTooling.vue'
import EcosystemIcon from './icons/IconEcosystem.vue'
import CommunityIcon from './icons/IconCommunity.vue'
import SupportIcon from './icons/IconSupport.vue'
</script>
<template>
<WelcomeItem>
<template #icon>
<DocumentationIcon />
</template>
<template #heading>Documentation</template>
Vues
<a href="https://vuejs.org/" target="_blank" rel="noopener">official documentation</a>
provides you with all information you need to get started.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<ToolingIcon />
</template>
<template #heading>Tooling</template>
This project is served and bundled with
<a href="https://vitejs.dev/guide/features.html" target="_blank" rel="noopener">Vite</a>. The
recommended IDE setup is
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a> +
<a href="https://github.com/johnsoncodehk/volar" target="_blank" rel="noopener">Volar</a>. If
you need to test your components and web pages, check out
<a href="https://www.cypress.io/" target="_blank" rel="noopener">Cypress</a> and
<a href="https://on.cypress.io/component" target="_blank" rel="noopener"
>Cypress Component Testing</a
>.
<br />
More instructions are available in <code>README.md</code>.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<EcosystemIcon />
</template>
<template #heading>Ecosystem</template>
Get official tools and libraries for your project:
<a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a>,
<a href="https://router.vuejs.org/" target="_blank" rel="noopener">Vue Router</a>,
<a href="https://test-utils.vuejs.org/" target="_blank" rel="noopener">Vue Test Utils</a>, and
<a href="https://github.com/vuejs/devtools" target="_blank" rel="noopener">Vue Dev Tools</a>. If
you need more resources, we suggest paying
<a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">Awesome Vue</a>
a visit.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<CommunityIcon />
</template>
<template #heading>Community</template>
Got stuck? Ask your question on
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Vue Land</a>, our official
Discord server, or
<a href="https://stackoverflow.com/questions/tagged/vue.js" target="_blank" rel="noopener"
>StackOverflow</a
>. You should also subscribe to
<a href="https://news.vuejs.org" target="_blank" rel="noopener">our mailing list</a> and follow
the official
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener">@vuejs</a>
twitter account for latest news in the Vue world.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<SupportIcon />
</template>
<template #heading>Support Vue</template>
As an independent project, Vue relies on community backing for its sustainability. You can help
us by
<a href="https://vuejs.org/sponsor/" target="_blank" rel="noopener">becoming a sponsor</a>.
</WelcomeItem>
</template>

View File

@ -0,0 +1,147 @@
<script setup lang="ts">
const props = defineProps({
tile: Object,
top: Number,
bottom: Number,
revealed: {
type: Boolean,
default: false
}
})
function getPipClasses(value: number | undefined): string[] {
if (value === undefined) return []
const positions = [
[],
['c'],
['l-t', 'r-b'],
['l-t', 'c', 'r-b'],
['l-t', 'r-t', 'l-b', 'r-b'],
['l-t', 'r-t', 'c', 'l-b', 'r-b'],
['l-t', 'r-t', 'l-m', 'r-m', 'l-b', 'r-b']
]
return positions[value]
}
console.log('props.tile :>> ', props.tile)
</script>
<template>
{{ tile }}
<button @click="$emit('tile-clicked')">
<div v-if="!revealed" class="tile"></div>
<div v-if="revealed" class="tile shown">
<div class="half top">
<div
:key="$index"
v-for="(clasz, $index) in getPipClasses(top)"
class="pip"
:class="clasz"
></div>
</div>
<div class="half bottom">
<div
:key="$index"
v-for="(clasz, $index) in getPipClasses(bottom)"
class="pip"
:class="clasz"
></div>
</div>
</div>
</button>
</template>
<style scoped lang="scss">
button {
border: none;
background: none;
padding: 0;
margin: 0;
line-height: 0;
}
.tile {
cursor: pointer;
display: inline-block;
border: 0;
padding: 0;
border-radius: 4px;
color: #000;
background-color: #fff;
width: 50px;
height: 100px;
&.shown {
display: flex;
flex-direction: column;
}
// &.shown::after {
// content: '';
// display: inline-block;
// border-bottom: 1px solid #ddd;
// width: calc(100% - 4px);
// height: 0;
// position: relative;
// margin: 0 2px;
// top: 30px;
// }
}
.top {
margin: 0 2px;
border-bottom: 2px solid #ddd;
width: calc(100% - 4px);
}
.half {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.pip {
width: 8px;
height: 8px;
background: black;
border-radius: 50%;
position: absolute;
}
.c {
left: 40%;
top: 40%;
}
.l {
&-t {
left: 10%;
top: 10%;
}
&-m {
left: 10%;
top: 40%;
}
&-b {
left: 10%;
bottom: 10%;
}
}
.r {
&-t {
right: 10%;
top: 10%;
}
&-m {
right: 10%;
top: 40%;
}
&-b {
right: 10%;
bottom: 10%;
}
}
</style>

View File

@ -0,0 +1,87 @@
<template>
<div class="item">
<i>
<slot name="icon"></slot>
</i>
<div class="details">
<h3>
<slot name="heading"></slot>
</h3>
<slot></slot>
</div>
</div>
</template>
<style scoped>
.item {
margin-top: 2rem;
display: flex;
position: relative;
}
.details {
flex: 1;
margin-left: 1rem;
}
i {
display: flex;
place-items: center;
place-content: center;
width: 32px;
height: 32px;
color: var(--color-text);
}
h3 {
font-size: 1.2rem;
font-weight: 500;
margin-bottom: 0.4rem;
color: var(--color-heading);
}
@media (min-width: 1024px) {
.item {
margin-top: 0;
padding: 0.4rem 0 1rem calc(var(--section-gap) / 2);
}
i {
top: calc(50% - 25px);
left: -26px;
position: absolute;
border: 1px solid var(--color-border);
background: var(--color-background);
border-radius: 8px;
width: 50px;
height: 50px;
}
.item:before {
content: ' ';
border-left: 1px solid var(--color-border);
position: absolute;
left: 0;
bottom: calc(50% + 25px);
height: calc(50% - 25px);
}
.item:after {
content: ' ';
border-left: 1px solid var(--color-border);
position: absolute;
left: 0;
top: calc(50% + 25px);
height: calc(50% - 25px);
}
.item:first-of-type:before {
display: none;
}
.item:last-of-type:after {
display: none;
}
}
</style>

View File

@ -0,0 +1,11 @@
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import HelloWorld from '../HelloWorld.vue'
describe('HelloWorld', () => {
it('renders properly', () => {
const wrapper = mount(HelloWorld, { props: { msg: 'Hello Vitest' } })
expect(wrapper.text()).toContain('Hello Vitest')
})
})

View File

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
/>
</svg>
</template>

View File

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
<path
d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
/>
</svg>
</template>

View File

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
<path
d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
/>
</svg>
</template>

View File

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
/>
</svg>
</template>

View File

@ -0,0 +1,19 @@
<!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
aria-hidden="true"
role="img"
class="iconify iconify--mdi"
width="24"
height="24"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
>
<path
d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
fill="currentColor"
></path>
</svg>
</template>

View File

@ -0,0 +1,32 @@
<script setup lang="ts">
import { useRouter } from 'vue-router'
import { RouterLink, RouterView } from 'vue-router'
const router = useRouter()
defineOptions({
name: 'AuthenticatedLayout'
})
function logout() {
localStorage.removeItem('isLoggedIn')
router.push({ name: 'landing' })
}
</script>
<template>
<div class="authenticated-layout">
<header>
<nav>
<button @click="logout">Logout</button>
</nav>
</header>
<main>
<RouterView></RouterView>
</main>
</div>
</template>
<style scoped>
/* Add styles for authenticated layout */
</style>

View File

@ -0,0 +1,17 @@
<script setup lang="ts">
import { RouterView } from 'vue-router'
defineOptions({
name: 'UnauthenticatedLayout'
})
</script>
<template>
<div class="unauthenticated-layout">
<RouterView></RouterView>
</div>
</template>
<style>
/* Add styles for unauthenticated layout */
</style>

18
src/main.ts Normal file
View File

@ -0,0 +1,18 @@
import './assets/main.css'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import socketService from '@/services/socket'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.provide('socket', socketService)
app.mount('#app')

65
src/router/index.ts Normal file
View File

@ -0,0 +1,65 @@
import { createRouter, createWebHistory } from 'vue-router'
import AuthenticatedLayout from '@/components/layouts/AuthenticatedLayout.vue'
import UnauthenticatedLayout from '@/components/layouts/UnauthenticatedLayout.vue'
import HomeView from '@/views/HomeView.vue'
import LandingView from '@/views/LandingView.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
component: UnauthenticatedLayout,
children: [
{
path: '',
component: LandingView,
name: 'landing'
}
]
},
{
path: '/home',
component: AuthenticatedLayout,
children: [
{
path: '',
name: 'home',
component: HomeView,
meta: {
requiresAuth: true
}
}
]
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
// component: () => import('../views/AboutView.vue')
},
{
path: '/game',
component: AuthenticatedLayout,
children: [
{
path: '',
name: 'game',
component: () => import('@/views/GameView.vue'),
meta: {
requiresAuth: true
}
}
]
}
]
})
router.beforeEach((to, from, next) => {
const isLoggedIn = !!localStorage.getItem('token')
if (to.matched.some((record) => record.meta.requiresAuth) && !isLoggedIn) {
next({ name: 'landing' })
} else {
next()
}
})
export default router

31
src/services/socket.ts Normal file
View File

@ -0,0 +1,31 @@
import { io } from 'socket.io-client'
const URL = 'http://localhost:3000'
process.env.NODE_ENV === 'production' ? undefined : 'http://localhost:3001'
console.log('URL :>> ', URL)
const socket = URL === undefined ? io() : io(URL)
socket.on('connect', () => {
console.log('---> connected')
})
socket.onAny((event, msg) => {
console.log('event :>> ', event)
console.log('msg :>> ', msg)
})
console.log('help :>> ')
export default {
socket,
sendMessage(event: any, data: any) {
socket.emit(event, data)
},
async sendMessageWithAck(event: any, data: any) {
return await socket.emitWithAck(event, data)
},
onMessage(event: any, callback: any) {
socket.on(event, callback)
},
disconnect() {
socket.disconnect()
}
}

12
src/stores/counter.ts Normal file
View File

@ -0,0 +1,12 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
})

143
src/utilities/Board.ts Normal file
View File

@ -0,0 +1,143 @@
import { Container, EventEmitter, Graphics, Text } from 'pixi.js'
import { Scale } from './scale'
import type { GameState } from './interfaces'
import type { Tile } from './Tile'
import { getColorBackground } from './backgrounds'
export class Board extends EventEmitter {
container: Container
height: number
width: number
scaleY: Function
scaleX: Function
state: GameState | undefined
initialContainer: Container = new Container()
mainContainer: Container = new Container()
leftContainer: Container = new Container()
rightContainer: Container = new Container()
tiles: Tile[] = []
boneyard: Tile[] = []
constructor(container: Container, canvas: HTMLCanvasElement) {
super()
this.container = container
this.height = canvas.height - 130
this.width = canvas.width
this.container.width = this.width
this.container.height = this.height
this.container.y = 0
const scaleXSteps = Math.floor(this.width / 25)
const scaleYSteps = Math.floor(this.height / 25)
this.scaleX = Scale([-scaleXSteps, scaleXSteps], [0, this.width])
this.scaleY = Scale([-scaleYSteps, scaleYSteps], [0, this.height])
this.initialContainer = new Container()
this.initialContainer.addChild(
new Text({
text: 'Initial Board',
style: {
fontFamily: 'Arial',
fontSize: 12,
fill: 0xff1010,
align: 'center'
}
})
)
this.container.addChild(this.initialContainer)
this.mainContainer = new Container()
this.mainContainer.addChild(
new Text({
text: 'Main Board',
style: {
fontFamily: 'Arial',
fontSize: 12,
fill: 0xff1010,
align: 'center'
}
})
)
this.container.addChild(this.mainContainer)
this.createLeftRightContainers()
this.initialContainer.visible = false
this.mainContainer.visible = false
}
private createLeftRightContainers() {
console.log('this.height :>> ', this.height)
this.leftContainer.x = 0
this.leftContainer.y = 0
this.leftContainer.width = 50
this.leftContainer.height = this.height
this.leftContainer.eventMode = 'static'
this.leftContainer.cursor = 'pointer'
const leftSide = new Graphics()
.rect(0, 0, 50, this.height)
// Draw the wheel
.fill({ color: 0x848484 })
leftSide.alpha = 0
this.leftContainer.addChild(leftSide)
this.leftContainer.on('pointerover', () => {
leftSide.alpha = 0.5
})
this.leftContainer.on('pointerout', () => {
leftSide.alpha = 0
})
this.leftContainer.on('pointerdown', () => {
this.emit('leftClick')
})
this.leftContainer.addChild(
new Text({
text: 'Left',
style: {
fontFamily: 'Arial',
fontSize: 12,
fill: 0xff1010,
align: 'center'
}
})
)
//
this.rightContainer.x = this.width - 50
this.rightContainer.y = 0
this.rightContainer.width = 50
this.rightContainer.height = this.height
this.rightContainer.eventMode = 'static'
this.rightContainer.cursor = 'pointer'
const rightSide = new Graphics()
.rect(0, 0, 50, this.height)
// Draw the wheel
.fill({ color: 0x848484 })
rightSide.alpha = 0
this.rightContainer.addChild(rightSide)
this.rightContainer.on('pointerover', () => {
rightSide.alpha = 0.5
})
this.rightContainer.on('pointerout', () => {
rightSide.alpha = 0
})
this.rightContainer.on('pointerdown', () => {
this.emit('rightClick')
})
this.rightContainer.addChild(
new Text({
text: 'Right',
style: {
fontFamily: 'Arial',
fontSize: 12,
fill: 0xff1010,
align: 'center'
}
})
)
this.container.addChild(this.leftContainer)
this.container.addChild(this.rightContainer)
}
setState(state: GameState) {
this.state = state
}
}

131
src/utilities/Hand.ts Normal file
View File

@ -0,0 +1,131 @@
import {
Application,
Container,
EventEmitter,
Graphics,
Rectangle,
RoundedRectangle,
Sprite,
Text,
Texture
} from 'pixi.js'
import { Tile } from './Tile'
import type { PlayerState } from './interfaces'
export default class Hand extends EventEmitter {
tiles: Tile[] = []
container: Container
height: number
width: number
constructor(container: Container, canvas: HTMLCanvasElement) {
super()
this.container = container
this.height = 130
this.width = canvas.width
this.container.y = canvas.height - this.height
this.container.width = this.width
this.container.height = this.height
this.addBg()
this.createPassButton()
}
setTiles(playerState: PlayerState) {
this.tiles = this.createTiles(playerState)
}
private addBg() {
console.log('addBg')
const bg = new Sprite(Texture.WHITE)
bg.alpha = 0.05
bg.width = this.width
bg.height = this.height
this.container.addChild(bg)
this.container.addChild(
new Text({
text: 'Hand',
style: {
fontFamily: 'Arial',
fontSize: 12,
fill: 0xff1010,
align: 'center'
}
})
)
}
private onClick(tile: Tile) {
const selected = this.tiles.find((t) => t.selectd)
if (selected) {
selected.y = selected.y + 10
selected.selectd = false
}
tile.selectd = true
tile.y = tile.y - 10
this.emit('tileClick', { id: tile.id })
}
private createPassButton() {
const rectangle = new Graphics().roundRect(0, 0, 80, 30, 10).fill(0xffff00)
const text = new Text({
text: 'PASS',
style: {
fontFamily: 'Arial',
fontSize: 12,
fontWeight: 'bold',
fill: 0x121212,
align: 'center'
}
})
text.anchor = 0.5
const buttonPassContainer = new Container()
buttonPassContainer.addChild(rectangle)
buttonPassContainer.addChild(text)
text.y = buttonPassContainer.height / 2 - 4
text.x = buttonPassContainer.width / 2 - 8
buttonPassContainer.eventMode = 'static'
buttonPassContainer.cursor = 'pointer'
buttonPassContainer.x = 20
buttonPassContainer.y = this.height / 2 - 10
rectangle.alpha = 0.7
text.alpha = 0.7
buttonPassContainer.on('pointerdown', () => {
this.emit('passClick')
})
buttonPassContainer.on('pointerover', () => {
rectangle.alpha = 1
text.alpha = 1
})
buttonPassContainer.on('pointerout', () => {
rectangle.alpha = 0.7
text.alpha = 0.7
})
this.container.addChild(buttonPassContainer)
}
private createTiles(playerState: PlayerState) {
const deltaX = (playerState.hand.length * 50 - 5) / 2
return playerState.hand.map((tile, i) => {
const newTile: Tile = new Tile(tile.id, tile.pips)
newTile.y = newTile.height / 2 + 20
newTile.x = deltaX + newTile.width / 2 + i * (newTile.width + 5)
newTile.eventMode = 'static'
newTile.cursor = 'pointer'
newTile.alpha = 0.7
this.container.addChild(newTile)
newTile.on('pointerdown', () => this.onClick(newTile))
newTile.on('pointerover', () => (newTile.alpha = 1))
newTile.on('pointerout', () => (newTile.alpha = 0.7))
return newTile
})
}
}

25
src/utilities/Tile.ts Normal file
View File

@ -0,0 +1,25 @@
import { Sprite, Texture } from 'pixi.js'
export class Tile extends Sprite {
id: string
pips: [number, number] | undefined
selectd: boolean = false
constructor(id: string, pips?: [number, number]) {
super()
this.id = id
this.anchor.set(0.5)
this.width = 50
this.height = 100
this.pips = pips
this.texture = this.getTexture()
}
private getTexture(): Texture {
if (this.pips !== undefined) {
return Texture.from(`tile-${this.pips[1]}_${this.pips[0]}`)
} else {
return Texture.from('tile-back')
}
}
}

61
src/utilities/assets.ts Normal file
View File

@ -0,0 +1,61 @@
import tileBack from '@/assets/images/tiles/back.png'
import tile0_0 from '@/assets/images/tiles/0-0.png'
import tile1_0 from '@/assets/images/tiles/1-0.png'
import tile1_1 from '@/assets/images/tiles/1-1.png'
import tile2_0 from '@/assets/images/tiles/2-0.png'
import tile2_1 from '@/assets/images/tiles/2-1.png'
import tile2_2 from '@/assets/images/tiles/2-2.png'
import tile3_0 from '@/assets/images/tiles/3-0.png'
import tile3_1 from '@/assets/images/tiles/3-1.png'
import tile3_2 from '@/assets/images/tiles/3-2.png'
import tile3_3 from '@/assets/images/tiles/3-3.png'
import tile4_0 from '@/assets/images/tiles/4-0.png'
import tile4_1 from '@/assets/images/tiles/4-1.png'
import tile4_2 from '@/assets/images/tiles/4-2.png'
import tile4_3 from '@/assets/images/tiles/4-3.png'
import tile4_4 from '@/assets/images/tiles/4-4.png'
import tile5_0 from '@/assets/images/tiles/5-0.png'
import tile5_1 from '@/assets/images/tiles/5-1.png'
import tile5_2 from '@/assets/images/tiles/5-2.png'
import tile5_3 from '@/assets/images/tiles/5-3.png'
import tile5_4 from '@/assets/images/tiles/5-4.png'
import tile5_5 from '@/assets/images/tiles/5-5.png'
import tile6_0 from '@/assets/images/tiles/6-0.png'
import tile6_1 from '@/assets/images/tiles/6-1.png'
import tile6_2 from '@/assets/images/tiles/6-2.png'
import tile6_3 from '@/assets/images/tiles/6-3.png'
import tile6_4 from '@/assets/images/tiles/6-4.png'
import tile6_5 from '@/assets/images/tiles/6-5.png'
import tile6_6 from '@/assets/images/tiles/6-6.png'
export const assets = [
{ alias: 'tile-back', src: tileBack },
{ alias: 'tile-0_0', src: tile0_0 },
{ alias: 'tile-1_0', src: tile1_0 },
{ alias: 'tile-1_1', src: tile1_1 },
{ alias: 'tile-2_0', src: tile2_0 },
{ alias: 'tile-2_1', src: tile2_1 },
{ alias: 'tile-2_2', src: tile2_2 },
{ alias: 'tile-3_0', src: tile3_0 },
{ alias: 'tile-3_1', src: tile3_1 },
{ alias: 'tile-3_2', src: tile3_2 },
{ alias: 'tile-3_3', src: tile3_3 },
{ alias: 'tile-4_0', src: tile4_0 },
{ alias: 'tile-4_1', src: tile4_1 },
{ alias: 'tile-4_2', src: tile4_2 },
{ alias: 'tile-4_3', src: tile4_3 },
{ alias: 'tile-4_4', src: tile4_4 },
{ alias: 'tile-5_0', src: tile5_0 },
{ alias: 'tile-5_1', src: tile5_1 },
{ alias: 'tile-5_2', src: tile5_2 },
{ alias: 'tile-5_3', src: tile5_3 },
{ alias: 'tile-5_4', src: tile5_4 },
{ alias: 'tile-5_5', src: tile5_5 },
{ alias: 'tile-6_0', src: tile6_0 },
{ alias: 'tile-6_1', src: tile6_1 },
{ alias: 'tile-6_2', src: tile6_2 },
{ alias: 'tile-6_3', src: tile6_3 },
{ alias: 'tile-6_4', src: tile6_4 },
{ alias: 'tile-6_5', src: tile6_5 },
{ alias: 'tile-6_6', src: tile6_6 }
]

View File

@ -0,0 +1,14 @@
import { Graphics, Container } from 'pixi.js'
export function getColorBackground(container: Container, colorName: string, alpha: number = 0.5) {
const graphics = new Graphics()
const color = 0xffffff
graphics.rect(0, 0, container.width, container.height)
graphics.fill(color)
graphics.alpha = alpha
graphics.x = 0
graphics.y = 0
console.log('graphics :>> ', graphics)
return graphics
}

View File

@ -0,0 +1,20 @@
export interface GameState {
players: any[]
boneyard: any[]
currentPlayer: string
board: any[]
gameInProgress: boolean
winner?: any
gameBlocked: boolean
gameTied: boolean
gameId: string
tileSelectionPhase: boolean
}
export interface PlayerState {
id: string
name: string
score: number
hand: any[]
teamedWith: string | undefined
}

42
src/utilities/mocks.ts Normal file
View File

@ -0,0 +1,42 @@
export const playerState = {
id: '6fddcf4f-eaa9-4c87-a599-2af944477091',
name: 'arhuako',
score: 0,
hand: [
{
id: '20ce403a-dccc-472e-94b2-90ba8feac538',
pips: [4, 5],
flipped: false
},
{
id: 'a0cd790b-34bb-40fe-9b25-8dc590729e15',
pips: [1, 2],
flipped: false
},
{
id: 'f516ef48-99f2-4add-96eb-877f03bf0cb1',
pips: [2, 3],
flipped: false
},
{
id: 'dd91e12d-4be1-40e2-b1b1-128a0bc3dad7',
pips: [0, 1],
flipped: false
},
{
id: 'c472f1e8-14e4-4a5b-bef0-df0e78f01c39',
pips: [1, 5],
flipped: false
},
{
id: 'c28c55e1-820f-43b1-9366-d4b20d7f62a6',
pips: [1, 3],
flipped: false
},
{
id: '6d812874-8610-43e3-8331-6b25584e759e',
pips: [0, 5],
flipped: false
}
]
}

10
src/utilities/scale.ts Normal file
View File

@ -0,0 +1,10 @@
/**
*
* @param domain example: [0, 100]
* @param range examaple: [0, width]
*/
export function Scale(domain: number[], range: number[]): Function {
return function (value: number): number {
return ((value - domain[0]) * (range[1] - range[0])) / (domain[1] - domain[0]) + range[0]
}
}

15
src/views/AboutView.vue Normal file
View File

@ -0,0 +1,15 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<style>
@media (min-width: 1024px) {
.about {
min-height: 100vh;
display: flex;
align-items: center;
}
}
</style>

301
src/views/GameView.vue Normal file
View File

@ -0,0 +1,301 @@
<script setup lang="ts">
import GameComponent from '@/components/GameComponent.vue'
import TileComponent from '@/components/TileComponent.vue'
import type { GameState, PlayerState } from '@/utilities/interfaces'
import { inject, onBeforeUnmount, ref } from 'vue'
import { onMounted } from 'vue'
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
const socketService: any = inject('socket')
const { socket } = socketService
let gameState = ref<GameState | undefined>(undefined)
let playerState = ref<PlayerState | undefined>(undefined)
let data = ref('')
let responseField = ref('')
let statusField = ref('')
let sessionId = ref('')
let selectdAction: any = undefined
let canSelectTile = false
let canMakeMove = false
let tileSelected = ''
let moveType = ''
const options = [
{ value: 'createSession', default: '{"user": "arhuako"}' },
{ value: 'startSession', default: (id: string) => `{"sessionId": "${id}"}` },
{ value: 'joinSession', default: '{"user": "pepe", "sessionId": "arhuako"}' },
{ value: 'leaveSession', default: '{"user": "pepe", "sessionId": "arhuako"}' },
{ value: 'chat message', default: 'chat message' }
]
onMounted(async () => {
socket.on('gameState', (data: GameState, callback: any) => {
gameState.value = data
statusField.value = statusField.value + JSON.stringify(data, null, 2)
callback({
status: 'ok'
})
})
socket.on('playerState', (data: PlayerState, callback: any) => {
console.log('playerState :>> ', data)
playerState.value = data
statusField.value = statusField.value + JSON.stringify(data, null, 2)
callback({
status: 'ok'
})
})
socket.on('makeMove', async (data: any, callback: any) => {
statusField.value = statusField.value + JSON.stringify(data, null, 2)
canMakeMove = true
while (canMakeMove) {
await wait(500)
}
callback({
status: 'ok',
tileId: tileSelected,
moveType
})
})
socket.on('chooseTile', async (data: any, callback: any) => {
statusField.value = statusField.value + JSON.stringify(data, null, 2)
canSelectTile = true
while (canSelectTile) {
await wait(500)
}
callback({
status: 'ok',
tileId: tileSelected
})
})
})
function selectTile(id: string) {
if (canSelectTile) {
tileSelected = id
canSelectTile = false
}
}
function selectTileToMove(id: string) {
if (canMakeMove) {
if (tileSelected === id) {
tileSelected = ''
return
}
tileSelected = id
}
}
function onTileClick(tileId: string) {
console.log('tileId :>> ', tileId)
selectTile(tileId)
}
function makeMove(type: string) {
if (canMakeMove) {
if (type === 'pass') {
tileSelected = ''
canMakeMove = false
} else if (tileSelected) {
moveType = type
canMakeMove = false
}
}
}
onBeforeUnmount(() => {
socketService.disconnect()
})
function actionSelected() {
console.log('event :>> ', selectdAction)
if (selectdAction.value === 'createSession') {
responseField.value = ''
} else if (selectdAction.value === 'startSession') {
data.value = selectdAction.default(sessionId.value)
return
}
data.value = selectdAction.default
}
const getMessage = (msg: string) => {
if (msg.startsWith('{') && msg.endsWith('}')) return JSON.parse(msg)
return msg
}
async function sendMessage() {
if (selectdAction && data.value.trim() !== '') {
console.log('socketService :>> ', socketService)
const response = await socketService.sendMessageWithAck(
selectdAction.value,
getMessage(data.value.trim())
)
console.log('response :>> ', response)
handleResponse(response)
}
// socketService.emit('message', data.value)
}
function handleResponse(response: any) {
if (selectdAction.value === 'createSession') {
sessionId.value = response.sessionId
}
data.value = ''
const responseStr = JSON.stringify(response, null, 2)
responseField.value = !responseField.value
? responseStr
: responseField.value + '\n---\n ' + responseStr
selectdAction = undefined
}
</script>
<template>
<div class="grid">
<div>
<GameComponent :gameState="gameState" :playerState="playerState" @tileClick="onTileClick" />
<p>SessionID: {{ sessionId }}</p>
<ul id="messages"></ul>
<form id="form" action="">
<p>
<select v-model="selectdAction" id="event" autocomplete="off" @change="actionSelected">
<option value="">Select event</option>
<option :key="option.value" v-for="option in options" :value="option">
{{ option.value }}
</option>
</select>
</p>
<!-- <p><input id="room" autocomplete="off" /></p> -->
<p>
<textarea v-model="data" id="message" autocomplete="off" placeholder="Data"></textarea>
</p>
<p><button @click.prevent.stop="sendMessage">Send</button></p>
<div class="grid">
<div>
<textarea
:value="responseField"
id="response"
autocomplete="off"
placeholder="Response"
></textarea>
</div>
<div>
<textarea
:value="statusField"
id="status"
autocomplete="off"
placeholder="Game status"
></textarea>
</div>
</div>
</form>
</div>
<div>
<!-- <div style="display: flex; gap: 4px">
<TileComponent :revealed="false" :top="6" :bottom="0" />
<TileComponent :revealed="true" :top="6" :bottom="0" />
</div> -->
<h4>Board</h4>
<!-- Board -->
<div class="board-container">
<div v-if="gameState?.tileSelectionPhase">
<div class="tiles-container">
<TileComponent
:key="tile.id"
v-for="tile in gameState.boneyard"
@tile-clicked="selectTile(tile.id)"
/>
</div>
<div v-if="canSelectTile">Please select a tile.</div>
<div v-else>Wait your turn.</div>
</div>
<div v-if="!gameState?.tileSelectionPhase">
<div class="tiles-container">
<TileComponent
:class="{ 'selected-tile': tileSelected === tile.id }"
:revealed="true"
:key="tile.id"
v-for="tile in gameState?.board"
:top="tile.pips[0]"
:bottom="tile.pips[1]"
/>
</div>
</div>
</div>
<!-- End board-->
<div class="hand-container">
<h4>
Your Hand <button class="control" @click="makeMove('left')">Left</button
><button class="control" @click="makeMove('right')">Right</button
><button class="control" @click="makeMove('pass')">Pass</button>
</h4>
<div class="tiles-container">
<TileComponent
:revealed="true"
:key="tile.id"
v-for="tile in playerState?.hand ?? []"
@tile-clicked="selectTileToMove(tile.id)"
:top="tile.pips[0]"
:bottom="tile.pips[1]"
/>
</div>
</div>
<!-- End hand-->
</div>
</div>
</template>
<style scoped lang="scss">
* {
box-sizing: border-box;
}
.control {
font-size: 60%;
padding: 8px;
margin-right: 4px;
}
textarea {
width: 100%;
height: 150px;
resize: none;
font-size: 70%;
}
#response,
#status {
height: 400px;
}
.tiles-container {
display: flex;
gap: 4px;
flex-flow: row wrap;
align-content: flex-start;
}
.board-container {
position: absolute;
height: 600px;
padding: 10px;
width: calc(50% - 50px);
background-color: var(--pico-form-element-background-color);
}
.hand-container {
position: fixed;
bottom: 0;
height: 200px;
padding: 10px;
width: calc(50% - 50px);
background-color: var(--pico-form-element-background-color);
}
</style>

24
src/views/HomeView.vue Normal file
View File

@ -0,0 +1,24 @@
<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
function startGame() {
router.push({ name: 'game' })
}
</script>
<template>
<div class="home">
<h1>Welcome to the Player's Home Page</h1>
<p>This is a protected route.</p>
<button @click="startGame">Start Game</button>
</div>
</template>
<style scoped lang="scss">
.home {
max-width: 600px;
margin: auto;
}
</style>

Some files were not shown because too many files have changed in this diff Show More