脚本编辑器修改。

This commit is contained in:
liteng 2018-09-12 12:09:23 +08:00
parent fbfbd0ef62
commit 97fdbe59fc
3 changed files with 18 additions and 6 deletions

View File

@ -23,6 +23,8 @@ function ScriptEditor(options) {
this.errorLines = []; // 代码错误行数
this.widgets = [];
this.callback = null;
};
ScriptEditor.prototype = Object.create(UI.Control.prototype);
@ -76,8 +78,9 @@ ScriptEditor.prototype.render = function () {
* @param {*} mode 类型 javascriptglsljson 默认javascript
* @param {*} source 源码 文件初始代码 默认
* @param {*} title 标题 文件标题 默认未命名.${文件类型}
* @param {*} callback 回调函数
*/
ScriptEditor.prototype.open = function (uuid, name, mode, source, title) {
ScriptEditor.prototype.open = function (uuid, name, mode, source, title, callback) {
var scriptTitle = UI.get('scriptTitle');
// 连续打开脚本时,自动保存上次打开的文件
@ -102,6 +105,7 @@ ScriptEditor.prototype.open = function (uuid, name, mode, source, title) {
this.mode = mode;
this.source = source;
this.title = title;
this.callback = callback;
this.show();
@ -156,10 +160,13 @@ ScriptEditor.prototype.hide = function () {
* 保存脚本
*/
ScriptEditor.prototype.save = function () {
var script = this.app.editor.scripts[this.uuid];
if (script) {
script.source = this.codemirror.getValue();
var value = this.codemirror.getValue();
if (typeof (this.callback) === 'function') {
this.callback.call(this, value);
}
this.app.log(`${this.uuid}脚本保存成功!`);
};
/**

View File

@ -129,7 +129,10 @@ ScriptWindow.prototype.onCreateScript = function () {
var uuid = THREE.Math.generateUUID();
this.app.script.open(uuid, scriptName, scriptType, initCode, scriptName);
this.app.script.open(uuid, scriptName, scriptType, initCode, scriptName, source => {
var script = this.app.editor.scripts[uuid];
script.source = source;
});
this.app.editor.scripts[uuid] = {
id: 0,

View File

@ -126,7 +126,9 @@ ScriptPanel.prototype.update = function () {
ScriptPanel.prototype.editScript = function (uuid) {
var script = this.app.editor.scripts[uuid];
if (script) {
this.app.script.open(uuid, script.name, script.type, script.source, script.name);
this.app.script.open(uuid, script.name, script.type, script.source, script.name, source => {
script.source = source;
});
}
};