From 595141e83fbe048add3cda6effd7042ea3c60fe2 Mon Sep 17 00:00:00 2001
From: oc
Date: Thu, 12 Apr 2018 23:49:25 +0800
Subject: [PATCH 01/16] equipment
---
project/functions.js | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/project/functions.js b/project/functions.js
index 4b1ab6f4..e7add5db 100644
--- a/project/functions.js
+++ b/project/functions.js
@@ -59,7 +59,7 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图
core.drawText([
- "\t[恭喜通关]你的分数是${status:hp}。"
+ "\t[" + (reason||"恭喜通关") + "]你的分数是${status:hp}。"
], function () {
core.events.gameOver(reason||'', replaying);
})
@@ -343,18 +343,52 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
this.useEquipment = function (itemId) { // 使用装备
if (itemId.indexOf("sword")==0) {
var now=core.getFlag('sword', 'sword0'); // 当前装备剑的ID
- core.status.hero.atk -= core.values[now];
+
+ if (typeof core.values[now] == 'number') {
+ core.status.hero.atk -= core.values[now];
+ }
+ else {
+ core.status.hero.atk -= core.values[now].atk || 0;
+ core.status.hero.def -= core.values[now].def || 0;
+ core.status.hero.mdef -= core.values[now].mdef || 0;
+ }
+
+ if (typeof core.values[itemId] == 'number') {
+ core.status.hero.atk += core.values[itemId];
+ }
+ else {
+ core.status.hero.atk -= core.values[itemId].atk || 0;
+ core.status.hero.def -= core.values[itemId].def || 0;
+ core.status.hero.mdef -= core.values[itemId].mdef || 0;
+ }
+
core.setItem(now, 1);
- core.status.hero.atk += core.values[itemId];
core.setItem(itemId, 0);
core.setFlag('sword', itemId);
core.drawTip("已装备"+core.material.items[itemId].name);
}
if (itemId.indexOf("shield")==0) {
var now=core.getFlag('shield', 'shield0');
- core.status.hero.def -= core.values[now];
+
+ if (typeof core.values[now] == 'number') {
+ core.status.hero.def -= core.values[now];
+ }
+ else {
+ core.status.hero.atk -= core.values[now].atk || 0;
+ core.status.hero.def -= core.values[now].def || 0;
+ core.status.hero.mdef -= core.values[now].mdef || 0;
+ }
+
+ if (typeof core.values[itemId] == 'number') {
+ core.status.hero.def += core.values[itemId];
+ }
+ else {
+ core.status.hero.atk -= core.values[itemId].atk || 0;
+ core.status.hero.def -= core.values[itemId].def || 0;
+ core.status.hero.mdef -= core.values[itemId].mdef || 0;
+ }
+
core.setItem(now, 1);
- core.status.hero.def += core.values[itemId];
core.setItem(itemId, 0);
core.setFlag('shield', itemId);
core.drawTip("已装备"+core.material.items[itemId].name);
From e38f131f53b35b2669720988da01ddc9008bec6b Mon Sep 17 00:00:00 2001
From: oc
Date: Tue, 17 Apr 2018 00:45:17 +0800
Subject: [PATCH 02/16] New empty map & autosave map
---
_server/blockly/MotaAction.g4 | 4 ++--
_server/editor_file.js | 15 +++++++++------
_server/editor_mode.js | 4 ++--
_server/vm.js | 8 +++++++-
editor.html | 2 +-
libs/control.js | 5 ++++-
更新说明.txt | 20 +++++++++++++++++++-
7 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4
index 027fe661..b71b4be9 100644
--- a/_server/blockly/MotaAction.g4
+++ b/_server/blockly/MotaAction.g4
@@ -553,7 +553,7 @@ return code;
*/
showImage_0_s
- : '显示图片' EvalString '起点像素位置' 'x' Int 'y' Int Newline
+ : '显示图片' EvalString '起点像素位置' 'x' Number 'y' Number Newline
;
/* showImage_0_s
@@ -561,7 +561,7 @@ tooltip : showImage:显示图片
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=showimage%ef%bc%9a%e6%98%be%e7%a4%ba%e5%9b%be%e7%89%87
default : ["bg.jpg",0,0]
colour : this.printColor
-var code = '{"type": "showImage", "name": "'+EvalString_0+'", "loc": ['+Int_0+','+Int_1+']},\n';
+var code = '{"type": "showImage", "name": "'+EvalString_0+'", "loc": ['+Number_0+','+Number_1+']},\n';
return code;
*/
diff --git a/_server/editor_file.js b/_server/editor_file.js
index 92982673..c7f3eb0d 100644
--- a/_server/editor_file.js
+++ b/_server/editor_file.js
@@ -69,7 +69,10 @@ editor_file = function(editor, callback){
} */
var filename = 'project/floors/' + editor.currentFloorId + '.js';
var datastr = ['main.floors.' , editor.currentFloorId , '=\n{'];
- editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
+ if (editor.currentFloorData.map == 'new')
+ editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(){return 0})});
+ else
+ editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
for(var ii in editor.currentFloorData)
if (editor.currentFloorData.hasOwnProperty(ii)) {
if (ii=='map')
@@ -84,16 +87,16 @@ editor_file = function(editor, callback){
});
}
//callback(err:String)
- editor_file.saveFloorFileAs = function(saveAsFilename,callback){
+ editor_file.saveNewFile = function(saveFilename,callback){
//saveAsFilename不含'/'不含'.js'
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')};
if (!isset(editor.currentFloorData)) {
callback('无数据');
}
- editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
- editor.currentFloorData=JSON.parse(JSON.stringify(editor.currentFloorData));
- editor.currentFloorData.floorId=saveAsFilename;
- editor.currentFloorId=saveAsFilename;
+ editor.currentFloorData={floorId: saveFilename, title: "新建楼层", name: "0", canFlyTo: true, canUseQuickShop: true, images: [], item_ratio: 1,
+ firstArrive: [], events: {}, changeFloor: {}, afterBattle: {}, afterGetItem: {}, afterOpenDoor: {}, cannotMove: {}};
+ editor.currentFloorData.map = "new";
+ editor.currentFloorId=saveFilename;
editor_file.saveFloorFile(callback);
}
//callback(err:String)
diff --git a/_server/editor_mode.js b/_server/editor_mode.js
index 7105d24f..c4996e34 100644
--- a/_server/editor_mode.js
+++ b/_server/editor_mode.js
@@ -363,10 +363,10 @@ editor_mode.prototype.listen = function(callback){
saveFloorAs.onclick = function(){
if (!saveAsName.value)return;
editor_mode.onmode('');
- editor.file.saveFloorFileAs(saveAsName.value,function(err){
+ editor.file.saveNewFile(saveAsName.value,function(err){
if(err){printe(err);throw(err)}
core.floorIds.push(saveAsName.value);
- editor.file.editTower([['change',"['main']['floorIds']",core.floorIds]],function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printe('另存为成功,请F5刷新编辑器生效');});
+ editor.file.editTower([['change',"['main']['floorIds']",core.floorIds]],function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printe('新建成功,请F5刷新编辑器生效');});
});
}
diff --git a/_server/vm.js b/_server/vm.js
index 0f2aaecd..6168489e 100644
--- a/_server/vm.js
+++ b/_server/vm.js
@@ -13,7 +13,13 @@ document.body.onmousedown = function(e){
});
//console.log(eid);
if(eid.indexOf('edit')===-1){
- if(eid.indexOf('tip')===-1)selectBox.isSelected = false;
+ if(eid.indexOf('tip')===-1) {
+ if (selectBox.isSelected) {
+ editor_mode.onmode('');
+ editor.file.saveFloorFile(function(err){if(err){printe(err);throw(err)};printf('地图保存成功');});
+ }
+ selectBox.isSelected = false;
+ }
}
//editor.mode.onmode('');
editor.info = {};
diff --git a/editor.html b/editor.html
index cf24e470..327ae7a0 100644
--- a/editor.html
+++ b/editor.html
@@ -20,7 +20,7 @@
-
+
diff --git a/libs/control.js b/libs/control.js
index 0bae3a0d..47c960a0 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -2075,8 +2075,11 @@ control.prototype.updateStatusBar = function () {
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
statusList.forEach(function (item) {
- core.statusBar[item].innerHTML = core.getStatus(item);
+ var val = core.getStatus(item);
+ if (val>=10000000) val = parseInt(val/10000) + "W";
+ core.statusBar[item].innerHTML = val;
});
+
// 进阶
if (core.flags.enableLevelUp && core.status.hero.lv
Date: Tue, 17 Apr 2018 17:04:26 +0800
Subject: [PATCH 03/16] Remove 999999999 for damage
---
.idea/codeStyles/Project.xml | 7 ++++
.idea/codeStyles/codeStyleConfig.xml | 5 +++
docs/element.md | 16 +++++++--
docs/personalization.md | 2 +-
libs/control.js | 51 +++++++++++++++++++---------
libs/enemys.js | 29 ++++++++++------
libs/events.js | 3 +-
libs/ui.js | 25 ++++++++++----
project/data.comment.js | 6 ++++
project/data.js | 9 ++---
project/functions.js | 5 ++-
更新说明.txt | 4 ++-
12 files changed, 118 insertions(+), 44 deletions(-)
create mode 100644 .idea/codeStyles/Project.xml
create mode 100644 .idea/codeStyles/codeStyleConfig.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 00000000..79a710fd
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 00000000..a55e7a17
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/element.md b/docs/element.md
index 299c00a6..0b1f5827 100644
--- a/docs/element.md
+++ b/docs/element.md
@@ -14,14 +14,26 @@
大多数宝物都有默认的效果,屠龙匕首暂未定义,如有自己的需求可参见[自定义道具效果](personalization#自定义道具效果)。
-如需让剑盾变成装备,可以直接在`data.js`中设置`'equipment': true`即可。
-
拿到道具后将触发`afterGetItem`事件,有关事件的详细介绍请参见[事件](event)。
如需修改某个道具的效果,在不同区域宝石数据发生变化等问题,请参见[自定义道具效果](personalization#自定义道具效果)的说明。
**有关轻按,在data.js的系统变量中有定义。如果`enableGentleClick`为true,则鼠标(触摸屏)通过双击勇士,键盘通过空格可达到轻按效果,即不向前移动而获得前方物品。**
+## 装备
+
+如果需要让剑盾等变成装备,可以直接在`data.js`中设置`'equipment': true`即可。
+
+值得注意的是,有时候会有一个装备加多种属性的需求,此时需要把剑盾的效果从数值改成一个对象:
+
+``` js
+"sword1": {"atk": 10, "def": 0, "mdef": 5}, // 铁剑加10攻和5魔防
+"shield1": {"atk": 0, "def": 10, "mdef": 10}, // 铁盾加10防和10魔防
+```
+
+将需要的项目按照如上方式修改即可。
+
+
## 门
本塔支持6种门,黄蓝红绿铁花。前五种门需要有对应的钥匙打开,花门只能通过调用`openDoor`事件进行打开。
diff --git a/docs/personalization.md b/docs/personalization.md
index 6d8b0880..2de9269c 100644
--- a/docs/personalization.md
+++ b/docs/personalization.md
@@ -286,7 +286,7 @@ control.prototype.checkBlock = function () {
你需自己指定一个special数字,修改getSpecialText函数(属性名)和getSpecialHint函数(属性提示文字)。
-如果要修改伤害计算公式,请修改下面的calDamage函数。请注意,如果无法战斗,该函数必须返回`999999999`。
+如果要修改伤害计算公式,请修改下面的calDamage函数。请注意,如果无法战斗,该函数必须返回`null`。
对于毒衰弱怪物的战斗后结算在`functions.js`中的afterBattle函数中。
diff --git a/libs/control.js b/libs/control.js
index 47c960a0..0dcd7817 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -1039,21 +1039,31 @@ control.prototype.snipe = function (snipes) {
snipe.blockIcon = core.material.icons[cls][block.event.id];
snipe.blockImage = core.material.images[cls];
snipe.height = height;
+
var damage = core.enemys.getDamage(block.event.id);
+ var color = '#000000';
- var color = "#000000";
- if (damage <= 0) color = '#00FF00';
- else if (damage < core.status.hero.hp / 3) color = '#FFFFFF';
- else if (damage < core.status.hero.hp * 2 / 3) color = '#FFFF00';
- else if (damage < core.status.hero.hp) color = '#FF7F00';
- else color = '#FF0000';
+ if (damage == null) {
+ damage = "???";
+ color = '#FF0000';
+ }
+ else {
+ if (damage <= 0) color = '#00FF00';
+ else if (damage < hero_hp / 3) color = '#FFFFFF';
+ else if (damage < hero_hp * 2 / 3) color = '#FFFF00';
+ else if (damage < hero_hp) color = '#FF7F00';
+ else color = '#FF0000';
- if (damage >= 999999999) damage = "???";
- else if (damage > 100000) damage = (damage / 10000).toFixed(1) + "w";
+ if (damage>=1e17) damage = (damage / 1e16).toFixed(1) + "j";
+ else if (damage>=1e13) damage = (damage / 1e12).toFixed(1) + "z";
+ else if (damage>=1e9) damage = (damage / 1e8).toFixed(1) + "e";
+ else if (damage>=1e5) damage = (damage / 1e4).toFixed(1) + "w";
+ }
snipe.damage = damage;
snipe.color = color;
snipe.block = core.clone(block);
+
})
var finishSnipe = function () {
@@ -1265,15 +1275,24 @@ control.prototype.updateFg = function () {
var id = mapBlocks[b].event.id;
var damage = core.enemys.getDamage(id);
- var color = "#000000";
- if (damage <= 0) color = '#00FF00';
- else if (damage < hero_hp / 3) color = '#FFFFFF';
- else if (damage < hero_hp * 2 / 3) color = '#FFFF00';
- else if (damage < hero_hp) color = '#FF7F00';
- else color = '#FF0000';
+ var color = '#000000';
- if (damage >= 999999999) damage = "???";
- else if (damage > 100000) damage = (damage / 10000).toFixed(1) + "w";
+ if (damage == null) {
+ damage = "???";
+ color = '#FF0000';
+ }
+ else {
+ if (damage <= 0) color = '#00FF00';
+ else if (damage < hero_hp / 3) color = '#FFFFFF';
+ else if (damage < hero_hp * 2 / 3) color = '#FFFF00';
+ else if (damage < hero_hp) color = '#FF7F00';
+ else color = '#FF0000';
+
+ if (damage>=1e17) damage = (damage / 1e16).toFixed(1) + "j";
+ else if (damage>=1e13) damage = (damage / 1e12).toFixed(1) + "z";
+ else if (damage>=1e9) damage = (damage / 1e8).toFixed(1) + "e";
+ else if (damage>=1e5) damage = (damage / 1e4).toFixed(1) + "w";
+ }
core.setFillStyle('fg', '#000000');
core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2);
diff --git a/libs/enemys.js b/libs/enemys.js
index d6bc65b0..af16347b 100644
--- a/libs/enemys.js
+++ b/libs/enemys.js
@@ -84,17 +84,17 @@ enemys.prototype.getSpecialHint = function (enemy, special) {
case 4: return "2连击:怪物每回合攻击2次";
case 5: return "3连击:怪物每回合攻击3次";
case 6: return (enemy.n||4)+"连击: 怪物每回合攻击"+(enemy.n||4)+"次";
- case 7: return "破甲:战斗前,怪物附加角色防御的"+parseInt(100*core.values.breakArmor)+"%作为伤害";
- case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+parseInt(100*core.values.counterAttack)+"%作为伤害,无视角色防御";
+ case 7: return "破甲:战斗前,怪物附加角色防御的"+parseInt(100*core.values.breakArmor||0)+"%作为伤害";
+ case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+parseInt(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";
case 9: return "净化:战斗前,怪物附加勇士魔防的"+core.values.purify+"倍作为伤害";
case 10: return "模仿:怪物的攻防和勇士攻防相等";
- case 11: return "吸血:战斗前,怪物首先吸取角色的"+parseInt(100*enemy.value)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
+ case 11: return "吸血:战斗前,怪物首先吸取角色的"+parseInt(100*enemy.value||0)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
case 12: return "中毒:战斗后,勇士陷入中毒状态,每一步损失生命"+core.values.poisonDamage+"点";
case 13: return "衰弱:战斗后,勇士陷入衰弱状态,攻防暂时下降"+core.values.weakValue+"点";
case 14: return "诅咒:战斗后,勇士陷入诅咒状态,战斗无法获得金币和经验";
case 15: return "领域:经过怪物周围"+(enemy.range||1)+"格时自动减生命"+(enemy.value||0)+"点";
case 16: return "夹击:经过两只相同的怪物中间,勇士生命值变成一半";
- case 17: return "仇恨:战斗前,怪物附加之前积累的仇恨值作为伤害"+(core.flags.hatredDecrease?";战斗后,释放一半的仇恨值":"")+"。(每杀死一个怪物获得"+core.values.hatred+"点仇恨值)";
+ case 17: return "仇恨:战斗前,怪物附加之前积累的仇恨值作为伤害"+(core.flags.hatredDecrease?";战斗后,释放一半的仇恨值":"")+"。(每杀死一个怪物获得"+(core.values.hatred||0)+"点仇恨值)";
case 18: return "阻击:经过怪物的十字领域时自动减生命"+(enemy.value||0)+"点,同时怪物后退一格";
case 19: return "自爆:战斗后勇士的生命值变成1";
case 20: return "无敌:勇士无法打败怪物,除非拥有十字架";
@@ -106,11 +106,17 @@ enemys.prototype.getSpecialHint = function (enemy, special) {
return "";
}
+////// 能否获胜 //////
+enemys.prototype.canBattle = function (monsterId) {
+ var damage = this.getDamage(monsterId);
+ return damage != null && damage < core.status.hero.hp;
+}
+
////// 获得某个怪物的伤害 //////
enemys.prototype.getDamage = function (monsterId) {
var monster = core.material.enemys[monsterId];
var damage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
- if (damage >= 999999999) return damage;
+ if (damage == null) return null;
return damage + this.getExtraDamage(monster);
}
@@ -134,10 +140,13 @@ enemys.prototype.getCritical = function (monsterId) {
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
+ if (last == null) return '???';
+
if (last <= 0) return 0;
for (var i = core.status.hero.atk + 1; i <= monster.hp + monster.def; i++) {
var damage = this.calDamage(monster, core.status.hero.hp, i, core.status.hero.def, core.status.hero.mdef);
+ if (damage == null) return '???';
if (damage < last)
return i - core.status.hero.atk;
last = damage;
@@ -152,7 +161,7 @@ enemys.prototype.getCriticalDamage = function (monsterId) {
if (c <= 0) return 0;
var monster = core.material.enemys[monsterId];
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
- if (last >= 999999999) return '???';
+ if (last == null) return '???';
return last - this.calDamage(monster, core.status.hero.hp, core.status.hero.atk + c, core.status.hero.def, core.status.hero.mdef);
}
@@ -162,7 +171,7 @@ enemys.prototype.getDefDamage = function (monsterId) {
var monster = core.material.enemys[monsterId];
var nowDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
var nextDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef);
- if (nowDamage >= 999999999 || nextDamage >= 999999999) return "???";
+ if (nowDamage == null || nextDamage ==null) return "???";
return nowDamage - nextDamage;
}
@@ -176,7 +185,7 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
hero_mdef=Math.max(0, hero_mdef);
if (this.hasSpecial(mon_special, 20) && !core.hasItem("cross")) // 如果是无敌属性,且勇士未持有十字架
- return 999999999; // 返回无限大
+ return null; // 返回不可战斗
var initDamage = 0; // 战前伤害
@@ -186,7 +195,7 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
// 如果有神圣盾免疫吸血等可以在这里写
- vampireDamage = parseInt(vampireDamage);
+ vampireDamage = parseInt(vampireDamage) || 0;
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
@@ -203,7 +212,7 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
if (this.hasSpecial(mon_special,2)) hero_def = 0;
// 坚固
if (this.hasSpecial(mon_special,3) && mon_def < hero_atk - 1) mon_def = hero_atk - 1;
- if (hero_atk <= mon_def) return 999999999; // 不可战斗时请直接返回999999999
+ if (hero_atk <= mon_def) return null; // 不可战斗时请直接返回null
var per_damage = mon_atk - hero_def;
if (per_damage < 0) per_damage = 0;
diff --git a/libs/events.js b/libs/events.js
index bac028d1..b7b32ec6 100644
--- a/libs/events.js
+++ b/libs/events.js
@@ -732,9 +732,8 @@ events.prototype.battle = function (id, x, y, force, callback) {
core.stopHero();
core.stopAutomaticRoute();
- var damage = core.enemys.getDamage(id);
// 非强制战斗
- if (damage >= core.status.hero.hp && !force) {
+ if (!core.enemys.canBattle(id) && !force) {
core.drawTip("你打不过此怪物!");
core.clearContinueAutomaticRoute();
return;
diff --git a/libs/ui.js b/libs/ui.js
index e01d802f..575684ad 100644
--- a/libs/ui.js
+++ b/libs/ui.js
@@ -1292,10 +1292,22 @@ ui.prototype.drawBook = function (index) {
core.canvas.ui.textAlign = "center";
var damage = enemy.damage;
+
var color = '#FFFF00';
- if (damage >= core.status.hero.hp) color = '#FF0000';
- if (damage <= 0) color = '#00FF00';
- if (damage >= 999999999) damage = '无法战斗';
+ if (damage == null) {
+ damage = '无法战斗';
+ color = '#FF0000';
+ }
+ else {
+ if (damage >= core.status.hero.hp) color = '#FF0000';
+ if (damage<=0) color = '#00FF00';
+
+ if (damage>=1e17) damage = (damage / 1e16).toFixed(2) + "j";
+ else if (damage>=1e13) damage = (damage / 1e12).toFixed(2) + "z";
+ else if (damage>=1e9) damage = (damage / 1e8).toFixed(2) + "e";
+ else if (damage>=1e5) damage = (damage / 1e4).toFixed(2) + "w";
+
+ }
core.fillText('ui', damage, damageOffset, 62 * i + 50, color, 'bold 13px Verdana');
core.canvas.ui.textAlign = "left";
@@ -1327,10 +1339,9 @@ ui.prototype.drawBookDetail = function (index) {
var enemyId=enemy.id;
var hints=core.enemys.getSpecialHint(core.material.enemys[enemyId]);
- if (hints.length==0) {
- core.drawTip("该怪物无特殊属性!");
- return;
- }
+
+ if (hints.length==0)
+ hints.push("该怪物无特殊属性。");
var content=hints.join("\n");
core.status.event.id = 'book-detail';
diff --git a/project/data.comment.js b/project/data.comment.js
index 92601f77..464163fa 100644
--- a/project/data.comment.js
+++ b/project/data.comment.js
@@ -488,6 +488,12 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_bool": "bool",
"_data": "是否地图怪物显伤;用户可以手动在菜单栏中开关"
},
+ "displayCritical": {
+ "_leaf": true,
+ "_type": "checkbox",
+ "_bool": "bool",
+ "_data": "是否地图显示临界;用户可以手动在菜单栏中开关"
+ },
"displayExtraDamage": {
"_leaf": true,
"_type": "checkbox",
diff --git a/project/data.js b/project/data.js
index 1059227c..247bd3a7 100644
--- a/project/data.js
+++ b/project/data.js
@@ -142,13 +142,13 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"enableLevelUp": false,
"enableDebuff": false,
"flyNearStair": true,
- "pickaxeFourDirections": true,
- "bombFourDirections": true,
+ "pickaxeFourDirections": false,
+ "bombFourDirections": false,
"bigKeyIsBox": false,
- "equipment": true,
+ "equipment": false,
"enableDeleteItem": true,
"enableAddPoint": false,
- "enableNegativeDamage": true,
+ "enableNegativeDamage": false,
"hatredDecrease": true,
"betweenAttackCeil": false,
"startDirectly": false,
@@ -156,6 +156,7 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"showBattleAnimateConfirm": true,
"battleAnimate": true,
"displayEnemyDamage": true,
+ "displayCritical": true,
"displayExtraDamage": true,
"enableGentleClick": true,
"potionWhileRouting": false,
diff --git a/project/functions.js b/project/functions.js
index e7add5db..03d7c3f0 100644
--- a/project/functions.js
+++ b/project/functions.js
@@ -116,8 +116,11 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
var enemy = core.material.enemys[enemyId];
+ var damage = core.enemys.getDamage(enemyId);
+ if (damage == null) damage = core.status.hero.hp+1;
+
// 扣减体力值
- core.status.hero.hp -= core.enemys.getDamage(enemyId);
+ core.status.hero.hp -= damage;
if (core.status.hero.hp<=0) {
core.status.hero.hp=0;
core.updateStatusBar();
diff --git a/更新说明.txt b/更新说明.txt
index b5533ed8..4a0336d1 100644
--- a/更新说明.txt
+++ b/更新说明.txt
@@ -2,6 +2,8 @@
编辑器添加“新建空白地图”按钮 √
编辑器的地图自动保存 √
+大数据魔塔的支持(临界计算等)
+支持用gif动图作为某层楼的背景图
APP端也能下载录像
图片显示增加淡入淡出效果
录像的倒退
@@ -9,7 +11,7 @@ APP端也能下载录像
单个存档清理
魔龙和章鱼添加到样板
大数据魔塔的显示 √
-修改999999999的上界问题
+修改999999999的上界问题 √
修复有时候无法输入ID的问题
修复坐标等不能为负数的问题
其他细节优化
From ece78a0c9ff48910abec05284427beb62dc75e6f Mon Sep 17 00:00:00 2001
From: ckcz123
Date: Tue, 17 Apr 2018 17:50:18 +0800
Subject: [PATCH 04/16] Update Critical Turn
---
libs/control.js | 10 ++-----
libs/core.js | 5 ++++
libs/enemys.js | 79 ++++++++++++++++++++++++++++++++++++++-----------
libs/ui.js | 5 +---
libs/utils.js | 12 ++++++++
5 files changed, 82 insertions(+), 29 deletions(-)
diff --git a/libs/control.js b/libs/control.js
index 0dcd7817..58515205 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -1054,10 +1054,7 @@ control.prototype.snipe = function (snipes) {
else if (damage < hero_hp) color = '#FF7F00';
else color = '#FF0000';
- if (damage>=1e17) damage = (damage / 1e16).toFixed(1) + "j";
- else if (damage>=1e13) damage = (damage / 1e12).toFixed(1) + "z";
- else if (damage>=1e9) damage = (damage / 1e8).toFixed(1) + "e";
- else if (damage>=1e5) damage = (damage / 1e4).toFixed(1) + "w";
+ damage = core.formatBigNumber(damage);
}
snipe.damage = damage;
@@ -1288,10 +1285,7 @@ control.prototype.updateFg = function () {
else if (damage < hero_hp) color = '#FF7F00';
else color = '#FF0000';
- if (damage>=1e17) damage = (damage / 1e16).toFixed(1) + "j";
- else if (damage>=1e13) damage = (damage / 1e12).toFixed(1) + "z";
- else if (damage>=1e9) damage = (damage / 1e8).toFixed(1) + "e";
- else if (damage>=1e5) damage = (damage / 1e4).toFixed(1) + "w";
+ damage = core.formatBigNumber(damage);
}
core.setFillStyle('fg', '#000000');
diff --git a/libs/core.js b/libs/core.js
index 0407eb51..d88d10f2 100644
--- a/libs/core.js
+++ b/libs/core.js
@@ -873,6 +873,11 @@ core.prototype.formatDate2 = function (date) {
return core.utils.formatDate2(date);
}
+////// 格式化大数 //////
+core.prototype.formatBigNumber = function (x) {
+ return core.utils.formatBigNumber(x);
+}
+
////// 两位数显示 //////
core.prototype.setTwoDigits = function (x) {
return core.utils.setTwoDigits(x);
diff --git a/libs/enemys.js b/libs/enemys.js
index af16347b..6e57d6a2 100644
--- a/libs/enemys.js
+++ b/libs/enemys.js
@@ -138,20 +138,44 @@ enemys.prototype.getCritical = function (monsterId) {
// 坚固、模仿怪物没有临界!
if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return "???";
- var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
+ if (monster.def + monster.hp/2 <= 10000) {
- if (last == null) return '???';
+ var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
- if (last <= 0) return 0;
+ if (last == null) return '???';
+
+ if (last <= 0) return 0;
+
+ for (var i = core.status.hero.atk + 1; i <= monster.hp + monster.def; i++) {
+ var damage = this.calDamage(monster, core.status.hero.hp, i, core.status.hero.def, core.status.hero.mdef);
+ if (damage == null) return '???';
+ if (damage < last)
+ return core.formatBigNumber(i - core.status.hero.atk);
+ last = damage;
+ }
+ return 0;
- for (var i = core.status.hero.atk + 1; i <= monster.hp + monster.def; i++) {
- var damage = this.calDamage(monster, core.status.hero.hp, i, core.status.hero.def, core.status.hero.mdef);
- if (damage == null) return '???';
- if (damage < last)
- return i - core.status.hero.atk;
- last = damage;
}
- return 0;
+ else {
+ var info = this.getDamageInfo(monster, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
+
+ if (info == null) return '???';
+ if (info.damage <= 0) return 0;
+
+ var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = monster.def, turn = info.turn;
+
+ // turn 是怪物攻击次数
+
+ if (turn<=0) return '???';
+ var nextTurn = turn - 1; // 怪物攻击次数少1
+
+ // 每回合最小伤害 = ⎡怪物生命/勇士攻击次数⎤
+ var nextAtk = parseInt((mon_hp - 1)/(nextTurn+1)) + 1 + mon_def;
+
+ if (nextAtk <= hero_atk) return '???';
+ return core.formatBigNumber(nextAtk - hero_atk);
+ }
+
}
////// 临界减伤计算 //////
@@ -161,9 +185,9 @@ enemys.prototype.getCriticalDamage = function (monsterId) {
if (c <= 0) return 0;
var monster = core.material.enemys[monsterId];
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
- if (last == null) return '???';
-
- return last - this.calDamage(monster, core.status.hero.hp, core.status.hero.atk + c, core.status.hero.def, core.status.hero.mdef);
+ var now = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk+c, core.status.hero.def, core.status.hero.mdef);
+ if (last == null || now==null) return '???';
+ return core.formatBigNumber(last - now);
}
////// 1防减伤计算 //////
@@ -172,11 +196,11 @@ enemys.prototype.getDefDamage = function (monsterId) {
var nowDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
var nextDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef);
if (nowDamage == null || nextDamage ==null) return "???";
- return nowDamage - nextDamage;
+ return core.formatBigNumber(nowDamage - nextDamage);
}
-////// 具体的伤害计算公式 //////
-enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, hero_mdef) {
+////// 获得战斗伤害信息 //////
+enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def, hero_mdef) {
var mon_hp = monster.hp, mon_atk = monster.atk, mon_def = monster.def, mon_special = monster.special;
hero_hp=Math.max(0, hero_hp);
@@ -245,7 +269,28 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
if (!core.flags.enableNegativeDamage)
ans=Math.max(0, ans);
- return ans;
+ return {
+ "hero_atk": hero_atk,
+ "hero_def": hero_def,
+ "hero_mdef": hero_mdef,
+ "mon_hp": mon_hp,
+ "mon_atk": mon_atk,
+ "mod_def": mon_def,
+ "mon_mdef": mon_mdef,
+ "per_damage": per_damage,
+ "initDamage": initDamage,
+ "turn": turn,
+ "damage": ans
+ };
+}
+
+////// 具体的伤害计算公式 //////
+enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, hero_mdef) {
+
+ var info = this.getDamageInfo(monster, hero_hp, hero_atk, hero_def, hero_mdef);
+ if (info == null) return null;
+ return info.damage;
+
}
////// 获得当前楼层的怪物列表 //////
diff --git a/libs/ui.js b/libs/ui.js
index 575684ad..37915b2a 100644
--- a/libs/ui.js
+++ b/libs/ui.js
@@ -1302,10 +1302,7 @@ ui.prototype.drawBook = function (index) {
if (damage >= core.status.hero.hp) color = '#FF0000';
if (damage<=0) color = '#00FF00';
- if (damage>=1e17) damage = (damage / 1e16).toFixed(2) + "j";
- else if (damage>=1e13) damage = (damage / 1e12).toFixed(2) + "z";
- else if (damage>=1e9) damage = (damage / 1e8).toFixed(2) + "e";
- else if (damage>=1e5) damage = (damage / 1e4).toFixed(2) + "w";
+ damage = core.formatBigNumber(damage);
}
core.fillText('ui', damage, damageOffset, 62 * i + 50, color, 'bold 13px Verdana');
diff --git a/libs/utils.js b/libs/utils.js
index 8c46819e..79f6c556 100644
--- a/libs/utils.js
+++ b/libs/utils.js
@@ -145,6 +145,18 @@ utils.prototype.setTwoDigits = function (x) {
return parseInt(x)<10?"0"+x:x;
}
+utils.prototype.formatBigNumber = function (x) {
+ x = parseInt(x);
+ if (!core.isset(x)) return x;
+
+ if (x>=1e17) return (x / 1e16).toFixed(1) + "j";
+ else if (x>=1e13) return (x / 1e12).toFixed(1) + "z";
+ else if (x>=1e9) return (x / 1e8).toFixed(1) + "e";
+ else if (x>=1e5) return (x / 1e4).toFixed(1) + "w";
+
+ return x;
+}
+
////// 数组转RGB //////
utils.prototype.arrayToRGB = function (color) {
var nowR = parseInt(color[0])||0, nowG = parseInt(color[1])||0, nowB = parseInt(color[2])||0;
From 85d45d01472d57be3e807b06cf79c4097b99146d Mon Sep 17 00:00:00 2001
From: oc
Date: Tue, 17 Apr 2018 23:04:47 +0800
Subject: [PATCH 05/16] support Huge integers
---
docs/personalization.md | 2 +-
libs/control.js | 6 ++----
libs/enemys.js | 43 ++++++++++++++++++++---------------------
libs/events.js | 2 +-
libs/ui.js | 36 +++++++++++++---------------------
libs/utils.js | 23 ++++++++++++++++------
6 files changed, 55 insertions(+), 57 deletions(-)
diff --git a/docs/personalization.md b/docs/personalization.md
index 2de9269c..64550140 100644
--- a/docs/personalization.md
+++ b/docs/personalization.md
@@ -249,7 +249,7 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
// 如果有神圣盾免疫吸血等可以在这里写
if (core.hasFlag("shield5")) vampireDamage = 0; // 存在神圣盾,吸血伤害为0
- vampireDamage = parseInt(vampireDamage);
+ vampireDamage = Math.floor(vampireDamage) || 0;
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
diff --git a/libs/control.js b/libs/control.js
index 58515205..f51c1133 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -946,7 +946,7 @@ control.prototype.updateCheckBlock = function() {
core.status.checkBlock.betweenAttack[13*x+y]=true;
var leftHp = core.status.hero.hp - core.status.checkBlock.damage[13*x+y];
if (leftHp>1)
- core.status.checkBlock.damage[13*x+y] += parseInt((leftHp+(core.flags.betweenAttackCeil?0:1))/2);
+ core.status.checkBlock.damage[13*x+y] += Math.floor((leftHp+(core.flags.betweenAttackCeil?0:1))/2);
}
}
}
@@ -2088,9 +2088,7 @@ control.prototype.updateStatusBar = function () {
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
statusList.forEach(function (item) {
- var val = core.getStatus(item);
- if (val>=10000000) val = parseInt(val/10000) + "W";
- core.statusBar[item].innerHTML = val;
+ core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item));
});
// 进阶
diff --git a/libs/enemys.js b/libs/enemys.js
index 6e57d6a2..4127ef40 100644
--- a/libs/enemys.js
+++ b/libs/enemys.js
@@ -84,11 +84,11 @@ enemys.prototype.getSpecialHint = function (enemy, special) {
case 4: return "2连击:怪物每回合攻击2次";
case 5: return "3连击:怪物每回合攻击3次";
case 6: return (enemy.n||4)+"连击: 怪物每回合攻击"+(enemy.n||4)+"次";
- case 7: return "破甲:战斗前,怪物附加角色防御的"+parseInt(100*core.values.breakArmor||0)+"%作为伤害";
- case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+parseInt(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";
+ case 7: return "破甲:战斗前,怪物附加角色防御的"+Math.floor(100*core.values.breakArmor||0)+"%作为伤害";
+ case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+Math.floor(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";
case 9: return "净化:战斗前,怪物附加勇士魔防的"+core.values.purify+"倍作为伤害";
case 10: return "模仿:怪物的攻防和勇士攻防相等";
- case 11: return "吸血:战斗前,怪物首先吸取角色的"+parseInt(100*enemy.value||0)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
+ case 11: return "吸血:战斗前,怪物首先吸取角色的"+Math.floor(100*enemy.value||0)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
case 12: return "中毒:战斗后,勇士陷入中毒状态,每一步损失生命"+core.values.poisonDamage+"点";
case 13: return "衰弱:战斗后,勇士陷入衰弱状态,攻防暂时下降"+core.values.weakValue+"点";
case 14: return "诅咒:战斗后,勇士陷入诅咒状态,战斗无法获得金币和经验";
@@ -138,7 +138,7 @@ enemys.prototype.getCritical = function (monsterId) {
// 坚固、模仿怪物没有临界!
if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return "???";
- if (monster.def + monster.hp/2 <= 10000) {
+ if (monster.def + monster.hp/2 <= 0) {
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
@@ -157,23 +157,22 @@ enemys.prototype.getCritical = function (monsterId) {
}
else {
- var info = this.getDamageInfo(monster, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
+
+ var info = this.getDamageInfo(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
if (info == null) return '???';
if (info.damage <= 0) return 0;
var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = monster.def, turn = info.turn;
- // turn 是怪物攻击次数
-
- if (turn<=0) return '???';
- var nextTurn = turn - 1; // 怪物攻击次数少1
+ // turn 是勇士攻击次数
+ if (turn<=1) return 0; // 攻杀
// 每回合最小伤害 = ⎡怪物生命/勇士攻击次数⎤
- var nextAtk = parseInt((mon_hp - 1)/(nextTurn+1)) + 1 + mon_def;
+ var nextAtk = Math.ceil(mon_hp/(turn-1)) + mon_def;
- if (nextAtk <= hero_atk) return '???';
- return core.formatBigNumber(nextAtk - hero_atk);
+ if (nextAtk <= hero_atk) return 0;
+ return nextAtk - hero_atk;
}
}
@@ -187,7 +186,7 @@ enemys.prototype.getCriticalDamage = function (monsterId) {
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
var now = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk+c, core.status.hero.def, core.status.hero.mdef);
if (last == null || now==null) return '???';
- return core.formatBigNumber(last - now);
+ return last - now;
}
////// 1防减伤计算 //////
@@ -196,7 +195,7 @@ enemys.prototype.getDefDamage = function (monsterId) {
var nowDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
var nextDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef);
if (nowDamage == null || nextDamage ==null) return "???";
- return core.formatBigNumber(nowDamage - nextDamage);
+ return nowDamage - nextDamage;
}
////// 获得战斗伤害信息 //////
@@ -219,7 +218,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
// 如果有神圣盾免疫吸血等可以在这里写
- vampireDamage = parseInt(vampireDamage) || 0;
+ vampireDamage = Math.floor(vampireDamage) || 0;
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
@@ -248,7 +247,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
var counterDamage = 0;
// 反击
- if (this.hasSpecial(mon_special, 8)) counterDamage += parseInt(core.values.counterAttack * hero_atk);
+ if (this.hasSpecial(mon_special, 8)) counterDamage += Math.floor(core.values.counterAttack * hero_atk);
// 先攻
if (this.hasSpecial(mon_special, 1))
@@ -256,14 +255,15 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
// 破甲
if (this.hasSpecial(mon_special, 7))
- initDamage += parseInt(core.values.breakArmor * hero_def);
+ initDamage += Math.floor(core.values.breakArmor * hero_def);
// 净化
if (this.hasSpecial(mon_special, 9))
- initDamage += parseInt(core.values.purify * hero_mdef);
+ initDamage += Math.floor(core.values.purify * hero_mdef);
- var turn = parseInt((mon_hp - 1) / (hero_atk - mon_def));
- var ans = initDamage + turn * per_damage + (turn + 1) * counterDamage;
+ // turn: 勇士攻击回合数
+ var turn = Math.ceil(mon_hp / (hero_atk - mon_def));
+ var ans = initDamage + (turn - 1) * per_damage + turn * counterDamage;
ans -= hero_mdef;
if (!core.flags.enableNegativeDamage)
@@ -275,8 +275,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
"hero_mdef": hero_mdef,
"mon_hp": mon_hp,
"mon_atk": mon_atk,
- "mod_def": mon_def,
- "mon_mdef": mon_mdef,
+ "mon_def": mon_def,
"per_damage": per_damage,
"initDamage": initDamage,
"turn": turn,
diff --git a/libs/events.js b/libs/events.js
index b7b32ec6..94dc708d 100644
--- a/libs/events.js
+++ b/libs/events.js
@@ -488,7 +488,7 @@ events.prototype.doAction = function() {
var value=core.calValue(data.value);
// 属性
if (data.name.indexOf("status:")==0) {
- value=parseInt(value);
+ value=parseFloat(value);
core.setStatus(data.name.substring(7), value);
}
// 道具
diff --git a/libs/ui.js b/libs/ui.js
index 37915b2a..4c3eee5e 100644
--- a/libs/ui.js
+++ b/libs/ui.js
@@ -787,7 +787,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
// 如果有神圣盾免疫吸血等可以在这里写
- vampireDamage = parseInt(vampireDamage);
+ vampireDamage = Math.floor(vampireDamage);
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
@@ -815,8 +815,8 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
if (core.enemys.hasSpecial(mon_special, 6)) turns=1+(monster.n||4);
// 初始伤害
- if (core.enemys.hasSpecial(mon_special, 7)) initDamage+=parseInt(core.values.breakArmor * hero_def);
- if (core.enemys.hasSpecial(mon_special, 9)) initDamage+=parseInt(core.values.purify * hero_mdef);
+ if (core.enemys.hasSpecial(mon_special, 7)) initDamage+=Math.floor(core.values.breakArmor * hero_def);
+ if (core.enemys.hasSpecial(mon_special, 9)) initDamage+=Math.floor(core.values.purify * hero_mdef);
hero_mdef-=initDamage;
if (hero_mdef<0) {
hero_hp+=hero_mdef;
@@ -1001,7 +1001,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
// 反击
if (core.enemys.hasSpecial(mon_special, 8)) {
- hero_mdef -= parseInt(core.values.counterAttack * hero_atk);
+ hero_mdef -= Math.floor(core.values.counterAttack * hero_atk);
if (hero_mdef<0) {
hero_hp+=hero_mdef;
@@ -1247,16 +1247,16 @@ ui.prototype.drawBook = function (index) {
}
core.canvas.ui.textAlign = "left";
core.fillText('ui', '生命', 165, 62 * i + 32, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.hp, 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.hp), 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '攻击', 255, 62 * i + 32, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.atk, 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.atk), 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '防御', 335, 62 * i + 32, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.def, 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.def), 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
var expOffset = 165, line_cnt=0;
if (core.flags.enableMoney) {
core.fillText('ui', '金币', 165, 62 * i + 50, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.money, 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.money), 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
expOffset = 255;
line_cnt++;
}
@@ -1265,7 +1265,7 @@ ui.prototype.drawBook = function (index) {
if (core.flags.enableAddPoint) {
core.canvas.ui.textAlign = "left";
core.fillText('ui', '加点', expOffset, 62 * i + 50, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.point, expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.point), expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
expOffset = 255;
line_cnt++;
}
@@ -1273,7 +1273,7 @@ ui.prototype.drawBook = function (index) {
if (core.flags.enableExperience && line_cnt<2) {
core.canvas.ui.textAlign = "left";
core.fillText('ui', '经验', expOffset, 62 * i + 50, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.experience, expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.experience), expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
line_cnt++;
}
@@ -1281,15 +1281,6 @@ ui.prototype.drawBook = function (index) {
if (line_cnt==1) damageOffset=326;
if (line_cnt==2) damageOffset=361;
- /*
- var damageOffet = 281;
- if (core.flags.enableMoney && core.flags.enableExperience)
- damageOffet = 361;
- else if (core.flags.enableMoney || core.flags.enableExperience)
- damageOffet = 326;
- */
-
-
core.canvas.ui.textAlign = "center";
var damage = enemy.damage;
@@ -1303,18 +1294,17 @@ ui.prototype.drawBook = function (index) {
if (damage<=0) color = '#00FF00';
damage = core.formatBigNumber(damage);
-
}
core.fillText('ui', damage, damageOffset, 62 * i + 50, color, 'bold 13px Verdana');
core.canvas.ui.textAlign = "left";
core.fillText('ui', '临界', 165, 62 * i + 68, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.critical, 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.critical), 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '减伤', 255, 62 * i + 68, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.criticalDamage, 285, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.criticalDamage), 285, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '1防', 335, 62 * i + 68, '#DDDDDD', '13px Verdana');
- core.fillText('ui', enemy.defDamage, 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
+ core.fillText('ui', core.formatBigNumber(enemy.defDamage), 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
if (index == start+i) {
core.strokeRect('ui', 10, 62 * i + 13, 416-10*2, 62, '#FFD700');
diff --git a/libs/utils.js b/libs/utils.js
index 79f6c556..bca7edfa 100644
--- a/libs/utils.js
+++ b/libs/utils.js
@@ -146,13 +146,24 @@ utils.prototype.setTwoDigits = function (x) {
}
utils.prototype.formatBigNumber = function (x) {
- x = parseInt(x);
- if (!core.isset(x)) return x;
+ x = parseFloat(x);
+ if (!core.isset(x)) return '???';
- if (x>=1e17) return (x / 1e16).toFixed(1) + "j";
- else if (x>=1e13) return (x / 1e12).toFixed(1) + "z";
- else if (x>=1e9) return (x / 1e8).toFixed(1) + "e";
- else if (x>=1e5) return (x / 1e4).toFixed(1) + "w";
+ var all = [
+ {"val": 10e20, "char": "g"},
+ {"val": 10e16, "char": "j"},
+ {"val": 10e12, "char": "z"},
+ {"val": 10e8, "char": "e"},
+ {"val": 10e4, "char": "w"},
+ ]
+
+ for (var i=0;i=10*one.val) {
+ var v = x/one.val;
+ return v.toFixed(Math.max(0, Math.floor(4-Math.log10(v)))) + one.char;
+ }
+ }
return x;
}
From 3dba1a375aef4c2d01102b1e4d28ff75f1008766 Mon Sep 17 00:00:00 2001
From: oc
Date: Tue, 17 Apr 2018 23:34:47 +0800
Subject: [PATCH 06/16] display critical on map
---
libs/actions.js | 10 +++++++--
libs/control.js | 59 +++++++++++++++++++++++++++++++------------------
libs/core.js | 1 +
libs/ui.js | 1 +
4 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/libs/actions.js b/libs/actions.js
index 48601e6f..17809fd5 100644
--- a/libs/actions.js
+++ b/libs/actions.js
@@ -1389,15 +1389,21 @@ actions.prototype.clickSwitchs = function (x,y) {
core.ui.drawSwitchs();
break;
case 4:
+ core.flags.displayCritical=!core.flags.displayCritical;
+ core.updateFg();
+ core.setLocalStorage('critical', core.flags.displayCritical);
+ core.ui.drawSwitchs();
+ break;
+ case 5:
core.flags.displayExtraDamage=!core.flags.displayExtraDamage;
core.updateFg();
core.setLocalStorage('extraDamage', core.flags.displayExtraDamage);
core.ui.drawSwitchs();
break;
- case 5:
+ case 6:
window.open(core.firstData.name+".zip", "_blank");
break;
- case 6:
+ case 7:
core.status.event.selection=0;
core.ui.drawSettings();
break;
diff --git a/libs/control.js b/libs/control.js
index f51c1133..85c001db 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -1252,7 +1252,7 @@ control.prototype.updateFg = function () {
if (!core.hasItem('book')) return;
core.setFont('fg', "bold 11px Arial");
var hero_hp = core.status.hero.hp;
- if (core.flags.displayEnemyDamage) {
+ if (core.flags.displayEnemyDamage || core.flags.displayCritical) {
core.canvas.fg.textAlign = 'left';
for (var b = 0; b < mapBlocks.length; b++) {
var x = mapBlocks[b].x, y = mapBlocks[b].y;
@@ -1271,31 +1271,46 @@ control.prototype.updateFg = function () {
var id = mapBlocks[b].event.id;
- var damage = core.enemys.getDamage(id);
- var color = '#000000';
+ if (core.flags.displayEnemyDamage) {
+ var damage = core.enemys.getDamage(id);
+ var color = '#000000';
- if (damage == null) {
- damage = "???";
- color = '#FF0000';
- }
- else {
- if (damage <= 0) color = '#00FF00';
- else if (damage < hero_hp / 3) color = '#FFFFFF';
- else if (damage < hero_hp * 2 / 3) color = '#FFFF00';
- else if (damage < hero_hp) color = '#FF7F00';
- else color = '#FF0000';
+ if (damage == null) {
+ damage = "???";
+ color = '#FF0000';
+ }
+ else {
+ if (damage <= 0) color = '#00FF00';
+ else if (damage < hero_hp / 3) color = '#FFFFFF';
+ else if (damage < hero_hp * 2 / 3) color = '#FFFF00';
+ else if (damage < hero_hp) color = '#FF7F00';
+ else color = '#FF0000';
- damage = core.formatBigNumber(damage);
+ damage = core.formatBigNumber(damage);
+ }
+
+ core.setFillStyle('fg', '#000000');
+ core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2);
+ core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1) - 2);
+ core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1));
+ core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1));
+
+ core.setFillStyle('fg', color);
+ core.canvas.fg.fillText(damage, 32 * x + 1, 32 * (y + 1) - 1);
}
- core.setFillStyle('fg', '#000000');
- core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1) - 2);
- core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1) - 2);
- core.canvas.fg.fillText(damage, 32 * x + 2, 32 * (y + 1));
- core.canvas.fg.fillText(damage, 32 * x, 32 * (y + 1));
-
- core.setFillStyle('fg', color);
- core.canvas.fg.fillText(damage, 32 * x + 1, 32 * (y + 1) - 1);
+ // 临界显伤
+ if (core.flags.displayCritical) {
+ var critical = core.formatBigNumber(core.enemys.getCritical(id));
+ if (critical == '???') critical = '?';
+ core.setFillStyle('fg', '#000000');
+ core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10);
+ core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 2 - 10);
+ core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 10);
+ core.canvas.fg.fillText(critical, 32 * x, 32 * (y + 1) - 10);
+ core.setFillStyle('fg', '#FFFFFF');
+ core.canvas.fg.fillText(critical, 32 * x + 1, 32 * (y + 1) - 1 - 10);
+ }
}
}
diff --git a/libs/core.js b/libs/core.js
index d88d10f2..a01080a5 100644
--- a/libs/core.js
+++ b/libs/core.js
@@ -268,6 +268,7 @@ core.prototype.init = function (coreData, callback) {
// switchs
core.flags.battleAnimate = core.getLocalStorage('battleAnimate', core.flags.battleAnimate);
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.material.ground = new Image();
diff --git a/libs/ui.js b/libs/ui.js
index 4c3eee5e..fb1d43ef 100644
--- a/libs/ui.js
+++ b/libs/ui.js
@@ -734,6 +734,7 @@ ui.prototype.drawSwitchs = function() {
"背景音效:"+(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]"),
"下载离线版本",
"返回主菜单"
From 3165a187a6b07666995e74eded89035e6c36299a Mon Sep 17 00:00:00 2001
From: oc
Date: Tue, 17 Apr 2018 23:35:07 +0800
Subject: [PATCH 07/16] display critical on map
---
更新说明.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/更新说明.txt b/更新说明.txt
index 4a0336d1..d0b4bc42 100644
--- a/更新说明.txt
+++ b/更新说明.txt
@@ -2,12 +2,12 @@
编辑器添加“新建空白地图”按钮 √
编辑器的地图自动保存 √
-大数据魔塔的支持(临界计算等)
+大数据魔塔的支持(临界计算等) √
支持用gif动图作为某层楼的背景图
APP端也能下载录像
图片显示增加淡入淡出效果
录像的倒退
-地图临界显伤
+地图临界显伤 √
单个存档清理
魔龙和章鱼添加到样板
大数据魔塔的显示 √
From bff5298c7a0e65e17575e92216188ec515058a82 Mon Sep 17 00:00:00 2001
From: oc
Date: Tue, 17 Apr 2018 23:42:31 +0800
Subject: [PATCH 08/16] Fix Negative Point
---
_server/blockly/MotaAction.g4 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4
index b71b4be9..eb9f3578 100644
--- a/_server/blockly/MotaAction.g4
+++ b/_server/blockly/MotaAction.g4
@@ -488,7 +488,7 @@ helpUrl : https://ckcz123.github.io/mota-js/#/event?id=changepos-%e5%bd%93%e5%89
default : [0,0,[['不变',''],['上','up'],['下','down'],['左','left'],['右','right']]]
colour : this.dataColor
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
-var code = '{"type": "changePos", "loc": ['+Int_0+','+Int_1+']'+DirectionEx_List_0+'},\n';
+var code = '{"type": "changePos", "loc": ['+Number_0+','+Number_1+']'+DirectionEx_List_0+'},\n';
return code;
*/
From 81df4a9b19cbb1ee15ac7dde31d8cc510078092d Mon Sep 17 00:00:00 2001
From: oc
Date: Wed, 18 Apr 2018 00:28:53 +0800
Subject: [PATCH 09/16] Reformat _server & delete map
---
_server/CodeMirror/codemirror.css | 574 +-
_server/CodeMirror/javascript-hint.js | 261 +-
_server/CodeMirror/javascript-lint.js | 101 +-
_server/CodeMirror/lint.css | 63 +-
_server/CodeMirror/lint.js | 465 +-
_server/CodeMirror/show-hint.css | 28 +-
_server/CodeMirror/show-hint.js | 874 +-
_server/blockly/blockly_compressed.js | 20448 +++++++++++++++++++--
_server/blockly/blocks_compressed.js | 2002 +-
_server/blockly/javascript_compressed.js | 850 +-
_server/blockly/media/sprites.svg | 130 +-
_server/css/editor.css | 526 +-
_server/css/editor_mode.css | 244 +-
_server/editor.js | 1082 +-
_server/editor_blockly.js | 308 +-
_server/editor_file.js | 1410 +-
_server/editor_mode.js | 1051 +-
_server/editor_multi.js | 277 +-
_server/fs.js | 188 +-
_server/fsTest_cs.html | 59 +-
_server/vm.js | 638 +-
editor.html | 518 +-
libs/utils.js | 2 +-
更新说明.txt | 2 +-
24 files changed, 26199 insertions(+), 5902 deletions(-)
diff --git a/_server/CodeMirror/codemirror.css b/_server/CodeMirror/codemirror.css
index c7a8ae70..07ccdf75 100644
--- a/_server/CodeMirror/codemirror.css
+++ b/_server/CodeMirror/codemirror.css
@@ -1,154 +1,285 @@
/* BASICS */
.CodeMirror {
- /* Set height, width, borders, and global font properties here */
- font-family: monospace;
- height: 300px;
- color: black;
- direction: ltr;
+ /* Set height, width, borders, and global font properties here */
+ font-family: monospace;
+ height: 300px;
+ color: black;
+ direction: ltr;
}
/* PADDING */
.CodeMirror-lines {
- padding: 4px 0; /* Vertical padding around content */
+ padding: 4px 0; /* Vertical padding around content */
}
+
.CodeMirror pre {
- padding: 0 4px; /* Horizontal padding of content */
+ padding: 0 4px; /* Horizontal padding of content */
}
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
- background-color: white; /* The little square between H and V scrollbars */
+ background-color: white; /* The little square between H and V scrollbars */
}
/* GUTTER */
.CodeMirror-gutters {
- border-right: 1px solid #ddd;
- background-color: #f7f7f7;
- white-space: nowrap;
-}
-.CodeMirror-linenumbers {}
-.CodeMirror-linenumber {
- padding: 0 3px 0 5px;
- min-width: 20px;
- text-align: right;
- color: #999;
- white-space: nowrap;
+ border-right: 1px solid #ddd;
+ background-color: #f7f7f7;
+ white-space: nowrap;
}
-.CodeMirror-guttermarker { color: black; }
-.CodeMirror-guttermarker-subtle { color: #999; }
+.CodeMirror-linenumbers {
+}
+
+.CodeMirror-linenumber {
+ padding: 0 3px 0 5px;
+ min-width: 20px;
+ text-align: right;
+ color: #999;
+ white-space: nowrap;
+}
+
+.CodeMirror-guttermarker {
+ color: black;
+}
+
+.CodeMirror-guttermarker-subtle {
+ color: #999;
+}
/* CURSOR */
.CodeMirror-cursor {
- border-left: 1px solid black;
- border-right: none;
- width: 0;
+ border-left: 1px solid black;
+ border-right: none;
+ width: 0;
}
+
/* Shown when moving in bi-directional text */
.CodeMirror div.CodeMirror-secondarycursor {
- border-left: 1px solid silver;
+ border-left: 1px solid silver;
}
+
.cm-fat-cursor .CodeMirror-cursor {
- width: auto;
- border: 0 !important;
- background: #7e7;
+ width: auto;
+ border: 0 !important;
+ background: #7e7;
}
+
.cm-fat-cursor div.CodeMirror-cursors {
- z-index: 1;
+ z-index: 1;
}
+
.cm-fat-cursor-mark {
- background-color: rgba(20, 255, 20, 0.5);
- -webkit-animation: blink 1.06s steps(1) infinite;
- -moz-animation: blink 1.06s steps(1) infinite;
- animation: blink 1.06s steps(1) infinite;
+ background-color: rgba(20, 255, 20, 0.5);
+ -webkit-animation: blink 1.06s steps(1) infinite;
+ -moz-animation: blink 1.06s steps(1) infinite;
+ animation: blink 1.06s steps(1) infinite;
}
+
.cm-animate-fat-cursor {
- width: auto;
- border: 0;
- -webkit-animation: blink 1.06s steps(1) infinite;
- -moz-animation: blink 1.06s steps(1) infinite;
- animation: blink 1.06s steps(1) infinite;
- background-color: #7e7;
+ width: auto;
+ border: 0;
+ -webkit-animation: blink 1.06s steps(1) infinite;
+ -moz-animation: blink 1.06s steps(1) infinite;
+ animation: blink 1.06s steps(1) infinite;
+ background-color: #7e7;
}
+
@-moz-keyframes blink {
- 0% {}
- 50% { background-color: transparent; }
- 100% {}
+ 0% {
+ }
+ 50% {
+ background-color: transparent;
+ }
+ 100% {
+ }
}
+
@-webkit-keyframes blink {
- 0% {}
- 50% { background-color: transparent; }
- 100% {}
+ 0% {
+ }
+ 50% {
+ background-color: transparent;
+ }
+ 100% {
+ }
}
+
@keyframes blink {
- 0% {}
- 50% { background-color: transparent; }
- 100% {}
+ 0% {
+ }
+ 50% {
+ background-color: transparent;
+ }
+ 100% {
+ }
}
/* Can style cursor different in overwrite (non-insert) mode */
-.CodeMirror-overwrite .CodeMirror-cursor {}
+.CodeMirror-overwrite .CodeMirror-cursor {
+}
-.cm-tab { display: inline-block; text-decoration: inherit; }
+.cm-tab {
+ display: inline-block;
+ text-decoration: inherit;
+}
.CodeMirror-rulers {
- position: absolute;
- left: 0; right: 0; top: -50px; bottom: -20px;
- overflow: hidden;
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: -50px;
+ bottom: -20px;
+ overflow: hidden;
}
+
.CodeMirror-ruler {
- border-left: 1px solid #ccc;
- top: 0; bottom: 0;
- position: absolute;
+ border-left: 1px solid #ccc;
+ top: 0;
+ bottom: 0;
+ position: absolute;
}
/* DEFAULT THEME */
-.cm-s-default .cm-header {color: blue;}
-.cm-s-default .cm-quote {color: #090;}
-.cm-negative {color: #d44;}
-.cm-positive {color: #292;}
-.cm-header, .cm-strong {font-weight: bold;}
-.cm-em {font-style: italic;}
-.cm-link {text-decoration: underline;}
-.cm-strikethrough {text-decoration: line-through;}
+.cm-s-default .cm-header {
+ color: blue;
+}
+
+.cm-s-default .cm-quote {
+ color: #090;
+}
+
+.cm-negative {
+ color: #d44;
+}
+
+.cm-positive {
+ color: #292;
+}
+
+.cm-header, .cm-strong {
+ font-weight: bold;
+}
+
+.cm-em {
+ font-style: italic;
+}
+
+.cm-link {
+ text-decoration: underline;
+}
+
+.cm-strikethrough {
+ text-decoration: line-through;
+}
+
+.cm-s-default .cm-keyword {
+ color: #708;
+}
+
+.cm-s-default .cm-atom {
+ color: #219;
+}
+
+.cm-s-default .cm-number {
+ color: #164;
+}
+
+.cm-s-default .cm-def {
+ color: #00f;
+}
-.cm-s-default .cm-keyword {color: #708;}
-.cm-s-default .cm-atom {color: #219;}
-.cm-s-default .cm-number {color: #164;}
-.cm-s-default .cm-def {color: #00f;}
.cm-s-default .cm-variable,
.cm-s-default .cm-punctuation,
.cm-s-default .cm-property,
-.cm-s-default .cm-operator {}
-.cm-s-default .cm-variable-2 {color: #05a;}
-.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
-.cm-s-default .cm-comment {color: #a50;}
-.cm-s-default .cm-string {color: #a11;}
-.cm-s-default .cm-string-2 {color: #f50;}
-.cm-s-default .cm-meta {color: #555;}
-.cm-s-default .cm-qualifier {color: #555;}
-.cm-s-default .cm-builtin {color: #30a;}
-.cm-s-default .cm-bracket {color: #997;}
-.cm-s-default .cm-tag {color: #170;}
-.cm-s-default .cm-attribute {color: #00c;}
-.cm-s-default .cm-hr {color: #999;}
-.cm-s-default .cm-link {color: #00c;}
+.cm-s-default .cm-operator {
+}
-.cm-s-default .cm-error {color: #f00;}
-.cm-invalidchar {color: #f00;}
+.cm-s-default .cm-variable-2 {
+ color: #05a;
+}
-.CodeMirror-composing { border-bottom: 2px solid; }
+.cm-s-default .cm-variable-3, .cm-s-default .cm-type {
+ color: #085;
+}
+
+.cm-s-default .cm-comment {
+ color: #a50;
+}
+
+.cm-s-default .cm-string {
+ color: #a11;
+}
+
+.cm-s-default .cm-string-2 {
+ color: #f50;
+}
+
+.cm-s-default .cm-meta {
+ color: #555;
+}
+
+.cm-s-default .cm-qualifier {
+ color: #555;
+}
+
+.cm-s-default .cm-builtin {
+ color: #30a;
+}
+
+.cm-s-default .cm-bracket {
+ color: #997;
+}
+
+.cm-s-default .cm-tag {
+ color: #170;
+}
+
+.cm-s-default .cm-attribute {
+ color: #00c;
+}
+
+.cm-s-default .cm-hr {
+ color: #999;
+}
+
+.cm-s-default .cm-link {
+ color: #00c;
+}
+
+.cm-s-default .cm-error {
+ color: #f00;
+}
+
+.cm-invalidchar {
+ color: #f00;
+}
+
+.CodeMirror-composing {
+ border-bottom: 2px solid;
+}
/* Default styles for common addons */
-div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
-div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
-.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
-.CodeMirror-activeline-background {background: #e8f2ff;}
+div.CodeMirror span.CodeMirror-matchingbracket {
+ color: #0b0;
+}
+
+div.CodeMirror span.CodeMirror-nonmatchingbracket {
+ color: #a22;
+}
+
+.CodeMirror-matchingtag {
+ background: rgba(255, 150, 0, .3);
+}
+
+.CodeMirror-activeline-background {
+ background: #e8f2ff;
+}
/* STOP */
@@ -156,129 +287,162 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
the editor. You probably shouldn't touch them. */
.CodeMirror {
- position: relative;
- overflow: hidden;
- background: white;
+ position: relative;
+ overflow: hidden;
+ background: white;
}
.CodeMirror-scroll {
- overflow: scroll !important; /* Things will break if this is overridden */
- /* 30px is the magic margin used to hide the element's real scrollbars */
- /* See overflow: hidden in .CodeMirror */
- margin-bottom: -30px; margin-right: -30px;
- padding-bottom: 30px;
- height: 100%;
- outline: none; /* Prevent dragging from highlighting the element */
- position: relative;
+ overflow: scroll !important; /* Things will break if this is overridden */
+ /* 30px is the magic margin used to hide the element's real scrollbars */
+ /* See overflow: hidden in .CodeMirror */
+ margin-bottom: -30px;
+ margin-right: -30px;
+ padding-bottom: 30px;
+ height: 100%;
+ outline: none; /* Prevent dragging from highlighting the element */
+ position: relative;
}
+
.CodeMirror-sizer {
- position: relative;
- border-right: 30px solid transparent;
+ position: relative;
+ border-right: 30px solid transparent;
}
/* The fake, visible scrollbars. Used to force redraw during scrolling
before actual scrolling happens, thus preventing shaking and
flickering artifacts. */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
- position: absolute;
- z-index: 6;
- display: none;
+ position: absolute;
+ z-index: 6;
+ display: none;
}
+
.CodeMirror-vscrollbar {
- right: 0; top: 0;
- overflow-x: hidden;
- overflow-y: scroll;
+ right: 0;
+ top: 0;
+ overflow-x: hidden;
+ overflow-y: scroll;
}
+
.CodeMirror-hscrollbar {
- bottom: 0; left: 0;
- overflow-y: hidden;
- overflow-x: scroll;
+ bottom: 0;
+ left: 0;
+ overflow-y: hidden;
+ overflow-x: scroll;
}
+
.CodeMirror-scrollbar-filler {
- right: 0; bottom: 0;
+ right: 0;
+ bottom: 0;
}
+
.CodeMirror-gutter-filler {
- left: 0; bottom: 0;
+ left: 0;
+ bottom: 0;
}
.CodeMirror-gutters {
- position: absolute; left: 0; top: 0;
- min-height: 100%;
- z-index: 3;
+ position: absolute;
+ left: 0;
+ top: 0;
+ min-height: 100%;
+ z-index: 3;
}
+
.CodeMirror-gutter {
- white-space: normal;
- height: 100%;
- display: inline-block;
- vertical-align: top;
- margin-bottom: -30px;
+ white-space: normal;
+ height: 100%;
+ display: inline-block;
+ vertical-align: top;
+ margin-bottom: -30px;
}
+
.CodeMirror-gutter-wrapper {
- position: absolute;
- z-index: 4;
- background: none !important;
- border: none !important;
+ position: absolute;
+ z-index: 4;
+ background: none !important;
+ border: none !important;
}
+
.CodeMirror-gutter-background {
- position: absolute;
- top: 0; bottom: 0;
- z-index: 4;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ z-index: 4;
}
+
.CodeMirror-gutter-elt {
- position: absolute;
- cursor: default;
- z-index: 4;
+ position: absolute;
+ cursor: default;
+ z-index: 4;
+}
+
+.CodeMirror-gutter-wrapper ::selection {
+ background-color: transparent
+}
+
+.CodeMirror-gutter-wrapper ::-moz-selection {
+ background-color: transparent
}
-.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
-.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
.CodeMirror-lines {
- cursor: text;
- min-height: 1px; /* prevents collapsing before first draw */
+ cursor: text;
+ min-height: 1px; /* prevents collapsing before first draw */
}
+
.CodeMirror pre {
- /* Reset some styles that the rest of the page might have set */
- -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
- border-width: 0;
- background: transparent;
- font-family: inherit;
- font-size: inherit;
- margin: 0;
- white-space: pre;
- word-wrap: normal;
- line-height: inherit;
- color: inherit;
- z-index: 2;
- position: relative;
- overflow: visible;
- -webkit-tap-highlight-color: transparent;
- -webkit-font-variant-ligatures: contextual;
- font-variant-ligatures: contextual;
+ /* Reset some styles that the rest of the page might have set */
+ -moz-border-radius: 0;
+ -webkit-border-radius: 0;
+ border-radius: 0;
+ border-width: 0;
+ background: transparent;
+ font-family: inherit;
+ font-size: inherit;
+ margin: 0;
+ white-space: pre;
+ word-wrap: normal;
+ line-height: inherit;
+ color: inherit;
+ z-index: 2;
+ position: relative;
+ overflow: visible;
+ -webkit-tap-highlight-color: transparent;
+ -webkit-font-variant-ligatures: contextual;
+ font-variant-ligatures: contextual;
}
+
.CodeMirror-wrap pre {
- word-wrap: break-word;
- white-space: pre-wrap;
- word-break: normal;
+ word-wrap: break-word;
+ white-space: pre-wrap;
+ word-break: normal;
}
.CodeMirror-linebackground {
- position: absolute;
- left: 0; right: 0; top: 0; bottom: 0;
- z-index: 0;
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ z-index: 0;
}
.CodeMirror-linewidget {
- position: relative;
- z-index: 2;
- padding: 0.1px; /* Force widget margins to stay inside of the container */
+ position: relative;
+ z-index: 2;
+ padding: 0.1px; /* Force widget margins to stay inside of the container */
}
-.CodeMirror-widget {}
+.CodeMirror-widget {
+}
-.CodeMirror-rtl pre { direction: rtl; }
+.CodeMirror-rtl pre {
+ direction: rtl;
+}
.CodeMirror-code {
- outline: none;
+ outline: none;
}
/* Force content-box sizing for the elements where we expect it */
@@ -287,60 +451,84 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
.CodeMirror-gutter,
.CodeMirror-gutters,
.CodeMirror-linenumber {
- -moz-box-sizing: content-box;
- box-sizing: content-box;
+ -moz-box-sizing: content-box;
+ box-sizing: content-box;
}
.CodeMirror-measure {
- position: absolute;
- width: 100%;
- height: 0;
- overflow: hidden;
- visibility: hidden;
+ position: absolute;
+ width: 100%;
+ height: 0;
+ overflow: hidden;
+ visibility: hidden;
}
.CodeMirror-cursor {
- position: absolute;
- pointer-events: none;
+ position: absolute;
+ pointer-events: none;
+}
+
+.CodeMirror-measure pre {
+ position: static;
}
-.CodeMirror-measure pre { position: static; }
div.CodeMirror-cursors {
- visibility: hidden;
- position: relative;
- z-index: 3;
+ visibility: hidden;
+ position: relative;
+ z-index: 3;
}
+
div.CodeMirror-dragcursors {
- visibility: visible;
+ visibility: visible;
}
.CodeMirror-focused div.CodeMirror-cursors {
- visibility: visible;
+ visibility: visible;
}
-.CodeMirror-selected { background: #d9d9d9; }
-.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
-.CodeMirror-crosshair { cursor: crosshair; }
-.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
-.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
+.CodeMirror-selected {
+ background: #d9d9d9;
+}
+
+.CodeMirror-focused .CodeMirror-selected {
+ background: #d7d4f0;
+}
+
+.CodeMirror-crosshair {
+ cursor: crosshair;
+}
+
+.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection {
+ background: #d7d4f0;
+}
+
+.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection {
+ background: #d7d4f0;
+}
.cm-searching {
- background-color: #ffa;
- background-color: rgba(255, 255, 0, .4);
+ background-color: #ffa;
+ background-color: rgba(255, 255, 0, .4);
}
/* Used to force a border model for a node */
-.cm-force-border { padding-right: .1px; }
+.cm-force-border {
+ padding-right: .1px;
+}
@media print {
- /* Hide the cursor when printing */
- .CodeMirror div.CodeMirror-cursors {
- visibility: hidden;
- }
+ /* Hide the cursor when printing */
+ .CodeMirror div.CodeMirror-cursors {
+ visibility: hidden;
+ }
}
/* See issue #2901 */
-.cm-tab-wrap-hack:after { content: ''; }
+.cm-tab-wrap-hack:after {
+ content: '';
+}
/* Help users use markselection to safely style text background */
-span.CodeMirror-selectedtext { background: none; }
+span.CodeMirror-selectedtext {
+ background: none;
+}
diff --git a/_server/CodeMirror/javascript-hint.js b/_server/CodeMirror/javascript-hint.js
index 21d1fe9a..e84049f1 100644
--- a/_server/CodeMirror/javascript-hint.js
+++ b/_server/CodeMirror/javascript-hint.js
@@ -1,156 +1,165 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
-(function(mod) {
+(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
- mod(require("../../lib/codemirror"));
+ mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
- define(["../../lib/codemirror"], mod);
+ define(["../../lib/codemirror"], mod);
else // Plain browser env
- mod(CodeMirror);
- })(function(CodeMirror) {
+ mod(CodeMirror);
+})(function (CodeMirror) {
var Pos = CodeMirror.Pos;
-
+
function forEach(arr, f) {
- for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
+ for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
-
+
function arrayContains(arr, item) {
- if (!Array.prototype.indexOf) {
- var i = arr.length;
- while (i--) {
- if (arr[i] === item) {
- return true;
- }
+ if (!Array.prototype.indexOf) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === item) {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
- return arr.indexOf(item) != -1;
+ return arr.indexOf(item) != -1;
}
-
+
function scriptHint(editor, keywords, getToken, options) {
- // Find the token at the cursor
- var cur = editor.getCursor(), token = getToken(editor, cur);
- if (/\b(?:string|comment)\b/.test(token.type)) return;
- token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
-
- // If it's not a 'word-style' token, ignore the token.
- if (!/^[\w$_]*$/.test(token.string)) {
- token = {start: cur.ch, end: cur.ch, string: "", state: token.state,
- type: token.string == "." ? "property" : null};
- } else if (token.end > cur.ch) {
- token.end = cur.ch;
- token.string = token.string.slice(0, cur.ch - token.start);
- }
-
- var tprop = token;
- // If it is a property, find out what it is a property of.
- while (tprop.type == "property") {
- tprop = getToken(editor, Pos(cur.line, tprop.start));
- if (tprop.string != ".") return;
- tprop = getToken(editor, Pos(cur.line, tprop.start));
- if (!context) var context = [];
- context.push(tprop);
- }
- return {list: getCompletions(token, context, keywords, options),
- from: Pos(cur.line, token.start),
- to: Pos(cur.line, token.end)};
+ // Find the token at the cursor
+ var cur = editor.getCursor(), token = getToken(editor, cur);
+ if (/\b(?:string|comment)\b/.test(token.type)) return;
+ token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
+
+ // If it's not a 'word-style' token, ignore the token.
+ if (!/^[\w$_]*$/.test(token.string)) {
+ token = {
+ start: cur.ch, end: cur.ch, string: "", state: token.state,
+ type: token.string == "." ? "property" : null
+ };
+ } else if (token.end > cur.ch) {
+ token.end = cur.ch;
+ token.string = token.string.slice(0, cur.ch - token.start);
+ }
+
+ var tprop = token;
+ // If it is a property, find out what it is a property of.
+ while (tprop.type == "property") {
+ tprop = getToken(editor, Pos(cur.line, tprop.start));
+ if (tprop.string != ".") return;
+ tprop = getToken(editor, Pos(cur.line, tprop.start));
+ if (!context) var context = [];
+ context.push(tprop);
+ }
+ return {
+ list: getCompletions(token, context, keywords, options),
+ from: Pos(cur.line, token.start),
+ to: Pos(cur.line, token.end)
+ };
}
-
+
function javascriptHint(editor, options) {
- return scriptHint(editor, javascriptKeywords,
- function (e, cur) {return e.getTokenAt(cur);},
- options);
+ return scriptHint(editor, javascriptKeywords,
+ function (e, cur) {
+ return e.getTokenAt(cur);
+ },
+ options);
};
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
-
+
function getCoffeeScriptToken(editor, cur) {
- // This getToken, it is for coffeescript, imitates the behavior of
- // getTokenAt method in javascript.js, that is, returning "property"
- // type and treat "." as indepenent token.
- var token = editor.getTokenAt(cur);
- if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
- token.end = token.start;
- token.string = '.';
- token.type = "property";
- }
- else if (/^\.[\w$_]*$/.test(token.string)) {
- token.type = "property";
- token.start++;
- token.string = token.string.replace(/\./, '');
- }
- return token;
+ // This getToken, it is for coffeescript, imitates the behavior of
+ // getTokenAt method in javascript.js, that is, returning "property"
+ // type and treat "." as indepenent token.
+ var token = editor.getTokenAt(cur);
+ if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
+ token.end = token.start;
+ token.string = '.';
+ token.type = "property";
+ }
+ else if (/^\.[\w$_]*$/.test(token.string)) {
+ token.type = "property";
+ token.start++;
+ token.string = token.string.replace(/\./, '');
+ }
+ return token;
}
-
+
function coffeescriptHint(editor, options) {
- return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
+ return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
}
+
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
-
+
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
- "toUpperCase toLowerCase split concat match replace search").split(" ");
+ "toUpperCase toLowerCase split concat match replace search").split(" ");
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
- "lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
+ "lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
var funcProps = "prototype apply call bind".split(" ");
var javascriptKeywords = ("break case catch class const continue debugger default delete do else export extends false finally for function " +
- "if in import instanceof new null return super switch this throw true try typeof var void while with yield").split(" ");
+ "if in import instanceof new null return super switch this throw true try typeof var void while with yield").split(" ");
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
- "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
-
+ "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
+
function forAllProps(obj, callback) {
- if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) {
- for (var name in obj) callback(name)
- } else {
- for (var o = obj; o; o = Object.getPrototypeOf(o))
- Object.getOwnPropertyNames(o).forEach(callback)
- }
- }
-
- function getCompletions(token, context, keywords, options) {
- var found = [], start = token.string, global = options && options.globalScope || window;
- function maybeAdd(str) {
- if (str==null || str==undefined) return;
- if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
- }
- function gatherCompletions(obj) {
- if (typeof obj == "string") forEach(stringProps, maybeAdd);
- else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
- else if (obj instanceof Function) forEach(funcProps, maybeAdd);
- forAllProps(obj, maybeAdd)
- }
-
- if (context && context.length) {
- // If this is a property, see if it belongs to some object we can
- // find in the current environment.
- var obj = context.pop(), base;
- if (obj.type && obj.type.indexOf("variable") === 0) {
- if (options && options.additionalContext)
- base = options.additionalContext[obj.string];
- if (!options || options.useGlobalScope !== false)
- base = base || global[obj.string];
- } else if (obj.type == "string") {
- base = "";
- } else if (obj.type == "atom") {
- base = 1;
- } else if (obj.type == "function") {
- if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
- (typeof global.jQuery == 'function'))
- base = global.jQuery();
- else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
- base = global._();
+ if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) {
+ for (var name in obj) callback(name)
+ } else {
+ for (var o = obj; o; o = Object.getPrototypeOf(o))
+ Object.getOwnPropertyNames(o).forEach(callback)
}
- while (base != null && context.length)
- base = base[context.pop().string];
- if (base != null) gatherCompletions(base);
- } else {
- // If not, just look in the global object and any local scope
- // (reading into JS mode internals to get at the local and global variables)
- for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
- for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
- if (!options || options.useGlobalScope !== false)
- gatherCompletions(global);
- forEach(keywords, maybeAdd);
- }
- return found;
}
- });
\ No newline at end of file
+
+ function getCompletions(token, context, keywords, options) {
+ var found = [], start = token.string, global = options && options.globalScope || window;
+
+ function maybeAdd(str) {
+ if (str == null || str == undefined) return;
+ if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
+ }
+
+ function gatherCompletions(obj) {
+ if (typeof obj == "string") forEach(stringProps, maybeAdd);
+ else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
+ else if (obj instanceof Function) forEach(funcProps, maybeAdd);
+ forAllProps(obj, maybeAdd)
+ }
+
+ if (context && context.length) {
+ // If this is a property, see if it belongs to some object we can
+ // find in the current environment.
+ var obj = context.pop(), base;
+ if (obj.type && obj.type.indexOf("variable") === 0) {
+ if (options && options.additionalContext)
+ base = options.additionalContext[obj.string];
+ if (!options || options.useGlobalScope !== false)
+ base = base || global[obj.string];
+ } else if (obj.type == "string") {
+ base = "";
+ } else if (obj.type == "atom") {
+ base = 1;
+ } else if (obj.type == "function") {
+ if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
+ (typeof global.jQuery == 'function'))
+ base = global.jQuery();
+ else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
+ base = global._();
+ }
+ while (base != null && context.length)
+ base = base[context.pop().string];
+ if (base != null) gatherCompletions(base);
+ } else {
+ // If not, just look in the global object and any local scope
+ // (reading into JS mode internals to get at the local and global variables)
+ for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
+ for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
+ if (!options || options.useGlobalScope !== false)
+ gatherCompletions(global);
+ forEach(keywords, maybeAdd);
+ }
+ return found;
+ }
+});
\ No newline at end of file
diff --git a/_server/CodeMirror/javascript-lint.js b/_server/CodeMirror/javascript-lint.js
index fc3dfdc2..a350ce66 100644
--- a/_server/CodeMirror/javascript-lint.js
+++ b/_server/CodeMirror/javascript-lint.js
@@ -1,63 +1,64 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
-(function(mod) {
+(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
- mod(require("../../lib/codemirror"));
+ mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
- define(["../../lib/codemirror"], mod);
+ define(["../../lib/codemirror"], mod);
else // Plain browser env
- mod(CodeMirror);
- })(function(CodeMirror) {
+ mod(CodeMirror);
+})(function (CodeMirror) {
"use strict";
+
// declare global: JSHINT
-
+
function validator(text, options) {
- if (!window.JSHINT) {
- if (window.console) {
- window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");
- }
- return [];
- }
- if (!options.indent) // JSHint error.character actually is a column index, this fixes underlining on lines using tabs for indentation
- options.indent = 1; // JSHint default value is 4
- JSHINT(text, options, options.globals);
- var errors = JSHINT.data().errors, result = [];
- if (errors) parseErrors(errors, result);
- return result;
- }
-
- CodeMirror.registerHelper("lint", "javascript", validator);
-
- function parseErrors(errors, output) {
- for ( var i = 0; i < errors.length; i++) {
- var error = errors[i];
- if (error) {
- if (error.line <= 0) {
+ if (!window.JSHINT) {
if (window.console) {
- window.console.warn("Cannot display JSHint error (invalid line " + error.line + ")", error);
+ window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");
}
- continue;
- }
-
- var start = error.character - 1, end = start + 1;
- if (error.evidence) {
- var index = error.evidence.substring(start).search(/.\b/);
- if (index > -1) {
- end += index;
- }
- }
-
- // Convert to format expected by validation service
- var hint = {
- message: error.reason,
- severity: error.code ? (error.code.startsWith('W') ? "warning" : "error") : "error",
- from: CodeMirror.Pos(error.line - 1, start),
- to: CodeMirror.Pos(error.line - 1, end)
- };
-
- output.push(hint);
+ return [];
}
- }
+ if (!options.indent) // JSHint error.character actually is a column index, this fixes underlining on lines using tabs for indentation
+ options.indent = 1; // JSHint default value is 4
+ JSHINT(text, options, options.globals);
+ var errors = JSHINT.data().errors, result = [];
+ if (errors) parseErrors(errors, result);
+ return result;
}
- });
\ No newline at end of file
+
+ CodeMirror.registerHelper("lint", "javascript", validator);
+
+ function parseErrors(errors, output) {
+ for (var i = 0; i < errors.length; i++) {
+ var error = errors[i];
+ if (error) {
+ if (error.line <= 0) {
+ if (window.console) {
+ window.console.warn("Cannot display JSHint error (invalid line " + error.line + ")", error);
+ }
+ continue;
+ }
+
+ var start = error.character - 1, end = start + 1;
+ if (error.evidence) {
+ var index = error.evidence.substring(start).search(/.\b/);
+ if (index > -1) {
+ end += index;
+ }
+ }
+
+ // Convert to format expected by validation service
+ var hint = {
+ message: error.reason,
+ severity: error.code ? (error.code.startsWith('W') ? "warning" : "error") : "error",
+ from: CodeMirror.Pos(error.line - 1, start),
+ to: CodeMirror.Pos(error.line - 1, end)
+ };
+
+ output.push(hint);
+ }
+ }
+ }
+});
\ No newline at end of file
diff --git a/_server/CodeMirror/lint.css b/_server/CodeMirror/lint.css
index 037a451d..a9a0e65b 100644
--- a/_server/CodeMirror/lint.css
+++ b/_server/CodeMirror/lint.css
@@ -1,9 +1,9 @@
/* The lint marker gutter */
.CodeMirror-lint-markers {
width: 16px;
- }
-
- .CodeMirror-lint-tooltip {
+}
+
+.CodeMirror-lint-tooltip {
background-color: #ffd;
border: 1px solid black;
border-radius: 4px 4px 4px 4px;
@@ -23,24 +23,22 @@
-webkit-transition: opacity .4s;
-o-transition: opacity .4s;
-ms-transition: opacity .4s;
- }
-
- .CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
+}
+
+.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
background-position: left bottom;
background-repeat: repeat-x;
- }
-
- .CodeMirror-lint-mark-error {
- background-image:
- url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==")
- ;
- }
-
- .CodeMirror-lint-mark-warning {
+}
+
+.CodeMirror-lint-mark-error {
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==");
+}
+
+.CodeMirror-lint-mark-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
- }
-
- .CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
+}
+
+.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
@@ -49,25 +47,26 @@
width: 16px;
vertical-align: middle;
position: relative;
- }
-
- .CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
+}
+
+.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
padding-left: 18px;
background-position: top left;
background-repeat: no-repeat;
- }
-
- .CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
+}
+
+.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
- }
-
- .CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
+}
+
+.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
- }
-
- .CodeMirror-lint-marker-multiple {
+}
+
+.CodeMirror-lint-marker-multiple {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
background-repeat: no-repeat;
background-position: right bottom;
- width: 100%; height: 100%;
- }
\ No newline at end of file
+ width: 100%;
+ height: 100%;
+}
\ No newline at end of file
diff --git a/_server/CodeMirror/lint.js b/_server/CodeMirror/lint.js
index df8a60b2..53b1e07d 100644
--- a/_server/CodeMirror/lint.js
+++ b/_server/CodeMirror/lint.js
@@ -1,252 +1,277 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
-(function(mod) {
+(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
- mod(require("../../lib/codemirror"));
+ mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
- define(["../../lib/codemirror"], mod);
+ define(["../../lib/codemirror"], mod);
else // Plain browser env
- mod(CodeMirror);
- })(function(CodeMirror) {
+ mod(CodeMirror);
+})(function (CodeMirror) {
"use strict";
var GUTTER_ID = "CodeMirror-lint-markers";
-
+
function showTooltip(e, content) {
- var tt = document.createElement("div");
- tt.className = "CodeMirror-lint-tooltip";
- tt.appendChild(content.cloneNode(true));
- document.body.appendChild(tt);
-
- function position(e) {
- if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
- tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
- tt.style.left = (e.clientX + 5) + "px";
- }
- CodeMirror.on(document, "mousemove", position);
- position(e);
- if (tt.style.opacity != null) tt.style.opacity = 1;
- return tt;
+ var tt = document.createElement("div");
+ tt.className = "CodeMirror-lint-tooltip";
+ tt.appendChild(content.cloneNode(true));
+ document.body.appendChild(tt);
+
+ function position(e) {
+ if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
+ tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
+ tt.style.left = (e.clientX + 5) + "px";
+ }
+
+ CodeMirror.on(document, "mousemove", position);
+ position(e);
+ if (tt.style.opacity != null) tt.style.opacity = 1;
+ return tt;
}
+
function rm(elt) {
- if (elt.parentNode) elt.parentNode.removeChild(elt);
+ if (elt.parentNode) elt.parentNode.removeChild(elt);
}
+
function hideTooltip(tt) {
- if (!tt.parentNode) return;
- if (tt.style.opacity == null) rm(tt);
- tt.style.opacity = 0;
- setTimeout(function() { rm(tt); }, 600);
+ if (!tt.parentNode) return;
+ if (tt.style.opacity == null) rm(tt);
+ tt.style.opacity = 0;
+ setTimeout(function () {
+ rm(tt);
+ }, 600);
}
-
+
function showTooltipFor(e, content, node) {
- var tooltip = showTooltip(e, content);
- function hide() {
- CodeMirror.off(node, "mouseout", hide);
- if (tooltip) { hideTooltip(tooltip); tooltip = null; }
- }
- var poll = setInterval(function() {
- if (tooltip) for (var n = node;; n = n.parentNode) {
- if (n && n.nodeType == 11) n = n.host;
- if (n == document.body) return;
- if (!n) { hide(); break; }
+ var tooltip = showTooltip(e, content);
+
+ function hide() {
+ CodeMirror.off(node, "mouseout", hide);
+ if (tooltip) {
+ hideTooltip(tooltip);
+ tooltip = null;
+ }
}
- if (!tooltip) return clearInterval(poll);
- }, 400);
- CodeMirror.on(node, "mouseout", hide);
+
+ var poll = setInterval(function () {
+ if (tooltip) for (var n = node; ; n = n.parentNode) {
+ if (n && n.nodeType == 11) n = n.host;
+ if (n == document.body) return;
+ if (!n) {
+ hide();
+ break;
+ }
+ }
+ if (!tooltip) return clearInterval(poll);
+ }, 400);
+ CodeMirror.on(node, "mouseout", hide);
}
-
+
function LintState(cm, options, hasGutter) {
- this.marked = [];
- this.options = options;
- this.timeout = null;
- this.hasGutter = hasGutter;
- this.onMouseOver = function(e) { onMouseOver(cm, e); };
- this.waitingFor = 0
+ this.marked = [];
+ this.options = options;
+ this.timeout = null;
+ this.hasGutter = hasGutter;
+ this.onMouseOver = function (e) {
+ onMouseOver(cm, e);
+ };
+ this.waitingFor = 0
}
-
+
function parseOptions(_cm, options) {
- if (options instanceof Function) return {getAnnotations: options};
- if (!options || options === true) options = {};
- return options;
+ if (options instanceof Function) return {getAnnotations: options};
+ if (!options || options === true) options = {};
+ return options;
}
-
+
function clearMarks(cm) {
- var state = cm.state.lint;
- if (state.hasGutter) cm.clearGutter(GUTTER_ID);
- for (var i = 0; i < state.marked.length; ++i)
- state.marked[i].clear();
- state.marked.length = 0;
+ var state = cm.state.lint;
+ if (state.hasGutter) cm.clearGutter(GUTTER_ID);
+ for (var i = 0; i < state.marked.length; ++i)
+ state.marked[i].clear();
+ state.marked.length = 0;
}
-
+
function makeMarker(labels, severity, multiple, tooltips) {
- var marker = document.createElement("div"), inner = marker;
- marker.className = "CodeMirror-lint-marker-" + severity;
- if (multiple) {
- inner = marker.appendChild(document.createElement("div"));
- inner.className = "CodeMirror-lint-marker-multiple";
- }
-
- if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
- showTooltipFor(e, labels, inner);
- });
-
- return marker;
- }
-
- function getMaxSeverity(a, b) {
- if (a == "error") return a;
- else return b;
- }
-
- function groupByLine(annotations) {
- var lines = [];
- for (var i = 0; i < annotations.length; ++i) {
- var ann = annotations[i], line = ann.from.line;
- (lines[line] || (lines[line] = [])).push(ann);
- }
- return lines;
- }
-
- function annotationTooltip(ann) {
- var severity = ann.severity;
- if (!severity) severity = "error";
- var tip = document.createElement("div");
- tip.className = "CodeMirror-lint-message-" + severity;
- if (typeof ann.messageHTML != 'undefined') {
- tip.innerHTML = ann.messageHTML;
- } else {
- tip.appendChild(document.createTextNode(ann.message));
- }
- return tip;
- }
-
- function lintAsync(cm, getAnnotations, passOptions) {
- var state = cm.state.lint
- var id = ++state.waitingFor
- function abort() {
- id = -1
- cm.off("change", abort)
- }
- cm.on("change", abort)
- getAnnotations(cm.getValue(), function(annotations, arg2) {
- cm.off("change", abort)
- if (state.waitingFor != id) return
- if (arg2 && annotations instanceof CodeMirror) annotations = arg2
- cm.operation(function() {updateLinting(cm, annotations)})
- }, passOptions, cm);
- }
-
- function startLinting(cm) {
- var state = cm.state.lint, options = state.options;
- /*
- * Passing rules in `options` property prevents JSHint (and other linters) from complaining
- * about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc.
- */
- var passOptions = options.options || options;
- var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
- if (!getAnnotations) return;
- if (options.async || getAnnotations.async) {
- lintAsync(cm, getAnnotations, passOptions)
- } else {
- var annotations = getAnnotations(cm.getValue(), passOptions, cm);
- if (!annotations) return;
- if (annotations.then) annotations.then(function(issues) {
- cm.operation(function() {updateLinting(cm, issues)})
- });
- else cm.operation(function() {updateLinting(cm, annotations)})
- }
- }
-
- function updateLinting(cm, annotationsNotSorted) {
- clearMarks(cm);
- var state = cm.state.lint, options = state.options;
-
- var annotations = groupByLine(annotationsNotSorted);
-
- for (var line = 0; line < annotations.length; ++line) {
- var anns = annotations[line];
- if (!anns) continue;
-
- var maxSeverity = null;
- var tipLabel = state.hasGutter && document.createDocumentFragment();
-
- for (var i = 0; i < anns.length; ++i) {
- var ann = anns[i];
- var severity = ann.severity;
- if (!severity) severity = "error";
- maxSeverity = getMaxSeverity(maxSeverity, severity);
-
- if (options.formatAnnotation) ann = options.formatAnnotation(ann);
- if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
-
- if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
- className: "CodeMirror-lint-mark-" + severity,
- __annotation: ann
- }));
+ var marker = document.createElement("div"), inner = marker;
+ marker.className = "CodeMirror-lint-marker-" + severity;
+ if (multiple) {
+ inner = marker.appendChild(document.createElement("div"));
+ inner.className = "CodeMirror-lint-marker-multiple";
}
-
- if (state.hasGutter)
- cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
- state.options.tooltips));
- }
- if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
+
+ if (tooltips != false) CodeMirror.on(inner, "mouseover", function (e) {
+ showTooltipFor(e, labels, inner);
+ });
+
+ return marker;
}
-
- function onChange(cm) {
- var state = cm.state.lint;
- if (!state) return;
- clearTimeout(state.timeout);
- state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
+
+ function getMaxSeverity(a, b) {
+ if (a == "error") return a;
+ else return b;
}
-
- function popupTooltips(annotations, e) {
- var target = e.target || e.srcElement;
- var tooltip = document.createDocumentFragment();
- for (var i = 0; i < annotations.length; i++) {
- var ann = annotations[i];
- tooltip.appendChild(annotationTooltip(ann));
- }
- showTooltipFor(e, tooltip, target);
+
+ function groupByLine(annotations) {
+ var lines = [];
+ for (var i = 0; i < annotations.length; ++i) {
+ var ann = annotations[i], line = ann.from.line;
+ (lines[line] || (lines[line] = [])).push(ann);
+ }
+ return lines;
}
-
- function onMouseOver(cm, e) {
- var target = e.target || e.srcElement;
- if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
- var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
- var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
-
- var annotations = [];
- for (var i = 0; i < spans.length; ++i) {
- var ann = spans[i].__annotation;
- if (ann) annotations.push(ann);
- }
- if (annotations.length) popupTooltips(annotations, e);
+
+ function annotationTooltip(ann) {
+ var severity = ann.severity;
+ if (!severity) severity = "error";
+ var tip = document.createElement("div");
+ tip.className = "CodeMirror-lint-message-" + severity;
+ if (typeof ann.messageHTML != 'undefined') {
+ tip.innerHTML = ann.messageHTML;
+ } else {
+ tip.appendChild(document.createTextNode(ann.message));
+ }
+ return tip;
}
-
- CodeMirror.defineOption("lint", false, function(cm, val, old) {
- if (old && old != CodeMirror.Init) {
+
+ function lintAsync(cm, getAnnotations, passOptions) {
+ var state = cm.state.lint
+ var id = ++state.waitingFor
+
+ function abort() {
+ id = -1
+ cm.off("change", abort)
+ }
+
+ cm.on("change", abort)
+ getAnnotations(cm.getValue(), function (annotations, arg2) {
+ cm.off("change", abort)
+ if (state.waitingFor != id) return
+ if (arg2 && annotations instanceof CodeMirror) annotations = arg2
+ cm.operation(function () {
+ updateLinting(cm, annotations)
+ })
+ }, passOptions, cm);
+ }
+
+ function startLinting(cm) {
+ var state = cm.state.lint, options = state.options;
+ /*
+ * Passing rules in `options` property prevents JSHint (and other linters) from complaining
+ * about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc.
+ */
+ var passOptions = options.options || options;
+ var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
+ if (!getAnnotations) return;
+ if (options.async || getAnnotations.async) {
+ lintAsync(cm, getAnnotations, passOptions)
+ } else {
+ var annotations = getAnnotations(cm.getValue(), passOptions, cm);
+ if (!annotations) return;
+ if (annotations.then) annotations.then(function (issues) {
+ cm.operation(function () {
+ updateLinting(cm, issues)
+ })
+ });
+ else cm.operation(function () {
+ updateLinting(cm, annotations)
+ })
+ }
+ }
+
+ function updateLinting(cm, annotationsNotSorted) {
clearMarks(cm);
- if (cm.state.lint.options.lintOnChange !== false)
- cm.off("change", onChange);
- CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
- clearTimeout(cm.state.lint.timeout);
- delete cm.state.lint;
- }
-
- if (val) {
- var gutters = cm.getOption("gutters"), hasLintGutter = false;
- for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
- var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
- if (state.options.lintOnChange !== false)
- cm.on("change", onChange);
- if (state.options.tooltips != false && state.options.tooltips != "gutter")
- CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
-
- startLinting(cm);
- }
+ var state = cm.state.lint, options = state.options;
+
+ var annotations = groupByLine(annotationsNotSorted);
+
+ for (var line = 0; line < annotations.length; ++line) {
+ var anns = annotations[line];
+ if (!anns) continue;
+
+ var maxSeverity = null;
+ var tipLabel = state.hasGutter && document.createDocumentFragment();
+
+ for (var i = 0; i < anns.length; ++i) {
+ var ann = anns[i];
+ var severity = ann.severity;
+ if (!severity) severity = "error";
+ maxSeverity = getMaxSeverity(maxSeverity, severity);
+
+ if (options.formatAnnotation) ann = options.formatAnnotation(ann);
+ if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
+
+ if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
+ className: "CodeMirror-lint-mark-" + severity,
+ __annotation: ann
+ }));
+ }
+
+ if (state.hasGutter)
+ cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
+ state.options.tooltips));
+ }
+ if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
+ }
+
+ function onChange(cm) {
+ var state = cm.state.lint;
+ if (!state) return;
+ clearTimeout(state.timeout);
+ state.timeout = setTimeout(function () {
+ startLinting(cm);
+ }, state.options.delay || 500);
+ }
+
+ function popupTooltips(annotations, e) {
+ var target = e.target || e.srcElement;
+ var tooltip = document.createDocumentFragment();
+ for (var i = 0; i < annotations.length; i++) {
+ var ann = annotations[i];
+ tooltip.appendChild(annotationTooltip(ann));
+ }
+ showTooltipFor(e, tooltip, target);
+ }
+
+ function onMouseOver(cm, e) {
+ var target = e.target || e.srcElement;
+ if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
+ var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
+ var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
+
+ var annotations = [];
+ for (var i = 0; i < spans.length; ++i) {
+ var ann = spans[i].__annotation;
+ if (ann) annotations.push(ann);
+ }
+ if (annotations.length) popupTooltips(annotations, e);
+ }
+
+ CodeMirror.defineOption("lint", false, function (cm, val, old) {
+ if (old && old != CodeMirror.Init) {
+ clearMarks(cm);
+ if (cm.state.lint.options.lintOnChange !== false)
+ cm.off("change", onChange);
+ CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
+ clearTimeout(cm.state.lint.timeout);
+ delete cm.state.lint;
+ }
+
+ if (val) {
+ var gutters = cm.getOption("gutters"), hasLintGutter = false;
+ for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
+ var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
+ if (state.options.lintOnChange !== false)
+ cm.on("change", onChange);
+ if (state.options.tooltips != false && state.options.tooltips != "gutter")
+ CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
+
+ startLinting(cm);
+ }
});
-
- CodeMirror.defineExtension("performLint", function() {
- if (this.state.lint) startLinting(this);
+
+ CodeMirror.defineExtension("performLint", function () {
+ if (this.state.lint) startLinting(this);
});
- });
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/_server/CodeMirror/show-hint.css b/_server/CodeMirror/show-hint.css
index 88c93df1..1d26fbeb 100644
--- a/_server/CodeMirror/show-hint.css
+++ b/_server/CodeMirror/show-hint.css
@@ -3,34 +3,34 @@
z-index: 301;
overflow: hidden;
list-style: none;
-
+
margin: 0;
padding: 2px;
-
- -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
- -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
- box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+
+ -webkit-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
+ -moz-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
+ box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
border-radius: 3px;
border: 1px solid silver;
-
+
background: white;
font-size: 90%;
font-family: monospace;
-
+
max-height: 20em;
overflow-y: auto;
- }
-
- .CodeMirror-hint {
+}
+
+.CodeMirror-hint {
margin: 0;
padding: 0 4px;
border-radius: 2px;
white-space: pre;
color: black;
cursor: pointer;
- }
-
- li.CodeMirror-hint-active {
+}
+
+li.CodeMirror-hint-active {
background: #08f;
color: white;
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/_server/CodeMirror/show-hint.js b/_server/CodeMirror/show-hint.js
index d7cd9427..ddf0cfa7 100644
--- a/_server/CodeMirror/show-hint.js
+++ b/_server/CodeMirror/show-hint.js
@@ -1,432 +1,484 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
-(function(mod) {
+(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
- mod(require("../../lib/codemirror"));
+ mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
- define(["../../lib/codemirror"], mod);
+ define(["../../lib/codemirror"], mod);
else // Plain browser env
- mod(CodeMirror);
- })(function(CodeMirror) {
+ mod(CodeMirror);
+})(function (CodeMirror) {
"use strict";
-
- var HINT_ELEMENT_CLASS = "CodeMirror-hint";
+
+ var HINT_ELEMENT_CLASS = "CodeMirror-hint";
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
-
+
// This is the old interface, kept around for now to stay
// backwards-compatible.
- CodeMirror.showHint = function(cm, getHints, options) {
- if (!getHints) return cm.showHint(options);
- if (options && options.async) getHints.async = true;
- var newOpts = {hint: getHints};
- if (options) for (var prop in options) newOpts[prop] = options[prop];
- return cm.showHint(newOpts);
+ CodeMirror.showHint = function (cm, getHints, options) {
+ if (!getHints) return cm.showHint(options);
+ if (options && options.async) getHints.async = true;
+ var newOpts = {hint: getHints};
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
+ return cm.showHint(newOpts);
};
-
- CodeMirror.defineExtension("showHint", function(options) {
- options = parseOptions(this, this.getCursor("start"), options);
- var selections = this.listSelections()
- if (selections.length > 1) return;
- // By default, don't allow completion when something is selected.
- // A hint function can have a `supportsSelection` property to
- // indicate that it can handle selections.
- if (this.somethingSelected()) {
- if (!options.hint.supportsSelection) return;
- // Don't try with cross-line selections
- for (var i = 0; i < selections.length; i++)
- if (selections[i].head.line != selections[i].anchor.line) return;
- }
-
- if (this.state.completionActive) this.state.completionActive.close();
- var completion = this.state.completionActive = new Completion(this, options);
- if (!completion.options.hint) return;
-
- CodeMirror.signal(this, "startCompletion", this);
- completion.update(true);
+
+ CodeMirror.defineExtension("showHint", function (options) {
+ options = parseOptions(this, this.getCursor("start"), options);
+ var selections = this.listSelections()
+ if (selections.length > 1) return;
+ // By default, don't allow completion when something is selected.
+ // A hint function can have a `supportsSelection` property to
+ // indicate that it can handle selections.
+ if (this.somethingSelected()) {
+ if (!options.hint.supportsSelection) return;
+ // Don't try with cross-line selections
+ for (var i = 0; i < selections.length; i++)
+ if (selections[i].head.line != selections[i].anchor.line) return;
+ }
+
+ if (this.state.completionActive) this.state.completionActive.close();
+ var completion = this.state.completionActive = new Completion(this, options);
+ if (!completion.options.hint) return;
+
+ CodeMirror.signal(this, "startCompletion", this);
+ completion.update(true);
});
-
+
function Completion(cm, options) {
- this.cm = cm;
- this.options = options;
- this.widget = null;
- this.debounce = 0;
- this.tick = 0;
- this.startPos = this.cm.getCursor("start");
- this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
-
- var self = this;
- cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
+ this.cm = cm;
+ this.options = options;
+ this.widget = null;
+ this.debounce = 0;
+ this.tick = 0;
+ this.startPos = this.cm.getCursor("start");
+ this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
+
+ var self = this;
+ cm.on("cursorActivity", this.activityFunc = function () {
+ self.cursorActivity();
+ });
}
-
- var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
- return setTimeout(fn, 1000/60);
+
+ var requestAnimationFrame = window.requestAnimationFrame || function (fn) {
+ return setTimeout(fn, 1000 / 60);
};
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
-
+
Completion.prototype = {
- close: function() {
- if (!this.active()) return;
- this.cm.state.completionActive = null;
- this.tick = null;
- this.cm.off("cursorActivity", this.activityFunc);
-
- if (this.widget && this.data) CodeMirror.signal(this.data, "close");
- if (this.widget) this.widget.close();
- CodeMirror.signal(this.cm, "endCompletion", this.cm);
- },
-
- active: function() {
- return this.cm.state.completionActive == this;
- },
-
- pick: function(data, i) {
- var completion = data.list[i];
- if (completion.hint) completion.hint(this.cm, data, completion);
- else this.cm.replaceRange(getText(completion), completion.from || data.from,
- completion.to || data.to, "complete");
- CodeMirror.signal(data, "pick", completion);
- this.close();
- },
-
- cursorActivity: function() {
- if (this.debounce) {
- cancelAnimationFrame(this.debounce);
- this.debounce = 0;
- }
-
- var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
- if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
- pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
- (pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
- this.close();
- } else {
- var self = this;
- this.debounce = requestAnimationFrame(function() {self.update();});
- if (this.widget) this.widget.disable();
- }
- },
-
- update: function(first) {
- if (this.tick == null) return
- var self = this, myTick = ++this.tick
- fetchHints(this.options.hint, this.cm, this.options, function(data) {
- if (self.tick == myTick) self.finishUpdate(data, first)
- })
- },
-
- finishUpdate: function(data, first) {
- if (this.data) CodeMirror.signal(this.data, "update");
-
- var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
- if (this.widget) this.widget.close();
-
- this.data = data;
-
- if (data && data.list.length) {
- if (picked && data.list.length == 1) {
- this.pick(data, 0);
- } else {
- this.widget = new Widget(this, data);
- CodeMirror.signal(data, "shown");
- }
- }
- }
- };
-
- function parseOptions(cm, pos, options) {
- var editor = cm.options.hintOptions;
- var out = {};
- for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
- if (editor) for (var prop in editor)
- if (editor[prop] !== undefined) out[prop] = editor[prop];
- if (options) for (var prop in options)
- if (options[prop] !== undefined) out[prop] = options[prop];
- if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
- return out;
- }
-
- function getText(completion) {
- if (typeof completion == "string") return completion;
- else return completion.text;
- }
-
- function buildKeyMap(completion, handle) {
- var baseMap = {
- Up: function() {handle.moveFocus(-1);},
- Down: function() {handle.moveFocus(1);},
- PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
- PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
- Home: function() {handle.setFocus(0);},
- End: function() {handle.setFocus(handle.length - 1);},
- Enter: handle.pick,
- Tab: handle.pick,
- Esc: handle.close
- };
- var custom = completion.options.customKeys;
- var ourMap = custom ? {} : baseMap;
- function addBinding(key, val) {
- var bound;
- if (typeof val != "string")
- bound = function(cm) { return val(cm, handle); };
- // This mechanism is deprecated
- else if (baseMap.hasOwnProperty(val))
- bound = baseMap[val];
- else
- bound = val;
- ourMap[key] = bound;
- }
- if (custom)
- for (var key in custom) if (custom.hasOwnProperty(key))
- addBinding(key, custom[key]);
- var extra = completion.options.extraKeys;
- if (extra)
- for (var key in extra) if (extra.hasOwnProperty(key))
- addBinding(key, extra[key]);
- return ourMap;
- }
-
- function getHintElement(hintsElement, el) {
- while (el && el != hintsElement) {
- if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
- el = el.parentNode;
- }
- }
-
- function Widget(completion, data) {
- this.completion = completion;
- this.data = data;
- this.picked = false;
- var widget = this, cm = completion.cm;
-
- var hints = this.hints = document.createElement("ul");
- hints.className = "CodeMirror-hints";
- this.selectedHint = data.selectedHint || 0;
-
- var completions = data.list;
- for (var i = 0; i < completions.length; ++i) {
- var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
- var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
- if (cur.className != null) className = cur.className + " " + className;
- elt.className = className;
- if (cur.render) cur.render(elt, data, cur);
- else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
- elt.hintId = i;
- }
-
- var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
- var left = pos.left, top = pos.bottom, below = true;
- hints.style.left = left + "px";
- hints.style.top = top + "px";
- // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
- var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
- var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
- (completion.options.container || document.body).appendChild(hints);
- var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
- var scrolls = hints.scrollHeight > hints.clientHeight + 1
- var startScroll = cm.getScrollInfo();
-
- if (overlapY > 0) {
- var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
- if (curTop - height > 0) { // Fits above cursor
- hints.style.top = (top = pos.top - height) + "px";
- below = false;
- } else if (height > winH) {
- hints.style.height = (winH - 5) + "px";
- hints.style.top = (top = pos.bottom - box.top) + "px";
- var cursor = cm.getCursor();
- if (data.from.ch != cursor.ch) {
- pos = cm.cursorCoords(cursor);
- hints.style.left = (left = pos.left) + "px";
- box = hints.getBoundingClientRect();
- }
- }
- }
- var overlapX = box.right - winW;
- if (overlapX > 0) {
- if (box.right - box.left > winW) {
- hints.style.width = (winW - 5) + "px";
- overlapX -= (box.right - box.left) - winW;
- }
- hints.style.left = (left = pos.left - overlapX) + "px";
- }
- if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
- node.style.paddingRight = cm.display.nativeBarWidth + "px"
-
- cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
- moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
- setFocus: function(n) { widget.changeActive(n); },
- menuSize: function() { return widget.screenAmount(); },
- length: completions.length,
- close: function() { completion.close(); },
- pick: function() { widget.pick(); },
- data: data
- }));
-
- if (completion.options.closeOnUnfocus) {
- var closingOnBlur;
- cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
- cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
- }
-
- cm.on("scroll", this.onScroll = function() {
- var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
- var newTop = top + startScroll.top - curScroll.top;
- var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
- if (!below) point += hints.offsetHeight;
- if (point <= editor.top || point >= editor.bottom) return completion.close();
- hints.style.top = newTop + "px";
- hints.style.left = (left + startScroll.left - curScroll.left) + "px";
- });
-
- CodeMirror.on(hints, "dblclick", function(e) {
- var t = getHintElement(hints, e.target || e.srcElement);
- if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
- });
-
- CodeMirror.on(hints, "click", function(e) {
- var t = getHintElement(hints, e.target || e.srcElement);
- if (t && t.hintId != null) {
- widget.changeActive(t.hintId);
- if (completion.options.completeOnSingleClick) widget.pick();
- }
- });
-
- CodeMirror.on(hints, "mousedown", function() {
- setTimeout(function(){cm.focus();}, 20);
- });
-
- CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
- return true;
- }
-
- Widget.prototype = {
- close: function() {
- if (this.completion.widget != this) return;
- this.completion.widget = null;
- this.hints.parentNode.removeChild(this.hints);
- this.completion.cm.removeKeyMap(this.keyMap);
-
- var cm = this.completion.cm;
- if (this.completion.options.closeOnUnfocus) {
- cm.off("blur", this.onBlur);
- cm.off("focus", this.onFocus);
- }
- cm.off("scroll", this.onScroll);
- },
-
- disable: function() {
- this.completion.cm.removeKeyMap(this.keyMap);
- var widget = this;
- this.keyMap = {Enter: function() { widget.picked = true; }};
- this.completion.cm.addKeyMap(this.keyMap);
- },
-
- pick: function() {
- this.completion.pick(this.data, this.selectedHint);
- },
-
- changeActive: function(i, avoidWrap) {
- if (i >= this.data.list.length)
- i = avoidWrap ? this.data.list.length - 1 : 0;
- else if (i < 0)
- i = avoidWrap ? 0 : this.data.list.length - 1;
- if (this.selectedHint == i) return;
- var node = this.hints.childNodes[this.selectedHint];
- node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
- node = this.hints.childNodes[this.selectedHint = i];
- node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
- if (node.offsetTop < this.hints.scrollTop)
- this.hints.scrollTop = node.offsetTop - 3;
- else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
- this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
- CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
- },
-
- screenAmount: function() {
- return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
- }
- };
-
- function applicableHelpers(cm, helpers) {
- if (!cm.somethingSelected()) return helpers
- var result = []
- for (var i = 0; i < helpers.length; i++)
- if (helpers[i].supportsSelection) result.push(helpers[i])
- return result
- }
-
- function fetchHints(hint, cm, options, callback) {
- if (hint.async) {
- hint(cm, callback, options)
- } else {
- var result = hint(cm, options)
- if (result && result.then) result.then(callback)
- else callback(result)
- }
- }
-
- function resolveAutoHints(cm, pos) {
- var helpers = cm.getHelpers(pos, "hint"), words
- if (helpers.length) {
- var resolved = function(cm, callback, options) {
- var app = applicableHelpers(cm, helpers);
- function run(i) {
- if (i == app.length) return callback(null)
- fetchHints(app[i], cm, options, function(result) {
- if (result && result.list.length > 0) callback(result)
- else run(i + 1)
+ close: function () {
+ if (!this.active()) return;
+ this.cm.state.completionActive = null;
+ this.tick = null;
+ this.cm.off("cursorActivity", this.activityFunc);
+
+ if (this.widget && this.data) CodeMirror.signal(this.data, "close");
+ if (this.widget) this.widget.close();
+ CodeMirror.signal(this.cm, "endCompletion", this.cm);
+ },
+
+ active: function () {
+ return this.cm.state.completionActive == this;
+ },
+
+ pick: function (data, i) {
+ var completion = data.list[i];
+ if (completion.hint) completion.hint(this.cm, data, completion);
+ else this.cm.replaceRange(getText(completion), completion.from || data.from,
+ completion.to || data.to, "complete");
+ CodeMirror.signal(data, "pick", completion);
+ this.close();
+ },
+
+ cursorActivity: function () {
+ if (this.debounce) {
+ cancelAnimationFrame(this.debounce);
+ this.debounce = 0;
+ }
+
+ var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
+ if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
+ pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
+ (pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
+ this.close();
+ } else {
+ var self = this;
+ this.debounce = requestAnimationFrame(function () {
+ self.update();
+ });
+ if (this.widget) this.widget.disable();
+ }
+ },
+
+ update: function (first) {
+ if (this.tick == null) return
+ var self = this, myTick = ++this.tick
+ fetchHints(this.options.hint, this.cm, this.options, function (data) {
+ if (self.tick == myTick) self.finishUpdate(data, first)
})
- }
- run(0)
+ },
+
+ finishUpdate: function (data, first) {
+ if (this.data) CodeMirror.signal(this.data, "update");
+
+ var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
+ if (this.widget) this.widget.close();
+
+ this.data = data;
+
+ if (data && data.list.length) {
+ if (picked && data.list.length == 1) {
+ this.pick(data, 0);
+ } else {
+ this.widget = new Widget(this, data);
+ CodeMirror.signal(data, "shown");
+ }
+ }
}
- resolved.async = true
- resolved.supportsSelection = true
- return resolved
- } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
- return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
- } else if (CodeMirror.hint.anyword) {
- return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
- } else {
- return function() {}
- }
- }
-
- CodeMirror.registerHelper("hint", "auto", {
- resolve: resolveAutoHints
- });
-
- CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
- var cur = cm.getCursor(), token = cm.getTokenAt(cur);
- var to = CodeMirror.Pos(cur.line, token.end);
- if (token.string && /\w/.test(token.string[token.string.length - 1])) {
- var term = token.string, from = CodeMirror.Pos(cur.line, token.start);
- } else {
- var term = "", from = to;
- }
- var found = [];
- for (var i = 0; i < options.words.length; i++) {
- var word = options.words[i];
- if (word.slice(0, term.length) == term)
- found.push(word);
- }
-
- if (found.length) return {list: found, from: from, to: to};
- });
-
- CodeMirror.commands.autocomplete = CodeMirror.showHint;
-
- var defaultOptions = {
- hint: CodeMirror.hint.auto,
- completeSingle: true,
- alignWithWord: true,
- closeCharacters: /[\s()\[\]{};:>,]/,
- closeOnUnfocus: true,
- completeOnSingleClick: true,
- container: null,
- customKeys: null,
- extraKeys: null
};
-
+
+ function parseOptions(cm, pos, options) {
+ var editor = cm.options.hintOptions;
+ var out = {};
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
+ if (editor) for (var prop in editor)
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
+ if (options) for (var prop in options)
+ if (options[prop] !== undefined) out[prop] = options[prop];
+ if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
+ return out;
+ }
+
+ function getText(completion) {
+ if (typeof completion == "string") return completion;
+ else return completion.text;
+ }
+
+ function buildKeyMap(completion, handle) {
+ var baseMap = {
+ Up: function () {
+ handle.moveFocus(-1);
+ },
+ Down: function () {
+ handle.moveFocus(1);
+ },
+ PageUp: function () {
+ handle.moveFocus(-handle.menuSize() + 1, true);
+ },
+ PageDown: function () {
+ handle.moveFocus(handle.menuSize() - 1, true);
+ },
+ Home: function () {
+ handle.setFocus(0);
+ },
+ End: function () {
+ handle.setFocus(handle.length - 1);
+ },
+ Enter: handle.pick,
+ Tab: handle.pick,
+ Esc: handle.close
+ };
+ var custom = completion.options.customKeys;
+ var ourMap = custom ? {} : baseMap;
+
+ function addBinding(key, val) {
+ var bound;
+ if (typeof val != "string")
+ bound = function (cm) {
+ return val(cm, handle);
+ };
+ // This mechanism is deprecated
+ else if (baseMap.hasOwnProperty(val))
+ bound = baseMap[val];
+ else
+ bound = val;
+ ourMap[key] = bound;
+ }
+
+ if (custom)
+ for (var key in custom) if (custom.hasOwnProperty(key))
+ addBinding(key, custom[key]);
+ var extra = completion.options.extraKeys;
+ if (extra)
+ for (var key in extra) if (extra.hasOwnProperty(key))
+ addBinding(key, extra[key]);
+ return ourMap;
+ }
+
+ function getHintElement(hintsElement, el) {
+ while (el && el != hintsElement) {
+ if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
+ el = el.parentNode;
+ }
+ }
+
+ function Widget(completion, data) {
+ this.completion = completion;
+ this.data = data;
+ this.picked = false;
+ var widget = this, cm = completion.cm;
+
+ var hints = this.hints = document.createElement("ul");
+ hints.className = "CodeMirror-hints";
+ this.selectedHint = data.selectedHint || 0;
+
+ var completions = data.list;
+ for (var i = 0; i < completions.length; ++i) {
+ var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
+ var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
+ if (cur.className != null) className = cur.className + " " + className;
+ elt.className = className;
+ if (cur.render) cur.render(elt, data, cur);
+ else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
+ elt.hintId = i;
+ }
+
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
+ var left = pos.left, top = pos.bottom, below = true;
+ hints.style.left = left + "px";
+ hints.style.top = top + "px";
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
+ var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
+ var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
+ (completion.options.container || document.body).appendChild(hints);
+ var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
+ var scrolls = hints.scrollHeight > hints.clientHeight + 1
+ var startScroll = cm.getScrollInfo();
+
+ if (overlapY > 0) {
+ var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
+ if (curTop - height > 0) { // Fits above cursor
+ hints.style.top = (top = pos.top - height) + "px";
+ below = false;
+ } else if (height > winH) {
+ hints.style.height = (winH - 5) + "px";
+ hints.style.top = (top = pos.bottom - box.top) + "px";
+ var cursor = cm.getCursor();
+ if (data.from.ch != cursor.ch) {
+ pos = cm.cursorCoords(cursor);
+ hints.style.left = (left = pos.left) + "px";
+ box = hints.getBoundingClientRect();
+ }
+ }
+ }
+ var overlapX = box.right - winW;
+ if (overlapX > 0) {
+ if (box.right - box.left > winW) {
+ hints.style.width = (winW - 5) + "px";
+ overlapX -= (box.right - box.left) - winW;
+ }
+ hints.style.left = (left = pos.left - overlapX) + "px";
+ }
+ if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
+ node.style.paddingRight = cm.display.nativeBarWidth + "px"
+
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
+ moveFocus: function (n, avoidWrap) {
+ widget.changeActive(widget.selectedHint + n, avoidWrap);
+ },
+ setFocus: function (n) {
+ widget.changeActive(n);
+ },
+ menuSize: function () {
+ return widget.screenAmount();
+ },
+ length: completions.length,
+ close: function () {
+ completion.close();
+ },
+ pick: function () {
+ widget.pick();
+ },
+ data: data
+ }));
+
+ if (completion.options.closeOnUnfocus) {
+ var closingOnBlur;
+ cm.on("blur", this.onBlur = function () {
+ closingOnBlur = setTimeout(function () {
+ completion.close();
+ }, 100);
+ });
+ cm.on("focus", this.onFocus = function () {
+ clearTimeout(closingOnBlur);
+ });
+ }
+
+ cm.on("scroll", this.onScroll = function () {
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
+ var newTop = top + startScroll.top - curScroll.top;
+ var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
+ if (!below) point += hints.offsetHeight;
+ if (point <= editor.top || point >= editor.bottom) return completion.close();
+ hints.style.top = newTop + "px";
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
+ });
+
+ CodeMirror.on(hints, "dblclick", function (e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {
+ widget.changeActive(t.hintId);
+ widget.pick();
+ }
+ });
+
+ CodeMirror.on(hints, "click", function (e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {
+ widget.changeActive(t.hintId);
+ if (completion.options.completeOnSingleClick) widget.pick();
+ }
+ });
+
+ CodeMirror.on(hints, "mousedown", function () {
+ setTimeout(function () {
+ cm.focus();
+ }, 20);
+ });
+
+ CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
+ return true;
+ }
+
+ Widget.prototype = {
+ close: function () {
+ if (this.completion.widget != this) return;
+ this.completion.widget = null;
+ this.hints.parentNode.removeChild(this.hints);
+ this.completion.cm.removeKeyMap(this.keyMap);
+
+ var cm = this.completion.cm;
+ if (this.completion.options.closeOnUnfocus) {
+ cm.off("blur", this.onBlur);
+ cm.off("focus", this.onFocus);
+ }
+ cm.off("scroll", this.onScroll);
+ },
+
+ disable: function () {
+ this.completion.cm.removeKeyMap(this.keyMap);
+ var widget = this;
+ this.keyMap = {
+ Enter: function () {
+ widget.picked = true;
+ }
+ };
+ this.completion.cm.addKeyMap(this.keyMap);
+ },
+
+ pick: function () {
+ this.completion.pick(this.data, this.selectedHint);
+ },
+
+ changeActive: function (i, avoidWrap) {
+ if (i >= this.data.list.length)
+ i = avoidWrap ? this.data.list.length - 1 : 0;
+ else if (i < 0)
+ i = avoidWrap ? 0 : this.data.list.length - 1;
+ if (this.selectedHint == i) return;
+ var node = this.hints.childNodes[this.selectedHint];
+ node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
+ node = this.hints.childNodes[this.selectedHint = i];
+ node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
+ if (node.offsetTop < this.hints.scrollTop)
+ this.hints.scrollTop = node.offsetTop - 3;
+ else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
+ this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
+ CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
+ },
+
+ screenAmount: function () {
+ return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
+ }
+ };
+
+ function applicableHelpers(cm, helpers) {
+ if (!cm.somethingSelected()) return helpers
+ var result = []
+ for (var i = 0; i < helpers.length; i++)
+ if (helpers[i].supportsSelection) result.push(helpers[i])
+ return result
+ }
+
+ function fetchHints(hint, cm, options, callback) {
+ if (hint.async) {
+ hint(cm, callback, options)
+ } else {
+ var result = hint(cm, options)
+ if (result && result.then) result.then(callback)
+ else callback(result)
+ }
+ }
+
+ function resolveAutoHints(cm, pos) {
+ var helpers = cm.getHelpers(pos, "hint"), words
+ if (helpers.length) {
+ var resolved = function (cm, callback, options) {
+ var app = applicableHelpers(cm, helpers);
+
+ function run(i) {
+ if (i == app.length) return callback(null)
+ fetchHints(app[i], cm, options, function (result) {
+ if (result && result.list.length > 0) callback(result)
+ else run(i + 1)
+ })
+ }
+
+ run(0)
+ }
+ resolved.async = true
+ resolved.supportsSelection = true
+ return resolved
+ } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
+ return function (cm) {
+ return CodeMirror.hint.fromList(cm, {words: words})
+ }
+ } else if (CodeMirror.hint.anyword) {
+ return function (cm, options) {
+ return CodeMirror.hint.anyword(cm, options)
+ }
+ } else {
+ return function () {
+ }
+ }
+ }
+
+ CodeMirror.registerHelper("hint", "auto", {
+ resolve: resolveAutoHints
+ });
+
+ CodeMirror.registerHelper("hint", "fromList", function (cm, options) {
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur);
+ var to = CodeMirror.Pos(cur.line, token.end);
+ if (token.string && /\w/.test(token.string[token.string.length - 1])) {
+ var term = token.string, from = CodeMirror.Pos(cur.line, token.start);
+ } else {
+ var term = "", from = to;
+ }
+ var found = [];
+ for (var i = 0; i < options.words.length; i++) {
+ var word = options.words[i];
+ if (word.slice(0, term.length) == term)
+ found.push(word);
+ }
+
+ if (found.length) return {list: found, from: from, to: to};
+ });
+
+ CodeMirror.commands.autocomplete = CodeMirror.showHint;
+
+ var defaultOptions = {
+ hint: CodeMirror.hint.auto,
+ completeSingle: true,
+ alignWithWord: true,
+ closeCharacters: /[\s()\[\]{};:>,]/,
+ closeOnUnfocus: true,
+ completeOnSingleClick: true,
+ container: null,
+ customKeys: null,
+ extraKeys: null
+ };
+
CodeMirror.defineOption("hintOptions", null);
- });
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/_server/blockly/blockly_compressed.js b/_server/blockly/blockly_compressed.js
index 75586e3d..6478672d 100644
--- a/_server/blockly/blockly_compressed.js
+++ b/_server/blockly/blockly_compressed.js
@@ -1,1604 +1,18850 @@
// Do not edit this file; automatically generated by build.py.
'use strict';
-var $jscomp=$jscomp||{};$jscomp.scope={};var COMPILED=!0,goog=goog||{};goog.global=this;goog.isDef=function(a){return void 0!==a};goog.isString=function(a){return"string"==typeof a};goog.isBoolean=function(a){return"boolean"==typeof a};goog.isNumber=function(a){return"number"==typeof a};
-goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&goog.isDef(b)?c[d]=b:c=c[d]&&c[d]!==Object.prototype[d]?c[d]:c[d]={}};
-goog.define=function(a,b){var c=b;COMPILED||(goog.global.CLOSURE_UNCOMPILED_DEFINES&&void 0===goog.global.CLOSURE_UNCOMPILED_DEFINES.nodeType&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_UNCOMPILED_DEFINES,a)?c=goog.global.CLOSURE_UNCOMPILED_DEFINES[a]:goog.global.CLOSURE_DEFINES&&void 0===goog.global.CLOSURE_DEFINES.nodeType&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]));goog.exportPath_(a,c)};goog.DEBUG=!1;goog.LOCALE="en";
-goog.TRUSTED_SITE=!0;goog.STRICT_MODE_COMPATIBLE=!1;goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG;goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1;goog.provide=function(a){if(goog.isInModuleLoader_())throw Error("goog.provide can not be used within a goog.module.");if(!COMPILED&&goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');goog.constructNamespace_(a)};
-goog.constructNamespace_=function(a,b){if(!COMPILED){delete goog.implicitNamespaces_[a];for(var c=a;(c=c.substring(0,c.lastIndexOf(".")))&&!goog.getObjectByName(c);)goog.implicitNamespaces_[c]=!0}goog.exportPath_(a,b)};goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/;
-goog.module=function(a){if(!goog.isString(a)||!a||-1==a.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInModuleLoader_())throw Error("Module "+a+" has been loaded incorrectly. Note, modules cannot be loaded as normal scripts. They require some kind of pre-processing step. You're likely trying to load a module via a script tag or as a part of a concatenated bundle without rewriting the module. For more info see: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.");if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module.");
-goog.moduleLoaderState_.moduleName=a;if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a]}};goog.module.get=function(a){return goog.module.getInternal_(a)};goog.module.getInternal_=function(a){if(!COMPILED){if(a in goog.loadedModules_)return goog.loadedModules_[a];if(!goog.implicitNamespaces_[a])return a=goog.getObjectByName(a),null!=a?a:null}return null};goog.moduleLoaderState_=null;
-goog.isInModuleLoader_=function(){return null!=goog.moduleLoaderState_};goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0};
-goog.setTestOnly=function(a){if(goog.DISALLOW_TEST_ONLY_CODE)throw a=a||"",Error("Importing test-only code into non-debug environment"+(a?": "+a:"."));};goog.forwardDeclare=function(a){};COMPILED||(goog.isProvided_=function(a){return a in goog.loadedModules_||!goog.implicitNamespaces_[a]&&goog.isDefAndNotNull(goog.getObjectByName(a))},goog.implicitNamespaces_={"goog.module":!0});
-goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e=0;e>>0);goog.uidCounter_=0;goog.getHashCode=goog.getUid;
-goog.removeHashCode=goog.removeUid;goog.cloneObject=function(a){var b=goog.typeOf(a);if("object"==b||"array"==b){if(a.clone)return a.clone();b="array"==b?[]:{};for(var c in a)b[c]=goog.cloneObject(a[c]);return b}return a};goog.bindNative_=function(a,b,c){return a.call.apply(a.bind,arguments)};
-goog.bindJs_=function(a,b,c){if(!a)throw Error();if(2Number(a[1])?!1:b('(()=>{"use strict";class X{constructor(){if(new.target!=String)throw 1;this.x=42}}let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof String))throw 1;for(const a of[2,3]){if(a==2)continue;function f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()==3}})()')});a("es6-impl",function(){return!0});a("es7",function(){return b("2 ** 2 == 4")});a("es8",function(){return b("async () => 1, true")});return c},goog.Transpiler.prototype.needsTranspile=
-function(a){if("always"==goog.TRANSPILE)return!0;if("never"==goog.TRANSPILE)return!1;this.requiresTranspilation_||(this.requiresTranspilation_=this.createRequiresTranspilation_());if(a in this.requiresTranspilation_)return this.requiresTranspilation_[a];throw Error("Unknown language mode: "+a);},goog.Transpiler.prototype.transpile=function(a,b){return goog.transpile_(a,b)},goog.transpiler_=new goog.Transpiler,goog.DebugLoader=function(){this.dependencies_={loadFlags:{},nameToPath:{},requires:{},visited:{},
-written:{},deferred:{}};this.oldIeWaiting_=!1;this.queuedModules_=[];this.lastNonModuleScriptIndex_=0},goog.DebugLoader.IS_OLD_IE_=!(goog.global.atob||!goog.global.document||!goog.global.document.all),goog.DebugLoader.prototype.earlyProcessLoad=function(a){goog.DebugLoader.IS_OLD_IE_&&this.maybeProcessDeferredDep_(a)},goog.DebugLoader.prototype.load=function(a){var b=this.getPathFromDeps_(a);if(b){var c=function(a){if(!(a in f.written||a in f.visited)){f.visited[a]=!0;if(a in f.requires)for(var b in f.requires[a])if(!g.isProvided(b))if(b in
-f.nameToPath)c(f.nameToPath[b]);else throw Error("Undefined nameToPath for "+b);a in e||(e[a]=!0,d.push(a))}},d=[],e={},f=this.dependencies_,g=this;c(b);for(a=0;a\x3c/script>')},goog.DebugLoader.prototype.appendScriptSrcNode_=function(a){var b=goog.global.document,c=b.createElement("script");c.type="text/javascript";c.src=a;c.defer=!1;c.async=!1;b.head.appendChild(c)},goog.DebugLoader.prototype.writeScriptTag_=function(a,b){if(this.inHtmlDocument()){var c=goog.global.document;if(!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING&&
-"complete"==c.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}if(void 0===b)if(goog.DebugLoader.IS_OLD_IE_){this.oldIeWaiting_=!0;var d=" onreadystatechange='goog.debugLoader_.onScriptLoad_(this, "+ ++this.lastNonModuleScriptIndex_+")' ";c.write('
-
-
+
+
+