From 36475c0a9b2ece810809a3b84408092e3b6ec6e6 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sat, 3 Feb 2024 21:25:57 -0600 Subject: [PATCH] add local dev mode --- site/src/App.vue | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/site/src/App.vue b/site/src/App.vue index 13d5a8b..d025cdb 100644 --- a/site/src/App.vue +++ b/site/src/App.vue @@ -37,9 +37,9 @@ const toggleDark = useToggle(dark); const theme = computed(() => dark.value ? 'dark' : 'light'); const themeIcon = computed(() => dark.value ? 'mdi-moon-waxing-crescent' : 'mdi-white-balance-sunny'); -const { status, data, send, open, close } = useWebSocket(`wss://${window.location.host}/queue`, { - immediate: false, -}); +const local = window.location.hostname === 'localhost'; + +const { status, data, send, open, close } = useWebSocket(`wss://${window.location.host}/queue`, {immediate: false}); const game = ref(null); const dealer = ref(null); watchEffect(() => { @@ -66,11 +66,31 @@ const playing = computed(() => game.value != null); const loading = computed(() => status.value === 'CONNECTING' || status.value === 'OPEN' && !playing.value); 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(); send('{"action":"ping"}'); } function action(evt: Action) { + if (local && game.value != null) { + game.value.dealer = !game.value.dealer; + return; + } if (evt.action === 'quit') { // Just close the connection. The server knows what to do. data.value = null; @@ -85,6 +105,11 @@ function action(evt: Action) { const loadingMe = ref(true); const me = ref(null); onMounted(async () => { + if (local) { + loadingMe.value = false; + me.value = 'a'; + return; + } loadingMe.value = true; try { const resp = await fetch('/user/me', {