172 lines
7.8 KiB
HTML
172 lines
7.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover">
|
|
<title>TurboSu - Forza Composite</title>
|
|
<style>
|
|
*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}
|
|
html,body{width:100%;height:100%;overflow:hidden;background:#0a0a0f;color:#fff;
|
|
font-family:'SF Pro Display',-apple-system,system-ui,sans-serif}
|
|
#root{width:100%;height:100%;display:flex;align-items:center;justify-content:center}
|
|
#box{position:relative;overflow:hidden}
|
|
#box.contain{max-width:100vw;max-height:100vh}
|
|
#box.cover{min-width:100vw;min-height:100vh}
|
|
#box.fill{width:100vw;height:100vh}
|
|
#content{position:relative;width:100%;height:100%;background:#0a0a0f}
|
|
|
|
/* RPM arc */
|
|
#rpm-area{position:absolute;left:3%;top:6%;width:60%;height:78%}
|
|
#rpm-svg{width:100%;height:100%}
|
|
|
|
/* Speed */
|
|
#speed-area{position:absolute;left:3%;bottom:8%;width:60%;text-align:center}
|
|
#speed-val{font-size:min(8vw,76px);font-weight:200;line-height:1;letter-spacing:-.02em}
|
|
#speed-unit{font-size:min(2vw,16px);color:rgba(255,255,255,.2);letter-spacing:.2em;margin-top:2px}
|
|
|
|
/* Gear */
|
|
#gear-area{position:absolute;right:6%;top:50%;transform:translateY(-55%);text-align:center}
|
|
#gear-box{width:min(16vw,140px);height:min(16vw,140px);border-radius:50%;border:2px solid rgba(255,255,255,.12);display:flex;align-items:center;justify-content:center}
|
|
#gear-box span{font-size:min(8vw,72px);font-weight:200;transition:.1s}
|
|
|
|
/* Pedals */
|
|
#pedals{position:absolute;right:4%;top:5%;width:18%}
|
|
.pedal{margin-bottom:12px}
|
|
.pedal .pl{font-size:min(1.3vw,10px);color:rgba(255,255,255,.2);margin-bottom:4px;text-transform:uppercase;letter-spacing:.1em}
|
|
.pedal .pb{height:6px;background:rgba(255,255,255,.06);overflow:hidden}
|
|
.pedal .pf{height:100%;transition:width .06s linear}
|
|
#tf{background:#fff}#bf{background:rgba(255,255,255,.4)}
|
|
|
|
/* Fuel / Temp */
|
|
#status{position:absolute;right:4%;bottom:6%;width:18%}
|
|
.st{margin-bottom:10px}
|
|
.st .sl{font-size:min(1.2vw,10px);color:rgba(255,255,255,.2);margin-bottom:3px;display:flex;justify-content:space-between}
|
|
.st .sb{height:3px;background:rgba(255,255,255,.06);overflow:hidden}
|
|
.st .sf{height:100%;transition:width .3s}
|
|
#ff{background:rgba(255,255,255,.3)}#wf{background:rgba(255,255,255,.15)}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="root"><div id="box" class="contain"><div id="content">
|
|
<div id="rpm-area"><svg id="rpm-svg" viewBox="0 0 640 480" preserveAspectRatio="xMidYMid meet"></svg></div>
|
|
<div id="speed-area"><div id="speed-val">0</div><div id="speed-unit">KM/H</div></div>
|
|
<div id="gear-area"><div id="gear-box"><span id="gear-val">1</span></div></div>
|
|
<div id="pedals">
|
|
<div class="pedal"><div class="pl">THR</div><div class="pb"><div class="pf" id="tf" style="width:0%"></div></div></div>
|
|
<div class="pedal"><div class="pl">BRK</div><div class="pb"><div class="pf" id="bf" style="width:0%"></div></div></div>
|
|
</div>
|
|
<div id="status">
|
|
<div class="st"><div class="sl"><span>FUEL</span><span id="fv">100%</span></div><div class="sb"><div class="sf" id="ff" style="width:100%"></div></div></div>
|
|
<div class="st"><div class="sl"><span>TEMP</span><span id="wv">--</span></div><div class="sb"><div class="sf" id="wf" style="width:20%"></div></div></div>
|
|
</div>
|
|
</div></div></div>
|
|
<script>
|
|
const M={aspect_ratio:"16:9",render_mode:"contain"};
|
|
let GAME_ID='';
|
|
|
|
(function(){
|
|
const box=document.getElementById('box'),svg=document.getElementById('rpm-svg'),
|
|
sV=document.getElementById('speed-val'),sU=document.getElementById('speed-unit'),
|
|
gV=document.getElementById('gear-val'),gBox=document.getElementById('gear-box'),
|
|
tF=document.getElementById('tf'),bF=document.getElementById('bf'),
|
|
fF=document.getElementById('ff'),fV=document.getElementById('fv'),
|
|
wF=document.getElementById('wf'),wV=document.getElementById('wv');
|
|
const proto=location.protocol==='https:'?'wss:':'ws:',wsUrl=proto+'//'+location.host+'/ws';
|
|
let ws,rt,lR=-1,lG=-999;
|
|
|
|
const CX=300,CY=420,R=300,SA=180,EA=270;
|
|
|
|
function d2r(d){return d*Math.PI/180}
|
|
|
|
function drawRpm(cur,max,gear){
|
|
max=max||8000;cur=cur||0;
|
|
const sx=CX+R*Math.cos(d2r(SA)),sy=CY+R*Math.sin(d2r(SA)); // arc start
|
|
const ex=CX+R*Math.cos(d2r(EA)),ey=CY+R*Math.sin(d2r(EA)); // arc end -> top of arc
|
|
const lx=620,ly=ey; // straight line end (right side, same Y as arc top)
|
|
|
|
// arc length (90°) = 2πR * 90/360
|
|
const arcLen=Math.PI*R*90/360;
|
|
const lineLen=lx-ex;
|
|
const totalLen=arcLen+lineLen;
|
|
|
|
let h='';
|
|
// background: arc + line
|
|
h+=`<path d="M${sx},${sy} A${R},${R} 0 0 0 ${ex},${ey} L${lx},${ly}" fill="none" stroke="rgba(255,255,255,.04)" stroke-width="22" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
|
|
// scale marks on arc
|
|
for(let r=0;r<=max;r+=1000){
|
|
const pct=r/max;
|
|
const ang=SA+(EA-SA)*pct;
|
|
if(ang<=EA){
|
|
const a=d2r(ang);
|
|
const x1=CX+(R-18)*Math.cos(a),y1=CY+(R-18)*Math.sin(a);
|
|
const x2=CX+(R+18)*Math.cos(a),y2=CY+(R+18)*Math.sin(a);
|
|
const c=r>=max*0.85?'rgba(255,255,255,.12)':(r%2000===0?'rgba(255,255,255,.15)':'rgba(255,255,255,.05)');
|
|
h+=`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${c}" stroke-width="${r%2000===0?2:1}"/>`;
|
|
if(r%2000===0){
|
|
h+=`<text x="${CX+(R-34)*Math.cos(a)}" y="${CY+(R-34)*Math.sin(a)+4}" text-anchor="middle" font-size="10" fill="rgba(255,255,255,.2)">${r/1000}</text>`;
|
|
}
|
|
}
|
|
}
|
|
|
|
// progress
|
|
if(cur>0){
|
|
const pct=Math.min(cur/max,1);
|
|
if(pct<=arcLen/totalLen){
|
|
// progress within arc
|
|
const ap=pct*totalLen/arcLen;
|
|
const ang=SA+(EA-SA)*ap;
|
|
const px=CX+R*Math.cos(d2r(ang)),py=CY+R*Math.sin(d2r(ang));
|
|
h+=`<path d="M${sx},${sy} A${R},${R} 0 0 0 ${px},${py}" fill="none" stroke="#fff" stroke-width="22" stroke-linecap="round"/>`;
|
|
}else{
|
|
// full arc + partial line
|
|
const lp=(pct*totalLen-arcLen)/lineLen;
|
|
const px=ex+lp*(lx-ex);
|
|
h+=`<path d="M${sx},${sy} A${R},${R} 0 0 0 ${ex},${ey} L${px},${ly}" fill="none" stroke="#fff" stroke-width="22" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
}
|
|
}
|
|
|
|
h+=`<text x="${CX}" y="${CY-24}" text-anchor="middle" font-size="22" font-weight="200" fill="#fff">${Math.round(cur).toLocaleString()}</text>`;
|
|
h+=`<text x="${CX}" y="${CY+4}" text-anchor="middle" font-size="10" fill="rgba(255,255,255,.15)">×1000 rpm</text>`;
|
|
svg.innerHTML=h;
|
|
}
|
|
|
|
function parseRatio(r){if(!r||r==='auto')return null;const p=r.split(':');if(p.length===2){const w=+p[0],h=+p[1];return w/h}return null}
|
|
|
|
function apply(){
|
|
const ratio=parseRatio(M.aspect_ratio||'16:9'),mode=M.render_mode||'contain';
|
|
if(!ratio){box.style.width='100vw';box.style.height='100vh';box.className='fill';return}
|
|
const vw=window.innerWidth,vh=window.innerHeight,vr=vw/vh;let cw,ch;
|
|
if(mode==='cover'){cw=vw;ch=vw/ratio;box.className='cover'}
|
|
else{box.className='contain';cw=vr>ratio?vh*ratio:vw;ch=vr>ratio?vh:vw/ratio}
|
|
box.style.width=cw+'px';box.style.height=ch+'px'
|
|
}
|
|
|
|
function connect(){
|
|
ws=new WebSocket(wsUrl);ws.onopen=()=>{if(rt){clearTimeout(rt);rt=null}}
|
|
ws.onmessage=(e)=>{try{const m=JSON.parse(e.data);
|
|
if(m.type==='connected')GAME_ID=m.selected_game_id||'';
|
|
if(m.type==='telemetry')update(m.data)
|
|
}catch(e){}}
|
|
ws.onclose=()=>{rt=setTimeout(connect,2000)}
|
|
}
|
|
|
|
function update(d){
|
|
const rpm=d.rpm||0,mr=d.max_rpm||8000,g=d.gear||0,sp=d.speed_kmh||0;
|
|
if(Math.abs(rpm-lR)>30||g!==lG){lR=rpm;lG=g;drawRpm(rpm,mr,g)}
|
|
sV.textContent=Math.round(sp);
|
|
const gv=g===0?'N':g===11?'R':g===21?'P':String(g);
|
|
gV.textContent=gv;
|
|
tF.style.width=(d.throttle*100).toFixed(0)+'%';
|
|
bF.style.width=(d.brake*100).toFixed(0)+'%';
|
|
const fp=Math.round((d.fuel||1)*100);fF.style.width=fp+'%';fV.textContent=fp+'%';
|
|
const et=d.engine_temp||0;
|
|
if(et>0){const ep=Math.min(et/120,1)*100;wF.style.width=ep+'%';wV.textContent=Math.round(et)+'\u00B0C'}
|
|
}
|
|
|
|
drawRpm(0,8000,1);apply();window.addEventListener('resize',apply);connect()
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|