This commit is contained in:
oc 2019-03-20 13:47:48 +08:00
parent da07c2dc7d
commit cc45359ea1
6 changed files with 96 additions and 106 deletions

View File

@ -176,6 +176,12 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_type": "textarea", "_type": "textarea",
"_lint": true, "_lint": true,
"_data": "瞬间移动处理" "_data": "瞬间移动处理"
},
"parallelDo": {
"_leaf": true,
"_type": "textarea",
"_lint": true,
"_data": "并行事件处理"
} }
} }
}, },
@ -201,23 +207,6 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_data": "绘制关于界面" "_data": "绘制关于界面"
} }
} }
},
"plugins": {
"_type": "object",
"_data": {
"parallelDo": {
"_leaf": true,
"_type": "textarea",
"_lint": true,
"_data": "并行事件处理"
},
"plugin": {
"_leaf": true,
"_type": "textarea",
"_lint": true,
"_data": "自定义插件编写"
}
}
} }
} }
} }

View File

@ -3,17 +3,17 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_type": "object", "_type": "object",
"_data": function (key) { "_data": function (key) {
var obj = { var obj = {
"test": { "init": {
"_leaf": true, "_leaf": true,
"_type": "textarea", "_type": "textarea",
"_range": "typeof(thiseval)=='string'", "_range": "typeof(thiseval)=='string'",
"_data": "插件函数执行测试, 这个函数在导入后被直接执行(因此不允许删除)" "_data": "自定义插件"
}, },
"drawLight": { "drawLight": {
"_leaf": true, "_leaf": true,
"_type": "textarea", "_type": "textarea",
"_range": "typeof(thiseval)=='string' || thiseval==null", "_range": "typeof(thiseval)=='string' || thiseval==null",
"_data": "绘制灯光/漆黑层效果" "_data": "绘制灯光效果"
}, },
} }
if (obj[key]) return obj[key]; if (obj[key]) return obj[key];

View File

@ -297,7 +297,7 @@ control.prototype._animationFrame_weather_fog = function () {
} }
control.prototype._animationFrame_parallelDo = function (timestamp) { control.prototype._animationFrame_parallelDo = function (timestamp) {
functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.parallelDo(timestamp); core.control.controldata.parallelDo(timestamp);
} }
control.prototype._animationFrame_checkConsoleOpened = function (timestamp) { control.prototype._animationFrame_checkConsoleOpened = function (timestamp) {

View File

@ -338,16 +338,23 @@ core.prototype._init_others = function () {
core.prototype._afterLoadResources = function (callback) { core.prototype._afterLoadResources = function (callback) {
core.control._setRequestAnimationFrame(); core.control._setRequestAnimationFrame();
core._initPlugins();
core.plugin = new function () {};
core.plugin.__init__ = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.plugin;
core.plugin.__init__();
core._forwardFunc("plugin");
core.showStartAnimate(); core.showStartAnimate();
if (callback) callback(); if (callback) callback();
} }
core.prototype._initPlugins = function () {
core.plugin = new function () {};
for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) {
if (plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name] instanceof Function) {
plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name].apply(core.plugin);
}
}
core._forwardFunc("plugin");
}
core.prototype._forwardFuncs = function () { core.prototype._forwardFuncs = function () {
for (var i = 0; i < main.loadList.length; ++i) { for (var i = 0; i < main.loadList.length; ++i) {
var name = main.loadList[i]; var name = main.loadList[i];

View File

@ -1265,6 +1265,37 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
return true; return true;
} }
return false; return false;
},
"parallelDo": function (timestamp) {
// 并行事件处理,可以在这里写任何需要并行处理的脚本或事件
// 该函数将被系统反复执行每次执行间隔视浏览器或设备性能而定一般约为16.6ms一次
// 参数timestamp为“从游戏资源加载完毕到当前函数执行时”的时间差以毫秒为单位
// 检查当前是否处于游戏开始状态
if (!core.isPlaying()) return;
// 执行当前楼层的并行事件处理
if (core.status.floorId) {
try {
eval(core.floors[core.status.floorId].parallelDo);
} catch (e) {
main.log(e);
}
}
// 下面是一个并行事件开门的样例
/*
// 如果某个flag为真
if (core.hasFlag("xxx")) {
// 千万别忘了将该flag清空否则下次仍然会执行这段代码。
core.removeFlag("xxx");
// 使用insertAction来插入若干自定义事件执行
core.insertAction([
{"type":"openDoor", "loc":[0,0], "floorId": "MT0"}
])
// 也可以写任意其他的脚本代码
}
*/
} }
}, },
"ui": { "ui": {
@ -1374,59 +1405,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.fillText('ui', "作者: 艾之葵", text_start, top + 112); core.fillText('ui', "作者: 艾之葵", text_start, top + 112);
core.fillText('ui', 'HTML5魔塔交流群539113091', text_start, top+112+32); core.fillText('ui', 'HTML5魔塔交流群539113091', text_start, top+112+32);
// TODO: 写自己的“关于”页面每次增加32像素即可 // TODO: 写自己的“关于”页面每次增加32像素即可
}
},
"plugins": {
"parallelDo": function (timestamp) {
// 并行事件处理,可以在这里写任何需要并行处理的脚本或事件
// 该函数将被系统反复执行每次执行间隔视浏览器或设备性能而定一般约为16.6ms一次
// 参数timestamp为“从游戏资源加载完毕到当前函数执行时”的时间差以毫秒为单位
// 检查当前是否处于游戏开始状态
if (!core.isPlaying()) return;
// 执行当前楼层的并行事件处理
if (core.status.floorId) {
try {
eval(core.floors[core.status.floorId].parallelDo);
} catch (e) {
main.log(e);
}
}
// 下面是一个并行事件开门的样例
/*
// 如果某个flag为真
if (core.hasFlag("xxx")) {
// 千万别忘了将该flag清空否则下次仍然会执行这段代码。
core.removeFlag("xxx");
// 使用insertAction来插入若干自定义事件执行
core.insertAction([
{"type":"openDoor", "loc":[0,0], "floorId": "MT0"}
])
// 也可以写任意其他的脚本代码
}
*/
},
"plugin": function () {
////// 插件编写,此处会导入插件编写中的所有函数 //////
// 在这里写的代码,在所有模块加载完毕后,游戏开始前会被执行
console.log("插件编写测试");
// 可以写一些其他的被直接执行的代码
var pluginsData=plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1
for(var functionName in pluginsData){
this[functionName]=pluginsData[functionName]
}
// 可以在任何地方如afterXXX或自定义脚本事件调用函数方法为 core.plugin.xxx();
// 可以在此处直接执行插件编写中的函数
core.plugin.test();
} }
} }
} }

View File

@ -1,9 +1,21 @@
var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
{ {
"test": function(){ "init": function () {
// 在这里写的代码,在所有模块加载完毕后,游戏开始前会被执行
console.log("插件编写测试");
// 可以写一些其他的被直接执行的代码
this.test = function () {
console.log("插件函数执行测试"); console.log("插件函数执行测试");
console.log(this);
}
// 可以在任何地方如afterXXX或自定义脚本事件调用函数方法为 core.plugin.xxx();
}, },
"drawLight": function (name, color, lights, lightDec) { "drawLight": function () {
// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...) // 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
// 【参数说明】 // 【参数说明】
// name必填要绘制到的画布名可以是一个系统画布或者是个自定义画布如果不存在则创建 // name必填要绘制到的画布名可以是一个系统画布或者是个自定义画布如果不存在则创建
@ -18,6 +30,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
// core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果灯光中心不透明度0.1。 // core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果灯光中心不透明度0.1。
// core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层且存在三个灯光效果分别是中心(25,11)半径46中心(105,121)半径88中心(301,221)半径106。 // core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层且存在三个灯光效果分别是中心(25,11)半径46中心(105,121)半径88中心(301,221)半径106。
// core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果它们在内圈40%范围内保持全亮且40%后才开始衰减。 // core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果它们在内圈40%范围内保持全亮且40%后才开始衰减。
this.drawLight = function (name, color, lights, lightDec) {
// 清空色调层也可以修改成其它层比如animate/weather层或者用自己创建的canvas // 清空色调层也可以修改成其它层比如animate/weather层或者用自己创建的canvas
var ctx = core.getContextByName(name); var ctx = core.getContextByName(name);
@ -44,7 +57,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
ctx.globalCompositeOperation = 'destination-out'; ctx.globalCompositeOperation = 'destination-out';
lights.forEach(function (light) { lights.forEach(function (light) {
// 坐标,半径,中心不透明度 // 坐标,半径,中心不透明度
var x = light[0], y = light[1], r = light[2]; var x = light[0],
y = light[1],
r = light[2];
// 计算衰减距离 // 计算衰减距离
var decDistance = parseInt(r * lightDec); var decDistance = parseInt(r * lightDec);
// 正方形区域的直径和左上角坐标 // 正方形区域的直径和左上角坐标
@ -60,3 +75,4 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
// 可以在任何地方如afterXXX或自定义脚本事件调用函数方法为 core.plugin.xxx(); // 可以在任何地方如afterXXX或自定义脚本事件调用函数方法为 core.plugin.xxx();
} }
} }
}