1
0
Fork 0
forked from Simnation/Main
Main/resources/[tools]/dc_propattach/nui/script.js

1 line
10 KiB
JavaScript
Raw Normal View History

2025-07-14 16:42:23 +02:00
document.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("propAttachContainer"),t=document.getElementById("animationSelect"),n=document.getElementById("animPrevBtn"),a=document.getElementById("animNextBtn"),o=document.getElementById("animFlagsInput"),d=document.getElementById("btnPlayAnim"),l=document.getElementById("btnStopAnim");let r=[],c=0;const u=document.getElementById("propSelect1"),i=document.getElementById("prop1PrevBtn"),s=document.getElementById("prop1NextBtn"),p=document.getElementById("customProp1");let m=0;const v=document.getElementById("propSelect2"),g=document.getElementById("prop2PrevBtn"),I=document.getElementById("prop2NextBtn"),E=document.getElementById("customProp2");let h=0;const y=document.getElementById("boneSelect1"),B=document.getElementById("boneSelect2"),x=document.getElementById("rotationOrder1"),L=document.getElementById("rotationOrder2"),f=document.getElementById("btnResetAll"),b=document.getElementById("btnCloseUI"),C=document.getElementById("moveSpeedSlider"),S=document.getElementById("rotateSpeedSlider"),A=document.getElementById("moveSpeedValue"),k=document.getElementById("rotateSpeedValue"),P=document.getElementById("moveSpeedPresets"),D=document.getElementById("rotateSpeedPresets"),F=document.getElementById("cameraFocusSelect"),w=document.getElementById("camDistance"),N=document.getElementById("distanceValue"),T=document.getElementById("camAngle"),R=document.getElementById("angleValue"),M=document.getElementById("camHeight"),H=document.getElementById("heightValue"),$=document.querySelectorAll(".camNudgeBtn");let q=[],O=null;function U(e,t){document.querySelectorAll(e).forEach((e=>{e.addEventListener("mousedown",(function(){O&&clearInterval(O);const e={};for(const t of this.attributes)t.name.startsWith("data-")&&(e[t.name.slice(5)]=t.value);t(e),O=setInterval((()=>{t(e)}),50)})),e.addEventListener("mouseup",(function(){O&&(clearInterval(O),O=null)})),e.addEventListener("mouseleave",(function(){O&&(clearInterval(O),O=null)}))}))}function V(e,t){fetch(`https://${GetParentResourceName()}/${e}`,{method:"POST",headers:{"Content-Type":"application/json; charset=UTF-8"},body:JSON.stringify(t)})}function j(){t.innerHTML="",r.forEach(((e,n)=>{const a=document.createElement("option");a.value=String(n),a.textContent=e.label,t.appendChild(a)})),c<0&&(c=0),c>=r.length&&(c=0),r.length>0&&(t.value=String(c))}function G(){const e=document.getElementById("customAnimDict").value.trim(),t=document.getElementById("customAnimName").value.trim();if(e&&t){return V("setAnimation",{dict:e,anim:t,flags:parseInt(o.value)||0}),void V("playAnim",{})}if(!r[c])return;const n=r[c],a=parseInt(o.value)||0;V("setAnimation",{dict:n.dict,anim:n.anim,flags:a}),V("playAnim",{})}function J(e){const t=1===e?u:v;let n=1===e?m:h;t.innerHTML="",q.forEach(((e,n)=>{const a=document.createElement("option");a.value=String(n),a.textContent=e,t.appendChild(a)})),n<0&&(n=q.length-1),n>=q.length&&(n=0),q.length>0&&(t.value=String(n)),1===e?m=n:h=n}function W(e){const t=q[1===e?m:h];t&&V("spawnProp",{propIndex:e,modelName:t})}window.addEventListener("message",(t=>{const n=t.data;"openUI"===n.type?(e.style.display="block",r=n.animations.slice(),c=0,j(),y.innerHTML="",B.innerHTML="",n.bones.forEach((e=>{const t=document.createElement("option");t.value=e.id,t.textContent=`${e.name} (${e.id})`,y.appendChild(t);const n=document.createElement("option");n.value=e.id,n.textContent=`${e.name} (${e.id})`,B.appendChild(n)})),y.options.length>0&&(y.value=y.options[0].value,V("setBone",{propIndex:1,boneId:parseInt(y.value)})),B.options.length>0&&(B.value=B.options[0].value,V("setBone",{propIndex:2,boneId:parseInt(B.value)})),q=n.props.slice(),m=0,h=0,J(1),J(2),C.value=n.moveSpeed.toString(),S.value=n.rotateSpeed.toString(),A.textContent=n.moveSpeed.toString(),k.textContent=n.rotateSpeed.toString(),P.innerHTML="",n.defaultMoveSpeeds.forEach((e=>{const t=document.createElement("button");t.className="preset-button",t.textContent=e,t.addEventListener("click",(()=>{C.value=e,A.textContent=e,V("updateMoveSpeed",{value:e})})),P.a