This commit is contained in:
YouWei Zhao 2019-03-19 14:23:43 -04:00
parent d017c5e549
commit eda91df9f0
6 changed files with 137 additions and 6 deletions

View File

@ -850,6 +850,65 @@ editor_file = function (editor, callback) {
////////////////////////////////////////////////////////////////////
var plmap = {};
var pljson = JSON.stringify(plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1, function (k, v) {
if (v instanceof Function) {
var id_ = editor.guid();
plmap[id_] = v.toString();
return id_;
} else if(v===null){
var id_ = editor.guid();
plmap[id_] = 'null';
return id_;
} return v
}, 4);
var plobj = JSON.parse(pljson);
editor_file.pluginsMap = plmap;
editor_file.pluginsObj = plobj;
var buildpllocobj = function (locObj) {
for (var key in locObj) {
if (typeof(locObj[key]) !== typeof('')) buildpllocobj(locObj[key]);
else locObj[key] = plmap[locObj[key]];
}
};
editor_file.editPlugins = function (actionList, callback) {
/*actionList:[
["change","['test']","function(x,y){console.log(x,y)}"],
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
saveSetting('plugins', actionList, function (err) {
callback([
(function () {
var locObj = JSON.parse(JSON.stringify(plobj));
buildpllocobj(locObj);
return locObj;
})(),
editor_file.pluginsComment,
err]);
});
} else {
callback([
(function () {
var locObj = JSON.parse(JSON.stringify(plobj));
buildpllocobj(locObj);
return locObj;
})(),
editor_file.pluginsComment,
null]);
}
}
//callback([obj,commentObj,err:String])
////////////////////////////////////////////////////////////////////
var isset = function (val) {
if (val == undefined || val == null) {
return false;
@ -1026,6 +1085,25 @@ editor_file = function (editor, callback) {
});
return;
}
if (file == 'plugins') {
actionList.forEach(function (value) {
if(value[0]==='add'){
eval("plobj" + value[1] + '=' + JSON.stringify(value[2]));
} else {
eval("plmap[plobj" + value[1] + ']=' + JSON.stringify(value[2]));
}
});
var plraw = JSON.stringify(plobj,null,4);
for (var id_ in plmap) {
plraw = plraw.replace('"' + id_ + '"', plmap[id_])
}
var datastr = 'var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = \n';
datastr += plraw;
fs.writeFile('project/plugins.js', encode(datastr), 'base64', function (err, data) {
callback(err);
});
return;
}
callback('出错了,要设置的文件名不识别');
}

View File

@ -13,6 +13,7 @@ editor_mode = function (editor) {
'appendpic': 'left1',
'commonevent': 'left9',
'plugins': 'left10',
}
this._ids = {}
this.dom = {}
@ -385,6 +386,9 @@ editor_mode = function (editor) {
case 'commonevent':
editor.file.editCommonEvent(actionList, cb);
break;
case 'plugins':
editor.file.editPlugins(actionList, cb);
break;
default:
break;
}
@ -394,7 +398,7 @@ editor_mode = function (editor) {
if (editor_mode.mode != mode) {
if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList);
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
editor_mode.mode = mode;
if (mode !== 'save') editor_mode.mode = mode;
editor_mode.actionList = [];
}
}
@ -526,6 +530,19 @@ editor_mode = function (editor) {
tableinfo.listen(tableinfo.guids);
if (Boolean(callback)) callback();
}
editor_mode.prototype.plugins = function (callback) {
var objs = [];
editor.file.editPlugins([], function (objs_) {
objs = objs_;
//console.log(objs_)
});
//只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids);
if (Boolean(callback)) callback();
}
/////////////////////////////////////////////////////////////////////////////

View File

@ -6,13 +6,13 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"test": {
"_leaf": true,
"_type": "textarea",
"_range": "thiseval instanceof Array",
"_range": "typeof(thiseval)=='string'",
"_data": "插件函数执行测试, 这个函数在导入后被直接执行(因此不允许删除)"
},
"drawLight": {
"_leaf": true,
"_type": "textarea",
"_range": "thiseval instanceof Array || thiseval==null",
"_range": "typeof(thiseval)=='string' || thiseval==null",
"_data": "绘制灯光/漆黑层效果"
},
}
@ -20,7 +20,7 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
return {
"_leaf": true,
"_type": "textarea",
"_range": "thiseval instanceof Array || thiseval==null",
"_range": "typeof(thiseval)=='string' || thiseval==null",
"_data": "自定义插件"
}
}

View File

@ -260,6 +260,23 @@
</div>
</div>
</div>
<div id="left10" class='leftTab' style="z-index:-1;opacity: 0;"><!-- plugins -->
<h3 class="leftTabHeader">插件编写&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
</h3>
<div class="leftTabContent">
<div class='etable'>
<table>
<tbody id='table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6'>
<tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="mid">
<div class="col" id='mapColMark'></div>
<div class="row" id='mapRowMark'></div>
@ -329,6 +346,7 @@
<option value="functions">脚本编辑</option>
<option value="appendpic">追加素材</option>
<option value="commonevent">公共事件</option>
<option value="plugins">插件编写</option>
</select>
<select id="brushMod" style="clear:right">
<option value="line">画线</option>

View File

@ -256,6 +256,23 @@
</div>
</div>
</div>
<div id="left10" class='leftTab' style="z-index:-1;opacity: 0;"><!-- plugins -->
<h3 class="leftTabHeader">插件编写&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
</h3>
<div class="leftTabContent">
<div class='etable'>
<table>
<tbody id='table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6'>
<tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="mid">
<table class="col" id='mapColMark'></table>
<table class="row" id='mapRowMark'></table>
@ -296,6 +313,7 @@
<option value="functions">脚本编辑</option>
<option value="appendpic">追加素材</option>
<option value="commonevent">公共事件</option>
<option value="plugins">插件编写</option>
</select>
<br/>
<span style="font-size: 12px;">

View File

@ -1,9 +1,9 @@
var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
{
"test": function(){
"test": function(){
console.log("插件函数执行测试");
},
"drawLight" : function (name, color, lights, lightDec) {
"drawLight": function (name, color, lights, lightDec) {
// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
// 【参数说明】
// name必填要绘制到的画布名可以是一个系统画布或者是个自定义画布如果不存在则创建