Files
TurboSu/dashboards/gear_indicator/index.html
T

136 lines
6.0 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 - 档位</title>
<style>
*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}
html,body{width:100%;height:100%;overflow:hidden;background:#000;
font-family:'SF Pro Text',-apple-system,'PingFang SC',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}
#box.center{width:auto;height:auto}
#content{width:100%;height:100%;display:flex;align-items:center;justify-content:center;
background:linear-gradient(135deg,#0a0a14,#1a1a30);flex-direction:column;gap:min(2.5vh,16px)}
.gear-circle{position:relative;width:min(28vmin,120px);height:min(28vmin,120px);
border-radius:50%;background:rgba(52,130,255,.08);border:3px solid rgba(52,130,255,.3);
display:flex;align-items:center;justify-content:center;
box-shadow:0 0 40px rgba(52,130,255,.1);transition:border-color .2s,border-width .2s}
.gear-circle span{font-size:min(13vmin,50px);font-weight:900;color:#fff;transition:.12s ease}
.gear-circle.r-active{border-color:rgba(233,70,52,.55);box-shadow:0 0 50px rgba(233,70,52,.2)}
.gear-circle.n-active{border-color:rgba(255,255,255,.25)}
.gear-circle.p-active{border-color:rgba(52,199,89,.3)}
.bar-row{display:flex;gap:min(1.2vw,6px);align-items:flex-end;padding:0 6px;flex-wrap:wrap;justify-content:center}
.bar-col{display:flex;flex-direction:column;align-items:center;gap:3px;min-width:min(7vw,32px)}
.bar-label{font-size:min(2.2vmin,12px);font-weight:600;color:rgba(255,255,255,.2);transition:color .2s}
.bar-fill{width:min(5vw,24px);height:min(5vw,24px);border-radius:5px;background:rgba(255,255,255,.05);transition:background .2s,transform .15s}
.bar-col.active .bar-fill{background:var(--accent,#3482FF);transform:scaleY(1.25)}
.bar-col.active .bar-label{color:#fff}
.bar-col.r .bar-fill{background:rgba(233,70,52,.25)}
.bar-col.r.active .bar-fill{background:#E94634}
.bar-col.n .bar-fill{background:rgba(255,255,255,.08)}
.bar-col.n.active .bar-fill{background:rgba(255,255,255,.2)}
.bar-col.p .bar-fill{background:rgba(52,199,89,.15)}
.bar-col.p.active .bar-fill{background:rgba(52,199,89,.5)}
</style>
</head>
<body>
<div id="root"><div id="box" class="contain"><div id="content">
<div class="gear-circle" id="gear-el"><span id="gear-txt">-</span></div>
<div class="bar-row" id="bar-row"></div>
</div></div></div>
<script>
const M={aspect_ratio:"1:1",render_mode:"contain"};
let GAME_ID='';
const AC_STYLE_LABELS=['R','N','1','2','3','4','5','6','7','8'];
const FORZA_LABELS=['N','1','2','3','4','5','6','7','8','9','10','R','P'];
function parseRatio(r){if(!r||r==='auto')return null;const p=r.split(':');if(p.length===2){const w=+p[0],h=+p[1];if(w>0&&h>0)return w/h;}return null;}
function buildBars(){
const isForza=GAME_ID&&GAME_ID.includes('forza');
const labels=isForza?FORZA_LABELS:AC_STYLE_LABELS;
barRow.innerHTML=labels.map((l,i)=>{
let cls='bar-col';
if(l==='R')cls+=' r';
if(l==='N')cls+=' n';
if(l==='P')cls+=' p';
return `<div class="${cls} g-${i}"><div class="bar-fill"></div><div class="bar-label">${l}</div></div>`;
}).join('');
}
// Forza: 0=N, 1-10=1-10, 11=R, 21=P
// AC/F1: -1=R, 0=N, 1-8=1-8
// iRacing: 0=N, 1=R, 2=1, 3=2...
function gearInfo(g){
const isForza=GAME_ID&&GAME_ID.includes('forza');
const isIracing=GAME_ID&&GAME_ID.includes('iracing');
if(isForza){
if(g===0)return{label:'N',cls:'n',idx:0};
if(g===11)return{label:'R',cls:'r',idx:11};
if(g===21)return{label:'P',cls:'p',idx:12};
if(g>=1&&g<=10)return{label:String(g),cls:'',idx:g};
return{label:String(g),cls:'',idx:-1};
}
if(isIracing){
if(g===0)return{label:'N',cls:'n',idx:0};
if(g===1)return{label:'R',cls:'r',idx:1};
if(g>=2&&g<=9)return{label:String(g-1),cls:'',idx:g};
return{label:String(g),cls:'',idx:-1};
}
// default AC/F1 style
if(g===-1)return{label:'R',cls:'r',idx:0};
if(g===0)return{label:'N',cls:'n',idx:1};
if(g>=1&&g<=8)return{label:String(g),cls:'',idx:g+1};
return{label:String(g),cls:'',idx:-1};
}
let lastGear=-999;
function updateGear(g){
if(g===lastGear)return;lastGear=g;
const info=gearInfo(g);
gearTxt.textContent=info.label;
gearEl.className='gear-circle active';
if(info.cls==='r')gearEl.classList.add('r-active');
else if(info.cls==='n')gearEl.classList.add('n-active');
else if(info.cls==='p')gearEl.classList.add('p-active');
barRow.querySelectorAll('.bar-col').forEach((el,i)=>{el.classList.toggle('active',i===info.idx)});
}
function apply(){
const ratio=parseRatio(M.aspect_ratio||'1:1'),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;
switch(mode){
case'cover':if(vr>ratio){cw=vw;ch=vw/ratio}else{ch=vh;cw=vh*ratio};box.className='cover';break;
case'fill':box.style.width='100vw';box.style.height='100vh';box.className='fill';return;
case'center':cw=Math.min(vw,800);ch=cw/ratio;if(ch>vh){ch=Math.min(vh,800);cw=ch*ratio};box.className='center';break;
default:if(vr>ratio){ch=vh;cw=vh*ratio}else{cw=vw;ch=vw/ratio};box.className='contain';
}
if(mode!=='fill'){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||'';buildBars()}
if(m.type==='telemetry')updateGear(m.data.gear||0)
}catch(e){}};
ws.onclose=()=>{rt=setTimeout(connect,2000)};
}
const box=document.getElementById('box'),gearTxt=document.getElementById('gear-txt'),
gearEl=document.getElementById('gear-el'),barRow=document.getElementById('bar-row');
const proto=location.protocol==='https:'?'wss:':'ws:',wsUrl=proto+'//'+location.host+'/ws';
let ws,rt;
buildBars();apply();window.addEventListener('resize',apply);connect();
</script>
</body>
</html>