Merge pull request #279 from ckcz123/v2.0

V2.0
This commit is contained in:
Zhang Chen 2018-12-14 00:30:31 +08:00 committed by GitHub
commit 4bfd5727d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 188 additions and 28 deletions

View File

@ -5,22 +5,23 @@ grammar MotaAction;
//事件 事件编辑器入口之一
event_m
: '事件' BGNL? Newline '覆盖触发器' Bool '启用' Bool '通行状态' B_0_List '显伤' Bool BGNL? Newline action+ BEND
: '事件' BGNL? Newline '覆盖触发器' Bool '启用' Bool '通行状态' B_0_List '动画' Bool '显伤' Bool BGNL? Newline action+ BEND
/* event_m
tooltip : 编辑魔塔的事件
helpUrl : https://h5mota.com/games/template/docs/#/event
default : [false,null,null,null]
default : [false,null,null,null,null]
B_0_List_0=eval(B_0_List_0);
var code = {
'trigger': Bool_0?'action':null,
'enable': Bool_1,
'noPass': B_0_List_0,
'displayDamage': Bool_2,
'animate': Bool_2,
'displayDamage': Bool_3,
'data': 'data_asdfefw'
}
if (!Bool_0 && Bool_1 && (B_0_List_0===null) && Bool_2) code = 'data_asdfefw';
if (!Bool_0 && Bool_1 && (B_0_List_0===null) && Bool_2 && Bool_3) code = 'data_asdfefw';
code=JSON.stringify(code,null,2).split('"data_asdfefw"').join('[\n'+action_0+']\n');
return code;
*/;
@ -1803,7 +1804,7 @@ ActionParser.prototype.parse = function (obj,type) {
if(typeof(obj)===typeof('')) obj={'data':[obj]};
if(obj instanceof Array) obj={'data':obj};
return MotaActionBlocks['event_m'].xmlText([
obj.trigger==='action',obj.enable,obj.noPass,obj.displayDamage,this.parseList(obj.data)
obj.trigger==='action',obj.enable,obj.noPass,obj.animate,obj.displayDamage,this.parseList(obj.data)
]);
case 'changeFloor':

View File

@ -261,7 +261,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_leaf": true,
"_type": "textarea",
"_range": "thiseval==null||(thiseval instanceof Array)",
"_data": "该图块的不可入方向\n可以在这里定义不能从哪个方向访问该图块,可以达到悬崖之类的效果\n例如 [\"down\", \"right\"] 代表不能从下或右访问此图块\n此值对背景层、事件层、前景层上的图块均有效"
"_data": "该图块的不可入方向\n可以在这里定义不能朝哪个方向进入该图块,可以达到悬崖之类的效果\n例如 [\"down\"] 代表不能从该图块的上方点朝向下进入此图块\n此值对背景层、事件层、前景层上的图块均有效"
},
"faceIds": {
"_leaf": true,

View File

@ -392,3 +392,21 @@ table.row td {
[v-cloak] {
display: none !important;
}
#searchBlock {
width: 100px;
background-color: #E9EBF2;
border-radius: 10px;
outline: none;
padding-left: 20px;
height: 14px;
}
.searchLogo {
width: 15px;
height: 15px;
position: absolute;
left: 6px;
top: 6px;
background-image:url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGJhc2VQcm9maWxlPSJmdWxsIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4bWxuczpldj0iaHR0cDovL3d3dy53My5vcmcvMjAwMS94bWwtZXZlbnRzIj4KPGc%2BCgk8cG9seWdvbiBmaWxsPSIjNjY2IiBwb2ludHM9IjkuMjA3LDYuMTI2IDcuNzkzLDcuNTQxIDExLjc5MywxMS41NDEgMTMuMjA3LDEwLjEyNiIgLz4KCTxwYXRoIGZpbGw9IiM2NjYiIGQ9Ik01LjkxNywyYzEuNjA4LDAsMi45MTcsMS4zMDgsMi45MTcsMi45MTdTNy41MjUsNy44MzMsNS45MTcsNy44MzNTMyw2LjUyNSwzLDQuOTE3UzQuMzA4LDIsNS45MTcsMgoJCSBNNS45MTcsMEMzLjIwMSwwLDEsMi4yMDEsMSw0LjkxN3MyLjIwMSw0LjkxNyw0LjkxNyw0LjkxN3M0LjkxNy0yLjIwMSw0LjkxNy00LjkxN0MxMC44MzMsMi4yMDEsOC42MzIsMCw1LjkxNywwTDUuOTE3LDB6IiAvPgo8L2c%2BCjwvc3ZnPgo%3D');
}

View File

@ -295,11 +295,18 @@ editor.prototype.drawPosSelection = function () {
}
editor.prototype.updateMap = function () {
var evs = {};
if (editor.currentFloorData && editor.currentFloorData.events) {
for (var loc in editor.currentFloorData.events) {
if (editor.currentFloorData.events[loc].animate == false)
evs[loc] = {"animate": false};
}
}
var blocks = main.editor.mapIntoBlocks(editor.map.map(function (v) {
return v.map(function (v) {
return v.idnum || v || 0
})
}), {'events': {}, 'changeFloor': {}}, editor.currentFloorId);
}), {'events': evs, 'changeFloor': {}}, editor.currentFloorId);
core.status.thisMap.blocks = blocks;
main.editor.updateMap();

View File

@ -4,12 +4,13 @@ editor_blockly = function () {
initscript = String.raw`
(function(){
var getCategory = function(name){
var getCategory = function(name,custom){
for(var node of document.getElementById('toolbox').children) {
if(node.getAttribute('name')==name) return node;
}
var node = document.createElement('category');
node.setAttribute('name',name);
if(custom)node.setAttribute('custom',custom);
document.getElementById('toolbox').appendChild(node);
return node;
}
@ -243,15 +244,19 @@ editor_blockly = function () {
}
]
},'event'),
],
'最近使用事件':[
'<label text="此处只是占位符,实际定义在editor_blockly.searchBlockCategoryCallback中"></label>',
]
}
var toolboxgap = '<sep gap="5"></sep>'
//xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event')
//MotaActionBlocks['idString_e'].xmlText()
for (var name in toolboxObj){
getCategory(name).innerHTML = toolboxObj[name].join(toolboxgap);
var custom = null;
if(name=='最近使用事件')custom='searchBlockCategory';
getCategory(name,custom).innerHTML = toolboxObj[name].join(toolboxgap);
}
var blocklyArea = document.getElementById('blocklyArea');
@ -269,6 +274,23 @@ var workspace = Blockly.inject(blocklyDiv,{
},
trashcan: false,
});
editor_blockly.searchBlockCategoryCallback = function(workspace) {
var xmlList = [];
var labels = editor_blockly.searchBlock();
for (var i = 0; i < labels.length; i++) {
var blockText = '<xml>' +
MotaActionBlocks[labels[i]].xmlText() +
'</xml>';
var block = Blockly.Xml.textToDom(blockText).firstChild;
block.setAttribute("gap", 5);
xmlList.push(block);
}
return xmlList;
};
workspace.registerToolboxCategoryCallback(
'searchBlockCategory', editor_blockly.searchBlockCategoryCallback);
var onresize = function(e) {
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
@ -289,8 +311,11 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
workspace.setScale(workspace.scale);
}
var doubleClickCheck=[[0,'abc']];
function omitedcheckUpdateFunction(event) {
var doubleClickCheck=[[0,'abc']];
function omitedcheckUpdateFunction(event) {
if(event.type==='create'){
editor_blockly.addIntoLastUsedType(event.blockId);
}
if(event.type==='ui'){
var newClick = [new Date().getTime(),event.blockId];
var lastClick = doubleClickCheck.shift();
@ -511,6 +536,97 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
}
}
editor_blockly.lastUsedType=[
'text_0_s',
'comment_s',
'show_s',
'hide_s',
'setValue_s',
'if_s',
'battle_s',
'openDoor_s',
'choices_s',
'setText_s',
'exit_s',
'revisit_s',
'sleep_s',
'setBlock_s'
]; // 最常用的15个图块
editor_blockly.lastUsedTypeNum=15;
editor_blockly.addIntoLastUsedType=function(blockId) {
var b = editor_blockly.workspace.getBlockById(blockId);
if(!b)return;
var blockType = b.type;
if(!blockType || blockType.indexOf("_s")!==blockType.length-2 || blockType==='pass_s')return;
editor_blockly.lastUsedType = editor_blockly.lastUsedType.filter(function (v) {return v!==blockType;});
if (editor_blockly.lastUsedType.length >= editor_blockly.lastUsedTypeNum)
editor_blockly.lastUsedType.pop();
editor_blockly.lastUsedType.unshift(blockType);
document.getElementById("searchBlock").value='';
}
// Index from 1 - 9
editor_blockly.openToolbox = function(index) {
// var element = document.getElementById(':'+index);
// if (element == null || element.getAttribute("aria-selected")=="true") return;
// element.click();
editor_blockly.workspace.toolbox_.tree_.setSelectedItem(editor_blockly.workspace.toolbox_.tree_.children_[index-1]);
}
editor_blockly.reopenToolbox = function(index) {
// var element = document.getElementById(':'+index);
// if (element == null) return;
// if (element.getAttribute("aria-selected")=="true") element.click();
// element.click();
editor_blockly.workspace.toolbox_.tree_.setSelectedItem(editor_blockly.workspace.toolbox_.tree_.children_[index-1]);
editor_blockly.workspace.getFlyout_().show(editor_blockly.workspace.toolbox_.tree_.children_[index-1].blocks);
}
editor_blockly.closeToolbox = function() {
/*
for (var i=1; i<=10; i++) {
var element = document.getElementById(':'+i);
if (element && element.getAttribute("aria-selected")=="true") {
element.click();
return;
}
}
*/
editor_blockly.workspace.toolbox_.clearSelection();
}
var searchInput = document.getElementById("searchBlock");
searchInput.onfocus = function () {
editor_blockly.reopenToolbox(9);
}
searchInput.oninput = function () {
editor_blockly.reopenToolbox(9);
}
editor_blockly.searchBlock = function (value) {
if (value == null) value = searchInput.value;
value = value.toLowerCase();
if (value == '') return editor_blockly.lastUsedType;
var results = [];
for (var name in MotaActionBlocks) {
if (typeof name !== 'string' || name.indexOf("_s") !== name.length-2) continue;
var block = MotaActionBlocks[name];
if(block && block.json) {
if ((block.json.type||"").toLowerCase().indexOf(value)>=0
|| (block.json.message0||"").toLowerCase().indexOf(value)>=0
|| (block.json.tooltip||"").toLowerCase().indexOf(value)>=0) {
results.push(name);
if (results.length>=editor_blockly.lastUsedTypeNum)
break;
}
}
}
return results.length == 0 ? editor_blockly.lastUsedType : results;
}
return editor_blockly;
}
//editor_blockly=editor_blockly();

View File

@ -179,6 +179,11 @@
<button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button>
<button onclick="editor_blockly.cancel()">取消</button>
<!-- 手机端放不下,因此不显示搜索框 -->
<div style="display: none">
<div class="searchLogo"></div>
<input type="text" id="searchBlock" placeholder="搜索图块"/>
</div>
<xml id="toolbox" style="display:none">
</xml>
</h3>

View File

@ -178,6 +178,10 @@
<button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button>
<button onclick="editor_blockly.cancel()">取消</button>
<div style="position: relative; display: inline-block; margin-left: 10px">
<div class="searchLogo"></div>
<input type="text" id="searchBlock" placeholder="搜索图块"/>
</div>
<xml id="toolbox" style="display:none">
</xml>
</h3>

View File

@ -179,7 +179,9 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
}
else { // 暴力for循环法
pre = info.damage;
for (var atk=hero_atk+1;atk<=mon_hp+mon_def;atk++) {
var per_add = Math.ceil(hero_atk / 5000);
if (per_add<0) per_add = 1;
for (var atk=hero_atk+per_add;atk<=mon_hp+mon_def;atk+=per_add) {
var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, atk, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
if (nextInfo==null) break;
if (pre>nextInfo.damage) {

View File

@ -1548,7 +1548,7 @@ events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback
////// 绘制图片 //////
events.prototype.showImage = function (name, x, y) {
if (core.isset(name) && core.isset(x) && core.isset(y) && core.isset(core.material.images.images[name])) {
core.canvas.image.drawImage(core.material.images.images[name], x, y);
core.canvas.image.drawImage(core.material.images.images[name], core.calValue(x), core.calValue(y));
}
else core.clearMap('image');
}

View File

@ -146,9 +146,13 @@ maps.prototype.addEvent = function (block, x, y, event) {
if (!core.isset(block.disable) && core.isset(event.enable)) {
block.disable=!event.enable;
}
// 覆盖animate
if (event.animate === false) {
block.event.animate = 1;
}
// 覆盖所有属性
for (var key in event) {
if (key!="enable" && core.isset(event[key])) {
if (key!="enable" && key!="animate" && core.isset(event[key])) {
block.event[key]=core.clone(event[key]);
}
}

View File

@ -1645,7 +1645,7 @@ ui.prototype.drawBookDetail = function (index) {
u.push(t);
}
});
hints.push(JSON.stringify(u.map(function (v) {return v[0]+":"+v[1];})));
hints.push(JSON.stringify(u.map(function (v) {return core.formatBigNumber(v[0])+":"+core.formatBigNumber(v[1]);})));
}
}
@ -1679,7 +1679,7 @@ ui.prototype.drawBookDetail = function (index) {
hints.push("");
var criticals = core.enemys.nextCriticals(enemyId, 10).map(function (v) {
return v[0]+":"+v[1];
return core.formatBigNumber(v[0])+":"+core.formatBigNumber(v[1]);
});
while (criticals[0]=='0:0') criticals.shift();
hints.push("临界表:"+JSON.stringify(criticals))

View File

@ -813,6 +813,12 @@ utils.prototype.encodeCanvas = function (ctx) {
////// 解析arr数组并绘制到tempCanvas上 //////
utils.prototype.decodeCanvas = function (arr, width, height) {
// 清空tempCanvas
var tempCanvas = core.bigmap.tempCanvas;
tempCanvas.canvas.width=width;
tempCanvas.canvas.height=height;
tempCanvas.clearRect(0, 0, width, height);
if (!core.isset(arr)) return null;
// to byte array
var curr = 0, list = [];
@ -820,11 +826,6 @@ utils.prototype.decodeCanvas = function (arr, width, height) {
for (var i=0;i<x;i++) list.push(curr);
curr = 1-curr;
})
// 使用tempCanvas
var tempCanvas = core.bigmap.tempCanvas;
tempCanvas.canvas.width=width;
tempCanvas.canvas.height=height;
tempCanvas.clearRect(0, 0, width, height);
var imgData = tempCanvas.getImageData(0, 0, width, height);
for (var i=0;i<imgData.data.length;i+=4) {
@ -840,6 +841,7 @@ utils.prototype.decodeCanvas = function (arr, width, height) {
utils.prototype.consoleOpened = function () {
if (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized)
return true;
if (!core.platform.isPC) return false;
var threshold = 160;
var zoom = Math.min(window.outerWidth/window.innerWidth, window.outerHeight/window.innerHeight);
return window.outerWidth - zoom*window.innerWidth > threshold

View File

@ -526,9 +526,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
init_damage += vampire_damage;
}
// 检查是否破防;否则直接返回不可战斗
if (hero_atk <= mon_def) return null;
// 每回合怪物对勇士造成的战斗伤害
var per_damage = mon_atk - hero_def;
// 魔攻:战斗伤害就是怪物攻击力
@ -557,7 +554,11 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
init_damage += Math.floor(core.values.purify * hero_mdef);
// 勇士每回合对怪物造成的伤害
var hero_per_damage = hero_atk - mon_def;
var hero_per_damage = Math.max(hero_atk - mon_def, 0);
// 如果没有破防,则不可战斗
if (hero_per_damage <= 0) return null;
// 勇士的攻击回合数;为怪物生命除以每回合伤害向上取整
var turn = Math.ceil(mon_hp / hero_per_damage);
// 最终伤害:初始伤害 + 怪物对勇士造成的伤害 + 反击伤害
@ -1040,8 +1041,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
ctx.drawImage(core.statusBar.icons[name], leftOffset, topOffset, 25, 25);
// 文字内容
var text = (core.statusBar[name]||{}).innerText || " ";
// 斜体判定:如果不是纯数字,斜体会非常难看,需要取消
if (!/^\d*$/.test(text)) ctx.font = 'bold 18px Verdana';
// 斜体判定:如果不是纯数字和字母,斜体会非常难看,需要取消
if (!/^[-+_.a-zA-Z0-9]*$/.test(text)) ctx.font = 'bold 18px Verdana';
// 绘制文字
ctx.fillText(text, leftOffset + 36, topOffset + 20);
ctx.font = 'italic bold 18px Verdana';