Skip to content
Snippets Groups Projects
Commit eb9cbf7f authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add design to project web api

parent f9d380b5
No related branches found
No related tags found
No related merge requests found
...@@ -69,7 +69,7 @@ public enum ModernColor implements DisplayableColor { ...@@ -69,7 +69,7 @@ public enum ModernColor implements DisplayableColor {
colors = Storage.load(inputStream, StorageTypes.JSON, ModernColorBean[].class); colors = Storage.load(inputStream, StorageTypes.JSON, ModernColorBean[].class);
} }
private Optional<ModernColorBean> getCurrentModernColor() { public Optional<ModernColorBean> getCurrentModernColor() {
return Stream.of(colors).filter(color -> color.getName().equals(name())).findAny(); return Stream.of(colors).filter(color -> color.getName().equals(name())).findAny();
} }
......
...@@ -3,10 +3,12 @@ package de.tobias.playpad.plugin.api.websocket.listener ...@@ -3,10 +3,12 @@ package de.tobias.playpad.plugin.api.websocket.listener
import de.tobias.playpad.plugin.GlobalAdapter import de.tobias.playpad.plugin.GlobalAdapter
import de.tobias.playpad.plugin.api.websocket.WebSocketHandler import de.tobias.playpad.plugin.api.websocket.WebSocketHandler
import de.tobias.playpad.plugin.api.websocket.serialize.ProjectSerializer import de.tobias.playpad.plugin.api.websocket.serialize.ProjectSerializer
import de.tobias.playpad.profile.Profile
import de.tobias.playpad.project.Project import de.tobias.playpad.project.Project
class ProjectListener extends GlobalAdapter { class ProjectListener extends GlobalAdapter {
override def projectOpened(newProject: Project): Unit = { override def projectOpened(newProject: Project): Unit = {
WebSocketHandler.instance.sendUpdate("project-changed", ProjectSerializer.serializeProject(newProject)) val jsonObject = ProjectSerializer.serializeProject(newProject, Profile.currentProfile())
WebSocketHandler.instance.sendUpdate("project-changed", jsonObject)
} }
} }
...@@ -5,6 +5,7 @@ import de.tobias.playpad.PlayPadPlugin ...@@ -5,6 +5,7 @@ import de.tobias.playpad.PlayPadPlugin
import de.tobias.playpad.plugin.api.websocket.MethodExecutable import de.tobias.playpad.plugin.api.websocket.MethodExecutable
import de.tobias.playpad.plugin.api.websocket.message.Message import de.tobias.playpad.plugin.api.websocket.message.Message
import de.tobias.playpad.plugin.api.websocket.serialize.ProjectSerializer import de.tobias.playpad.plugin.api.websocket.serialize.ProjectSerializer
import de.tobias.playpad.profile.Profile
import org.eclipse.jetty.websocket.api.Session import org.eclipse.jetty.websocket.api.Session
class ProjectCurrentMethod extends MethodExecutable { class ProjectCurrentMethod extends MethodExecutable {
...@@ -14,7 +15,7 @@ class ProjectCurrentMethod extends MethodExecutable { ...@@ -14,7 +15,7 @@ class ProjectCurrentMethod extends MethodExecutable {
if (currentProject == null) { if (currentProject == null) {
new JsonObject new JsonObject
} else { } else {
ProjectSerializer.serializeProject(currentProject) ProjectSerializer.serializeProject(currentProject, Profile.currentProfile)
} }
} }
} }
package de.tobias.playpad.plugin.api.websocket.serialize package de.tobias.playpad.plugin.api.websocket.serialize
import com.google.gson.{JsonArray, JsonObject} import com.google.gson.{JsonArray, JsonObject}
import de.tobias.playpad.design.modern.ModernColor
import de.tobias.playpad.profile.Profile
import de.tobias.playpad.project.Project import de.tobias.playpad.project.Project
object ProjectSerializer { object ProjectSerializer {
def serializeProject(project: Project): JsonObject = { def serializeProject(project: Project, profile: Profile): JsonObject = {
val result = new JsonObject val result = new JsonObject
result.addProperty("id", project.getProjectReference.getUuid.toString) result.addProperty("id", project.getProjectReference.getUuid.toString)
...@@ -31,6 +33,11 @@ object ProjectSerializer { ...@@ -31,6 +33,11 @@ object ProjectSerializer {
padObject.addProperty("position", pad.getPosition) padObject.addProperty("position", pad.getPosition)
padObject.addProperty("page", pad.getPage.getPosition) padObject.addProperty("page", pad.getPage.getPosition)
val padDesign = new JsonObject
padDesign.add("normal", serializeDesign(pad.getPadSettings.getDesign.getBackgroundColor))
padDesign.add("play", serializeDesign(pad.getPadSettings.getDesign.getPlayColor))
padObject.add("design", padDesign)
padArray.add(padObject) padArray.add(padObject)
}) })
pageObject.add("pads", padArray) pageObject.add("pads", padArray)
...@@ -38,6 +45,27 @@ object ProjectSerializer { ...@@ -38,6 +45,27 @@ object ProjectSerializer {
pageArray.add(pageObject) pageArray.add(pageObject)
}) })
result.add("pages", pageArray) result.add("pages", pageArray)
val globalDesign = new JsonObject
globalDesign.add("normal", serializeDesign(profile.getProfileSettings.getDesign.getBackgroundColor))
globalDesign.add("play", serializeDesign(profile.getProfileSettings.getDesign.getPlayColor))
result.add("design", globalDesign)
result result
} }
private def serializeDesign(color: ModernColor): JsonObject = {
val json = new JsonObject
color.getCurrentModernColor.ifPresent(c => {
json.addProperty("hi", c.getColors.getHi)
json.addProperty("low", c.getColors.getLow)
json.addProperty("font", c.getColors.getFont)
json.addProperty("button", c.getColors.getButton)
json.addProperty("playbarBackground", c.getColors.getPlaybar.getBackground)
json.addProperty("playbarTrack", c.getColors.getPlaybar.getTrack)
})
json
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment