Skip to content

Commit

Permalink
Merge branch 'v2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
unanmed committed Jul 10, 2022
2 parents 49f7e52 + 9f78c0c commit 232a336
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 65 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ HTML5 canvas制作的魔塔样板,支持全平台游戏!
* [Demo / 样板效果](https://ckcz123.com/games/template/)
* [Docs / 使用文档说明](https://ckcz123.github.io/mota-js/)
* [Video / 视频教程](https://www.bilibili.com/video/av32781473/)
* [Video / 新版视频教程](https://www.bilibili.com/video/BV1SB4y1p7bg?share_source=copy_web)
* [Video / 脚本教程](https://www.bilibili.com/video/BV1uL411J7yZ?share_source=copy_web)

![样板](./docs/sample0.png)

Expand Down Expand Up @@ -65,6 +67,37 @@ HTML5 canvas制作的魔塔样板,支持全平台游戏!

## 更新说明

### 2022.7.10 HTML5魔塔样板V2.9.1

* [x] 修复更新状态栏延迟到下一动画帧引发的一系列bug,修改为增加一个是否立即更新的参数
* [x] 修复resize导致canvas被清空的bug
* [x] 修复怪物属性栏光环叠加的说明bug
* [x] 修复自2.7.3增加薄墙以来导致的terrains模糊
* [x] 修复手机端绘制缩略图的模糊问题
* [x] 更新部分文档
* [x] 增加F8为debug按键,不删除F7,避免部分浏览器的按键冲突
* [x] 删除脚本编辑中多行注释中的带缩进空行,避免出现编辑器的神秘bug
* [x] 修复自定义js脚本中使用insertAction导致转换时出现中文导致脚本不可用的bug

### 2022.2.2 HTML5魔塔样板V2.9

* [x] 修复浏览地图使用楼传可无视楼梯边的bug
* [x] 修复utils.js里面的语法bug
* [x] 修复设置前景层背景层的图块后立刻刷新地图导致图块重新出现的bug
* [x] 修复商店长按与keyUp冲突的bug
* [x] 修复图片缩放以后缩放浏览器导致图片大小还原的bug
* [x] 修复缩略图不高清的bug
* [x] 修复大怪物的boxAnimate的bug
* [x] 优化updateStatusBar的性能
* [x] \i支持enemy48和npc48
* [x] 启动服务加入魔塔小课堂
* [x] 分离怪物属性,将value分离成zone laser repulse等
* [x] 复写可以新增参数
* [x] 杀掉main.log
* [x] 完善runtime.d.ts,建议使用vscode进行编辑脚本
* [x] 自动缩放最大化
* [x] 缩放最高支持2.5倍缩放

### 2021.9.1 HTML5魔塔样板V2.8.2

* [x] 在游戏中,可以在大地图长按后拖动预览。(超大地图福音!)
Expand Down
3 changes: 2 additions & 1 deletion _docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ ckcz123)特意制作了这样一部HTML5魔塔样板。

继续查看文档的详细介绍,让你学会如何使用这一个样板来制作属于自己的HTML5魔塔,或者……任何非即时的网格地图游戏。

本说明文档配有较为过时的B站视频教程,可供参考:[https://www.bilibili.com/video/av32781473/](https://www.bilibili.com/video/av32781473/)
* [新版视频教程](https://www.bilibili.com/video/BV1SB4y1p7bg?share_source=copy_web)
* [脚本教程](https://www.bilibili.com/video/BV1uL411J7yZ?share_source=copy_web)

==========================================================================================

Expand Down
2 changes: 1 addition & 1 deletion _docs/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

在V2.6版本中,基本对整个项目代码进行了重写,更加方便造塔者的使用。

可配合基础js教学视频 https://www.bilibili.com/video/BV1uL411J7yZ/ 使用。
* [脚本教程视频](https://www.bilibili.com/video/BV1uL411J7yZ?share_source=copy_web)

## 控制台的使用

Expand Down
3 changes: 3 additions & 0 deletions _docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

?> 在这一节中,将详细介绍做一部塔的流程。现在,让我们来做一部单层塔!

* [新版视频教程](https://www.bilibili.com/video/BV1SB4y1p7bg?share_source=copy_web)
* [脚本教程](https://www.bilibili.com/video/BV1uL411J7yZ?share_source=copy_web)

## 前置需求
你需要满足如下条件才能进行制作:[样板下载地址](https://github.com/ckcz123/mota-js/releases)
1. 操作系统:
Expand Down
6 changes: 3 additions & 3 deletions _server/CodeMirror/defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2408,8 +2408,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!type": "fn(type?: string, level?: number)"
},
"updateStatusBar": {
"!doc": "立刻刷新状态栏和地图显伤<br/>doNotCheckAutoEvents: 是否不检查自动事件",
"!type": "fn(doNotCheckAutoEvents?: bool)"
"!doc": "刷新状态栏和地图显伤<br/>doNotCheckAutoEvents: 是否不检查自动事件",
"!type": "fn(doNotCheckAutoEvents?: bool, immediate?: bool)"
},
"autosave": {
"!doc": "自动存档",
Expand Down Expand Up @@ -3393,7 +3393,7 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!doc": "负责一切UI界面的绘制。主要包括三个部分:<br/>- 设置某个画布的属性与在某个画布上绘制的相关API<br/>- 具体的某个UI界面的绘制<br/>- 动态创建画布相关的API",
"resizeCanvas": {
"!doc": "重新设置一个自定义画布的大小",
"!type": "fn(name: string, x: number, y: number)"
"!type": "fn(name: string, x?: number, y?: number, styleOnly?: bool, isTempCanvas?: bool)"
},
"deleteCanvas": {
"!doc": "删除一个自定义画布<br/>name: 画布名,也可以传入一个函数对所有画布进行筛选",
Expand Down
11 changes: 7 additions & 4 deletions _server/MotaActionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,11 +1421,14 @@ MotaActionFunctions.workspace = function(){return workspace}

MotaActionFunctions.parse = function(obj,type) {
try {
obj = JSON.parse(MotaActionFunctions.replaceToName(JSON.stringify(obj)));
} catch (e) {}
obj = obj.map(function (e) {
if (e.type == "function") return e;
else return JSON.parse(MotaActionFunctions.replaceToName(JSON.stringify(e)));
});
} catch (e) { }
MotaActionFunctions.workspace().clear();
xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event');
xml = Blockly.Xml.textToDom('<xml>'+xml_text+'</xml>');
xml_text = MotaActionFunctions.actionParser.parse(obj, type || 'event');
xml = Blockly.Xml.textToDom('<xml>' + xml_text + '</xml>');
Blockly.Xml.domToWorkspace(xml, MotaActionFunctions.workspace());
}

Expand Down
4 changes: 2 additions & 2 deletions _server/table/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"haloAdd": {
"_leaf": true,
"_type": "checkbox",
"_docs": "吸血加到自身",
"_docs": "光环是否叠加",
"_data": "光环是否叠加"
},
"atkValue": {
Expand Down Expand Up @@ -661,7 +661,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"ratio": {
"_leaf": true,
"_type": "textarea",
"_range": "thiseval==~~thiseval && thiseval>=0",
"_range": "thiseval <= Number.MAX_SAFE_INTEGER && thiseval>=0",
"_docs": "宝石血瓶效果",
"_data": "每一层的宝石/血瓶效果,即获得宝石和血瓶时框内\"ratio\"的值。"
}
Expand Down
6 changes: 6 additions & 0 deletions _server/table/data.comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
},
"_data": "状态栏显示项"
},
"autoScale": {
"_leaf": true,
"_type": "checkbox",
"_docs": "自动缩放最大化",
"_data": "是否自动缩放最大化,关闭后不再最大化"
},
"extendToolbar": {
"_leaf": true,
"_type": "checkbox",
Expand Down
71 changes: 42 additions & 29 deletions libs/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ control.prototype._init = function () {
this.replayActions = [];
this.weathers = {};
this.resizes = [];
this.needUpdate = false;
this.noAutoEvents = true;
// --- 注册系统的animationFrame
this.registerAnimationFrame("totalTime", false, this._animationFrame_totalTime);
Expand All @@ -29,7 +28,6 @@ control.prototype._init = function () {
this.registerAnimationFrame("weather", true, this._animationFrame_weather);
this.registerAnimationFrame("tip", true, this._animateFrame_tip);
this.registerAnimationFrame("parallelDo", false, this._animationFrame_parallelDo);
this.registerAnimationFrame("updateStatusBar", true, this.updateStatusBar_update);
// --- 注册系统的天气
this.registerWeather("rain", this._weather_rain, this._animationFrame_weather_rain);
this.registerWeather("snow", this._weather_snow, this._animationFrame_weather_snow);
Expand Down Expand Up @@ -1134,11 +1132,11 @@ control.prototype.checkBlock = function () {
core.status.hero.statistics.extraDamage += damage;
if (core.status.hero.hp <= 0) {
core.status.hero.hp = 0;
core.updateStatusBar();
core.updateStatusBar(false, true);
core.events.lose();
return;
} else {
core.updateStatusBar();
core.updateStatusBar(false, true);
}
}
this._checkBlock_ambush(core.status.checkBlock.ambush[loc]);
Expand Down Expand Up @@ -1350,7 +1348,7 @@ control.prototype.startReplay = function (list) {
core.createCanvas('replay', 0, core.__PIXELS__ - 40, core.__PIXELS__, 40, 199);
core.setOpacity('replay', 0.6);
this._replay_drawProgress();
core.updateStatusBar();
core.updateStatusBar(false, true);
core.drawTip("开始播放");
this.replay();
}
Expand All @@ -1365,7 +1363,7 @@ control.prototype.triggerReplay = function () {
control.prototype.pauseReplay = function () {
if (!core.isPlaying() || !core.isReplaying()) return;
core.status.replay.pausing = true;
core.updateStatusBar();
core.updateStatusBar(false, true);
core.drawTip("暂停播放");
}

Expand All @@ -1377,7 +1375,7 @@ control.prototype.resumeReplay = function () {
return core.drawTip("请等待当前事件的处理结束");
}
core.status.replay.pausing = false;
core.updateStatusBar();
core.updateStatusBar(false, true);
core.drawTip("恢复播放");
core.replay();
}
Expand Down Expand Up @@ -1442,7 +1440,7 @@ control.prototype.stopReplay = function (force) {
core.status.replay.steps = 0;
core.status.replay.save = [];
core.deleteCanvas('replay');
core.updateStatusBar();
core.updateStatusBar(false, true);
core.drawTip("停止播放并恢复游戏");
}

Expand Down Expand Up @@ -1477,7 +1475,7 @@ control.prototype.rewindReplay = function () {
core.createCanvas('replay', 0, core.__PIXELS__ - 40, core.__PIXELS__, 40, 199);
core.setOpacity('replay', 0.6);
core.control._replay_drawProgress();
core.updateStatusBar();
core.updateStatusBar(false, true);
core.drawTip("成功回退到上一个节点");
});
}
Expand Down Expand Up @@ -3045,19 +3043,21 @@ control.prototype.clearStatusBar = function () {
}

////// 更新状态栏 //////
control.prototype.updateStatusBar = function (doNotCheckAutoEvents) {
this.needUpdate = true;
control.prototype.updateStatusBar = function (doNotCheckAutoEvents, immediate) {
if (immediate) {
return this.updateStatusBar_update();
}
if (!doNotCheckAutoEvents) this.noAutoEvents = false;
if (core.isReplaying()) this.updateStatusBar_update();
requestAnimationFrame(this.updateStatusBar_update)
}

control.prototype.updateStatusBar_update = function () {
if (!core.control.needUpdate) return;
if (!core.isPlaying() || core.hasFlag('__statistics__')) return;
core.control.controldata.updateStatusBar();
if (!core.control.noAutoEvents) core.checkAutoEvents();
core.control._updateStatusBar_setToolboxIcon();
core.clearRouteFolding();
core.control.needUpdate = false;
core.control.noAutoEvents = true;
}

Expand Down Expand Up @@ -3284,7 +3284,7 @@ control.prototype.resize = function () {
else {
// 竖屏
core.domStyle.isVertical = true;
core.domStyle.scale = Math.min(1, (clientWidth - 2 * BORDER) / CANVAS_WIDTH);
core.domStyle.scale = Math.min((clientWidth - 2 * BORDER) / CANVAS_WIDTH);
core.domStyle.availableScale = [];
extendToolbar = false;
}
Expand Down Expand Up @@ -3363,15 +3363,17 @@ control.prototype._resize_gameGroup = function (obj) {

control.prototype._resize_canvas = function (obj) {
var innerSize = (obj.CANVAS_WIDTH * core.domStyle.scale) + "px";
for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
var ctx = core.dom.gameCanvas[i].getContext('2d');
// core.maps._setHDCanvasSize(ctx);
core.resizeCanvas(ctx, core.__PIXELS__, core.__PIXELS__);
if (core.status && core.status.maps && core.status.floorId && core.status.maps[core.status.floorId]) {
core.redrawMap();
core.drawHero();
core.setWeather(core.animateFrame.weather.type, core.animateFrame.weather.level);
if (!core.isPlaying()) {
for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
var ctx = core.dom.gameCanvas[i].getContext('2d');
core.resizeCanvas(ctx, core.__PIXELS__, core.__PIXELS__);
core.dom.gameCanvas[i].style.width = core.dom.gameCanvas[i].style.height = innerSize;
}
} else {
requestAnimationFrame(function () {
for (var i = 0; i < core.dom.gameCanvas.length; ++i)
core.dom.gameCanvas[i].style.width = core.dom.gameCanvas[i].style.height = innerSize;
});
}
core.dom.gif.style.width = core.dom.gif.style.height = innerSize;
core.dom.gif2.style.width = core.dom.gif2.style.height = innerSize;
Expand All @@ -3386,13 +3388,24 @@ control.prototype._resize_canvas = function (obj) {
core.canvas[cn].canvas.style.height = core.canvas[cn].canvas.height / ratio * core.domStyle.scale + "px";
});
// resize dynamic canvas
for (var name in core.dymCanvas) {
var ctx = core.dymCanvas[name], canvas = ctx.canvas;
// core.maps._setHDCanvasSize(ctx, parseFloat(canvas.getAttribute('_width')), parseFloat(canvas.getAttribute('_height')));
canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
var scale = canvas.getAttribute('_scale') || 1;
core.resizeCanvas(canvas, canvas.width * scale / core.domStyle.scale, canvas.height * scale / core.domStyle.scale);
if (!core.isPlaying()) {
for (var name in core.dymCanvas) {
var ctx = core.dymCanvas[name], canvas = ctx.canvas;
// core.maps._setHDCanvasSize(ctx, parseFloat(canvas.getAttribute('_width')), parseFloat(canvas.getAttribute('_height')));
canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
var scale = canvas.getAttribute('_scale') || 1;
core.resizeCanvas(canvas, canvas.width * scale / core.domStyle.scale, canvas.height * scale / core.domStyle.scale);
}
} else {
for (var name in core.dymCanvas) {
var ctx = core.dymCanvas[name], canvas = ctx.canvas;
var ratio = canvas.hasAttribute('isHD') ? core.domStyle.ratio : 1;
canvas.style.width = canvas.width / ratio * core.domStyle.scale + "px";
canvas.style.height = canvas.height / ratio * core.domStyle.scale + "px";
canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
}
}
// resize next
main.dom.next.style.width = main.dom.next.style.height = 5 * core.domStyle.scale + "px";
Expand Down
2 changes: 1 addition & 1 deletion libs/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ events.prototype._action_function = function (data, x, y, prefix) {
}

events.prototype._action_update = function (data, x, y, prefix) {
core.updateStatusBar(data.doNotCheckAutoEvents);
core.updateStatusBar(data.doNotCheckAutoEvents, true);
core.doAction();
}

Expand Down
4 changes: 2 additions & 2 deletions libs/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ items.prototype.getItemEffect = function (itemId, itemNum) {
console.error(e);
}
}
core.updateStatusBar();
core.updateStatusBar(false, true);
}
else {
core.addItem(itemId, itemNum);
Expand Down Expand Up @@ -121,7 +121,7 @@ items.prototype._afterUseItem = function (itemId) {
core.status.hero.items[itemCls][itemId]--;
if (core.status.hero.items[itemCls][itemId] <= 0)
delete core.status.hero.items[itemCls][itemId];
core.updateStatusBar();
core.updateStatusBar(false, true);
}

////// 当前能否使用道具 //////
Expand Down
11 changes: 6 additions & 5 deletions libs/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ maps.prototype._resetFloorImages = function () {
}
}

maps.prototype._setHDCanvasSize = function (ctx, width, height) {
maps.prototype._setHDCanvasSize = function (ctx, width, height, isTempCanvas) {
ctx.setTransform(1, 0, 0, 1, 0, 0);
var ratio = core.domStyle.ratio;
if (ctx === core.bigmap.tempCanvas) ratio = core.domStyle.scale;
if (isTempCanvas) ratio = core.domStyle.ratio;
if (width != null) ctx.canvas.width = width * ratio;
if (height != null) ctx.canvas.height = height * ratio;
ctx.scale(ratio, ratio);
Expand Down Expand Up @@ -1736,7 +1737,7 @@ maps.prototype._drawThumbnail_drawTempCanvas = function (floorId, blocks, option
if (options.noHD) {
tempCanvas.canvas.width = width * 32 * scale;
tempCanvas.canvas.height = height * 32 * scale;
} else core.resizeCanvas(tempCanvas, width * 32 * scale, height * 32 * scale);
} else core.resizeCanvas(tempCanvas, width * 32 * scale, height * 32 * scale, false, true);
tempCanvas.scale(scale, scale);
} else if (width * height > core.bigmap.threshold) {
options.v2 = true;
Expand All @@ -1749,13 +1750,13 @@ maps.prototype._drawThumbnail_drawTempCanvas = function (floorId, blocks, option
if (centerY == null) centerY = Math.floor(height / 2);
var offsetX = core.clamp(centerX - core.__HALF_SIZE__, 0, width - core.__SIZE__),
offsetY = core.clamp(centerY - core.__HALF_SIZE__, 0, height - core.__SIZE__);
tempCanvas.translate(-32 * offsetX, -32 * offsetY);
tempCanvas.translate(-32 * offsetX, -32 * offsetY, false, true);
} else {
options.v2 = false;
if (options.noHD) {
tempCanvas.canvas.width = width * 32;
tempCanvas.canvas.height = height * 32;
} else core.resizeCanvas(tempCanvas, width * 32, height * 32);
} else core.resizeCanvas(tempCanvas, width * 32, height * 32, false, true);
}
options.ctx = tempCanvas;

Expand Down Expand Up @@ -2068,7 +2069,7 @@ maps.prototype.showBlock = function (x, y, floorId) {
} else {
core.drawBlock(block);
core.addGlobalAnimate(block);
core.updateStatusBar();
core.updateStatusBar(false, true);
}
}
}
Expand Down
Loading

0 comments on commit 232a336

Please sign in to comment.