var delayedSearch = null; function genMonster() { var panel = document.getElementById("panel"); panel.innerHTML = `

在周围生成怪物

`; updateEntityList(); document.getElementById("entity-search").oninput = (e) => { if (e.target.value.length > 0) { document.getElementById("clear").style.flex = 1; document.getElementById("clear").style.opacity = 1; } else { document.getElementById("clear").style.flex = 0; document.getElementById("clear").style.opacity = 0; } if (delayedSearch) { clearTimeout(delayedSearch); } delayedSearch = setTimeout(() => updateEntityList(), 500); document.getElementById("name-list").style.height = "10em"; }; document.getElementById("clear").onclick = ()=>{ document.getElementById("entity-search").value = ""; updateEntityList(); } document.getElementById("entity-search").onkeydown = (e) => { if(e.key == "Escape") { document.getElementById("entity-search").value = ""; updateEntityList(); } } document.getElementById("entity-id").setvalue = (v) => { document.getElementById("entity-id").value = v; if (v) { document.getElementById("execute").disabled = false; } else { document.getElementById("execute").disabled = true; } } document.getElementById("name-list").onclick = (e) => { if (e.target.tagName == "INPUT") { var list = document.getElementById("name-list"); list.style.height = "3em"; var name = e.target.attributes['entity-name'].nodeValue ? e.target.attributes['entity-name'].nodeValue : "UNKNOWN"; var color = {0:'blue',1: 'orange'}[e.target.attributes['entity-level'].nodeValue]; var content = ` ${name} - ${e.target.attributes['entity-id'].nodeValue} `; list.innerHTML = content; document.getElementById("entity-search").value = name; document.getElementById("clear").style.flex = 1; document.getElementById("clear").style.opacity = 1; document.getElementById("entity-id").setvalue(e.target.attributes['entity-id'].nodeValue); } } // updateWeaponList(); // document.getElementById("weapon-filter").onchange = updateWeaponList; document.getElementById("execute").onclick = () => { var entityId = document.getElementById("entity-id").value; var amount = document.getElementById("amount").value; var level = document.getElementById("level").value; sendCommand(`spawn ${entityId} ${amount} ${level}`); } } function updateEntityList() { var filter = document.getElementById("entity-search").value; var list = document.getElementById("name-list"); list.innerHTML = ""; list.style.height = "10em"; monster_data.forEach(element => { if (filter == "" || element.name.toLowerCase().indexOf(filter.toLowerCase()) != -1) { var o = document.createElement("label"); o.style.marginLeft = "0.1em"; var color = {0:'blue',1: 'orange'}[element.type]; var content = ` ${element.name ? element.name : "UNKNOWN"} `; o.innerHTML = content; list.appendChild(o); } }); }