Merge pull request #207 from ckcz123/v2.0

V2.0
This commit is contained in:
Zhang Chen 2018-09-06 15:16:50 +08:00 committed by GitHub
commit 493018b748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 207 additions and 50 deletions

View File

@ -235,6 +235,7 @@ action
| break_s
| continue_s
| input_s
| input2_s
| choices_s
| function_s
| pass_s
@ -1057,18 +1058,31 @@ return code;
*/;
input_s
: '接受用户输入,提示' ':' EvalString Newline
: '接受用户输入数字,提示' ':' EvalString Newline
/* input_s
tooltip : input接受用户输入, 事件只能接受非负整数输入, 所有非法的输入将全部变成0
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%EF%BC%9A%E6%8E%A5%E5%8F%97%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5
tooltip : input接受用户输入数字, 事件只能接受非负整数输入, 所有非法的输入将全部变成0
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%95%b0%e5%ad%97
default : ["请输入一个数"]
colour : this.dataColor
var code = '{"type": "input", "text": "'+EvalString_0+'"},\n';
return code;
*/;
input2_s
: '接受用户输入文本,提示' ':' EvalString Newline
/* input2_s
tooltip : input2接受用户输入文本, 允许用户输入任何形式的文本
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input2%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%96%87%e6%9c%ac
default : ["请输入文本"]
colour : this.dataColor
var code = '{"type": "input2", "text": "'+EvalString_0+'"},\n';
return code;
*/;
if_s
: '如果' ':' expression BGNL? Newline action+ '否则' ':' BGNL? Newline action+ BEND Newline
@ -1773,6 +1787,10 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['input_s'].xmlText([
data.text,this.next]);
break;
case "input2":
this.next = MotaActionBlocks['input2_s'].xmlText([
data.text,this.next]);
break;
case "if": // 条件判断
this.next = MotaActionBlocks['if_s'].xmlText([
MotaActionBlocks['evalString_e'].xmlText([data.condition]),

View File

@ -589,6 +589,12 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_type": "checkbox",
"_bool": "bool",
"_data": "是否允许瞬间移动"
},
"clickMoveDirectly": {
"_leaf": true,
"_type": "checkbox",
"_bool": "bool",
"_data": "是否默认开启单击瞬移,用户可在菜单栏手动开关"
}
}
}

View File

@ -333,6 +333,10 @@ editor.prototype.changeFloor = function (floorId, callback) {
})
});
core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () {
core.bigmap.offsetX=0;
core.bigmap.offsetY=0;
editor.moveViewport(0,0);
editor.drawMapBg();
var mapArray = core.maps.save(core.status.maps, core.status.floorId);
editor.map = mapArray.map(function (v) {

View File

@ -88,6 +88,7 @@ editor_blockly = function () {
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['input_s'].xmlText(),
MotaActionBlocks['input2_s'].xmlText(),
MotaActionBlocks['update_s'].xmlText(),
MotaActionBlocks['updateEnemys_s'].xmlText(),
MotaActionBlocks['moveHero_s'].xmlText(),

View File

@ -441,10 +441,7 @@ editor_mode = function (editor) {
selectFloor.onchange = function () {
editor_mode.onmode('nextChange');
editor_mode.onmode('floor');
core.bigmap.offsetX=0;
core.bigmap.offsetY=0;
editor.changeFloor(selectFloor.value);
editor.moveViewport(0,0);
}
});

View File

@ -995,13 +995,13 @@ value为音量大小在0到100之间默认为100。设置后BGM和SE都
该事件会显示失败页面,并重新开始游戏。
### input接受用户输入
### input接受用户输入数字
使用`{"type": "input"}`可以接受用户的输入。
使用`{"type": "input"}`可以接受用户的输入的数字
``` js
"x,y": [ // 实际执行的事件列表
{"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入内容
{"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入数字
"你刚刚输入的数是${flag:input}" // 输入结果将被赋值为flag:input
]
```
@ -1014,6 +1014,25 @@ text为提示文字可以在这里给输入提示文字。这里同样可以
输入得到的结果将被赋值给flag:input可以供后续if来进行判断。
### input2接受用户输入文本
类似于input事件使用`{"type": "input2"}`可以接受用户的输入的文本。
``` js
"x,y": [ // 实际执行的事件列表
{"type": "input2", "text": "请输入你的ID"}, // 显示一个弹窗让用户输入文本
"你好,${flag:input},欢迎来到本塔" // 输入结果将被赋值为flag:input
]
```
text为提示文字可以在这里给输入提示文字。这里同样可以使用${ }来计算表达式的值。
当执行input2事件时将显示一个弹窗并提示用户输入一个内容。
该事件可以接收任何形式的文本输入,包括中文,空格,标点符号等等。如果用户点击取消按钮,则视为空字符串。
输入得到的结果也将被赋值给flag:input可以供后续使用。
### if条件判断
使用`{"type": "if"}`可以对条件进行判断,根据判断结果将会选择不同的分支执行。
@ -1585,9 +1604,9 @@ core.insertAction([
当角色走上冰面时将触发ski事件并会一直向前滑行直到撞上不可通行的块会触发事件比如撞上怪物会触发battle撞上门会触发openDoor等等或者离开冰面为止。
!> 由于H5魔塔只有事件一层因此滑冰的冰面上将无法摆放任何东西如道具
!> 由于H5魔塔只有事件一层因此滑冰的冰面上将无法摆放任何东西怪物,门或道具;不过可以在战后/开门后/道具后的事件写转变图块成167从而继续滑冰
!> 撞上怪物将触发battle进行战斗此战斗的触发和直接撞上怪物相同(战斗前自动存档,打不过则无法战斗);如需不自动存档的强制战斗请使用自定义事件覆盖。开门同理
!> 撞上怪物将触发battle进行战斗该战斗是强制战斗,打不过将直接死亡
关于推箱子存在三种状态168箱子169和已经推到花的箱子170

View File

@ -1591,17 +1591,22 @@ actions.prototype.clickSwitchs = function (x,y) {
core.ui.drawSwitchs();
break;
case 6:
core.status.automaticRoute.clickMoveDirectly=!core.status.automaticRoute.clickMoveDirectly;
core.setLocalStorage('clickMoveDirectly', core.status.automaticRoute.clickMoveDirectly);
core.flags.clickMoveDirectly=!core.flags.clickMoveDirectly;
core.setLocalStorage('clickMoveDirectly', core.flags.clickMoveDirectly);
core.ui.drawSwitchs();
break;
case 7:
window.open(core.platform.isPC?"editor.html":"editor-mobile.html", "_blank");
core.platform.useLocalForage=!core.platform.useLocalForage;
core.setLocalStorage('useLocalForage', core.platform.useLocalForage);
core.ui.drawSwitchs();
break;
case 8:
window.open(core.firstData.name+".zip", "_blank");
window.open(core.platform.isPC?"editor.html":"editor-mobile.html", "_blank");
break;
case 9:
window.open(core.firstData.name+".zip", "_blank");
break;
case 10:
core.status.event.selection=0;
core.ui.drawSettings();
break;
@ -2020,9 +2025,15 @@ actions.prototype.clickStorageRemove = function (x, y) {
var selection = y - topIndex;
switch (selection) {
case 0:
localforage.clear(function () {
if (core.platform.useLocalForage) {
localforage.clear(function () {
core.drawText("\t[操作成功]你的所有存档已被清空。");
});
}
else {
localStorage.clear();
core.drawText("\t[操作成功]你的所有存档已被清空。");
});
}
break;
case 1:
for (var i=1;i<=5*(main.savePages||30);i++) {

View File

@ -295,8 +295,6 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value
// 保存的Index
core.status.saveIndex = core.getLocalStorage('saveIndex2', 1);
core.status.automaticRoute.clickMoveDirectly = core.getLocalStorage('clickMoveDirectly', true);
if (core.isset(values))
core.values = core.clone(values);
else core.values = core.clone(core.data.values);
@ -457,7 +455,7 @@ control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
if (core.timeout.turnHeroTimeout!=null) return;
// 单击瞬间移动
if (core.status.automaticRoute.clickMoveDirectly && core.status.heroStop) {
if (core.flags.clickMoveDirectly && core.status.heroStop) {
if (core.control.tryMoveDirectly(destX, destY))
return;
}
@ -754,7 +752,14 @@ control.prototype.moveAction = function (callback) {
}
////// 转向 //////
control.prototype.turnHero = function() {
control.prototype.turnHero = function(direction) {
if (core.isset(direction)) {
core.setHeroLoc('direction', direction);
core.drawHero();
core.clearMap('route');
core.status.route.push("turn:"+direction);
return;
}
if (core.status.hero.loc.direction == 'up') core.status.hero.loc.direction = 'right';
else if (core.status.hero.loc.direction == 'right') core.status.hero.loc.direction = 'down';
else if (core.status.hero.loc.direction == 'down') core.status.hero.loc.direction = 'left';
@ -2010,6 +2015,11 @@ control.prototype.replay = function () {
core.replay();
return;
}
else if (action.indexOf("turn:")==0) {
core.turnHero(action.substring(5));
core.replay();
return;
}
else if (action=='getNext') {
if (core.flags.enableGentleClick && core.getBlock(core.nextX(), core.nextY())!=null) {
var nextX = core.nextX(), nextY = core.nextY();
@ -2182,7 +2192,10 @@ control.prototype.autosave = function (removeLast) {
var x=null;
if (removeLast)
x=core.status.route.pop();
// 加入当前方向
core.status.route.push("turn:"+core.getHeroLoc('direction'));
core.setLocalForage("autoSave", core.saveData())
core.status.route.pop();
if (removeLast && core.isset(x))
core.status.route.push(x);
}

View File

@ -60,6 +60,7 @@ function core() {
'isQQ': false, // 是否是QQ
'isChrome': false, // 是否是Chrome
'supportCopy': false, // 是否支持复制到剪切板
'useLocalForage': true,
'fileInput': null, // FileInput
'fileReader': null, // 是否支持FileReader
@ -112,7 +113,6 @@ function core() {
'cursorX': null,
'cursorY': null,
"moveDirectly": false,
'clickMoveDirectly': true,
},
// 按下键的时间:为了判定双击
@ -230,6 +230,27 @@ core.prototype.init = function (coreData, callback) {
core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent);
core.platform.isQQ = /QQ/i.test(navigator.userAgent);
core.platform.isWeChat = /MicroMessenger/i.test(navigator.userAgent);
core.platform.useLocalForage = core.getLocalStorage('useLocalForage', true);
if (core.platform.useLocalForage) {
try {
core.setLocalForage("__test__", "__test__", function() {
try {
core.getLocalForage("__test__", null, function(data) {
if (data!="__test__") {
console.log("localForage unsupported!");
core.platform.useLocalForage=false;
}
else {
console.log("localForage supported!")
core.removeLocalForage("__test__");
}
}, function(e) {console.log(e); core.platform.useLocalForage=false;})
}
catch (e) {console.log(e); core.platform.useLocalForage=false;}
}, function(e) {console.log(e); core.platform.useLocalForage=false;})
}
catch (e) {console.log(e); core.platform.useLocalForage=false;}
}
if (window.FileReader) {
core.platform.fileReader = new FileReader();
@ -266,12 +287,13 @@ core.prototype.init = function (coreData, callback) {
core.flags.displayEnemyDamage = core.getLocalStorage('enemyDamage', core.flags.displayEnemyDamage);
core.flags.displayCritical = core.getLocalStorage('critical', core.flags.displayCritical);
core.flags.displayExtraDamage = core.getLocalStorage('extraDamage', core.flags.displayExtraDamage);
core.flags.clickMoveDirectly = core.getLocalStorage('clickMoveDirectly',
!(core.isset(core.flags.clickMoveDirectly) && !core.flags.clickMoveDirectly));
core.material.ground = new Image();
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);
@ -452,8 +474,8 @@ core.prototype.moveAction = function (callback) {
}
////// 转向 //////
core.prototype.turnHero = function() {
core.control.turnHero();
core.prototype.turnHero = function(direction) {
core.control.turnHero(direction);
}
////// 勇士能否前往某方向 //////

View File

@ -750,6 +750,32 @@ events.prototype.doAction = function() {
this.doAction();
}
break;
case "input2":
{
var value;
if (core.status.replay.replaying) {
var action = core.status.replay.toReplay.shift();
try {
if (action.indexOf("input2:")!=0) throw new Error("Input2 Error. Current action: "+action);
value = core.decodeBase64(action.substring(7));
}
catch (e) {
console.log(e);
core.stopReplay();
core.drawTip("录像文件出错");
return;
}
}
else {
core.interval.onDownInterval = 'tmp';
value = prompt(core.replaceText(data.text));
if (!core.isset(value)) value="";
}
core.status.route.push("input2:"+core.encodeBase64(value));
core.setFlag("input", value);
this.doAction();
}
break;
case "if": // 条件判断
if (core.calValue(data.condition))
core.events.insertAction(data["true"])
@ -1013,7 +1039,7 @@ events.prototype.battle = function (id, x, y, force, callback) {
core.stopAutomaticRoute();
// 非强制战斗
if (!core.enemys.canBattle(id) && !force) {
if (!core.enemys.canBattle(id) && !force && !core.isset(core.status.event.id)) {
core.drawTip("你打不过此怪物!");
core.clearContinueAutomaticRoute();
return;

View File

@ -214,6 +214,9 @@ maps.prototype.load = function (data, floorId) {
////// 将当前地图重新变成二维数组形式 //////
maps.prototype.getMapArray = function (blockArray,width,height){
width=width||13;
height=height||13;
var blocks = [];
for (var x=0;x<height;x++) {
blocks[x]=[];
@ -222,7 +225,7 @@ maps.prototype.getMapArray = function (blockArray,width,height){
}
}
blockArray.forEach(function (block) {
if (!block.disable)
if (!block.disable && block.x<width && block.y<height)
blocks[block.y][block.x] = block.id;
});
return blocks;

View File

@ -793,13 +793,14 @@ ui.prototype.drawSwitchs = function() {
core.status.event.id = 'switchs';
var choices = [
"背景音乐:"+(core.musicStatus.bgmStatus ? "[ON]" : "[OFF]"),
"背景音效:"+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"),
"背景音乐: "+(core.musicStatus.bgmStatus ? "[ON]" : "[OFF]"),
"背景音效: "+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"),
"战斗动画: "+(core.flags.battleAnimate ? "[ON]" : "[OFF]"),
"怪物显伤: "+(core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"),
"临界显伤: "+(core.flags.displayCritical ? "[ON]" : "[OFF]"),
"领域显伤: "+(core.flags.displayExtraDamage ? "[ON]" : "[OFF]"),
"单击瞬移: "+(core.status.automaticRoute.clickMoveDirectly ? "[ON]" : "[OFF]"),
"单击瞬移: "+(core.flags.clickMoveDirectly ? "[ON]" : "[OFF]"),
"新版存档: "+(core.platform.useLocalForage ? "[ON]":"[OFF]"),
"查看工程",
"下载离线版本",
"返回主菜单"
@ -1782,24 +1783,26 @@ ui.prototype.drawSLPanel = function(index, refresh) {
}
};
var drawSave = function (i) {
function loadSave(i, callback) {
if (i==6) {
callback();
return;
}
core.getLocalForage(i==0?"autoSave":"save"+(5*page+i), null, function(data) {
draw(data, i);
}, function(err) {
console.log(err);
})
core.status.event.ui[i]=data;
loadSave(i+1, callback);
}, function(err) {console.log(err);});
}
if (page == last_page && !refresh) {
for (var i=0;i<6;i++) {
draw(core.status.event.ui[i]||null, i);
}
function drawAll() {
for (var i=0;i<6;i++)
draw(core.status.event.ui[i], i);
}
else {
for (var i=0;i<6;i++) {
drawSave(i);
}
if (refresh || page!=last_page) {
core.status.event.ui = [];
loadSave(0, drawAll);
}
else drawAll();
this.drawPagination(page+1, max_page);

View File

@ -125,6 +125,13 @@ utils.prototype.removeLocalStorage = function (key) {
}
utils.prototype.setLocalForage = function (key, value, successCallback, errorCallback) {
if (!core.platform.useLocalForage) {
this.setLocalStorage(key, value);
if (core.isset(successCallback)) successCallback();
return;
}
// Save to localforage
var compressed = LZString.compress(JSON.stringify(value));
localforage.setItem(core.firstData.name+"_"+key, compressed, function (err) {
@ -136,6 +143,15 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal
}
utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) {
if (!core.platform.useLocalForage) {
var value=this.getLocalStorage(key, defaultValue);
if (core.isset(successCallback)) {
successCallback(value);
}
return;
}
localforage.getItem(core.firstData.name+"_"+key, function (err, value) {
if (core.isset(err)) {
if (core.isset(errorCallback)) errorCallback(err);
@ -162,6 +178,13 @@ utils.prototype.getLocalForage = function (key, defaultValue, successCallback, e
}
utils.prototype.removeLocalForage = function (key, successCallback, errorCallback) {
if (!core.platform.useLocalForage) {
this.removeLocalStorage(key);
if (core.isset(successCallback)) successCallback();
return;
}
localforage.removeItem(core.firstData.name+"_"+key, function (err) {
if (core.isset(err)) {
if (core.isset(errorCallback)) errorCallback(err);
@ -309,10 +332,14 @@ utils.prototype.encodeRoute = function (route) {
ans+="S"+t.substring(5);
else if (t=='turn')
ans+='T';
else if (t.indexOf('turn:')==0)
ans+="t"+t.substring(5).substring(0,1).toUpperCase()+":";
else if (t=='getNext')
ans+='G';
else if (t.indexOf('input:')==0)
ans+="P"+t.substring(6);
else if (t.indexOf('input2:')==0)
ans+="Q"+t.substring(7)+":";
else if (t=='no')
ans+='N';
else if (t.indexOf('move:')==0)
@ -347,7 +374,7 @@ utils.prototype.decodeRoute = function (route) {
}
var getString = function () {
var str="";
while (index<route.length && /\w/.test(route.charAt(index))) {
while (index<route.length && route.charAt(index)!=':') {
str+=route.charAt(index++);
}
index++;
@ -356,20 +383,26 @@ utils.prototype.decodeRoute = function (route) {
while (index<route.length) {
var c=route.charAt(index++);
var nxt=(c=='I'||c=='F'||c=='S')?getString():getNumber();
var nxt=(c=='I'||c=='F'||c=='S'||c=='Q'||c=='t')?getString():getNumber();
var mp = {
"U": "up",
"D": "down",
"L": "left",
"R": "right"
}
switch (c) {
case "U": for (var i=0;i<nxt;i++) ans.push("up"); break;
case "D": for (var i=0;i<nxt;i++) ans.push("down"); break;
case "L": for (var i=0;i<nxt;i++) ans.push("left"); break;
case "R": for (var i=0;i<nxt;i++) ans.push("right"); break;
case "U": case "D": case "L": case "R": for (var i=0;i<nxt;i++) ans.push(mp[c]); break;
case "I": ans.push("item:"+nxt); break;
case "F": ans.push("fly:"+nxt); break;
case "C": ans.push("choices:"+nxt); break;
case "S": ans.push("shop:"+nxt+":"+getNumber(true)); break;
case "T": ans.push("turn"); break;
case "t": ans.push("turn:"+mp[nxt]); break;
case "G": ans.push("getNext"); break;
case "P": ans.push("input:"+nxt); break;
case "Q": ans.push("input2:"+nxt); break;
case "N": ans.push("no"); break;
case "M": ++index; ans.push("move:"+nxt+":"+getNumber()); break;
case "K": ans.push("key:"+nxt); break;
@ -693,7 +726,7 @@ utils.prototype._export = function (floorIds) {
// map
var content = floorIds.length+"\n13 13\n\n";
floorIds.forEach(function (floorId) {
var arr = core.maps.getMapArray(core.status.maps[floorId].blocks);
var arr = core.maps.getMapArray(core.status.maps[floorId].blocks, 13, 13);
content += arr.map(function (x) {
// check monster
x.forEach(function (t) {

View File

@ -168,5 +168,6 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"portalWithoutTrigger": true,
"canGoDeadZone": false,
"enableMoveDirectly": true,
"clickMoveDirectly": true,
}
}