add local dev mode

This commit is contained in:
Branden J Brown 2024-02-03 21:25:57 -06:00
parent 566de4066b
commit 36475c0a9b
1 changed files with 28 additions and 3 deletions

View File

@ -37,9 +37,9 @@ const toggleDark = useToggle(dark);
const theme = computed(() => dark.value ? 'dark' : 'light'); const theme = computed(() => dark.value ? 'dark' : 'light');
const themeIcon = computed(() => dark.value ? 'mdi-moon-waxing-crescent' : 'mdi-white-balance-sunny'); const themeIcon = computed(() => dark.value ? 'mdi-moon-waxing-crescent' : 'mdi-white-balance-sunny');
const { status, data, send, open, close } = useWebSocket<string>(`wss://${window.location.host}/queue`, { const local = window.location.hostname === 'localhost';
immediate: false,
}); const { status, data, send, open, close } = useWebSocket<string>(`wss://${window.location.host}/queue`, {immediate: false});
const game = ref<Game | null>(null); const game = ref<Game | null>(null);
const dealer = ref<boolean | null>(null); const dealer = ref<boolean | null>(null);
watchEffect(() => { watchEffect(() => {
@ -66,11 +66,31 @@ const playing = computed(() => game.value != null);
const loading = computed(() => status.value === 'CONNECTING' || status.value === 'OPEN' && !playing.value); const loading = computed(() => status.value === 'CONNECTING' || status.value === 'OPEN' && !playing.value);
function clickPlay() { function clickPlay() {
if (local) {
data.value = JSON.stringify({
action: "Start",
damage: 1,
dealer: false,
players: [
{hp: 4, items: ['', '', '', '', '', '', '', '']},
{hp: 4, items: ['', '', '', '', '', '', '', '']},
],
previous: null,
round: 1,
blank: 3,
live: 2,
});
return;
}
open(); open();
send('{"action":"ping"}'); send('{"action":"ping"}');
} }
function action(evt: Action) { function action(evt: Action) {
if (local && game.value != null) {
game.value.dealer = !game.value.dealer;
return;
}
if (evt.action === 'quit') { if (evt.action === 'quit') {
// Just close the connection. The server knows what to do. // Just close the connection. The server knows what to do.
data.value = null; data.value = null;
@ -85,6 +105,11 @@ function action(evt: Action) {
const loadingMe = ref(true); const loadingMe = ref(true);
const me = ref<string | null>(null); const me = ref<string | null>(null);
onMounted(async () => { onMounted(async () => {
if (local) {
loadingMe.value = false;
me.value = 'a';
return;
}
loadingMe.value = true; loadingMe.value = true;
try { try {
const resp = await fetch('/user/me', { const resp = await fetch('/user/me', {