Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fixed wrong script title when editing shader #28444

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions editor/js/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,49 @@ function Script( editor ) {

} );

function setTitle( object, script ) {

if ( typeof script === 'object' ) {

title.setValue( object.name + ' / ' + script.name );

} else {

switch ( script ) {

case 'vertexShader':

title.setValue( object.material.name + ' / Vertex Shader' ); // TODO: l10n
break;

case 'fragmentShader':

title.setValue( object.material.name + ' / Fragment Shader' ); // TODO: l10n
break;

case 'programInfo':

title.setValue( object.material.name + ' / Program Properties ' ); // TODO: l10n
break;

default:

throw new Error( 'setTitle: Unknown script' );

}

}

}

signals.editScript.add( function ( object, script ) {

let mode, name, source;
let mode, source;

if ( typeof ( script ) === 'object' ) {

mode = 'javascript';
name = script.name;
source = script.source;
title.setValue( object.name + ' / ' + name );

} else {

Expand All @@ -377,36 +410,39 @@ function Script( editor ) {
case 'vertexShader':

mode = 'glsl';
name = 'Vertex Shader';
source = object.material.vertexShader || '';

break;

case 'fragmentShader':

mode = 'glsl';
name = 'Fragment Shader';
source = object.material.fragmentShader || '';

break;

case 'programInfo':

mode = 'json';
name = 'Program Properties';
const json = {
defines: object.material.defines,
uniforms: object.material.uniforms,
attributes: object.material.attributes
};
source = JSON.stringify( json, null, '\t' );

}
break;

title.setValue( object.material.name + ' / ' + name );
default:

throw new Error( 'editScript: Unknown script' );

}

}

setTitle( object, script );

currentMode = mode;
currentScript = script;
currentObject = object;
Expand All @@ -431,24 +467,34 @@ function Script( editor ) {

signals.objectChanged.add( function ( object ) {

if ( object === currentObject ) {
if ( object !== currentObject ) return;

title.setValue( currentObject.name + ' / ' + currentScript.name );
if ( [ 'programInfo', 'vertexShader', 'fragmentShader' ].includes( currentScript ) ) return;

}
setTitle( currentObject, currentScript );

} );

signals.scriptChanged.add( function ( script ) {

if ( script === currentScript ) {

title.setValue( currentObject.name + ' / ' + currentScript.name );
setTitle( currentObject, currentScript );

}

} );

signals.materialChanged.add( function ( object, slot ) {

if ( object !== currentObject ) return;

// TODO: Adds multi-material support

setTitle( currentObject, currentScript );

} );

return container;

}
Expand Down