删除素材
This commit is contained in:
parent
2ec1615dc4
commit
54d5cd064e
@ -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 () {
|
||||
|
||||
@ -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:[
|
||||
|
||||
@ -147,13 +147,15 @@
|
||||
<div id='newIdIdnum'><!-- id and idnum -->
|
||||
<input placeholder="新id(唯一标识符)"/>
|
||||
<input placeholder="新idnum(10000以内数字)"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
<br/>
|
||||
<button style="margin-top: 10px">自动注册</button>
|
||||
<button style="margin-top: 10px; margin-left: 10px">删除此素材</button>
|
||||
</div>
|
||||
<div id='changeId'><!-- id and idnum -->
|
||||
<input placeholder="修改图块id为"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
<button style="margin-left: 10px">删除此素材</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -174,12 +176,12 @@
|
||||
</div>
|
||||
<div id='changeFloorId'><!-- id and idnum -->
|
||||
<input placeholder="修改floorId为"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
</div>
|
||||
<div id='changeFloorSize' style="font-size: 13px;">
|
||||
修改地图大小:宽<input style="width: 25px;" value="13" />,高<input style="width: 25px;" value="13" />,
|
||||
偏移x<input style="width: 25px;" value="0" /> y<input style="width: 25px;" value="0" />
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
10
editor.html
10
editor.html
@ -144,13 +144,15 @@
|
||||
<div id='newIdIdnum'><!-- id and idnum -->
|
||||
<input placeholder="新id(唯一标识符)"/>
|
||||
<input placeholder="新idnum(10000以内数字)"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
<br/>
|
||||
<button style="margin-top: 10px">自动注册</button>
|
||||
<button style="margin-top: 10px; margin-left: 10px">删除此素材</button>
|
||||
</div>
|
||||
<div id='changeId'><!-- id and idnum -->
|
||||
<input placeholder="修改图块id为"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
<button style="margin-left: 10px">删除此素材</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -171,12 +173,12 @@
|
||||
</div>
|
||||
<div id='changeFloorId'><!-- id and idnum -->
|
||||
<input placeholder="修改floorId为"/>
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
</div>
|
||||
<div id='changeFloorSize' style="font-size: 13px;">
|
||||
修改地图大小:宽<input style="width: 25px;" value="13" />,高<input style="width: 25px;" value="13" />,
|
||||
偏移x<input style="width: 25px;" value="0" /> y<input style="width: 25px;" value="0" />
|
||||
<button>save</button>
|
||||
<button>确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user