commonEventShop

This commit is contained in:
oc 2019-03-31 00:22:26 +08:00
parent 31facb29e4
commit 8aca0760c0
8 changed files with 77 additions and 118 deletions

View File

@ -85,13 +85,25 @@ shopcommonevent
tooltip : 全局商店, 执行一个公共事件
helpUrl : https://h5mota.com/games/template/docs/#/
default : ["shop1","回收钥匙商店",false,"回收钥匙商店",""]
if (EvalString_2) {
if (EvalString_2.indexOf('"')>=0)
throw new Error('请勿在此处使用双引号!尝试使用单引号吧~');
// 检查是不是数组
try {
EvalString_2 = JSON.parse(EvalString_2.replace(/'/g, '"'));
if (!(EvalString_2 instanceof Array)) throw new Error();
}
catch (e) {
throw new Error('参数列表必须是个有效的数组!');
}
}
var code = {
'id': IdString_0,
'textInList': EvalString_0,
'mustEnable': Bool_0,
'commonEvent': EvalString_1,
'args': EvalString_2
'commonEvent': EvalString_1
}
if (EvalString_2) code.args = EvalString_2;
code=JSON.stringify(code,null,2)+',\n';
return code;
*/;
@ -322,7 +334,7 @@ action
| callBook_s
| callSave_s
| callLoad_s
| unknow_s
| unknown_s
| function_s
| pass_s
;
@ -1746,17 +1758,19 @@ var code = '{"type": "callLoad"},\n';
return code;
*/;
unknow_s
unknown_s
: '自定义事件' BGNL? RawEvalString
/* unknow_s
/* unknown_s
tooltip : 通过脚本自定义的事件类型, 以及编辑器不识别的事件类型
helpUrl : https://h5mota.com/games/template/docs/#/
default : ['{"type":"eventType1"}']
default : ['{"type":"test", "data": "这是自定义的参数"}']
colour : this.dataColor
var tempobj={};
eval("tempobj='"+RawEvalString_0+"'");
var code = tempobj +',\n';
try {
var tempobj = JSON.parse(RawEvalString_0);
} catch (e) {throw new Error("不合法的JSON格式");}
if (!tempobj.type) throw new Error("自定义事件需要一个type:xxx");
var code = JSON.stringify(tempobj) +',\n';
return code;
*/;
@ -2148,8 +2162,13 @@ ActionParser.prototype.parse = function (obj,type) {
]);
}
var buildcommentevent = function(obj,parser,next){
if (obj.args instanceof Array) {
try { obj.args = JSON.stringify(obj.args).replace(/"/g, "'"); }
catch (e) {obj.args = '';}
}
else obj.args = null;
return MotaActionBlocks['shopcommonevent'].xmlText([
obj.id,parser.EvalString(obj.textInList),obj.mustEnable,parser.EvalString(obj.commonEvent),parser.EvalString(obj.args),next
obj.id,parser.EvalString(obj.textInList),obj.mustEnable,parser.EvalString(obj.commonEvent),obj.args,next
]);
}
var next=null;
@ -2651,13 +2670,8 @@ ActionParser.prototype.parseAction = function() {
case "animateImage": // 兼容 animateImage
break;
default:
var rawdata = JSON.stringify(data,function(k,v){
if(typeof(v)=='string')return v.split('\n').join('\\n');
else return v;
},2);
rawdata=rawdata.split('\n').join('\\n');
this.next = MotaActionBlocks['unknow_s'].xmlText([
rawdata,this.next]);
this.next = MotaActionBlocks['unknown_s'].xmlText([
JSON.stringify(data),this.next]);
}
this.parseAction();
return;

View File

@ -159,6 +159,7 @@ editor_blockly = function () {
],
'原生脚本':[
MotaActionBlocks['function_s'].xmlText(),
MotaActionBlocks['unknown_s'].xmlText(),
],
'值块':[
MotaActionBlocks['setValue_s'].xmlText([

View File

@ -1198,35 +1198,21 @@ actions.prototype._keyUpShop = function (keycode) {
////// 快捷商店界面时的点击操作 //////
actions.prototype._clickQuickShop = function (x, y) {
var keys = [];
if (core.flags.quickCommonEvents) {
keys = core.getFlag("__commonEventList__", []);
}
else {
keys = Object.keys(core.status.shops).filter(function (shopId) {
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
});
}
var keys = Object.keys(core.status.shops).filter(function (shopId) {
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
});
if (x >= this.CHOICES_LEFT && x <= this.CHOICES_RIGHT) {
var topIndex = this.HSIZE - parseInt(keys.length / 2);
if (y >= topIndex && y < topIndex + keys.length) {
if (core.flags.quickCommonEvents) {
var name = keys[y - topIndex];
core.ui.closePanel();
core.status.route.push("common:" + core.encodeBase64(name));
core.insertAction(name);
}
else {
var reason = core.events.canUseQuickShop(keys[y - topIndex]);
if (!core.flags.enableDisabledShop && reason) {
core.drawText(reason);
return;
}
core.events.openShop(keys[y - topIndex], true);
if (core.status.event.id == 'shop')
core.status.event.data.fromList = true;
var reason = core.events.canUseQuickShop(keys[y - topIndex]);
if (!core.flags.enableDisabledShop && reason) {
core.drawText(reason);
return;
}
core.events.openShop(keys[y - topIndex], true);
if (core.status.event.id == 'shop')
core.status.event.data.fromList = true;
}
// 离开
else if (y == topIndex + keys.length)
@ -1240,17 +1226,10 @@ actions.prototype._keyUpQuickShop = function (keycode) {
core.ui.closePanel();
return;
}
var length = 0;
if (core.flags.quickCommonEvents) {
length = core.getFlag("__commonEventList__", []).length;
}
else {
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
return shopList[shopId].visited || !shopList[shopId].mustEnable
});
length = keys.length;
}
this._selectChoices(length + 1, keycode, this._clickQuickShop);
var keys = Object.keys(core.status.shops).filter(function (shopId) {
return core.status.shops[shopId].visited || !core.status.shops[shopId].mustEnable
});
this._selectChoices(keys.length + 1, keycode, this._clickQuickShop);
return;
}

View File

@ -33,7 +33,6 @@ control.prototype._init = function () {
this.registerReplayAction("fly", this._replayAction_fly);
this.registerReplayAction("shop", this._replayAction_shop);
this.registerReplayAction("turn", this._replayAction_turn);
this.registerReplayAction("common", this._replayAction_common);
this.registerReplayAction("getNext", this._replayAction_getNext);
this.registerReplayAction("moveDirectly", this._replayAction_moveDirectly);
this.registerReplayAction("key", this._replayAction_key);
@ -1412,6 +1411,12 @@ control.prototype._replayAction_shop = function (action) {
if (selections.length == 0) return false;
var shop=core.status.shops[shopId];
if (!shop || !shop.visited) return false;
// --- 判定commonEvent
if (shop.commonEvent) {
core.openShop(shopId, false);
setTimeout(core.replay);
return true;
}
var choices = shop.choices;
var topIndex = core.__HALF_SIZE__ - parseInt(choices.length / 2);
core.status.event.selection = parseInt(selections.shift());
@ -1443,16 +1448,6 @@ control.prototype._replayAction_turn = function (action) {
return true;
}
control.prototype._replayAction_common = function (action) {
if (action.indexOf("common:") != 0) return false;
var name = core.decodeBase64(action.substring(7));
if (core.getFlag("__commonEventList__").indexOf(name) == -1) return false;
core.status.route.push(action);
core.insertAction(name);
setTimeout(core.replay);
return true;
}
control.prototype._replayAction_getNext = function (action) {
if (action != "getNext") return false;
if (!core.getNextItem()) return false;

View File

@ -806,10 +806,7 @@ events.prototype.insertAction = function (action, x, y, callback, addToLast) {
// ------ 判定commonEvent
var commonEvent = this.getCommonEvent(action);
if (commonEvent instanceof Array) {
this._addCommentEventToList(action, commonEvent);
action = commonEvent;
}
if (commonEvent instanceof Array) action = commonEvent;
if (!action) return;
if (core.status.event.id != 'action') {
@ -830,22 +827,6 @@ events.prototype.getCommonEvent = function (name) {
return this.commonEvent[name] || null;
}
events.prototype._addCommentEventToList = function (name, list) {
if (list == null) list = this.getCommonEvent(name);
if (!list || !core.flags.quickCommonEvents) return;
var addToList = false;
for (var x in list) {
if (list[x].type == 'addToList') {
addToList = true;
break;
}
}
if (!addToList) return;
var obj = core.getFlag("__commonEventList__", []);
if (obj.indexOf(name) == -1) obj.push(name);
core.setFlag("__commonEventList__", obj);
}
////// 恢复一个事件 //////
events.prototype.recoverEvents = function (data) {
if (data) {
@ -1144,13 +1125,12 @@ events.prototype._action_useItem = function (data, x, y, prefix) {
}
events.prototype._action_openShop = function (data, x, y, prefix) {
if (core.isReplaying()) { // 正在播放录像简单将visited置为true
core.status.shops[data.id].visited = true;
this.setEvents([]);
core.doAction();
}
else
core.status.shops[data.id].visited = true;
this.setEvents([]);
if (!core.isReplaying())
this.openShop(data.id);
if (core.status.event.id == 'action')
core.doAction();
}
events.prototype._action_disableShop = function (data, x, y, prefix) {
@ -1207,10 +1187,6 @@ events.prototype._action_insert = function (data, x, y, prefix) {
core.doAction();
}
events.prototype._action_addToList = function (data, x, y, prefix) {
core.doAction();
}
events.prototype._action_playBgm = function (data, x, y, prefix) {
core.playBgm(data.name);
core.doAction();
@ -2109,9 +2085,9 @@ events.prototype.openShop = function (shopId, needVisited) {
shop.times = shop.times || 0;
if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0);
if (needVisited && !shop.visited) {
if (!core.flags.enableDisabledShop) {
if (shop.times == 0) core.drawTip("该商店尚未开启");
else core.drawTip("该商店已失效");
if (!core.flags.enableDisabledShop || shop.commonEvent) {
if (shop.times == 0) core.drawTip("该尚未开启");
else core.drawTip("该已失效");
return;
}
else {
@ -2119,6 +2095,13 @@ events.prototype.openShop = function (shopId, needVisited) {
}
}
else shop.visited = true;
// --- 商店
if (shop.commonEvent) {
core.status.route.push("shop:"+shopId+":0");
core.insertAction({"type": "insert", "name": shop.commonEvent, "args": shop.args});
return;
}
core.ui.drawShop(shopId);
}

View File

@ -1118,18 +1118,12 @@ ui.prototype.drawSettings = function () {
////// 绘制快捷商店选择栏 //////
ui.prototype.drawQuickShop = function () {
core.status.event.id = 'selectShop';
var choices;
if (core.flags.quickCommonEvents) {
choices = core.clone(core.getFlag("__commonEventList__", []));
}
else {
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
return shopList[shopId].visited || !shopList[shopId].mustEnable
});
choices = keys.map(function (shopId) {
return {"text": shopList[shopId].textInList, "color": shopList[shopId].visited?null:"#999999"};
});
}
var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {
return shopList[shopId].visited || !shopList[shopId].mustEnable
});
var choices = keys.map(function (shopId) {
return {"text": shopList[shopId].textInList, "color": shopList[shopId].visited?null:"#999999"};
});
choices.push("返回游戏");
this.drawChoices(null, choices);
}

View File

@ -467,8 +467,6 @@ utils.prototype._encodeRoute_encodeOne = function (t) {
return "P" + t.substring(6);
else if (t.indexOf('input2:') == 0)
return "Q" + t.substring(7) + ":";
else if (t.indexOf('common:') == 0)
return "c" + t.substring(7) + ":";
else if (t == 'no')
return 'N';
else if (t.indexOf('move:') == 0)
@ -527,7 +525,7 @@ utils.prototype._decodeRoute_number2id = function (number) {
}
utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't' || c == 'c') ?
var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ?
this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
@ -572,9 +570,6 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
case "Q":
decodeObj.ans.push("input2:" + nxt);
break;
case "c":
decodeObj.ans.push("common:" + nxt);
break;
case "N":
decodeObj.ans.push("no");
break;

View File

@ -303,10 +303,9 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
},
{
"id": "keyShop1",
"textInList": "1F回收钥匙商店",
"textInList": "回收钥匙商店",
"mustEnable": false,
"commonEvent": "回收钥匙商店",
"args": ""
"commonEvent": "回收钥匙商店"
}
],
"levelUp": [
@ -408,7 +407,6 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"enableMoveDirectly": true,
"enableDisabledShop": true,
"disableShopOnDamage": false,
"quickCommonEvents": false,
"checkConsole": false
}
}