Merge pull request #204 from ckcz123/v2.0

V2.0
This commit is contained in:
Zhang Chen 2018-08-30 21:27:39 +08:00 committed by GitHub
commit 5d9690c966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 191 additions and 7 deletions

View File

@ -62,6 +62,8 @@ HTML5 canvas制作的魔塔样板支持全平台游戏
### 2018.8.28 V2.4
* [x] 大地图的支持
* [x] 突破了5M的存档空间大小限制
* [x] 事件:隐藏/显示贴图
* [x] 同点多事件的颜色块绘制
* [x] 录像播放时可以按PgUp/PgDn浏览地图
* [x] 录像播放时对于瞬间移动绘制箭头

View File

@ -187,6 +187,8 @@ action
| setValue_s
| show_s
| hide_s
| showFloorImg_s
| hideFloorImg_s
| trigger_s
| revisit_s
| exit_s
@ -417,6 +419,68 @@ var code = '{"type": "hide"'+floorstr+IdString_0+''+Int_0+'},\n';
return code;
*/;
showFloorImg_s
: '显示贴图' 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? Newline
/* showFloorImg_s
tooltip : showFloorImg: 显示一个贴图xy为左上角坐标可用逗号分隔表示多个点
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=showFloorImg%ef%bc%9a%e6%98%be%e7%a4%ba%e8%b4%b4%e5%9b%be
default : ["","",""]
colour : this.eventColor
var floorstr = '';
if (EvalString_0 && EvalString_1) {
var pattern1 = /^flag:[0-9a-zA-Z_][0-9a-zA-Z_\-:]*$/;
if(pattern1.test(EvalString_0) || pattern1.test(EvalString_1)){
EvalString_0=MotaActionFunctions.PosString_pre(EvalString_0);
EvalString_1=MotaActionFunctions.PosString_pre(EvalString_1);
EvalString_0=[EvalString_0,EvalString_1]
} else {
var pattern2 = /^([+-]?\d+)(,[+-]?\d+)*$/;
if(!pattern2.test(EvalString_0) || !pattern2.test(EvalString_1))throw new Error('坐标格式错误,请右键点击帮助查看格式');
EvalString_0=EvalString_0.split(',');
EvalString_1=EvalString_1.split(',');
if(EvalString_0.length!==EvalString_1.length)throw new Error('坐标格式错误,请右键点击帮助查看格式');
for(var ii=0;ii<EvalString_0.length;ii++)EvalString_0[ii]='['+EvalString_0[ii]+','+EvalString_1[ii]+']';
}
floorstr = ', "loc": ['+EvalString_0.join(',')+']';
}
IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"');
var code = '{"type": "showFloorImg"'+floorstr+IdString_0+'},\n';
return code;
*/;
hideFloorImg_s
: '隐藏贴图' 'x' EvalString? ',' 'y' EvalString? '楼层' IdString? Newline
/* hideFloorImg_s
tooltip : hideFloorImg: 隐藏一个贴图xy为左上角坐标可用逗号分隔表示多个点
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=hideFloorImg%ef%bc%9a%e9%9a%90%e8%97%8f%e8%b4%b4%e5%9b%be
default : ["","",""]
colour : this.eventColor
var floorstr = '';
if (EvalString_0 && EvalString_1) {
var pattern1 = /^flag:[0-9a-zA-Z_][0-9a-zA-Z_\-:]*$/;
if(pattern1.test(EvalString_0) || pattern1.test(EvalString_1)){
EvalString_0=MotaActionFunctions.PosString_pre(EvalString_0);
EvalString_1=MotaActionFunctions.PosString_pre(EvalString_1);
EvalString_0=[EvalString_0,EvalString_1]
} else {
var pattern2 = /^([+-]?\d+)(,[+-]?\d+)*$/;
if(!pattern2.test(EvalString_0) || !pattern2.test(EvalString_1))throw new Error('坐标格式错误,请右键点击帮助查看格式');
EvalString_0=EvalString_0.split(',');
EvalString_1=EvalString_1.split(',');
if(EvalString_0.length!==EvalString_1.length)throw new Error('坐标格式错误,请右键点击帮助查看格式');
for(var ii=0;ii<EvalString_0.length;ii++)EvalString_0[ii]='['+EvalString_0[ii]+','+EvalString_1[ii]+']';
}
floorstr = ', "loc": ['+EvalString_0.join(',')+']';
}
IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"');
var code = '{"type": "hideFloorImg"'+floorstr+IdString_0+'},\n';
return code;
*/;
trigger_s
: '触发事件' 'x' PosString ',' 'y' PosString Newline
@ -1529,6 +1593,30 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['hide_s'].xmlText([
x_str.join(','),y_str.join(','),data.floorId||'',data.time||0,this.next]);
break;
case "showFloorImg": // 显示贴图
data.loc=data.loc||[];
if (!(data.loc[0] instanceof Array))
data.loc = [data.loc];
var x_str=[],y_str=[];
data.loc.forEach(function (t) {
x_str.push(t[0]);
y_str.push(t[1]);
})
this.next = MotaActionBlocks['showFloorImg_s'].xmlText([
x_str.join(','),y_str.join(','),data.floorId||'',this.next]);
break;
case "hideFloorImg": // 隐藏贴图
data.loc=data.loc||[];
if (!(data.loc[0] instanceof Array))
data.loc = [data.loc];
var x_str=[],y_str=[];
data.loc.forEach(function (t) {
x_str.push(t[0]);
y_str.push(t[1]);
})
this.next = MotaActionBlocks['hideFloorImg_s'].xmlText([
x_str.join(','),y_str.join(','),data.floorId||'',this.next]);
break;
case "setBlock": // 设置图块
data.loc=data.loc||['',''];
this.next = MotaActionBlocks['setBlock_s'].xmlText([

View File

@ -112,6 +112,8 @@ editor_blockly = function () {
MotaActionBlocks['exit_s'].xmlText(),
MotaActionBlocks['show_s'].xmlText(),
MotaActionBlocks['hide_s'].xmlText(),
MotaActionBlocks['showFloorImg_s'].xmlText(),
MotaActionBlocks['hideFloorImg_s'].xmlText(),
MotaActionBlocks['trigger_s'].xmlText(),
MotaActionBlocks['move_s'].xmlText(),
MotaActionBlocks['jump_s'].xmlText(),

View File

@ -459,6 +459,38 @@ revisit常常使用在一些商人之类的地方当用户购买物品后不
]
```
### hideFloorImg隐藏贴图
使用`{"type":"hideFloorImg"}`可以隐藏某个楼层的贴图。
有关贴图说明请参见[使用自己的图片作为某层楼的背景/前景素材](personalization#使用自己的图片作为某层楼的背景前景素材)。
``` js
"x,y": [ // 实际执行的事件列表
{"type": "hideFloorImg", "loc": [3,6], "floorId": "MT1"}, // 隐藏[3,6]的贴图
{"type": "hideFloorImg", "loc": [3,6]}, // 如果是当前层则可以省略floorId项
{"type": "hideFloorImg", "loc": [[3,6],[2,9],[1,2]]} // 我们也可以同时隐藏多个贴图。
]
```
loc为要隐藏的贴图的左上角坐标可以简单的写[x,y]代表一个点,也可以写个二维数组[[x1,y1],[x2,y2],...]来同时显示多个点。
如果同时存在若干个贴图都是是该坐标为左上角,则这些贴图全部会被隐藏。
floorId为目标点的楼层如果是当前楼层可以忽略不写。
### showFloorImg显示贴图
使用`{"type":"showFloorImg"}`可以显示某个楼层的贴图。
其做法和参数,和隐藏贴图是完全一致的。
``` js
"x,y": [ // 实际执行的事件列表
{"type": "showFloorImg", "loc": [3,6], "floorId": "MT1"}, // 显示[3,6]的贴图
]
```
### setBlock设置某个图块
我们可以采用 `{"type": "setBlock"}` 来改变某个地图块。

View File

@ -83,6 +83,8 @@ images为一个数组代表当前层所有作为背景素材的图片信息
!> 如果写2的话请确保图片高度是32的倍数
楼层贴图可以被事件隐藏和显示,详见[隐藏贴图](event#hideFloorImg隐藏贴图)的写法。
**如果你需要让某些点不可通行(比如你建了个房子,墙壁和家具等位置不让通行),则需在`events`中指定`{"noPass": false}`,参见[自定义事件](event#自定义事件)的写法。**
``` js

View File

@ -1596,9 +1596,12 @@ actions.prototype.clickSwitchs = function (x,y) {
core.ui.drawSwitchs();
break;
case 7:
window.open(core.firstData.name+".zip", "_blank");
window.open(core.platform.isPC?"editor.html":"editor-mobile.html", "_blank");
break;
case 8:
window.open(core.firstData.name+".zip", "_blank");
break;
case 9:
core.status.event.selection=0;
core.ui.drawSettings();
break;

View File

@ -454,6 +454,8 @@ control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
return;
}
if (core.timeout.turnHeroTimeout!=null) return;
// 单击瞬间移动
if (core.status.automaticRoute.clickMoveDirectly && core.status.heroStop) {
if (core.control.tryMoveDirectly(destX, destY))

View File

@ -271,6 +271,7 @@ core.prototype.init = function (coreData, callback) {
core.material.ground.src = "project/images/ground.png";
core.bigmap.tempCanvas = document.createElement('canvas').getContext('2d');
core.getLocalForage("test");
core.loader.load(function () {
console.log(core.material);

View File

@ -399,6 +399,26 @@ events.prototype.doAction = function() {
}
else this.doAction();
break;
case "showFloorImg": // 显示贴图
if (!core.isset(data.loc))
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
core.maps.setFloorImage("show", data.loc, data.floorId, function() {
core.events.doAction();
})
break;
case "hideFloorImg": // 隐藏贴图
if (!core.isset(data.loc))
data.loc = [x,y];
if ((typeof data.loc[0] == 'number' || typeof data.loc[0] == 'string')
&& (typeof data.loc[1] == 'number' || typeof data.loc[1] == 'string'))
data.loc = [[core.calValue(data.loc[0]), core.calValue(data.loc[1])]];
core.maps.setFloorImage("hide", data.loc, data.floorId, function() {
core.events.doAction();
})
break;
case "setBlock": // 设置某图块
{
if (core.isset(data.loc)) {

View File

@ -361,7 +361,9 @@ maps.prototype.drawMap = function (mapName, callback) {
}
images.forEach(function (t) {
var dx=parseInt(t[0]), dy=parseInt(t[1]), p=t[2];
if (core.isset(dx) && core.isset(dy) && core.isset(core.material.images.images[p])) {
if (core.isset(dx) && core.isset(dy) &&
!core.hasFlag("floorimg_"+mapName+"_"+dx+"_"+dy) &&
core.isset(core.material.images.images[p])) {
var image = core.material.images.images[p];
if (!t[3]) {
if (/.*\.gif/i.test(p) && main.mode=='play') {
@ -1079,6 +1081,27 @@ maps.prototype.drawAnimate = function (name, x, y, callback) {
}, 50);
}
maps.prototype.setFloorImage = function (type, loc, floorId, callback) {
if (type!='show') type='hide';
if (typeof loc[0] == 'number' && typeof loc[1] == 'number')
loc = [loc];
floorId = floorId||core.status.floorId;
if (loc.length==0) return;
loc.forEach(function (t) {
var x=t[0], y=t[1];
var flag = "floorimg_"+floorId+"_"+x+"_"+y;
core.setFlag(flag, type=='show'?false:true);
})
if (floorId==core.status.floorId) {
core.drawMap(floorId, callback);
}
else {
if (core.isset(callback)) callback();
}
}
maps.prototype.resetMap = function(floorId) {
var floorId = floorId||core.status.floorId;
core.status.maps[floorId] = this.loadFloor(floorId);

View File

@ -800,6 +800,7 @@ ui.prototype.drawSwitchs = function() {
"临界显伤: "+(core.flags.displayCritical ? "[ON]" : "[OFF]"),
"领域显伤: "+(core.flags.displayExtraDamage ? "[ON]" : "[OFF]"),
"单击瞬移: "+(core.status.automaticRoute.clickMoveDirectly ? "[ON]" : "[OFF]"),
"查看工程",
"下载离线版本",
"返回主菜单"
];
@ -1250,8 +1251,7 @@ ui.prototype.drawCursor = function () {
////// 绘制怪物手册 //////
ui.prototype.drawBook = function (index) {
var enemys = core.enemys.getCurrentEnemys(core.floorIds[core.status.event.selection]);
var enemys = core.enemys.getCurrentEnemys(core.floorIds[(core.status.event.selection||{}).index]);
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
clearInterval(core.interval.tipAnimate);
@ -1395,7 +1395,7 @@ ui.prototype.drawBook = function (index) {
////// 绘制怪物属性的详细信息 //////
ui.prototype.drawBookDetail = function (index) {
var enemys = core.enemys.getCurrentEnemys(core.floorIds[core.status.event.selection]);
var enemys = core.enemys.getCurrentEnemys(core.floorIds[(core.status.event.selection||{}).index]);
if (enemys.length==0) return;
if (index<0) index=0;
if (index>=enemys.length) index=enemys.length-1;
@ -1842,7 +1842,9 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, cente
}
images.forEach(function (t) {
var dx=parseInt(t[0]), dy=parseInt(t[1]), p=t[2];
if (core.isset(dx) && core.isset(dy) && core.isset(core.material.images.images[p])) {
if (core.isset(dx) && core.isset(dy) &&
!core.hasFlag("floorimg_"+floorId+"_"+dx+"_"+dy) &&
core.isset(core.material.images.images[p])) {
var image = core.material.images.images[p];
if (!t[3])
tempCanvas.drawImage(image, 32 * dx, 32 * dy, image.width, image.height);
@ -1880,7 +1882,9 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, cente
// draw fg
images.forEach(function (t) {
var dx=parseInt(t[0]), dy=parseInt(t[1]), p=t[2];
if (core.isset(dx) && core.isset(dy) && core.isset(core.material.images.images[p])) {
if (core.isset(dx) && core.isset(dy) &&
!core.hasFlag("floorimg_"+floorId+"_"+dx+"_"+dy) &&
core.isset(core.material.images.images[p])) {
var image = core.material.images.images[p];
if (t[3]==1)
tempCanvas.drawImage(image, 32*dx, 32*dy, image.width, image.height);

View File

@ -58,6 +58,10 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.waitHeroToStop(function() {
core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图
// 请注意:
// 成绩统计时是按照hp进行上传并排名因此光在这里改${status:hp}是无效的
// 如需按照其他的的分数统计方式请先将hp设置为你的得分
// core.setStatus('hp', ...);
core.drawText([
"\t[" + (reason||"恭喜通关") + "]你的分数是${status:hp}。"
], function () {

View File

@ -2,6 +2,7 @@
大地图的支持
突破了5M的存档空间大小限制
可以隐藏和显示楼层贴图
同点多事件的颜色块绘制
录像播放时可以按PgUp/PgDn浏览地图
录像播放时对于瞬间移动绘制箭头