楼层贴图图块化

This commit is contained in:
ckcz123 2020-05-21 10:58:20 +08:00
parent b2b60b133e
commit e6b4c78114
11 changed files with 126 additions and 59 deletions

View File

@ -412,6 +412,51 @@ var code = ' \n';
return code;
*/;
floorImage_m
: '楼层贴图' BGNL? Newline floorImageList+ BEND
/* floorImage_m
tooltip : 楼层贴图
helpUrl : https://h5mota.com/games/template/_docs/#/event
var code = '[\n'+floorImageList_0+']\n';
return code;
*/;
floorImageList
: floorOneImage
| floorEmptyImage;
floorOneImage
: '图片名' EvalString '翻转' Reverse_List '图层' Bg_Fg2_List '绘制坐标' 'x' Int 'y' Int '初始禁用' Bool BGNL? Newline
'裁剪起点坐标' 'x' IntString? 'y' IntString? '宽' IntString? '高' IntString? '帧数' IntString? BEND
/* floorOneImage
tooltip : 楼层贴图
default : ["bg.jpg","null","bg",0,0,false,"","","","",""]
helpUrl : https://h5mota.com/games/template/_docs/#/event
if (Reverse_List_0 && Reverse_List_0 != 'null') {
Reverse_List_0 = ', "reverse": "' + Reverse_List_0 + '"';
} else Reverse_List_0 = '';
Bool_0 = Bool_0 ? (', "disable": true') : '';
IntString_0 = IntString_0 && (', "sx": '+IntString_0);
IntString_1 = IntString_1 && (', "sy": '+IntString_1);
IntString_2 = IntString_2 && (', "w": '+IntString_2);
IntString_3 = IntString_3 && (', "h": '+IntString_3);
IntString_4 = IntString_4 && (', "frame": '+IntString_4);
return '{"name": "'+EvalString_0+'"'+Reverse_List_0+', "canvas": "'+Bg_Fg2_List_0+'", "x": '+Int_0+', "y": '+Int_1+Bool_0+IntString_0+IntString_1+IntString_2+IntString_3+IntString_4+'},\n';
*/;
floorEmptyImage
: Newline
/* floorEmptyImage
var code = ' \n';
return code;
*/;
//为了避免关键字冲突,全部加了_s
//动作
@ -2910,6 +2955,10 @@ Bg_Fg_List
: '背景层'|'前景层'
/*Bg_Fg_List ['bg','fg']*/;
Bg_Fg2_List
: '背景层'|'前景层'|'自适配'
/*Bg_Fg2_List ['bg','fg','auto']*/;
IgnoreChangeFloor_List
: '全局默认值' | '可穿透' | '不可穿透'
/*IgnoreChangeFloor_List ['null','true','false']*/;

View File

@ -74,6 +74,17 @@ ActionParser.prototype.parse = function (obj,type) {
}
return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage)]);
case 'floorImage':
if(!obj) obj=[];
var text_choices = null;
for(var ii=obj.length-1,choice;choice=obj[ii];ii--) {
text_choices=MotaActionBlocks['floorOneImage'].xmlText([
choice.name, choice.reverse, choice.canvas||'bg', choice.x||0, choice.y||0, choice.disable||false,
choice.sx, choice.sy, choice.w, choice.h, choice.frame, text_choices]);
}
return MotaActionBlocks['floorImage_m'].xmlText([text_choices]);
case 'shop':
var buildsub = function(obj,parser,next){
var text_choices = null;

View File

@ -78,6 +78,9 @@ editor_blockly = function () {
MotaActionFunctions.actionParser.parse({
"type": 0, "value": {"atk": 10}, "percentage": {"speed": 10},
}, 'equip'),
MotaActionFunctions.actionParser.parse([{
"name": "bg.jpg", "x": 0, "y": 0, "canvas": "bg"
}], 'floorImage'),
],
'显示文字':[
MotaActionBlocks['text_0_s'].xmlText(),

View File

@ -458,7 +458,8 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
},
"images": {
"_leaf": true,
"_type": "textarea",
"_type": "event",
"_event": "floorImage",
"_docs": "楼层贴图",
"_data": "背景/前景图;你可以选择若干张图片来作为背景/前景素材。详细用法请参见文档“自定义素材”中的说明。"
},

View File

@ -219,6 +219,7 @@
<option value="item">item</option>
<option value="levelChoose">levelChoose</option>
<option value="equip">equip</option>
<option value="floorImage">floorImage</option>
</select>
<button onclick="editor_blockly.confirm()">确认</button>
<button id='blocklyParse' onclick="editor_blockly.parse()">解析</button>

View File

@ -215,6 +215,7 @@
<option value="item">item</option>
<option value="levelChoose">levelChoose</option>
<option value="equip">equip</option>
<option value="floorImage">floorImage</option>
</select>
<button onclick="editor_blockly.confirm()">确认</button>
<button id='blocklyParse' onclick="editor_blockly.parse()">解析</button>

View File

@ -928,6 +928,8 @@ events.prototype.doAction = function (keepUI) {
}
events.prototype._doAction_finishEvents = function () {
if (core.status.gameOver) return true;
// 事件处理完毕
if (core.status.event.data.list.length == 0) {
// 检测并执行延迟自动事件

View File

@ -22,6 +22,17 @@ maps.prototype._setFloorSize = function (floorId) {
core.floors[floorId].height = core.floors[floorId].height || core.__SIZE__;
}
maps.prototype._resetFloorImages = function () {
for (var floorId in core.status.maps) {
(core.status.maps[floorId].images || []).forEach(function (one) {
var flag = "__floorImg__" + floorId + "_" + one.x + "_" + one.y;
if (core.getFlag(flag) == null) {
if (one.disabled) core.setFlag(flag, true);
}
})
}
}
// ------ 加载地图与地图的存档读档(压缩与解压缩) ------ //
////// 加载某个楼层(从剧本或存档中) //////
@ -896,39 +907,25 @@ maps.prototype._drawFloorImages = function (floorId, ctx, name, images, currStat
floorId = floorId || core.status.floorId;
if (!images) images = this._getFloorImages(floorId);
var redraw = currStatus != null;
images.forEach(function (t) {
if (typeof t == 'string') t = [0, 0, t];
var dx = parseInt(t[0]), dy = parseInt(t[1]), imageName = t[2], frame = core.clamp(parseInt(t[4]), 1, 8);
if (imageName.endsWith(':x') || imageName.endsWith(':y') || imageName.endsWith(':o')) {
imageName = imageName.substring(0, imageName.length - 2);
}
imageName = core.getMappedName(imageName);
var image = core.material.images.images[imageName];
images.forEach(function (one) {
var image = core.material.images.images[core.getMappedName(one.name)];
var frame = one.frame || 1;
if (!image) return;
var flag = "__floorImg__" + floorId + "_" + one.x + "_" + one.y;
if (core.hasFlag(flag)) return;
if (redraw && frame == 1) return; // 不重绘
if (core.isset(dx) && core.isset(dy) && image &&
!core.hasFlag("__floorImg__" + floorId + "_" + dx + "_" + dy)) {
var width = parseInt(image.width / frame), offsetX = (currStatus || 0) % frame * width;
if (/.*\.gif/i.test(imageName) && main.mode == 'play') {
if (redraw) return; // 忽略gif
this._drawFloorImages_gif(image, dx, dy);
return;
}
core.maps._drawFloorImage(ctx, name, t[3], t[2], image, offsetX, width, dx, dy, redraw);
if (/.*\.gif/i.test(one.name)) {
if (redraw) return;
this._drawFloorImages_gif(image, one.x, one.y);
return;
}
});
this._drawFloorImage(ctx, name, one, image, currStatus);
}, this);
}
maps.prototype._getFloorImages = function (floorId) {
floorId = floorId || core.status.floorId;
var images = [];
if ((core.status.maps || core.floors)[floorId].images) {
images = (core.status.maps || core.floors)[floorId].images;
if (typeof images == 'string') {
images = [[0, 0, images]];
}
}
return images;
return ((core.status.maps || core.floors)[floorId || core.status.floorId] || {}).images || [];
}
maps.prototype._drawFloorImages_gif = function (image, dx, dy) {
@ -944,30 +941,26 @@ maps.prototype._drawFloorImages_gif = function (image, dx, dy) {
return;
}
maps.prototype._drawFloorImage = function (ctx, name, type, imageName, image, offsetX, width, dx, dy, redraw) {
maps.prototype._drawFloorImage = function (ctx, name, one, image, currStatus) {
var height = image.height;
var _draw = function () {
if (redraw) core.clearMap(ctx, dx, dy, width, height);
core.drawImage(ctx, imageName, offsetX, 0, width, height, dx, dy, width, height);
}
if (!type) {
if (name != 'bg') return;
return _draw();
}
if (type == 1) {
if (name != 'fg') return;
return _draw();
}
if (type == 2) {
var imageName = one.name + (one.reverse||'');
var width = parseInt((one.w == null ? image.width : one.w) / (one.frame || 1));
var height = one.h == null ? image.height : one.h;
var sx = (one.sx || 0) + (currStatus || 0) % (one.frame || 1) * width;
var sy = one.sy || 0;
if (one.canvas != 'auto' && one.canvas != name) return;
if (one.canvas != 'auto') {
if (currStatus != null) core.clearMap(ctx, one.x, one.y, width, height);
core.drawImage(ctx, imageName, sx, sy, width, height, one.x, one.y, width, height);
} else {
if (name == 'bg') {
if (redraw) core.clearMap(ctx, dx, dy + height - 32, width, 32);
core.drawImage('bg', imageName, offsetX, height - 32, width, 32, dx, dy + height - 32, width, 32);
if (currStatus != null) core.clearMap(ctx, one.x, one.y + height - 32, width, 32);
core.drawImage(ctx, imageName, sx, sy + height - 32, width, 32, one.x, one.y+height - 32, width, 32);
} else if (name == 'fg') {
if (currStatus != null) core.clearMap(ctx, one.x, one.y, width, height - 32);
core.drawImage(ctx, imageName, sx, sy, width, height - 32, one.x, one.y, width, height - 32);
}
else if (name == 'fg') {
if (redraw) core.clearMap(ctx, dx, dy, width, height - 32);
core.drawImage('fg', imageName, offsetX, 0, width, height - 32, dx, dy, width, height - 32);
}
return;
}
}

View File

@ -7,12 +7,14 @@ main.floors.sample1=
"canUseQuickShop": true,
"defaultGround": "grass",
"images": [
[
0,
0,
"bg.jpg",
0
]
{
"name": "bg.jpg",
"canvas": "bg",
"x": 0,
"y": 0,
"w": 416,
"h": 416
}
],
"weather": [
"snow",
@ -263,13 +265,13 @@ main.floors.sample1=
}
],
"10,4": [
"\t[blackKing]你终于还是来了。",
"\t[blackMS]你终于还是来了。",
"\t[hero]放开我们的公主!",
"\t[blackKing]如果我不愿意呢?",
"\t[blackMS]如果我不愿意呢?",
"\t[hero]无需多说,拔剑吧!",
{
"type": "battle",
"id": "blackKing"
"id": "blackMS"
},
{
"type": "hide",
@ -285,7 +287,7 @@ main.floors.sample1=
7
]
},
"\t[blackKing]没想到你已经变得这么强大了... 算你厉害。\n公主就交给你了请好好对她。",
"\t[blackMS]没想到你已经变得这么强大了... 算你厉害。\n公主就交给你了请好好对她。",
{
"type": "hide"
}

View File

@ -26,6 +26,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 初始化地图
core.status.floorId = floorId;
core.status.maps = maps;
core.maps._resetFloorImages();
// 初始化怪物和道具
core.material.enemys = core.enemys.getEnemys();
core.material.items = core.items.getItems();

View File

@ -64,6 +64,9 @@
右键图块选择复制/粘贴事件
(已完成!) showImage, drawImage立绘等加上对称选项
更多的图块blockly化
勇士帧抖动
怪物名和特殊属性自动缩小
-------------