From 00392c33b5255b8fe12546f455a71380acc28cee Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Fri, 6 Oct 2023 23:51:58 +0200 Subject: [PATCH] #187 - Add option to trigger cart by index --- .../api/websocket/methods/CartActionMethod.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CartActionMethod.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CartActionMethod.scala index 2b5b82df..afddc207 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CartActionMethod.scala +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CartActionMethod.scala @@ -2,8 +2,10 @@ package de.tobias.playpad.plugin.api.websocket.methods import com.google.gson.JsonObject import de.tobias.playpad.PlayPadPlugin +import de.tobias.playpad.pad.PadStatus import de.tobias.playpad.plugin.api.websocket.MethodExecutable import de.tobias.playpad.plugin.api.websocket.message.Message +import de.tobias.playpad.project.page.PadIndex import javafx.application.Platform import org.eclipse.jetty.websocket.api.Session @@ -12,11 +14,23 @@ import java.util.UUID class CartActionMethod extends MethodExecutable { override def execute(session: Session, message: Message): JsonObject = { - val padId = UUID.fromString(message.payload.get("pad").getAsString) + val padId = if (message.payload.get("padId") != null) { + UUID.fromString(message.payload.get("padId").getAsString) + } else if (message.payload.get("padIndex") != null) { + val padIndex = message.payload.get("padIndex").getAsInt + val currentPage = PlayPadPlugin.getInstance().getMainViewController.getPage + val pad = PlayPadPlugin.getInstance().getCurrentProject.getPad(new PadIndex(padIndex, currentPage)) + pad.getUuid + } else { + throw new IllegalArgumentException("Neither pad nor padIndex provided") + } val currentProject = PlayPadPlugin.getInstance().getCurrentProject val pad = currentProject.getPad(padId) + if (pad == null || pad.getStatus == PadStatus.EMPTY || pad.getStatus == PadStatus.ERROR) { + return null + } Platform.runLater(() => { if (pad.isPlay) { pad.stop() -- GitLab