From 54d5cd064e0f39e0104f58c3508391c6cf17ba5d Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 23 Jul 2021 22:42:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=B4=A0=E6=9D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor_datapanel.js | 26 +++++++++++++++++ _server/editor_file.js | 56 +++++++++++++++++++++++++++++++++++++ editor-mobile.html | 10 ++++--- editor.html | 10 ++++--- 4 files changed, 94 insertions(+), 8 deletions(-) diff --git a/_server/editor_datapanel.js b/_server/editor_datapanel.js index 0cffb4a1..da3f7932 100644 --- a/_server/editor_datapanel.js +++ b/_server/editor_datapanel.js @@ -321,6 +321,17 @@ editor_datapanel_wrapper = function (editor) { printe('该列所有剩余项全部自动注册成功,请F5刷新编辑器'); }) } + newIdIdnum.children[5].onclick = function () { + if (!confirm("警告!你确定要删除此素材吗?此过程不可逆!")) return; + editor.file.removeMaterial(editor_mode.info, function (err) { + if (err) { + printe(err); + throw err; + } + alert('删除此素材成功!'); + window.location.reload(); + }); + } } editor.uifunctions.changeId_func = function () { @@ -355,6 +366,21 @@ editor_datapanel_wrapper = function (editor) { printe('请输入要修改到的ID'); } } + changeId.children[2].onclick = function () { + if (editor_mode.info.isTile) { + printe("额外素材不可删除!"); + return; + } + if (!confirm("警告!你确定要删除此素材吗?此过程不可逆!\n请务必首先进行备份操作,并保证此素材没有在地图的任何位置使用,否则可能会出现不可知的后果!")) return; + editor.file.removeMaterial(editor_mode.info, function (err) { + if (err) { + printe(err); + return; + } + alert('删除此素材成功!'); + window.location.reload(); + }); + } } editor.uifunctions.copyPasteEnemyItem_func = function () { diff --git a/_server/editor_file.js b/_server/editor_file.js index 5125ffa3..8ce57667 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -490,6 +490,62 @@ editor_file = function (editor, callback) { } } + + editor.file.removeMaterial = function (info, callback) { + console.log(info); + + // Step 1: 尝试删除图片 + var _deleteMaterialImage = function (cb) { + if (info.images == 'autotile') return cb(); + var img = core.material.images[info.images]; + if (img == null) return callback('该素材不存在!'); + + var canvas = document.createElement('canvas'); + var ctx = canvas.getContext('2d'); + ctx.mozImageSmoothingEnabled = false; + ctx.webkitImageSmoothingEnabled = false; + ctx.msImageSmoothingEnabled = false; + ctx.imageSmoothingEnabled = false; + + var width = img.width, height = img.height, per_height = info.images.endsWith('48') ? 48 : 32 + if (height == per_height) return callback('该素材图片只有一个素材,无法删除'); + canvas.width = width; + canvas.height = height - per_height; + ctx.drawImage(img, 0, 0, width, info.y * per_height, 0, 0, width, info.y * per_height); + ctx.drawImage(img, 0, (info.y + 1) * per_height, width, height - (info.y + 1) * per_height, 0, info.y * per_height, width, height - (info.y + 1) * per_height); + var imgbase64 = canvas.toDataURL('image/png'); + fs.writeFile('./project/materials/' + info.images + '.png', imgbase64.split(',')[1], 'base64', function (err, data) { + if (err) return callback(err); + cb(); + }); + } + + _deleteMaterialImage(function () { + // Step 2: 删除图块信息 + if (info.id) { + delete icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1[info.images][info.id]; + delete maps_90f36752_8815_4be8_b32b_d7fad1d0542e[info.idnum]; + if (info.images == 'items') { + delete items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a[info.id]; + } + if (info.images == 'enemys' || info.images == 'enemy48') { + delete enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80[info.id]; + } + } + + // Step 3: 将所有素材向下移动一格 + if (info.images != 'autotile') { + var value = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1[info.images]; + Object.keys(value).forEach(function (one) { + if (value[one] > info.y) value[one]--; + }); + } + + // Step 4: 保存并删除成功! + editor.file.save_icons_maps_items_enemys(callback); + }); + } + //callback(err:String) editor.file.editItem = function (id, actionList, callback) { /*actionList:[ diff --git a/editor-mobile.html b/editor-mobile.html index a2569747..9f3548d6 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -147,13 +147,15 @@
- +
+
- + +
@@ -174,12 +176,12 @@
- +
修改地图大小:宽,高, 偏移x y - +
diff --git a/editor.html b/editor.html index 831e1ada..b290022f 100644 --- a/editor.html +++ b/editor.html @@ -144,13 +144,15 @@
- +
+
- + +
@@ -171,12 +173,12 @@
- +
修改地图大小:宽,高, 偏移x y - +