Update dynamicMapEditor

This commit is contained in:
ckcz123 2019-10-22 10:26:45 +08:00
parent 80715f20de
commit 46f0aa7e0e
4 changed files with 159 additions and 52 deletions

View File

@ -25,6 +25,8 @@ function dynamicMapEditor() {
this.dom = null;
this.canvas = null;
this.mapRecord = {};
this.enemyModified = false;
this.valueModified = false;
this.pageId = 0;
this.pageMaxItems = 21;
this.pageMax = 0;
@ -57,6 +59,7 @@ dynamicMapEditor.prototype._init = function () {
core.registerAction('onkeyUp', 'plugin_dme_keydown', this.onKeyDown.bind(this), 200);
core.registerAction('onclick', 'plugin_dme_click', this.onMapClick.bind(this), 200);
this.dom.addEventListener("click",this.onBoxClick.bind(this));
this.showInitHelp();
}
dynamicMapEditor.prototype.initInfos = function () {
@ -70,23 +73,30 @@ dynamicMapEditor.prototype.initInfos = function () {
this.items.push(core.getBlockInfo(u.id));
}
}
} else if (v == 'none') {
this.items.push({"number": 0, "id": "none", "name": "清除块"});
} else {
this.items.push(core.getBlockInfo(v));
}
}, this);
this.items = this.items.filter(function (v) { return v && v.id && v.number >= 0; });
}
// ------ bind actions
dynamicMapEditor.prototype.isValid = function () {
return main.mode == 'play' && core.isPlaying() && !core.isReplaying() && !core.status.lockControl;
}
dynamicMapEditor.prototype.onKeyDown = function(e) {
if(!core.isPlaying() || core.isReplaying() || core.status.lockControl) return false;
if (!this.isValid()) return false;
var func = this.key2Function[e.keyCode];
func && func.call(this);
return false;
}
dynamicMapEditor.prototype.onMapClick = function(x, y) {
if (!core.isPlaying() || core.isReplaying() || core.status.lockControl) return false;
if (!this.isValid()) return false;
if (!this.isUsingTool || !this.selectedItem) return false;
var number = this.selectedItem.number;
this.addOperation('put', number, x, y, core.status.floorId);
@ -101,7 +111,7 @@ dynamicMapEditor.prototype.getClickLoc = function (e) {
}
dynamicMapEditor.prototype.onBoxClick = function (e) {
if (!core.isPlaying() || core.isReplaying() || !this.isUsingTool) return;
if (!this.isValid() || !this.isUsingTool) return false;
var loc = this.getClickLoc(e), x = loc.x, y = loc.y;
for(var i = 0; i < this.pageMaxItems; i++) {
var rect = this.itemRect(i);
@ -110,11 +120,12 @@ dynamicMapEditor.prototype.onBoxClick = function (e) {
return;
}
}
// TODO: page up, page down,help
if(y>=350) {
if(x>=this.offsetX && x<=this.offsetX+60){
if(y>=350 && y <= 370) {
if (x >= this.offsetX && x <= this.offsetX + 40) {
this.changePage(-1);
}else{
} else if (x >= this.offsetX + 40 && x <= this.offsetX + 80) {
this.showHelp(true);
} else if (x >= this.offsetX + 80 && x <= this.offsetX + 120) {
this.changePage(1);
}
}
@ -126,9 +137,9 @@ dynamicMapEditor.prototype.onItemClick = function(index) {
if(!item) return;
if(index == this.selectedIndex) {
var enemy = core.material.enemys[item.id];
if (!enemy) return;
if (!enemy) {
var nowData = [enemy.hp, enemy.atk, enemy.def, enemy.special].join(';');
core.myprompt("请输入血;攻;防;能力,以分号分隔", nowData, function (result) {
core.myprompt("请输入新怪物属性\n血;攻;防;能力,以分号分隔", nowData, function (result) {
if (result) {
try {
var finalData = result.split(';');
@ -136,7 +147,8 @@ dynamicMapEditor.prototype.onItemClick = function(index) {
var hp = parseInt(finalData[0]) || 0;
var atk = parseInt(finalData[1]) || 0;
var def = parseInt(finalData[2]) || 0;
var special = finalData[3].replace(/[\[\]]/g, "").split(',');
var special = finalData[3].replace(/[\[\]]/g, "")
.split(',').map(function (x) { return parseInt(x); });
if (special.length == 0) special = 0;
else if (special.length == 1) special = special[0];
dynamicMapEditor.addOperation('modify', item.id, hp, atk, def, special);
@ -146,6 +158,19 @@ dynamicMapEditor.prototype.onItemClick = function(index) {
}
core.drawTip('无效的输入数据');
});
return;
}
if (core.values[item.id] != null) {
var nowData = core.values[item.id];
core.myprompt("请输入新" + (item.name || "") + "数值:", core.values[item.id], function (result) {
if (result) {
dynamicMapEditor.addOperation('value', item.id, parseInt(result) || 0, item.name || "");
core.drawTip('已更新' + (item.name || "") + "的数值");
return;
}
core.drawTip('无效的输入数据');
})
}
} else {
this.selectedIndex = index;
this.selectedItem = item;
@ -170,6 +195,7 @@ dynamicMapEditor.prototype.openToolBox = function() {
this.dom.height = core.dom.statusCanvas.height;
this.offsetX = this.dom.width / 2 - 60;
this.refreshToolBox();
if (this.isUsingTool) this.showHelp();
}
dynamicMapEditor.prototype.addOperation = function() {
@ -185,7 +211,7 @@ dynamicMapEditor.prototype.addOperation = function() {
core.floors[operation.floorId].map[operation.y][operation.x] = operation.number;
core.setBlock(operation.number, operation.x, operation.y, operation.floorId);
this.mapRecord[operation.floorId] = true;
} else if(type == 'modify') {
} else if (type == 'modify') {
operation.enemyId = arguments[1];
operation.hp = arguments[2];
operation.atk = arguments[3];
@ -200,6 +226,14 @@ dynamicMapEditor.prototype.addOperation = function() {
enemy.atk = operation.atk;
enemy.def = operation.def;
enemy.special = operation.special;
this.enemyModified = true;
} else if (type == 'value') {
operation.id = arguments[1];
operation.value = arguments[2];
operation.name = arguments[3];
operation.originValue = core.values[operation.id];
core.values[operation.id] = operation.value;
this.valueModified = true;
}
this.userChanged.push(operation);
}
@ -220,7 +254,7 @@ dynamicMapEditor.prototype.undo = function() {
core.setBlock(originNumber, x, y, floorId);
this.mapRecord[floorId] = true;
core.drawTip('已撤销' + floorId + '在(' + x + ',' + y + ')的图块操作');
} else { // {enemyId, originHp, originAtk, originDef, originSpecial}
} else if (type == 'modify') { // {enemyId, originHp, originAtk, originDef, originSpecial}
var enemyId = operation.enemyId;
var hp = operation.originHp;
var atk = operation.originAtk;
@ -232,6 +266,13 @@ dynamicMapEditor.prototype.undo = function() {
enemy.def = def;
enemy.special = special;
core.drawTip('已撤销对' + enemy.name + '的属性修改');
this.enemyModified = true;
} else if (type == 'value') { // {id, value, originValue}
var id = operation.id;
var value = operation.originValue;
core.values[operation.id] = operation.originValue;
core.drawTip('已撤销对' + operation.name + "数值的修改");
this.valueModified = true;
}
}
@ -240,6 +281,7 @@ dynamicMapEditor.prototype.changePage = function(delta) {
if (newId < 0 || newId >= this.pageMax) return;
this.pageId = newId;
this.selectedItem = null;
this.selectedIndex = -1;
this.refreshToolBox();
}
@ -260,42 +302,92 @@ dynamicMapEditor.prototype.refreshToolBox = function() {
var startIndex = this.pageId * this.pageMaxItems;
for (var i = 0; i < this.pageMaxItems; ++i) {
var item = this.items[startIndex + i];
if (item.number == 0) continue;
if (!item) break;
var rect = this.itemRect(i);
core.drawImage(this.canvas, item.image, 0, item.height * item.posY, 32, 32, rect.x + 4, rect.y, 32, 32);
if (item.image) core.drawImage(this.canvas, item.image, 0, item.height * item.posY, 32, 32, rect.x + 4, rect.y, 32, 32);
if (item.name) {
this.canvas.textAlign = 'center';
if (item.name) core.fillText(this.canvas, item.name, rect.x + 20, rect.y + 44, null, '#FFFFFF', 40);
core.fillText(this.canvas, item.name, rect.x + 20, rect.y + 44, '#FFFFFF', null, 40);
}
if (core.material.enemys[item.id]) {
this.canvas.textAlign = 'left';
var damageString = core.enemys.getDamageString(item.id);
core.fillBoldText(this.canvas, damageString.damage, rect.x + 5, rect.y + 31, damageString.color);
var critical = core.enemys.nextCriticals(item.id, 1);
critical = core.formatBigNumber((critical[0]||[])[0], true);
if (critical == '???') critical = '?';
core.fillBoldText(this.canvas, critical, rect.x+1, rect.y+21, '#FFFFFF');
core.fillBoldText(this.canvas, critical, rect.x+5, rect.y+21, '#FFFFFF');
}
}
if(this.pageId > 0) this.canvas.fillText('上一页', this.offsetX + 30, 380);
if(this.pageId < this.pageMax-1) this.canvas.fillText('下一页',this.offsetX + 90, 380);
this.canvas.textAlign = 'center';
this.canvas.fillStyle = '#FFFFFF';
if(this.pageId > 0) core.fillText(this.canvas, '上一页', this.offsetX + 20, 365, '#FFFFFF');
if(this.pageId < this.pageMax-1) core.fillText(this.canvas, '下一页',this.offsetX + 100, 365, '#FFFFFF');
core.fillText(this.canvas, '帮助', this.offsetX + 60, 365, '#FFFFFF');
var text1 = core.formatBigNumber(core.getRealStatus('hp'), true) + "/" +
core.formatBigNumber(core.getRealStatus('atk'), true) + "/" +
core.formatBigNumber(core.getRealStatus("def"), true) + "/" +
core.formatBigNumber(core.getRealStatus("mdef"), true);
core.fillText(this.canvas, text1, this.offsetX + 60, 380, '#FF7F00', 120);
var text2 = core.formatBigNumber(core.getRealStatus('money', true)) + "/" +
core.formatBigNumber(core.getRealStatus('experience'), true) + "/" +
core.itemCount('yellowKey') + '/' + core.itemCount('blueKey') + '/' +
core.itemCount('redKey');
core.fillText(this.canvas, text2, this.offsetX + 60, 395, '#FF7F00', 120);
var text3 = core.itemCount('pickaxe') + '/' + core.itemCount('bomb') + '/' +
core.itemCount('centerFly');
if (core.hasFlag('poison')) text3 += "/毒";
if (core.hasFlag('weak')) text3 += "/衰";
if (core.hasFlag('curse')) text3 += "/咒";
core.fillText(this.canvas, text3, this.offsetX + 60, 410, '#FF7F00', 120);
if(this.selectedItem) {
this.canvas.strokeStyle = '#FFFFFF';
var rect = this.itemRect(this.selectedIndex);
this.canvas.strokeRect(rect.x, rect.y, rect.w, rect.h);
core.strokeRect(this.canvas, rect.x, rect.y, rect.w, rect.h, '#FF7F00', 4);
}
}
dynamicMapEditor.prototype.showInitHelp = function () {
if (main.mode != 'play' || core.getLocalStorage('_dynamicMapEditor_init')) return;
var text = "新拓展:运行时动态编辑地图!\n\n在此状态下你可以一边游戏一边编辑地图或者修改数据。\n\n";
text += "进游戏后按 [ 键可以激活,快来尝试吧!\n\n";
text += "点取消后将不再提示本页面。";
core.myconfirm(text, null, function () {
core.setLocalStorage('_dynamicMapEditor_init', true);
if (core.firstData.name != 'template') {
localStorage.removeItem('template__dynamicMapEditor_init');
localStorage.removeItem('template__dynamicMapEditor_help');
}
});
}
dynamicMapEditor.prototype.showHelp = function (fromButton) {
if (main.mode != 'play' || (!fromButton && core.getLocalStorage('_dynamicMapEditor_help'))) return;
var text = "欢迎使用黄鸡编写的运行时编辑拓展!你可以一边游戏一边编辑地图或者修改数据。\n\n";
text += "基本操作:\n - 点击图块再点地图可以放置;\n - 双击图块可以编辑数据;\n";
text += " - [ 键将开关此模式;\n - ] 键将会把改动保存到文件;\n - \\ 键将撤销上步操作。\n\n";
text += "最下面三行数据分别是:\n"
text += "血攻防魔防金经黄蓝红破炸飞和debuff";
if (!fromButton) text += "\n\n点取消将不再提示本页面。";
core.myconfirm(text, null, function () {
if (!fromButton) core.setLocalStorage("_dynamicMapEditor_help", true);
})
}
// ------ save
dynamicMapEditor.prototype.applyCurrentChange = function() {
this.saveEnemys();
this.saveValues();
this.saveFloors();
this.enemyModified = false;
this.valueModified = false;
this.mapRecord = {};
core.drawTip('已将所有改动应用到文件,刷新后生效');
core.drawTip('已将所有改动应用到文件,记得刷新编辑器哦');
}
dynamicMapEditor.prototype.saveEnemys = function () {
if (!this.enemyModified) return;
core.enemys.enemys = core.clone(core.material.enemys);
var datastr = 'var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = \n';
var emap = {};
@ -313,7 +405,14 @@ dynamicMapEditor.prototype.saveEnemys = function () {
fs.writeFile('project/enemys.js', core.encodeBase64(datastr), 'base64', function (e, d) {});
}
dynamicMapEditor.prototype.saveValues = function () {
if (!this.valueModified) return;
core.data.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values = core.clone(core.values);
fs.writeFile('project/data.js', core.encodeBase64(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d), 'base64', function (e, d) {});
}
dynamicMapEditor.prototype.saveFloors = function () {
if (Object.keys(this.mapRecord).length == 0) return;
core.initStatus.maps = core.maps._initMaps();
for (var floorId in this.mapRecord) {
if (this.mapRecord[floorId]) {
@ -335,14 +434,14 @@ dynamicMapEditor.prototype.saveFloor = function (floorId) {
});
var tempJson = JSON.stringify(tempJsonObj, null, 4);
tempMap.forEach(function (v) {
tempJson = tempJson.replace('"' + v[1] + '"', '[\n' + dynamicMapEditor.formatMap(v[2], v[0] != 'map') + '\n]')
});
tempJson = tempJson.replace('"' + v[1] + '"', '[\n' + this.formatMap(v[2], v[0] != 'map') + '\n]')
}, this);
datastr = datastr.concat([tempJson]);
datastr = datastr.join('');
fs.writeFile(filename, core.encodeBase64(datastr), 'base64', function (e, d) {});
}
dynamicMapEditor.prototype.formapMap = function (mapArr, trySimplify) {
dynamicMapEditor.prototype.formatMap = function (mapArr, trySimplify) {
if (!mapArr || JSON.stringify(mapArr) == JSON.stringify([])) return '';
if (trySimplify) {
//检查是否是全0二维数组
@ -369,10 +468,16 @@ dynamicMapEditor.prototype.formapMap = function (mapArr, trySimplify) {
// ------ rewrite
var dynamicMapEditor = new dynamicMapEditor();
dynamicMapEditor._resize_statusBar = core.control._resize_statusBar;
core.control._resize_statusBar = function (obj) {
dynamicMapEditor._resize_statusBar.call(this,obj);
dynamicMapEditor.refreshToolBox();
}
var dynamicMapEditor = new dynamicMapEditor();
dynamicMapEditor.updateStatusBar = core.control.updateStatusBar;
core.control.updateStatusBar = function () {
dynamicMapEditor.refreshToolBox();
dynamicMapEditor.updateStatusBar.apply(core.control, Array.prototype.slice.call(arguments));
}

View File

@ -1365,6 +1365,8 @@ maps.prototype.getBlockInfo = function (block) {
faceIds = block.event.faceIds || {};
if (core.material.enemys[id]) {
name = core.material.enemys[id].name;
} else if (core.material.items[id]) {
name = core.material.items[id].name;
}
}

View File

@ -330,6 +330,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
}
// 自爆
if (core.enemys.hasSpecial(special, 19)) {
core.status.hero.statistics.battleDamage += core.status.hero.hp - 1;
core.status.hero.hp = 1;
}
// 退化

View File

@ -347,11 +347,10 @@ p#name {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -60%);
transform: translate(-50%, -55%);
background: white;
width: 250px;
min-height: 50px;
max-height: 250px;
}
#inputMessage {