◆少前百科是非盈利性、非官方的少女前线维基百科。
◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!点这里 加入少前百科
◆有任何意见、建议、纠错,欢迎在 GFwiki:反馈与建议 提出和讨论。编辑事务讨论QQ群:597764980,微博@GFwiki少前百科
◆To foreigners,You can use twitter to contact us.
Icon Nyto Silver.png

“Widget:融合势力属性”的版本间的差异

来自少前百科GFwiki
跳转至: 导航搜索
第6行: 第6行:
 
const size_coef = [100, 102, 105, 108, 110];
 
const size_coef = [100, 102, 105, 108, 110];
 
const rank_coef = [80, 90, 100, 110, 120];
 
const rank_coef = [80, 90, 100, 110, 120];
 +
const sizes = ['微', '小', '中', '大', '巨'];
 
let div, type, ratios, grow;
 
let div, type, ratios, grow;
 
let maxform = 5;
 
let maxform = 5;
第13行: 第14行:
 
let stars;
 
let stars;
 
let resFlower;
 
let resFlower;
 +
let checked = {size: null, rank: null};
  
 
function calc(attr, lv, rank, size, resolve, form) {
 
function calc(attr, lv, rank, size, resolve, form) {
第37行: 第39行:
 
function addInputs(container, name, labels, base = 0) {
 
function addInputs(container, name, labels, base = 0) {
 
     for (let i = 0; i < 5; i++) {
 
     for (let i = 0; i < 5; i++) {
         let label = document.createElement('label');
+
         let radio = document.createElement('span');
         let input = document.createElement('input');
+
         if (name == 'size') radio.textContent = sizes[i];
         input.type = 'radio';
+
         else radio.textContent = '×' + (i+1);
         input.value = i;
+
         radio.id = name + i;
         input.name = name;
+
         radio.value = i;
        label.appendChild(input);
+
         container.appendChild(radio);
        if (labels) label.insertAdjacentText('beforeend', labels[i]);
+
         radio.addEventListener('click', e => {
         container.appendChild(label);
 
         input.addEventListener('click', e => {
 
 
             let val = +e.currentTarget.value + base;
 
             let val = +e.currentTarget.value + base;
 
             if (variables[name] != val) {
 
             if (variables[name] != val) {
第51行: 第51行:
 
                 updateAttrs();
 
                 updateAttrs();
 
             }
 
             }
 +
            if (checked[name]) checked[name].className = '';
 +
            checked[name] = e.currentTarget;
 +
            checked[name].className = 'checked';
 
         });
 
         });
 
     }
 
     }
     container.children[4].children[0].checked = true;
+
     container.children[4].click();
 
}
 
}
  

2022年5月2日 (一) 22:51的版本

<script> const type_coef = [

   [4.79, 3.67, 0.46, 0.55, 0.75, 0.18],
   [3.84, 2.94, 0.42, 0.44, 0.60, 0.15],
   [3.60, 2.76, 0.42, 0.42, 0.57, 0.14]];

const size_coef = [100, 102, 105, 108, 110]; const rank_coef = [80, 90, 100, 110, 120]; const sizes = ['微', '小', '中', '大', '巨']; let div, type, ratios, grow; let maxform = 5; let resolution = new Array(5);

let variables = {size: 0, formation: 5, lv: 100, rank: 4, resolution: 4}; let stars; let resFlower; let checked = {size: null, rank: null};

function calc(attr, lv, rank, size, resolve, form) {

   let ratio = ratios[attr];
   let formation = attr == 1 ? 1 : (attr == 0 ? form : maxform);
   let base = type_coef[type][attr] * ratio * 2 * grow *
       size_coef[size] * rank_coef[rank] * formation / (maxform * 5e6);
   let accretion = type_coef[type][attr] * ratio * (lv - 1) * grow *
       size_coef[size] * rank_coef[rank] * formation / (maxform * 1e8);
   return Math.ceil(base + accretion) + (attr == 0 ? form : 1) * resolution[resolve][attr];

}

function updateAttrs() {

   for (let i = 7; --i;) document.getElementById('attr-td-' + i).textContent = calc(
       i-1, variables.lv, variables.rank, variables.size, variables.resolution, variables.formation);

}

function updateResSignal() {

   let res = variables.resolution;
   if (res) resFlower.setAttribute('mask', `url(#res${res})`);
   else resFlower.setAttribute('mask', );

}

function addInputs(container, name, labels, base = 0) {

   for (let i = 0; i < 5; i++) {
       let radio = document.createElement('span');
       if (name == 'size') radio.textContent = sizes[i];
       else radio.textContent = '×' + (i+1);
       radio.id = name + i;
       radio.value = i;
       container.appendChild(radio);
       radio.addEventListener('click', e => {
           let val = +e.currentTarget.value + base;
           if (variables[name] != val) {
               variables[name] = val;
               updateAttrs();
           }
           if (checked[name]) checked[name].className = ;
           checked[name] = e.currentTarget;
           checked[name].className = 'checked';
       });
   }
   container.children[4].click();

}

function addControl() {

   let sizeCtrl = document.getElementById('size-control');
   let formCtrl = document.getElementById('formation-control');
   let resSignal = document.getElementById('resolve-signal');
   let lvCtrl = document.getElementById('lv-control');
   let rankCtrl = document.getElementById('rank-control');
   let resCtrl = document.getElementById('resolve-control');
   if (sizeCtrl) addInputs(sizeCtrl, 'size', ['微', '小', '中', '大', '巨']);
   if (maxform == 5) addInputs(formCtrl, 'formation', ['×1', '×2', '×3', '×4', '×5'], 1);
   else formCtrl.textContent = '×1';
   resSignal.insertAdjacentHTML('beforeend', `<svg xmlns="http://www.w3.org/2000/svg" width="94" height="94"><defs><g id="diamonds"><polygon points="0,47 23.5,33 70.5,61 94,47 70.5,33 23.5,61"\/><polygon points="47,0 33,23.5 61,70.5 47,94 33,70.5 61,23.5"\/><\/g><\/defs><mask id="res1"><rect width="94" height="94" fill="#fff"\/><polygon points="0,0 94,0 47,47"\/><\/mask><mask id="res2"><rect width="94" height="94" fill="#fff"\/><polygon points="0,0 94,0 0,94 94,94"\/><\/mask><mask id="res3"><rect width="94" height="94"\/><polygon points="94,0 47,47 94,94" fill="#fff"\/><\/mask><mask id="res4"><rect width="94" height="94"\/><\/mask><rect x="23" y="23" width="48" height="48" fill="#3d3d3d"\/><use fill="#ff004e" href="#diamonds"\/><use id="flower" fill="#161616" mask="url(#res4)" href="#diamonds"\/><\/svg>`);
   resFlower = document.getElementById('flower');
   let lvLabel = document.createElement('label');
   lvLabel.textContent = '等级';
   let lvInput = document.createElement('input');
   lvInput.type = 'number';
   lvInput.max = 100;
   lvInput.min = 1;
   lvInput.value = 100;
   lvLabel.appendChild(lvInput);
   lvCtrl.appendChild(lvLabel);
   lvInput.addEventListener('input', e => {
       let val = e.currentTarget.value;
       if (variables.lv != val) {
           variables.lv = val;
           updateAttrs();
       }
   });
   stars = rankCtrl.children;
   for (let i = 5; i--;) stars[i].src = '/images/0/0a/StarWhite.svg';
   for (let i = 2 - type; i < 5; i++) {
       let star = stars[i];
       stars[i].addEventListener('click', e => {
           let rank = +e.currentTarget.dataset.id;
           if (variables.rank != rank) {
               variables.rank = rank;
               for (let j = 3 - type; j <= rank; j++) stars[j].className = ;
               for (let j = rank + 1; j < 5; j++) stars[j].className = 'star-dark';
               updateAttrs();
           }
       });
   }
   for (let i = 0; i < 5; i++) {
       let input = document.createElement('input');
       input.type = 'radio';
       input.value = i;
       input.name = 'resolution';
       resCtrl.appendChild(input);
       input.addEventListener('click', e => {
           let val = +e.currentTarget.value;
           if (variables.resolution != val)
           variables.resolution = val;
           updateAttrs();
           updateResSignal();
       });
   }
   resCtrl.children[4].checked = true;

}

function main() {

   div = document.getElementById('attrs');
   let unitid = div.dataset.id;
   if (unitid < 2000 || unitid == 2006 || unitid == 3010) maxform = 1;
   variables.formation = maxform;
   type = div.dataset.type;
   ratios = div.dataset.attrs.split(',').map(x => +x);
   grow = div.dataset.grow;
   let r2d = div.dataset.resolution.split(';');
   for (let i = 0; i < 5; i++) {
       rs = r2d[i].split(',');
       resolution[i] = new Array(6);
       for (let j = 0; j < 6; j++) resolution[i][j] = +rs[j];
   }
   addControl();
   updateAttrs();

}

window.onload = main; </script>