优化脚本编辑器结构。

This commit is contained in:
tengge1 2019-08-12 21:49:24 +08:00
parent 232916a949
commit f1eb680b56
4 changed files with 38 additions and 12 deletions

View File

@ -699,6 +699,8 @@ class MaterialComponent extends React.Component {
attributes: material.attributes
};
app.call(`editScript`, this, uuid, script.name, script.type, script.source);
app.script.open(material.uuid, this.selected.name + '-ProgramInfo', 'json', JSON.stringify(obj), this.selected.name + `-${L_SHADER_INFO}`, source => {
try {
obj = JSON.parse(source);

View File

@ -16,6 +16,7 @@ class ScriptPanel extends React.Component {
this.handleAddScript = this.handleAddScript.bind(this);
this.handleEditScript = this.handleEditScript.bind(this);
this.handleSaveScript = this.handleSaveScript.bind(this);
this.handleRemoveScript = this.handleRemoveScript.bind(this);
this.update = this.update.bind(this);
}
@ -78,10 +79,22 @@ class ScriptPanel extends React.Component {
handleEditScript(uuid) {
var script = app.editor.scripts[uuid];
if (script) {
app.call(`editScript`, this, uuid, script.name, script.type, script.source);
app.call(`editScript`, this, uuid, script.name, script.type, script.source, this.handleSaveScript);
}
}
handleSaveScript(uuid, name, type, source) {
app.editor.scripts[uuid] = {
id: null,
uuid,
name,
type,
source,
};
app.call(`scriptChanged`, this);
}
handleRemoveScript(uuid) {
const script = app.editor.scripts[uuid];

View File

@ -29,6 +29,7 @@ class ScriptWindow extends React.Component {
this.handleTypeChange = this.handleTypeChange.bind(this);
this.handleOK = this.handleOK.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleSaveScript = this.handleSaveScript.bind(this);
}
render() {
@ -117,7 +118,19 @@ class ScriptWindow extends React.Component {
source: '',
});
app.call(`editScript`, this, uuid, name, type, source);
app.call(`editScript`, this, uuid, name, type, source, this.handleSaveScript);
}
handleSaveScript(uuid, name, type, source) {
app.editor.scripts[uuid] = {
id: null,
uuid,
name,
type,
source,
};
app.call(`scriptChanged`, this);
}
handleClose() {

View File

@ -18,6 +18,8 @@ class ScriptEditorPanel extends React.Component {
source: '',
};
this.callback = null;
this.ref = React.createRef();
this.handleEditScript = this.handleEditScript.bind(this);
@ -59,7 +61,9 @@ class ScriptEditorPanel extends React.Component {
app.on(`editScript.ScriptPanel`, this.handleEditScript);
}
handleEditScript(uuid, name, type, source) {
handleEditScript(uuid, name, type, source, callback) {
this.callback = callback;
this.setState({
show: true,
uuid,
@ -76,13 +80,9 @@ class ScriptEditorPanel extends React.Component {
const source = app.scriptEditor.getValue();
app.editor.scripts[uuid] = {
id: null,
name,
type,
source,
uuid,
};
this.callback && this.callback(uuid, name, type, source);
this.callback = null;
this.setState({
show: false,
@ -91,8 +91,6 @@ class ScriptEditorPanel extends React.Component {
type: 'javascript',
source: '',
});
app.call(`scriptChanged`, this);
}
}