PageSourceSearch

https://gamevibe.us/assets/178-Baseball-CHhAZYvJ.js

js gamevibe.us collected 2026-10-10 01:13:58 UTC 15,793 bytes, 1 lines download raw bytes

1import{a as se,j as e}from"./index-B8j-9aKy.js";import{b as n}from"./vendor-react-BWjNeuN-.js";import{G as he}from"./GameShell-oaSlFUww.js";import{g as fe}from"./audio-Dg-qQ4GC.js";import{e as xe,N as de,a3 as me,G as pe,f as ge,F as ye,c as be,M as je}from"./sfx-BbGp0Yq0.js";import"./NotFoundPage-fRqBHVvP.js";import"./circle-check-2tRLWn78.js";import"./heart-CBVLvJjs.js";import"./GameEditDialog-CFlo6OZu.js";import"./label-BmL1bEKx.js";import"./categorySlug-BTIspAdd.js";import"./pencil-bEuV4KQn.js";import"./chevron-right-7ZPkw_L-.js";const G=560,le=360,E={x:280,y:128},b={cx:280,cy:262,hw:46,hh:56},we=235,ke=["Fastball","Curveball","Changeup"],ve={HomeRun:"HOME RUN!",Triple:"Triple!",Double:"Double!",Single:"Single!",Out:"Out",Foul:"Foul ball",SwingMiss:"Swing and a miss!",CalledStrike:"Called strike",Ball:"Ball"},Se={inning:1,outs:0,balls:0,strikes:0,bases:0,inningPitchesLeft:10,runs:0,score:0,hits:0,homeRuns:0,walks:0,strikeouts:0},k={x:222,y:272},re=66,Ne=Math.PI/180,M=190,U=385,D=470,Me=.32,J=t=>t*t*(3-2*t);function ne(t){if(t<0||t>700)return{phi:M,lift:44};if(t<110){const l=J(t/110);return{phi:M+(U-M)*l,lift:44-46*l}}if(t<280){const l=J((t-110)/170);return{phi:U+(D-U)*l,lift:-2+30*l}}if(t<420)return{phi:D,lift:28};const i=J((t-420)/280);return{phi:D+(M+360-D)*i,lift:28+16*i}}function B(t,i){const l=t*Ne,h=1+.28*-Math.sin(l),m=k.x+re*Math.cos(l),c=k.y-re*Math.sin(l)*Me-i,p=m-k.x,x=c-k.y,j=Math.hypot(p,x)||1,w=-x/j,F=p/j,a=(R,v,L)=>`${(k.x+p*R+w*v*h*L).toFixed(1)},${(k.y+x*R+F*v*h*L).toFixed(1)}`;return[a(0,1.4,1),a(.62,1.7,1),a(.86,3.6,1),a(1,3,1),a(1,3,-1),a(.86,3.6,-1),a(.62,1.7,-1),a(0,1.4,-1)].join(" ")}function Re(t,i){const l=t.children[0],u=t.children[1],h=t.children[2];if(!l||!u||!h)return;const m=ne(i);l.setAttribute("points",B(m.phi,m.lift));const c=i>=0&&i<300,p=(x,j)=>{const w=ne(i-j);x.setAttribute("points",B(w.phi,w.lift)),x.setAttribute("opacity",c?"0.28":"0")};p(u,18),p(h,36)}function ie(t,i){const l=b.cx+t.px/1e3*b.hw,u=b.cy+t.py/1e3*b.hh,h=Math.sin(Math.PI*Math.min(1,Math.max(0,i)));let m=E.x+(l-E.x)*i,c=E.y+(u-E.y)*i;return t.type===1&&(m+=52*h*(l<E.x?-1:1),c-=30*h),t.type===2&&(c-=26*h),{x:m,y:c,r:3+9*i*i}}function Ze(){const[t,i]=n.useState(!1),[l,u]=n.useState(0),[h,m]=n.useState(!1),[c,p]=n.useState(null),[x,j]=n.useState(Se),[w,F]=n.useState(null),[a,R]=n.useState(null),[v,L]=n.useState(null),[Y,Q]=n.useState(null),V=n.useRef(null),$=n.useRef(null),O=n.useRef(0),A=n.useRef(!0),_=n.useRef(0),W=n.useRef(null),S=n.useRef(null),P=n.useRef(null),X=n.useRef(null),ee=n.useRef(null),T=n.useRef(!0);n.useEffect(()=>(T.current=!0,()=>{T.current=!1,S.current&&window.clearTimeout(S.current),P.current&&cancelAnimationFrame(P.current)}),[]);const H=n.useCallback(async(s,f={})=>{try{return await se(s,{method:"POST",body:JSON.stringify({sessionId:V.current,...f})})}catch(g){return Q((g==null?void 0:g.message)??"Something went wrong."),xe(),null}},[]),Z=n.useCallback(()=>{P.current=requestAnimationFrame(Z);const s=performance.now(),f=X.current,g=ee.current,d=$.current;if(g){const o=_.current?s-_.current:9999;Re(g,o)}if(!f)return;const r=W.current;if(r){const o=Math.min(1,(s-r.t0)/1300),K=r.from.x+r.dx*o,y=r.from.y-(r.hr?250:120)*Math.sin(Math.PI*Math.min(1,o*.5+(r.hr?.1:0)))*(r.hr?1:o)+(r.hr?0:70*o*o);f.setAttribute("transform",`translate(${K} ${y}) scale(${Math.max(.3,1.4-o)})`),f.setAttribute("opacity",String(o<1?1:0));return}if(!d||O.current===0){f.setAttribute("opacity","0");return}const N=s-O.current,I=N/d.arrivalMs;if(I<=1.12){const o=ie(d,Math.min(I,1));f.setAttribute("transform",`translate(${o.x} ${o.y}) scale(${o.r/9})`),f.setAttribute("opacity","1")}else f.setAttribute("opacity","0");!A.current&&N>d.arrivalMs+we&&q(!1,N)},[]);n.useEffect(()=>{if(h)return P.current=requestAnimationFrame(Z),()=>{P.current&&cancelAnimationFrame(P.current)}},[h,Z]);const C=n.useCallback(async()=>{const s=await H("/api/baseball/pitch");!s||!T.current||(Q(null),R(null),W.current=null,_.current=0,$.current=s.pitch,F(s.pitch),j(s.state),A.current=!1,O.current=performance.now())},[H]),q=n.useCallback(async(s,f)=>{const g=$.current;if(!g||A.current)return;A.current=!0,s&&(_.current=performance.now(),de());const d=await H("/api/baseball/swing",{pitch:g.index,swing:s,tMs:Math.round(f)});if(!T.current)return;if(!d){S.current=window.setTimeout(()=>void C(),1200);return}const r=d.result;j(d.state),u(y=>y+1);const N=["Single","Double","Triple","HomeRun"].includes(r.outcome);if(r.outcome==="HomeRun"?me():N?pe():r.outcome==="Ball"?ge():ye(),N||r.outcome==="Foul"||r.outcome==="Out"&&s){const y=ie(g,1),ue=(r.errMs??0)<0?-1:1;W.current={t0:performance.now(),from:{x:y.x,y:y.y}
1,dx:ue*(r.outcome==="Foul"?230:120),hr:r.outcome==="HomeRun"}}const I=r.note==="Strikeout"?"Strikeout!":r.note==="Walk"?"Walk":ve[r.outcome]??r.outcome;let o="";if(r.errMs!==null){const y=r.errMs;o=Math.abs(y)<=8?"Perfect timing":`${Math.abs(y)} ms ${y<0?"early":"late"}`,r.outcome==="Out"&&!r.strike&&(o="Chased a ball — "+o)}r.runs>0&&(o=`${r.runs} run${r.runs>1?"s":""} score! ${o}`.trim());const K=r.runs>0||N?"good":r.outcome==="Ball"?"neutral":"bad";R({text:I,sub:r.inningOver&&!d.done?`${o} · Side retired`:o,tone:K}),d.done?(be(),S.current=window.setTimeout(()=>{T.current&&L(d.finalScore??d.totalScore)},1600)):S.current=window.setTimeout(()=>void C(),r.inningOver?2e3:1100)},[H,C]),z=n.useCallback(()=>{A.current||v!==null||q(!0,performance.now()-O.current)},[q,v]);n.useEffect(()=>{const s=f=>{(f.code==="Space"||f.key==="Enter")&&(f.preventDefault(),z())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[z]);const te=n.useCallback(async()=>{fe(),S.current&&window.clearTimeout(S.current),i(!0),Q(null);try{const s=await se("/api/baseball/start",{method:"POST"});V.current=s.sessionId,p({innings:s.innings,pitchesPerInning:s.pitchesPerInning,ceiling:s.ceiling,runPoints:s.runPoints}),j(s.state),L(null),R(null),F(null),$.current=null,W.current=null,A.current=!0,m(!0),je()}finally{i(!1)}await C()},[C]),oe=e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Baseball"}),": you are the batter. The pitcher throws, you decide whether to swing — and when."]}),e.jsxs("ul",{children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Swing"})," with Space / Enter or by clicking or tapping the field, timed to the moment the ball reaches the plate. The page tells you how early or late you were."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Take"})," a pitch by not swinging: outside the zone it is a ball, inside it is a called strike."]}),e.jsxs("li",{children:["A strike swung at on the dot is a ",e.jsx("strong",{children:"home run"}),"; a little off is a triple, double or single, further off a weak out, a foul or a miss. Safe hits can still be caught. Chasing a ball outside the zone can only ever be a weak out or a foul."]}),e.jsx("li",{children:"Three strikes is out; a foul is a strike unless you already have two. Four balls is a walk. Hits move your runners along as many bases as the hit."}),e.jsxs("li",{children:["Five innings. An inning ends on three outs ",e.jsx("strong",{children:"or"})," after ten pitches. Each run is worth ",(c==null?void 0:c.runPoints)??100," points."]}),e.jsxs("li",{children:["Pitches get faster each inning, and curveballs and changeups change the timing. The theoretical maximum is ",((c==null?void 0:c.ceiling)??5e3).toLocaleString()," — a home run on every pitch — but about four pitches in ten are balls you should leave alone, so a flawless game lands nearer 3,000."]})]}),e.jsx("p",{className:"text-xs opacity-70",children:'Inspired by "Baseball Game" in the GameZone collection (Apache-2.0); the pitching, timing and server-held scoring are new. The pitcher is the server: every pitch and every result is decided there, so the page cannot set an outcome or a score.'})]}),ae=s=>e.jsxs("div",{className:"flex flex-col items-center gap-6 py-8 px-4",children:[e.jsx(Te,{}),s&&e.jsx("p",{className:"text-muted-foreground text-sm text-center max-w-sm leading-relaxed",children:s}),e.jsx("button",{onClick:te,className:"rounded-xl bg-primary px-10 py-3 text-base font-bold text-primary-foreground hover:bg-primary/90 transition-all hover:scale-105 active:scale-95",children:"Play Ball"})]}),ce=(a==null?void 0:a.tone)==="good"?"text-emerald-300":(a==null?void 0:a.tone)==="bad"?"text-rose-300":"text-slate-100";return e.jsx(he,{scoreRefreshKey:l,rules:oe,gameLoading:t,titleContent:ae,children:h?e.jsxs("div",{className:"w-full max-w-[600px] mx-auto select-none",children:[e.jsx(Ae,{st:x,innings:(c==null?void 0:c.innings)??5}),e.jsxs("div",{className:"relative mt-2 rounded-xl overflow-hidden shadow-lg touch-none cursor-pointer",onPointerDown:s=>{s.preventDefault(),z()},children:[e.jsxs("svg",{viewBox:`0 0 ${G} ${le}`,className:"w-full h-auto block",role:"img","aria-label":"Batter's view of the plate. The pitcher throws toward the strike zone.",children:[e.jsx(Pe,{}),e.jsx("rect",{x:b.cx-b.hw,y:b.cy-b.hh,width:b.hw*2,height:b.hh*2,fill:"rgba(255,255,255,0.07)",stroke:"rgba(255,255,255,0.75)",strokeWidth:"2",rx:"2"}),e.jsx(Le,{batRef:ee}),e.jsxs("g",{ref:X,opacity:"0",children:[e.jsx("circle",{r:"9",fill:"#fafafa",stroke:"#9ca3af",strokeWidth:"0.8"}),e.jsx("path",{d:"M-6 -5 Q-2 0 -6 5 M6 -5 Q2 0 6 5",fill:"none",stroke:"#dc2626",strokeWidth:"1.2"})]}),w&&!a&&e.jsxs("text",{x:"280",y:"92",textAnchor:"middle",fontSize:"13",fontWeight:"800",fill:"#fff",opacity:"0.9",fontFamily:"sans-serif",children:[ke[w.type]," · ",w.mph," mph"]}
1)]}),a&&e.jsxs("div",{className:"absolute inset-x-0 top-6 flex flex-col items-center pointer-events-none",children:[e.jsx("div",{className:`text-3xl sm:text-4xl font-black drop-shadow-[0_2px_4px_rgba(0,0,0,0.9)] ${ce}`,children:a.text}),a.sub&&e.jsx("div",{className:"mt-1 text-sm font-semibold text-white drop-shadow-[0_1px_3px_rgba(0,0,0,0.9)]",children:a.sub})]}),v!==null&&e.jsxs("div",{className:"absolute inset-0 bg-black/70 flex flex-col items-center justify-center gap-3 text-white text-center p-4",children:[e.jsx("div",{className:"text-2xl font-black",children:"Game over"}),e.jsx("div",{className:"text-5xl font-black tabular-nums",children:v.toLocaleString()}),e.jsxs("div",{className:"text-sm opacity-80",children:[x.runs," ",x.runs===1?"run":"runs"," · ",x.hits," hits · ",x.homeRuns," HR · ",x.walks," walks · ",x.strikeouts," K"]}),e.jsx("button",{onClick:s=>{s.stopPropagation(),te()},onPointerDown:s=>s.stopPropagation(),className:"mt-2 rounded-xl bg-primary px-8 py-2.5 font-bold text-primary-foreground hover:bg-primary/90 active:scale-95 transition-all",children:"Play Again"})]})]}),e.jsxs("p",{className:"mt-2 text-center text-xs text-muted-foreground",children:["Press ",e.jsx("kbd",{className:"rounded bg-muted px-1",children:"Space"})," or tap the field to swing — leave it alone to take the pitch."]}),Y&&e.jsx("p",{className:"mt-1 text-center text-sm text-red-500",children:Y})]}):null})}function Ae({st:t,innings:i}){const l=(u,h,m)=>e.jsx("span",{className:"inline-flex gap-1",children:Array.from({length:h},(c,p)=>e.jsx("span",{className:`h-2.5 w-2.5 rounded-full border ${p<u?m:"bg-transparent border-slate-500"}`},p))});return e.jsxs("div",{className:"grid grid-cols-[auto_1fr_auto] items-center gap-3 rounded-xl bg-slate-900 text-slate-100 px-4 py-2.5 text-sm tabular-nums",children:[e.jsxs("svg",{viewBox:"0 0 40 36",className:"h-10 w-11","aria-label":"Runners on base",children:[[{x:20,y:4,m:2},{x:33,y:17,m:1},{x:7,y:17,m:4}].map(u=>e.jsx("rect",{x:u.x-5,y:u.y-5,width:"10",height:"10",transform:`rotate(45 ${u.x} ${u.y})`,fill:t.bases&u.m?"#facc15":"#1e293b",stroke:"#94a3b8",strokeWidth:"1.2"},u.m)),e.jsx("rect",{x:"15",y:"26",width:"10",height:"7",fill:"#e2e8f0"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{children:["Inning ",e.jsx("strong",{children:t.inning})," / ",i," ",e.jsxs("span",{className:"opacity-60",children:["· ",t.inningPitchesLeft," pitches left"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:["Outs ",l(t.outs,3,"bg-rose-400 border-rose-400")]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:["B ",l(t.balls,3,"bg-emerald-400 border-emerald-400")]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:["S ",l(t.strikes,2,"bg-amber-400 border-amber-400")]})]})]}),e.jsxs("div",{className:"text-right leading-tight",children:[e.jsxs("div",{className:"text-xs opacity-70",children:["Runs ",t.runs]}),e.jsx("div",{className:"text-xl font-black",children:t.score.toLocaleString()})]})]})}function Pe(){return e.jsxs("g",{children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"bbSky",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0",stopColor:"#7dd3fc"}),e.jsx("stop",{offset:"1",stopColor:"#e0f2fe"})]}),e.jsxs("linearGradient",{id:"bbGrass",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0",stopColor:"#4ade80"}),e.jsx("stop",{offset:"1",stopColor:"#15803d"})]})]}),e.jsx("rect",{width:G,height:le,fill:"url(#bbSky)"}),e.jsx("rect",{y:"38",width:G,height:"40",fill:"#64748b"}),Array.from({length:56},(t,i)=>e.jsx("circle",{cx:6+i*10,cy:48+i%3*9,r:"3",fill:["#f87171","#fbbf24","#e2e8f0","#60a5fa"][i%4],opacity:"0.85"},i)),e.jsx("rect",{y:"78",width:G,height:"282",fill:"url(#bbGrass)"}),e.jsx("path",{d:"M280 100 L470 215 L280 360 L90 215 Z",fill:"#c08457",opacity:"0.9"}),e.jsx("ellipse",{cx:"280",cy:"138",rx:"26",ry:"9",fill:"#a9703f"}),e.jsx("rect",{x:"268",y:"135",width:"24",height:"3",rx:"1",fill:"#fff"}),e.jsxs("g",{children:[e.jsx("ellipse",{cx:"280",cy:"124",rx:"7",ry:"9",fill:"#1e3a8a"}),e.jsx("circle",{cx:"280",cy:"112",r:"5",fill:"#fcd9b6"}),e.jsx("rect",{x:"274",y:"105",width:"12",height:"4",rx:"2",fill:"#1e3a8a"})]}),e.jsx("path",{d:"M260 322 L300 322 L300 332 L280 342 L260 332 Z",fill:"#f8fafc",stroke:"#cbd5e1"}),e.jsx("rect",{x:"196",y:"285",width:"44",height:"64",fill:"none",stroke:"#f8fafc",strokeWidth:"2",opacity:"0.8"}),e.jsx("rect",{x:"320",y:"285",width:"44",height:"64",fill:"none",stroke:"#f8fafc",strokeWidth:"2",opacity:"0.8"})]})}function Le({batRef:t}){return e.jsxs("g",{children:[e.jsx("ellipse",{cx:"208",cy:"318",rx:"14",ry:"4",fill:"rgba(0,0,0,0.25)"}),e.jsx("rect",{x:"198",y:"262",width:"22",height:"50",rx:"9",fill:"#1d4ed8"}
1),e.jsx("rect",{x:"199",y:"305",width:"8",height:"18",rx:"3",fill:"#e2e8f0"}),e.jsx("rect",{x:"211",y:"305",width:"8",height:"18",rx:"3",fill:"#e2e8f0"}),e.jsx("circle",{cx:"209",cy:"252",r:"9",fill:"#fcd9b6"}),e.jsx("path",{d:"M199 250 Q209 238 219 250 L222 252 L198 252 Z",fill:"#1e3a8a"}),e.jsxs("g",{ref:t,children:[e.jsx("polygon",{points:B(M,44),fill:"#d6a15c",stroke:"#8a5a24",strokeWidth:"0.8",strokeLinejoin:"round"}),e.jsx("polygon",{points:B(M,44),fill:"#e9c58a",opacity:"0"}),e.jsx("polygon",{points:B(M,44),fill:"#e9c58a",opacity:"0"})]}),e.jsx("circle",{cx:k.x,cy:k.y,r:"3.4",fill:"#fcd9b6"})]})}function Te(){return e.jsxs("svg",{viewBox:"0 0 230 100",className:"h-24 w-auto","aria-hidden":"true",children:[e.jsx("rect",{width:"230",height:"100",rx:"8",fill:"#15803d"}),e.jsx("path",{d:"M115 14 L190 58 L115 100 L40 58 Z",fill:"#c08457"}),e.jsx("rect",{x:"108",y:"56",width:"14",height:"14",transform:"rotate(45 115 63)",fill:"#f8fafc"}),e.jsx("rect",{x:"62",y:"30",width:"6",height:"52",rx:"3",transform:"rotate(35 65 56)",fill:"#d6a15c",stroke:"#8a5a24"}),e.jsx("circle",{cx:"160",cy:"34",r:"12",fill:"#fafafa",stroke:"#9ca3af"}),e.jsx("path",{d:"M152 28 Q157 34 152 40 M168 28 Q163 34 168 40",fill:"none",stroke:"#dc2626",strokeWidth:"2"}),e.jsx("text",{x:"115",y:"94",textAnchor:"middle",fontSize:"13",fontWeight:"900",fill:"#fff",fontFamily:"sans-serif",letterSpacing:"2",children:"BASEBALL"})]})}export{Ze as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.