Skip to content

Commit

Permalink
Merge pull request #3 from samdems/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
samdems authored Apr 28, 2024
2 parents 0495fea + eeae061 commit d92a78c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 45 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=2.0" />
<title>tracker</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
"preview": "vite preview --host 0.0.0.0"
},
"dependencies": {
"@supabase/supabase-js": "^2.42.7",
Expand Down
9 changes: 8 additions & 1 deletion src/components/Attack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ref } from 'vue';
import { usePlayersStore } from '../stores/playersStore';
import Selector from './Selector.vue';
const playersStore = usePlayersStore();
const activePlayer = playersStore.getActivePlayer();
type PlayerAttack = {
value: number,
name: string,
Expand All @@ -41,6 +41,8 @@ const combat = ref(0);
const attack = ref<{[key:string]:PlayerAttack}>({});
const setup = () => {
const activePlayer = playersStore.getActivePlayer();
Object.keys(playersStore.players).forEach(player => {
if(player == activePlayer?.id) return;
attack.value[player] = {
Expand All @@ -52,20 +54,23 @@ const setup = () => {
});
if(!activePlayer) return console.log('no active player');
combat.value = activePlayer.combat;
//@ts-ignore
window.attackModal.showModal();
}
const decrement = (player:{value:number}) => {
const activePlayer = playersStore.getActivePlayer();
if(!activePlayer) return console.log('no active player');
if(combat.value == 0) return console.log('no more points');
if(player.value == 0) return console.log('not enough points');
player.value -= 1;
combat.value -= 1;
}
const increment = (player:{value:number,start:number}) => {
const activePlayer = playersStore.getActivePlayer();
if(!activePlayer) return console.log('no active player');
if(combat.value+1 > activePlayer.combat) return console.log('not enough points');
if(player.value+1 > player.start) return console.log('not enough points');
Expand All @@ -74,6 +79,8 @@ const increment = (player:{value:number,start:number}) => {
}
const makeAttack = () => {
const activePlayer = playersStore.getActivePlayer();
if(!activePlayer) return console.log('no active player');
Object.keys(attack.value).forEach(player => {
playersStore.updatePlayer(player, 'authority', attack.value[player].value)
Expand Down
6 changes: 3 additions & 3 deletions src/components/GameSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<div class="modal-box">
<div class="p-2 flex flex-col justify-center items-center">
<p>Scan the QR code to join the game</p>
<qrcode-vue :value="value" level="H" class="m-2 p-2 bg-white" />
<p>{{value}}</p>
<qrcode-vue :value="value" :size="200" level="H" class="m-4 p-2 bg-white" />
<p class="text-xs">{{value}}</p>
</div>
<div class="modal-action">
<form method="dialog">
Expand All @@ -20,5 +20,5 @@
<script setup lang="ts">
import QrcodeVue from 'qrcode.vue';
const value = window.location.href;
const value = "https://star-realms.samcross.uk/#pqri9jw31" // window.location.href.replace('http://','');
</script>
8 changes: 7 additions & 1 deletion src/components/Selector.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="flex gap-2 justify-center items-center" >
<button @click="decrement()" class="btn" :class="btnClass">-</button>
<h2 class="w-7">{{ props.value }}</h2>
<h2 class="w-7 text-center">{{ props.value }}</h2>
<button @click="increment()" class="btn" :class="btnClass">+</button>
</div>
</template>
Expand All @@ -13,6 +13,7 @@
const props = defineProps<{
value: number;
color: string;
size?: string;
increment: () => void;
decrement: () => void;
}>();
Expand All @@ -22,4 +23,9 @@
btnClass['btn-primary'] = props.color === 'primary';
btnClass['btn-error'] = props.color === 'error';
btnClass['btn-warning'] = props.color === 'warning';
btnClass['btn-xs'] = props.size === 'xs';
btnClass['btn-sm'] = props.size === 'sm';
btnClass['btn-lg'] = props.size === 'lg';
</script>
96 changes: 59 additions & 37 deletions src/components/addPlayer.vue
Original file line number Diff line number Diff line change
@@ -1,52 +1,74 @@
<template>
<button class="btn" onclick="newPlayerModal.showModal()"> Manage players
</button>
<dialog id="newPlayerModal" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg">Add new player</h3>
<p>current players: </p>
<span class="text-sm">press to remove</span>
<div class="flex gap-2 flex-wrap items-center">
<div
class="badge badge-primary cursor-pointer"
v-for="player in playersStore.players"
:key="player.id"
@click="playersStore.removePlayer(player.id)"
>
{{player.name}}
<button class="btn" onclick="newPlayerModal.showModal()">
Manage players
</button>
<dialog id="newPlayerModal" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg">Manage Players</h3>
<table class="table table-compact table-zebra">
<tbody>
<tr class="" v-for="player in playersStore.players" :key="player.id">
<td class="p-0" >{{ player.name }}</td>
<td class="p-2">
<Selector
:value="player.authority"
color="primary"
size="sm"
:increment="() => playersStore.increment(player.id,'authority')"
:decrement="() => playersStore.decrement(player.id,'authority')"
/>
</td>
<td class="p-1">
<button class="btn btn-sm btn-error" @click="playersStore.removePlayer(player.id)">
X
</button>
</td>
</tr>
</tbody>
</table>
<div class="divider"></div>
<div class="text-error mb-2">{{ alert }}</div>
<div class="flex justify-around gap-2">
<input
v-model="name"
type="text"
placeholder="Name"
class="input input-bordered w-40"
@keyup.enter="addPlayer"
/>
<input v-model="authority" type="number" placeholder="Authority" class="input input-bordered w-20" />
<button @click="addPlayer" class="btn btn-primary ms-2">Add</button>
</div>
<div class="modal-action">
<button class="btn" onclick="newPlayerModal.close()">Close</button>
</div>
</div>
<div class="divider"></div>
<div class="text-error">{{alert}}</div>
<input v-model="name" type="text" placeholder="Name" class="input input-bordered" @keyup.enter="addPlayer"
/>
<div class="modal-action">
<button @click="addPlayer" class="btn btn-primary">Add</button>
<button class="btn" onclick="newPlayerModal.close()">Close</button>
</div>
</div>
</dialog>
</dialog>
</template>


<script setup lang="ts">
import { ref } from 'vue';
import { usePlayersStore } from '../stores/playersStore';
import { ref } from "vue";
import { usePlayersStore } from "../stores/playersStore";
import Selector from "./Selector.vue";
const playersStore = usePlayersStore();
const name = ref('');
const alert = ref('');
const name = ref("");
const alert = ref("");
const authority = ref(50);
const addPlayer = () => {
if (!name.value) {
alert.value = 'Name is required';
alert.value = "Name is required";
return;
}
const id = Math.random().toString(36).substr(2, 9)
playersStore.addPlayer({id, name: name.value, authority: 50, combat: 0, trade: 0});
name.value = '';
const id = Math.random().toString(36).substr(2, 9);
playersStore.addPlayer({
id,
name: name.value,
authority: authority.value ,
combat: 0,
trade: 0,
});
name.value = "";
};
</script>


2 changes: 1 addition & 1 deletion src/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const supabaseKey = import.meta.env.VITE_SUPABASE_KEY
export const supabase = createClient(supabaseUrl, supabaseKey)

if(!window.location.hash) {
window.location.hash = Math.random().toString(36).substr(2, 9)
window.location.hash = Math.random().toString(36).substr(2, 8)
}

export const roomid = window.location.hash.substr(1);
Expand Down

0 comments on commit d92a78c

Please sign in to comment.