PhaserEditor2D-v3 icon indicating copy to clipboard operation
PhaserEditor2D-v3 copied to clipboard

Add "Reset to default" to properties of components

Open robinheidrich opened this issue 2 years ago • 8 comments

It would be a helpful addition if there was an option to reset the value of a property from a user component to its default.

Currently you have to enter the default value yourself.

robinheidrich avatar Apr 02 '22 01:04 robinheidrich

Try this, delete everything in the field and press ENTER. It should return to the default value.

PhaserEditor2D avatar Apr 02 '22 03:04 PhaserEditor2D

Here: https://phasereditor2d.com/blog/2020/08/phaser-editor-2d-v350-released-new-tutorial

But I think I don't mention it in the documentation of the editor.

image

PhaserEditor2D avatar Apr 02 '22 03:04 PhaserEditor2D

Yet I think it is valid to add a visual option for resetting the default value.

In case the property is part of a prefab instance, you can reset its value by locking it. However, I should think how to add a general option.

PhaserEditor2D avatar Apr 02 '22 03:04 PhaserEditor2D

I've already tried deleting everything and then pressing enter, but it stays blank and in the generated JS file it stays too, just with no value.

robinheidrich avatar Apr 02 '22 14:04 robinheidrich

I've already tried deleting everything and then pressing enter, but it stays blank and in the generated JS file it stays too, just with no value.

What's the type of the property you want to reset?

PhaserEditor2D avatar Apr 02 '22 14:04 PhaserEditor2D

It is an Expression. I just checked again and it works for the others.

robinheidrich avatar Apr 02 '22 15:04 robinheidrich

It is an Expression. I just checked again and it works for the others.

Yes because the empty string is a valid value for the Expression type. I should implement a straight forward method for resetting a value. I'm thinking that in case the field is not part of a prefab instance, I can show a reset button in the place of the lock/unlock button.

PhaserEditor2D avatar Apr 02 '22 16:04 PhaserEditor2D

That would be great! But if the value is empty, the component is generated like this in the code:

const gameObjectComponent = new Component(gameObject);
gameObjectComponent.someValue;

Is this really supposed to be a valid value?

robinheidrich avatar Apr 02 '22 16:04 robinheidrich

Thinking more about this.

Making a field blank and pressing ENTER restores it to its default value. If the parameter is part of a prefab instance, then you have the "unlock" icon, for restoring the value to its prefab's default.

The problem is in the parameters of string type in the user components. But user components are deprecated, now we have the Script Nodes. The script nodes work just like prefabs.

PhaserEditor2D avatar Apr 26 '23 15:04 PhaserEditor2D