index.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Your Electron App</title>
  5. <style>
  6. #nav {
  7. /* 导航栏样式 */
  8. }
  9. #content {
  10. /* 内容区样式 */
  11. }
  12. #level-list {
  13. width: 200px;
  14. float: left;
  15. }
  16. #level-details {
  17. margin-left: 210px;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="hdr" style="background-color: antiquewhite; margin-bottom: 20px;">
  23. <input type="text" id="group-suffix" placeholder="分组文件的后缀">
  24. <button id="load_grp">加载分组信息</button>
  25. </div>
  26. <div id="panels-area" style="display: flex; height: 95vh;">
  27. <div id="nav" style="overflow-y: scroll; height: 90%; width: 5%; background-color: coral;">
  28. <ul>
  29. <li>
  30. <button id="levels" style="margin-top: 10px;">关卡</button>
  31. </li>
  32. <li>
  33. <button id="examples" style="margin-top: 10px;">实例</button>
  34. </li>
  35. <li>
  36. <button id="templates"style="margin-top: 10px;">模板</button>
  37. </li>
  38. </ul>
  39. </div>
  40. <div id="content" style="overflow-y: scroll; height: 90%; width: 85%; background-color: beige;">
  41. <!-- 动态内容 -->
  42. </div>
  43. </div>
  44. <script>
  45. var levels = null;
  46. var instances = null;
  47. var templateFNs = null;
  48. var templateFNsByDir = null;
  49. var groupSuffix = "";
  50. function getInstanceByName(name) {
  51. for (let i = 0; i < instances.length; i++) {
  52. if (instances[i].lvinst == name) {
  53. return instances[i];
  54. }
  55. }
  56. return null;
  57. }
  58. function getTemplateByName(name) {
  59. for (let i = 0; i < templateFNs.length; i++) {
  60. if (templateFNs[i] == name) {
  61. return templateFNs[i];
  62. }
  63. }
  64. return null;
  65. }
  66. function getAllLvIdsByInstName(name) {
  67. // 返回所有用到了该实例的关卡的id
  68. const ids = [];
  69. for (let i = 0; i < levels.length; i++) {
  70. if (levels[i].lvinst == name) {
  71. ids.push(levels[i].lvid);
  72. }
  73. }
  74. return ids;
  75. }
  76. function saveInst(div, inst) {
  77. // 从 div中获取实例信息
  78. const instName = div.querySelector('#instid-in-inst-detail').textContent.split(':')[1].trim();
  79. var inst = null;
  80. for (let i = 0; i < instances.length; i++) {
  81. if (instances[i].lvinst == instName) {
  82. inst = instances[i];
  83. break;
  84. }
  85. }
  86. if (inst == null) {
  87. alert('实例不存在');
  88. return;
  89. }
  90. inst['template'] = div.querySelector('#template-select').value;
  91. for (let i = 1; i <= 10; i++) {
  92. const tileCnt = div.querySelector('#try' + i + '_tileCnt').value;
  93. const seed = div.querySelector('#try' + i + '_seed').value;
  94. const param_template = div.querySelector('#try' + i + '_param_template').value;
  95. const trynParams = tileCnt + '|' + seed + '|' + param_template;
  96. inst['try' + i + '(tileCnt|seed|param_template)'] = trynParams;
  97. }
  98. window.electron.send('save2csv', '../../conf/levelInstInfo'+groupSuffix+'.csv', instances);
  99. }
  100. function showInstanceInfoAt(div, inst) {
  101. // 将其显示在页面上,其中template应该是一个下拉框
  102. // try1-10应该是一个表格, 表格的头部应该是:尝试次数,瓦片数,种子,参数模板,表格里面的每个值是可以编辑的
  103. div.innerHTML = `
  104. <h2 id='instid-in-inst-detail'>实例名: ${inst.lvinst}</h2>
  105. `;
  106. // 显示所有用到了该实例的关卡
  107. const lvIds = getAllLvIdsByInstName(inst.lvinst);
  108. div.innerHTML += `
  109. <p style="display: inline;">用到了该实例的关卡: ${lvIds}</p>
  110. `;
  111. // 加入 template 下拉框
  112. {
  113. var div1 = document.createElement('div');
  114. const p = document.createElement('p');
  115. p.style.display = 'inline';
  116. p.appendChild(document.createTextNode('模板名称: '));
  117. div1.appendChild(p);
  118. const templateSelect = document.createElement('select');
  119. templateSelect.id = 'template-select';
  120. templateFNs.forEach(fn => {
  121. const option = document.createElement('option');
  122. option.value = fn;
  123. option.textContent = fn;
  124. if (fn == inst.template) {
  125. option.selected = true;
  126. }
  127. templateSelect.appendChild(option);
  128. });
  129. div1.appendChild(templateSelect);
  130. // 增加一个编辑模板的按钮
  131. const editTemplateButton = document.createElement('button');
  132. editTemplateButton.id = 'edit-template-button';
  133. editTemplateButton.textContent = '编辑模板';
  134. editTemplateButton.style.marginLeft = '10px';
  135. editTemplateButton.addEventListener('click', () => {
  136. // 获取当前的模板名称
  137. const templateName = document.getElementById('template-select').value;
  138. // 判断模板是在哪个目录下
  139. for (let dir in templateFNsByDir) {
  140. if (templateFNsByDir[dir].has(templateName)) {
  141. window.electron.send('open-app', dir, '/Applications/Tiled.app/Contents/MacOS/Tiled ' + dir + '/' + inst.template + '.json');
  142. return;
  143. }
  144. }
  145. });
  146. div1.appendChild(editTemplateButton);
  147. // 增加一个复制模板的按钮
  148. const copyTemplateButton = document.createElement('button');
  149. copyTemplateButton.id = 'copy-template-button';
  150. copyTemplateButton.textContent = '复制模板';
  151. copyTemplateButton.style.marginLeft = '10px';
  152. copyTemplateButton.addEventListener('click', () => {
  153. // 获取当前的实例
  154. const inst = getInstanceByName(document.getElementById('instid-in-inst-detail').textContent.split(':')[1].trim());
  155. if (inst.template == "") {
  156. // 取options里面当前显示的值
  157. inst.template = document.getElementById('template-select').value;
  158. }
  159. var path = "";
  160. for (let dir in templateFNsByDir) {
  161. if (templateFNsByDir[dir].has(inst.template)) {
  162. path = dir + '/' + inst.template + '.json';
  163. break;
  164. }
  165. }
  166. window.electron.send('copy-template', path);
  167. });
  168. div1.appendChild(copyTemplateButton);
  169. div.appendChild(div1);
  170. }
  171. // 加入表格
  172. const table = document.createElement('table');
  173. const thead = document.createElement('thead');
  174. const tbody = document.createElement('tbody');
  175. const tr = document.createElement('tr');
  176. const th1 = document.createElement('th');
  177. const th2 = document.createElement('th');
  178. const th3 = document.createElement('th');
  179. const th4 = document.createElement('th');
  180. th1.textContent = '尝试次数';
  181. th2.textContent = '瓦片数';
  182. th3.textContent = '种子';
  183. th4.textContent = '参数模板';
  184. tr.appendChild(th1);
  185. tr.appendChild(th2);
  186. tr.appendChild(th3);
  187. tr.appendChild(th4);
  188. thead.appendChild(tr);
  189. table.appendChild(thead);
  190. table.appendChild(tbody);
  191. div.appendChild(table);
  192. // 加入表格内容
  193. for (let i = 1; i <= 10; i++) {
  194. var trynParams = inst['try' + i + '(tileCnt|seed|param_template)'].split('|');
  195. const tr = document.createElement('tr');
  196. const td1 = document.createElement('td');
  197. const td2 = document.createElement('td');
  198. const td3 = document.createElement('td');
  199. const td4 = document.createElement('td');
  200. const input1 = document.createElement('input');
  201. const input2 = document.createElement('input');
  202. const input3 = document.createElement('input');
  203. const input4 = document.createElement('input');
  204. input1.type = 'text';
  205. input1.value = trynParams[0];
  206. input1.id = 'try' + i + '_tileCnt';
  207. input2.type = 'text';
  208. input2.value = trynParams[1];
  209. input2.id = 'try' + i + '_seed';
  210. input3.type = 'text';
  211. input3.value = trynParams[2];
  212. input3.id = 'try' + i + '_param_template';
  213. td1.textContent = i;
  214. td2.appendChild(input1);
  215. td3.appendChild(input2);
  216. td4.appendChild(input3);
  217. tr.appendChild(td1);
  218. tr.appendChild(td2);
  219. tr.appendChild(td3);
  220. tr.appendChild(td4);
  221. tbody.appendChild(tr);
  222. }
  223. // 增加一个按钮,点击后可以保存
  224. const saveButton = document.createElement('button');
  225. saveButton.id = 'save-instance-button';
  226. saveButton.textContent = '保存';
  227. div.appendChild(saveButton);
  228. saveButton.addEventListener('click', () => {
  229. // 保存实例信息
  230. saveInst(div, inst);
  231. });
  232. }
  233. function showTemplateInfoAt(div, templateInfo) {
  234. }
  235. // 过滤实例列表
  236. function filterInstance() {
  237. // 获取输入框的值
  238. var filter = document.getElementById('instance-filter').value;
  239. // 获取实例列表
  240. var list = document.getElementById('instance-list').getElementsByTagName('li');
  241. // 遍历实例列表
  242. for (var i = 0; i < list.length; i++) {
  243. // 获取实例的名字
  244. var name = list[i].innerHTML;
  245. // 如果实例的名字包含输入框的值,显示实例
  246. if (name.indexOf(filter) > -1) {
  247. list[i].style.display = '';
  248. } else {
  249. // 否则隐藏实例
  250. list[i].style.display = 'none';
  251. }
  252. }
  253. }
  254. function initData() {
  255. // 读取关卡信息并填充到页面
  256. if (levels == null) {
  257. window.electron.send('parse-csv', '../../conf/levelInfo'+groupSuffix+'.csv')
  258. window.electron.receive('csv-data', (data) => {
  259. if (levels == null) {
  260. levels = data;
  261. window.electron.send('parse-csv', '../../conf/levelInstInfo'+groupSuffix+'.csv')
  262. } else {
  263. if (instances == null) {
  264. instances = data
  265. }
  266. }
  267. });
  268. }
  269. if (templateFNs == null) {
  270. templateFNs = [];
  271. templateFNsByDir = {};
  272. window.electron.send('get-file-list', '../../tf_templates;../../miniGame;../../templates')
  273. window.electron.receive('file-list-error', (data) => {
  274. console.error('Error reading directory: ', err);
  275. });
  276. window.electron.receive('file-list-data', (data, path) => {
  277. templateFNsByDir[path] = new Set();
  278. // 过滤掉非 .json 后缀的文件
  279. for (let i = 0; i < data.length; i++) {
  280. if (data[i].endsWith('.json')) {
  281. // 去掉后缀
  282. const name = data[i].substring(0, data[i].length - 5);
  283. templateFNs.push(name);
  284. templateFNsByDir[path].add(name);
  285. }
  286. }
  287. });
  288. }
  289. //
  290. }
  291. // 创建一个新实例,并将其关联到指定的关卡中
  292. function addNewInst(level) {
  293. const instDetails = document.getElementById('instance-details');
  294. // 获取实例名称
  295. window.electron.send('open-newinst-prompt', 'some data');
  296. }
  297. function saveLvInfo() {
  298. const lvDetails = document.getElementById('level-details');
  299. // 保存关卡的详细信息
  300. const lvid = lvDetails.querySelector('#lvid-in-lvdetails').textContent.split(':')[1].trim();
  301. const instid = lvDetails.querySelector('#inst-select').value;
  302. const type = lvDetails.querySelector('#type-select-in-lvdetails').value;
  303. const ddaType = lvDetails.querySelector('#ddatype-in-lvdetails').textContent.split(':')[1].trim();
  304. const ddaPara = lvDetails.querySelector('#ddapara-in-lvdetails').textContent.split(':')[1].trim();
  305. var lv = null;
  306. for (let i = 0; i < levels.length; i++) {
  307. if (levels[i].lvid == lvid) {
  308. lv = levels[i];
  309. break;
  310. }
  311. }
  312. lv['lvinst'] = instid;
  313. lv['type(normal=0,hard=1,superHard=2)'] = type;
  314. lv['dda_type'] = ddaType;
  315. lv['dda_para'] = ddaPara;
  316. // 保存到文件
  317. window.electron.send('save2csv', '../../conf/levelInfo"+groupSuffix+".csv', levels);
  318. }
  319. function fillLvInfo() {
  320. // 读取关卡信息并填充到页面
  321. if (levels != null) {
  322. const levelList = document.getElementById('level-list');
  323. const levelDetails = document.getElementById('level-details');
  324. const instDetails = document.getElementById('instance-details');
  325. const templateDetails = document.getElementById('tempalte-details');
  326. // 先清空
  327. levelList.innerHTML = '';
  328. // 将levels里面的信息填充到页面
  329. levels.forEach(level => {
  330. const listItem = document.createElement('li');
  331. listItem.textContent = level.lvid;
  332. listItem.addEventListener('click', () => {
  333. // 将选中的关卡id条目的背景颜色设置为蓝色
  334. Array.from(levelList.children).forEach(node => {
  335. if (node.textContent == level.lvid) {
  336. node.style.backgroundColor = 'lightblue';
  337. } else {
  338. node.style.backgroundColor = 'white';
  339. }
  340. });
  341. levelDetails.innerHTML = `
  342. <h2 id='lvid-in-lvdetails'>关卡ID: ${level.lvid}</h2>`
  343. // 关卡实例名称
  344. {
  345. const div = document.createElement('div');
  346. const p = document.createElement('p');
  347. p.style.display = 'inline';
  348. p.appendChild(document.createTextNode('关卡实例名称: '));
  349. div.appendChild(p);
  350. // 显示一个下来列表,选择实例
  351. const instSelect = document.createElement('select');
  352. instSelect.id = 'inst-select';
  353. instances.forEach(inst => {
  354. const option = document.createElement('option');
  355. option.value = inst.lvinst;
  356. option.textContent = inst.lvinst;
  357. if (inst.lvinst == level.lvinst) {
  358. option.selected = true;
  359. }
  360. instSelect.appendChild(option);
  361. });
  362. div.appendChild(instSelect);
  363. levelDetails.appendChild(div);
  364. }
  365. // 加入一个按钮,点击后可以创建实例
  366. {
  367. const div = document.createElement('div');
  368. const createInstButton = document.createElement('button');
  369. createInstButton.id = 'create-instance-button';
  370. createInstButton.textContent = '创建新的实例';
  371. createInstButton.style.marginBottom = '15px';
  372. div.appendChild(createInstButton);
  373. levelDetails.appendChild(div);
  374. // createInstButton.addEventListener('click', () => {
  375. // addNewInst(level);
  376. // });
  377. }
  378. {
  379. const div = document.createElement('div');
  380. // 增加一个下拉框,选择类型:normal,hard,super-hard
  381. const type = level['type(normal=0,hard=1,superHard=2)'];
  382. const typeSelect = document.createElement('select');
  383. typeSelect.id = 'type-select-in-lvdetails';
  384. const normalOption = document.createElement('option');
  385. normalOption.value = '0';
  386. normalOption.textContent = 'normal';
  387. normalOption.selected = type == '0';
  388. const hardOption = document.createElement('option');
  389. hardOption.value = '1';
  390. hardOption.textContent = 'hard';
  391. hardOption.selected = type == '1';
  392. const superHardOption = document.createElement('option');
  393. superHardOption.value = '2';
  394. superHardOption.textContent = 'super-hard';
  395. superHardOption.selected = type == '2';
  396. typeSelect.appendChild(normalOption);
  397. typeSelect.appendChild(hardOption);
  398. typeSelect.appendChild(superHardOption);
  399. const p = document.createElement('p');
  400. p.style.display = 'inline';
  401. p.appendChild(document.createTextNode('关卡难度级别:'));
  402. div.appendChild(p);
  403. div.appendChild(typeSelect);
  404. levelDetails.appendChild(div);
  405. }
  406. // 显示dda类型和参数
  407. const ddatype = document.createElement('p');
  408. ddatype.id = 'ddatype-in-lvdetails';
  409. ddatype.textContent = 'DDA类型: ' + level.dda_type;
  410. levelDetails.appendChild(ddatype);
  411. const ddapara = document.createElement('p');
  412. ddapara.id = 'ddapara-in-lvdetails';
  413. ddapara.textContent = 'DDA参数: ' + level.dda_para;
  414. levelDetails.appendChild(ddapara);
  415. // 增加一个按钮,点击后可以保存
  416. const saveButton = document.createElement('button');
  417. saveButton.id = 'save-lv-button';
  418. saveButton.textContent = '保存';
  419. levelDetails.appendChild(saveButton);
  420. levelDetails.addEventListener('click', (event) => {
  421. if (event.target.id === 'create-instance-button') {
  422. addNewInst(level);
  423. } else if (event.target.id === 'save-lv-button') {
  424. saveLvInfo();
  425. }
  426. });
  427. // 显示实例信息
  428. const inst = getInstanceByName(level.lvinst);
  429. if (inst != null) {
  430. showInstanceInfoAt(instDetails, inst);
  431. // 显示模板信息
  432. const template = getTemplateByName(inst.template);
  433. if (template != null) {
  434. showTemplateInfoAt(templateDetails, getTemplateByName(inst.template));
  435. }
  436. } else {
  437. instDetails.innerHTML = `
  438. <h2>实例名: Error:未定义</h2>
  439. `
  440. }
  441. });
  442. levelList.appendChild(listItem);
  443. });
  444. }
  445. }
  446. function fillInstanceInfo() {
  447. // 读取关卡信息并填充到页面
  448. if (instances != null) {
  449. const lst = document.getElementById('instance-list');
  450. const details = document.getElementById('instance-details');
  451. // 将levels里面的信息填充到页面
  452. instances.forEach(inst => {
  453. const listItem = document.createElement('li');
  454. listItem.textContent = inst.lvinst;
  455. listItem.addEventListener('click', () => {
  456. showInstanceInfoAt(details, inst)
  457. });
  458. lst.appendChild(listItem);
  459. });
  460. }
  461. }
  462. function fillTemplateInfo() {
  463. if (templateFNs != null) {
  464. const lst = document.getElementById('template-list');
  465. const details = document.getElementById('template-details');
  466. // 将levels里面的信息填充到页面
  467. templateFNs.forEach(fn => {
  468. const listItem = document.createElement('li');
  469. listItem.textContent = fn;
  470. listItem.addEventListener('click', () => {
  471. // 放入截图
  472. });
  473. lst.appendChild(listItem);
  474. });
  475. }
  476. }
  477. // 处理新增关卡的回复
  478. window.electron.receive('prompt-newlv-reply', (event, arg) => {
  479. const lvid = event;
  480. // 检查是否已经存在
  481. for (let i = 0; i < levels.length; i++) {
  482. if (levels[i].lvid == lvid) {
  483. alert('关卡id已经存在');
  484. return;
  485. }
  486. }
  487. // 不存在则加入
  488. const level = {
  489. lvid: lvid,
  490. lvinst: '',
  491. type: 0,
  492. dda_type: '0',
  493. dda_para: '0|10000'
  494. };
  495. levels.push(level);
  496. // 刷新页面
  497. fillLvInfo();
  498. // 选中该关卡
  499. const levelList = document.getElementById('level-list');
  500. levelList.childNodes.forEach(node => {
  501. if (node.textContent == lvid) {
  502. node.click();
  503. }
  504. });
  505. })
  506. // 处理新增实例的回复
  507. window.electron.receive('prompt-newinst-reply', (event, arg) => {
  508. const instName = event;
  509. // 检查是否已经存在
  510. for (let i = 0; i < instances.length; i++) {
  511. if (instances[i].lvinst == instName) {
  512. alert('实例已经存在');
  513. return;
  514. }
  515. }
  516. // 不存在则加入
  517. const inst = {
  518. lvinst: instName,
  519. template: '',
  520. 'try1(tileCnt|seed|param_template)': '0|100|normal',
  521. 'try2(tileCnt|seed|param_template)': '0|200|normal',
  522. 'try3(tileCnt|seed|param_template)': '0|300|normal',
  523. 'try4(tileCnt|seed|param_template)': '0|400|normal',
  524. 'try5(tileCnt|seed|param_template)': '0|500|normal',
  525. 'try6(tileCnt|seed|param_template)': '0|600|normal',
  526. 'try7(tileCnt|seed|param_template)': '0|700|normal',
  527. 'try8(tileCnt|seed|param_template)': '0|800|normal',
  528. 'try9(tileCnt|seed|param_template)': '0|900|normal',
  529. 'try10(tileCnt|seed|param_template)': '0|1000|normal'
  530. };
  531. instances.push(inst);
  532. const instDetails = document.getElementById('instance-details');
  533. showInstanceInfoAt(instDetails, inst);
  534. // 将当前关卡关联到该实例
  535. const lvid = document.getElementById('lvid-in-lvdetails').textContent.split(':')[1].trim();
  536. for (let i = 0; i < levels.length; i++) {
  537. if (levels[i].lvid == lvid) {
  538. levels[i].lvinst = instName;
  539. break;
  540. }
  541. }
  542. // 刷新页面, 增加一个option,并置为选中
  543. const instId = document.getElementById('inst-select');
  544. const option = document.createElement('option');
  545. option.value = instName;
  546. option.textContent = instName;
  547. option.selected = true;
  548. instId.appendChild(option);
  549. });
  550. // 处理复制模板的回复
  551. window.electron.receive('copy-template-replay', (data) => {
  552. if (data.length == "0") {
  553. // 失败了
  554. } else {
  555. const inst = getInstanceByName(document.getElementById('instid-in-inst-detail').textContent.split(':')[1].trim());
  556. // 得到文件名和路径前缀
  557. const arr = data.split('/');
  558. const filename = arr[arr.length - 1];
  559. const prefix = arr.slice(0, arr.length - 1).join('/');
  560. // 放入到templateFNsByDir中
  561. const templateName = filename.split(".")[0];
  562. if (templateFNsByDir[prefix] == null) {
  563. templateFNsByDir[prefix] = new Set();
  564. }
  565. templateFNsByDir[prefix].add(templateName);
  566. // 放入到templateFNs中
  567. templateFNs.push(templateName);
  568. // 设置为新的模板
  569. inst.template = templateName;
  570. // 刷新页面,增加templateSelect的选项,并选中新的,同时取消旧的选中状态
  571. const option = document.createElement('option');
  572. option.value = templateName;
  573. option.textContent = templateName;
  574. option.selected = true;
  575. const templateSelect = document.getElementById('template-select');
  576. templateSelect.appendChild(option);
  577. }
  578. });
  579. document.getElementById('load_grp').addEventListener('click', function() {
  580. const suffix = document.getElementById('group-suffix').value;
  581. // 初始化数据
  582. if (suffix != '') {
  583. groupSuffix = "-"+suffix;
  584. }
  585. initData();
  586. });
  587. document.getElementById('levels').addEventListener('click', function() {
  588. fetch('level.html')
  589. .then(response => response.text())
  590. .then(data => {
  591. document.getElementById('content').innerHTML = data;
  592. fillLvInfo();
  593. // 绑定新增关卡按钮
  594. document.getElementById('add-level-button').addEventListener('click', function() {
  595. window.electron.send('open-newlv-prompt', 'some data')
  596. });
  597. })
  598. .catch(error => {
  599. console.error('Error loading the levels content:', error);
  600. });
  601. });
  602. document.getElementById('examples').addEventListener('click', function() {
  603. fetch('instance.html')
  604. .then(response => response.text())
  605. .then(data => {
  606. document.getElementById('content').innerHTML = data;
  607. fillInstanceInfo();
  608. // 给过滤按钮添加事件,点击时调用filterInstance函数
  609. document.getElementById('intance-btn-filter').addEventListener('click', filterInstance);
  610. })
  611. .catch(error => {
  612. console.error('Error loading the intance content:', error);
  613. });
  614. });
  615. document.getElementById('templates').addEventListener('click', function() {
  616. fetch('template.html')
  617. .then(response => response.text())
  618. .then(data => {
  619. document.getElementById('content').innerHTML = data;
  620. fillTemplateInfo();
  621. })
  622. .catch(error => {
  623. console.error('Error loading the intance content:', error);
  624. });
  625. });
  626. </script>
  627. </body>
  628. </html>