Improve LayerMapComponent performances

This commit is contained in:
fgnm
2023-09-21 09:30:18 +02:00
parent 063eff53d5
commit 3fdae535f7
3 changed files with 18 additions and 2 deletions
@@ -1,5 +1,6 @@
package games.rednblack.editor.controller.commands;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import games.rednblack.editor.renderer.components.LayerMapComponent;
import games.rednblack.editor.renderer.data.LayerItemVO;
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
@@ -20,9 +21,20 @@ public class NewLayerCommand extends EntityModifyRevertibleCommand {
int index = (int) payload[0];
layerName = (String) payload[1];
if (layerName.isEmpty()) {
cancel();
return;
}
int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity();
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
if (layerMapComponent.getLayer(layerName) != null) {
cancel();
Dialogs.showErrorDialog(Sandbox.getInstance().getUIStage(), "Layer name already exists.").padBottom(20).pack();
return;
}
LayerItemVO vo = new LayerItemVO(layerName);
vo.isVisible = true;
layerMapComponent.addLayer(index, vo);
@@ -37,7 +37,9 @@ public class RenameLayerCommand extends EntityModifyRevertibleCommand {
String oldName = payload[0];
String newName = payload[1];
if(oldName.equals(newName)) cancel();
if(oldName.equals(newName) || newName.isEmpty()) {
cancel();
}
renameLayer(oldName, newName);
@@ -56,6 +58,8 @@ public class RenameLayerCommand extends EntityModifyRevertibleCommand {
}
private void renameLayer(String fromName, String toName) {
if (isCancelled) return;
int viewEntity = Sandbox.getInstance().getCurrentViewingEntity();
NodeComponent nodeComponent = SandboxComponentRetriever.get(viewEntity, NodeComponent.class);
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewEntity, LayerMapComponent.class);