data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: make pet be able to be shaken on mobile devices

dusk ddfc3725 c0ecb189

+42 -10
+33 -3
src/components/pet.svelte
··· 74 74 }; 75 75 76 76 const move = () => { 77 - if (dragged) { 78 - return; 79 - } 77 + if (dragged) return; 80 78 81 79 // Apply physics when pet is in motion 82 80 if (velocityX !== 0 || velocityY !== 0 || position.y !== 0) { ··· 151 149 152 150 setInterval(move, tickRate); 153 151 152 + const shake = (event: DeviceMotionEvent) => { 153 + const accel = event.acceleration; 154 + if (accel === null || accel.x === null || accel.y === null || accel.z === null) return; 155 + if (Math.abs(accel.x) + Math.abs(accel.z) < 40.0) return; 156 + velocityX += accel.x * 4.0; 157 + velocityY += accel.z * 3.0; 158 + }; 159 + 160 + self.ondevicemotion = shake; 161 + 162 + // this is for ios 163 + const askForShakePermission = () => { 164 + if ( 165 + typeof DeviceMotionEvent !== 'undefined' && 166 + // eslint-disable-next-line @typescript-eslint/no-explicit-any 167 + typeof (DeviceMotionEvent as any).requestPermission === 'function' 168 + ) { 169 + // eslint-disable-next-line @typescript-eslint/no-explicit-any 170 + (DeviceMotionEvent as any) 171 + .requestPermission() 172 + .then((permissionState: string) => { 173 + if (permissionState === 'granted') { 174 + self.ondevicemotion = shake; 175 + } 176 + }) 177 + .catch(console.error); 178 + } 179 + }; 180 + 154 181 const pickNewTargetX = () => { 155 182 const viewportWidth = self.innerWidth || null; 156 183 if (viewportWidth !== null && Math.abs(position.x - targetX) < 5) { ··· 210 237 class="absolute bottom-[5vh] z-[1000] hover:animate-squiggle" 211 238 style="cursor: url('/icons/gaze.webp'), pointer;" 212 239 > 240 + <!-- svelte-ignore a11y_no_noninteractive_element_interactions --> 241 + <!-- svelte-ignore a11y_click_events_have_key_events --> 213 242 <img 214 243 draggable="false" 244 + onclick={askForShakePermission} 215 245 style=" 216 246 image-rendering: pixelated !important; 217 247 transform: rotate({rotation}rad) scaleX({flip ? -1 : 1});
+4 -1
src/lib/metrics.ts
··· 3 3 import { pushMetrics } from 'prometheus-remote-write'; 4 4 import { get, writable } from 'svelte/store'; 5 5 6 + const endpoint = env.PROMETHEUS_URL; 7 + 6 8 export const pushMetric = async ( 7 9 metrics: Record<string, number>, 8 10 labels: Record<string, string> = {} 9 11 ) => { 12 + if (endpoint === undefined) return; 10 13 const result = await pushMetrics(metrics, { 11 - url: env.PROMETHEUS_URL, 14 + url: endpoint, 12 15 labels: { 13 16 service: 'website', 14 17 ...labels
+1 -3
src/routes/+layout.svelte
··· 143 143 {@render children?.()} 144 144 </div> 145 145 146 - {#if !isMobile()} 147 - <Pet></Pet> 148 - {/if} 146 + <Pet></Pet> 149 147 150 148 <nav class="w-full min-h-[5vh] max-h-[5vh] fixed bottom-0 z-[999] bg-ralsei-black overflow-visible"> 151 149 <div
+4 -3
vite.config.ts
··· 2 2 import { defineConfig } from 'vite'; 3 3 4 4 export default defineConfig({ 5 - plugins: [ 6 - sveltekit(), 7 - ] 5 + plugins: [sveltekit()], 6 + server: { 7 + //allowedHosts: true 8 + } 8 9 });