Pokemon
var _nature, _stats, _type, _gen;
 
export var nature;
export var stats;
export var type;
export var gen;
export var loading = async()=>{
    var a = await Promise.all(
        ['nature', 'stats', 'type', 'gen'].map(async v=>(
            await fetch(`/local--files/pokemon/${v}.json`)
        ).json())
    );
    [_nature, _stats, _type, _gen] = a;
    [nature, stats, type, gen] = a.map(v=>Object.assign({}, v));
    return true;
}
 
export var chemistry = (version, ...key)=>{
    var _ = {};
    var __ = {};
    var t = _type[version];
    Object.keys(t).forEach(k=>{_[k]=1})
    for(var k of key) {
        var a = t[k].chem;
        a[0].forEach(function(t) {
            _[t] = 0;
        });
        a[50].forEach(function(t) {
            _[t] /= 2;
        });
        a[200].forEach(function(t) {
            _[t] *= 2;
        });
    }
    for(var k in _) {
        if(_[k]!==1) {
            __[_[k]] = __[_[k]] || [];
            __[_[k]].push(t[k].name);
        }
    }
    return {received: key.map(k=>t[k].name), chemistry: __};
}
 
export var tool = {};
var tree = {a: '', i: '', u: '', e: '', o: '', k: {a: '', i: '', u: '', e: '', o: '',y: { a: 'キャ', i: 'キィ', u: 'キュ', e: 'キェ', o: 'キョ' }},s: {a: '', i: '', u: '', e: '', o: '',h: { a: 'シャ', i: '', u: 'シュ', e: 'シェ', o: 'ショ' },y: { a: 'キャ', i: 'キィ', u: 'キュ', e: 'キェ', o: 'キョ' }},t: {a: '', i: '', u: '', e: '', o: '',h: { a: 'テャ', i: 'ティ', u: 'テュ', e: 'テェ', o: 'テョ' },y: { a: 'チャ', i: 'チィ', u: 'チュ', e: 'チェ', o: 'チョ' },s: { a: 'ツァ', i: 'ツィ', u: '', e: 'ツェ', o: 'ツォ' }},c: {a: '', i: '', u: '', e: '', o: '',h: { a: 'チャ', i: '', u: 'チュ', e: 'チェ', o: 'チョ' },y: { a: 'チャ', i: 'チィ', u: 'チュ', e: 'チェ', o: 'チョ' }},q: {a: 'クァ', i: 'クィ', u: '', e: 'クェ', o: 'クォ'},n: {a: '', i: '', u: '', e: '', o: '', n: '',y: { a: 'ニャ', i: 'ニィ', u: 'ニュ', e: 'ニェ', o: 'ニョ' }},h: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ヒャ', i: 'ヒィ', u: 'ヒュ', e: 'ヒェ', o: 'ヒョ' }},f: {a: 'ファ', i: 'フィ', u: '', e: 'フェ', o: 'フォ',y: { a: 'フャ', u: 'フュ', o: 'フョ' }},m: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ミャ', i: 'ミィ', u: 'ミュ', e: 'ミェ', o: 'ミョ' }},y: { a: '', i: '', u: '', e: 'イェ', o: '' },r: {a: '', i: '', u: '', e: '', o: '',y: { a: 'リャ', i: 'リィ', u: 'リュ', e: 'リェ', o: 'リョ' }},w: { a: '', i: 'ウィ', u: '', e: 'ウェ', o: '' },g: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ギャ', i: 'ギィ', u: 'ギュ', e: 'ギェ', o: 'ギョ' }},z: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ジャ', i: 'ジィ', u: 'ジュ', e: 'ジェ', o: 'ジョ' }},j: {a: 'ジャ', i: '', u: 'ジュ', e: 'ジェ', o: 'ジョ',y: { a: 'ジャ', i: 'ジィ', u: 'ジュ', e: 'ジェ', o: 'ジョ' }},d: {a: '', i: '', u: '', e: '', o: '',h: { a: 'デャ', i: 'ディ', u: 'デュ', e: 'デェ', o: 'デョ' },y: { a: 'ヂャ', i: 'ヂィ', u: 'ヂュ', e: 'ヂェ', o: 'ヂョ' }},b: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ビャ', i: 'ビィ', u: 'ビュ', e: 'ビェ', o: 'ビョ' }},v: {a: 'ヴァ', i: 'ヴィ', u: '', e: 'ヴェ', o: 'ヴォ',y: { a: 'ヴャ', i: 'ヴィ', u: 'ヴュ', e: 'ヴェ', o: 'ヴョ' }},p: {a: '', i: '', u: '', e: '', o: '',y: { a: 'ピャ', i: 'ピィ', u: 'ピュ', e: 'ピェ', o: 'ピョ' }},x: {a: '', i: '', u: '', e: '', o: '',y: {a: '', i: '', u: '', e: '', o: ''},t: {u: '',s: {u: ''}}},l: {a: '', i: '', u: '', e: '', o: '',y: {a: '', i: '', u: '', e: '', o: ''},t: {u: '',s: {u: ''}}}, '-': ''};
tool.romaToKana =r=>{
  var str = r.replace(/[A-Za-z]/, s => String.fromCharCode(s.charCodeAt(0)-65248)).toLowerCase(), result = '', tmp = '', index = 0, len = str.length, node = tree, push = (c,t=true)=>(result+=c, tmp='', node=t?tree:node);
  while(index < len) {
    var char = str.charAt(index);
    if(char.match(/[a-z\-]/)) {
      if(char in node) {
        var next = node[char];
        if(typeof next === 'string') {
          push(next);
        }else {
          tmp += r.charAt(index);
          node = next;
        }
        index++;
        continue;
      }
      var prev = str.charAt(index - 1);
      if(prev && (prev === 'n' || prev === char)) {
        push(prev === 'n' ? '' : '', false);
      }
      if(node !== tree && char in tree) {
        push(tmp);
        continue;
      }
    }
    push(tmp + char);
    index++;
  }
  tmp = tmp.replace(/n$/, '');
  push(tmp);
  return result;
};
tool.hiraToKana = s=>s.replace(/[\u3041-\u3096]/g, m=>String.fromCharCode(m.charCodeAt(0)+0x60));
 
//tool.romaToKana('jyaro-da');
//tool.hiraToKana('じゃろーだ');
// 'ジャローダ'
 
export var hiddenPower = (()=>{
    var _ = {0:{0:{0:{0:{0:{0:1,1:2},1:{0:8,1:10}},1:{0:{0:4,1:6},1:{0:12,1:14}}},1:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:13,1:15}}}},1:{0:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:12,1:14}}},1:{0:{0:{0:2,1:4},1:{0:10,1:11}},1:{0:{0:6,1:8},1:{0:13,1:15}}}}},1:{0:{0:{0:{0:{0:1,1:3},1:{0:8,1:10}},1:{0:{0:5,1:6},1:{0:12,1:14}}},1:{0:{0:{0:2,1:4},1:{0:9,1:11}},1:{0:{0:6,1:7},1:{0:13,1:15}}}},1:{0:{0:{0:{0:1,1:3},1:{0:9,1:11}},1:{0:{0:5,1:7},1:{0:13,1:15}}},1:{0:{0:{0:2,1:4},1:{0:10,1:12}},1:{0:{0:6,1:8},1:{0:14,1:16}}}}}};
    var t = (n,r)=>(n%4==2||n%4==3)?r:0;
    var _hp = ({h=0,a=0,b=0,c=0,d=0,s=0}={})=>({received: {h:h,a:a,b:b,c:c,d:d,s:s}, type: _type.old[_[h%2][a%2][b%2][c%2][d%2][s%2]].name, power: (t(h,1)+t(a,2)+t(b,4)+t(s,8)+t(c,16)+t(d,32))*40/63+30|0});
    return _hp;
})();
 
/*
hiddenPower({
  h: 31,
  a: 28,
  b: 31,
  c: 9,
  d: 31,
  s: 10
})
*/
 
export var I = (()=>{
    function _I({h=100, a=100, b=100, c=100, d=100, s=100}={}) {
        var _ = function(n) {
            return isNaN(n) || n == '';
        }
        if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) {
            throw new Error('Invalid base stats');
        }
        this.indivisual = {};
        this.effort = {};
        this.value = {};
        this.base = {},
        this.base.h = h,
        this.base.a = a,
        this.base.b = b,
        this.base.c = c,
        this.base.d = d,
        this.base.s = s;
    }
 
    _I.prototype.setNature = function(nature='がんばりや') {
        this.nature = _nature[nature];
        return this;
    }
    _I.prototype.setLv = function(lv=1) {
        if (lv < 0 || 100 < lv) {
            throw new Error('Invalid Lv');
        }
        this.lv = lv;
        return this;
    }
    _I.prototype.setValues = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) {
        var _ = function(n) {
            return n < 0 || isNaN(n);
        }
        if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) {
            throw new Error('Invalid values');
        }
        this.value.h = h,
        this.value.a = a,
        this.value.b = b,
        this.value.c = c,
        this.value.d = d,
        this.value.s = s;
        return this;
    }
    _I.prototype.setIndivisuals = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) {
        var _ = function(n) {
            return n > 31 || n < 0 || isNaN(n);
        }
        if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s)) {
            throw new Error('Invalid indivisual values');
        }
        this.indivisual.h = h,
        this.indivisual.a = a,
        this.indivisual.b = b,
        this.indivisual.c = c,
        this.indivisual.d = d,
        this.indivisual.s = s;
        return this;
    }
    _I.prototype.setEfforts = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) {
        var _ = function(n) {
            return n > 255 || n < 0 || isNaN(n);
        }
        if (_(h) || _(a) || _(b) || _(c) || _(d) || _(s) || (h + a + b + c + d + s) > 510) {
            throw new Error('Invalid effort values');
        }
        this.effort.h = h,
        this.effort.a = a,
        this.effort.b = b,
        this.effort.c = c,
        this.effort.d = d,
        this.effort.s = s;
        return this;
    }
    _I.prototype.getIndivisuals = function({h=0, a=0, b=0, c=0, d=0, s=0}={}) {
        var _ = {
            h: null,
            a: null,
            b: null,
            c: null,
            d: null,
            s: null,
        };
        for(var k in _) {
            var x = 1;
            if(this.nature.up == k) {
                x = 1.1;
            }
            else if(this.nature.down == k) {
                x = 0.9;
            }
            var y;
            try {
                y = ((400 * this.value[k] - (k=='h' ? 4000 : 2000)) / this.lv - (k=='h' ? 400 : 0) - 8 * this.base[k] - this.effort[k]) / 4;
            }catch(e) {}
            _[k] = y;
        }
        return _;
    }
 
    return _I;
})();
// dummy
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0"/>
<script type="module">
import * as Pokemon from '/local--code_/pokemon/1'
 
var wrap = document.querySelector('#wrap');
var area = document.querySelectorAll('textarea');
var _ip = (n, p)=>{
    var l = document.createElement('label');
    var s = document.createElement('span');
    var i = document.createElement('input');
    l.appendChild(s);
    l.appendChild(i);
    p.appendChild(l);
    s.innerHTML = n;
    i.type = 'number';
    i.max = 31;
    i.min = 0;
    i.value = 31;
    return i;
}
 
(async()=>{
    await Pokemon.loading();
    wrap.innerText ='';
    var [h,a,b,c,d,s] = ['h','a','b','c','d','s'].map(v=>_ip(`<b>${v}: </b>`, wrap));
    var calc = ()=>{
        var r = Pokemon.hiddenPower({h:h.value, a:a.value, b:b.value, c:c.value, d:d.value, s:s.value});
        area[0].value = `タイプ: ${r.type}\n威力: ${r.power}`;
    }
    for(var i of [h,a,b,c,d,s]) {
        i.addEventListener('change', calc);
    }
    calc();
})();
</script>
</head>
<body>
<div id="wrap"><h1>読み込み中です</h1></div>
<textarea readonly></textarea>
</body>
特に明記しない限り、このページのコンテンツは次のライセンスの下にあります: Creative Commons Attribution-ShareAlike 3.0 License