mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
脚本编辑器修改。
This commit is contained in:
parent
fbfbd0ef62
commit
97fdbe59fc
@ -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 类型 javascript、glsl、json 默认: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}脚本保存成功!`);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user