Skip to content

Commit

Permalink
Full rewrite of the Stream Deck plugin
Browse files Browse the repository at this point in the history
Note: Will likely wipe any settings setup already in the Stream Deck software
  • Loading branch information
MoSadie committed Sep 1, 2024
1 parent 556f5c8 commit a7f998f
Show file tree
Hide file tree
Showing 181 changed files with 2,974 additions and 4,529 deletions.
60 changes: 29 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,53 +200,51 @@ jobs:
needs: buildCore

steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it
- uses: actions/checkout@v4

# # Setup JDK
# - name: Set up JDK 1.8
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt'
# java-version: 8

# # Build Core
# - name: Build/Install Core
# working-directory: ./MinecraftMod/core
# run: './gradlew.bat publishToMavenLocal'

# Setup JDK
- name: Set up JDK 16
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: microsoft
java-version: 16
distribution: adopt
java-version: 8

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

# Download Core
- name: Download Core Artifact
uses: actions/download-artifact@v4
- name: Set up Node.js
uses: actions/setup-node@v2
with:
name: maven
path: ~/.m2/repository
node-version: '20'

- name: Install Stream Deck CLI
run: 'npm install -g @elgato/cli'

# Build Core
- name: Build/Install Core
working-directory: ./MinecraftMod/core
run: './gradlew run'

# Copy effects.json
- name: Copy effects.json
run: 'cp ./MinecraftMod/core/effects.json ./effectmc/effects.json'

# Generate Stream Deck Plugin
- name: Generate Stream Deck Plugin
working-directory: ./StreamDeckPlugin
run: './gradlew.bat run --no-daemon'

# Run DistributionTool
- name: Run DistributionTool
uses: MoSadie/streamdeck-distribution-tool@22472fe2a1ae677822b11328d0df0f98dc7febab
with:
input: 'com.mosadie.effectmc.sdPlugin'
working-directory: 'StreamDeckPlugin'
working-directory: ./effectmc
run: 'npm run generate'

- name: Build Stream Deck Plugin
working-directory: ./effectmc
run: 'npm run build'

- name: Package Stream Deck Plugin
working-directory: ./effectmc
run: 'streamdeck pack .\com.mosadie.effectmc.sdPlugin'

# Upload Artifact
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: Stream Deck Plugin
path: ./StreamDeckPlugin/*.streamDeckPlugin
path: ./effectmc/*.streamDeckPlugin
1 change: 1 addition & 0 deletions MinecraftMod/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
effects.json
5 changes: 5 additions & 0 deletions MinecraftMod/core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'application'
}

version = 3.0
Expand Down Expand Up @@ -46,4 +47,8 @@ publishing {
from components.java
}
}
}

application {
mainClassName = 'com.mosadie.effectmc.core.export.EffectExporter'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PlaySoundEffect() {
getPropertyManager().addFloatProperty("volume", 1.0f, true, "Volume", 0.0f, 1.0f);
getPropertyManager().addFloatProperty("pitch", 1.0f, true, "Pitch", 0.0f, 2.0f);
getPropertyManager().addBooleanProperty("repeat", false, true, "Repeat", "Enabled", "Disabled");
getPropertyManager().addIntegerProperty("repeatDelay", 0, false, "Repeat Delay", "0");
getPropertyManager().addIntegerProperty("repeatDelay", 5, false, "Repeat Delay", "0");
getPropertyManager().addSelectionProperty("attenuationType", ATTENUATION_TYPE.NONE.toString(), true, "Attenuation Type", ATTENUATION_TYPE.toStringArray());
getPropertyManager().addIntegerProperty("x", 0, true, "X", "0");
getPropertyManager().addIntegerProperty("y", 0, true, "Y", "0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public ShowTitleEffect() {
getPropertyManager().addCommentProperty("Set color using § color codes.");
getPropertyManager().addStringProperty("title", "", true, "Title", "Hello");
getPropertyManager().addStringProperty("subtitle", "", true, "Subtitle", "World!");
getPropertyManager().addCommentProperty("For a blank title/subtitle, use a single space.");
getPropertyManager().lock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public ShowToastEffect() {
getPropertyManager().addCommentProperty("Set color using § color codes.");
getPropertyManager().addStringProperty("title", "", true, "Title", "Hello");
getPropertyManager().addStringProperty("subtitle", "", true, "Subtitle", "World!");
getPropertyManager().addCommentProperty("For a blank subtitle, use a single space.");
getPropertyManager().lock();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mosadie.effectmc.core.export;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mosadie.effectmc.core.EffectMCCore;
import com.mosadie.effectmc.core.effect.internal.Effect;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class EffectExporter {
public static void main(String[] args) {
System.out.println("Exporting effects...");
EffectMCCore core = new EffectMCCore(null, null, null);

GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
builder.registerTypeAdapter(Effect.class, new EffectSerializer());
Gson gson = builder.create();

String file = "effects.json";

if (args.length > 0) {
file = args[0];
}

File outputFile = new File(file);

if (outputFile.exists()) {
System.out.println("Output file already exists, overwriting...");
}


try {
FileWriter writer = new FileWriter(outputFile);
writer.write(gson.toJson(core.getEffects().toArray(new Effect[0])));
writer.close();
System.out.println("Effects exported to " + outputFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
System.out.println("Failed to export effects: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mosadie.effectmc.core.export;

import com.google.gson.*;
import com.mosadie.effectmc.core.effect.internal.Effect;

import java.lang.reflect.Type;
import java.util.List;

public class EffectListSerializer implements JsonSerializer<List<Effect>> {
@Override
public JsonElement serialize(List<Effect> src, Type typeOfSrc, JsonSerializationContext context) {
JsonArray array = new JsonArray();
for (Effect effect : src) {
array.add(context.serialize(effect));
}
return array;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mosadie.effectmc.core.export;

import com.google.gson.*;
import com.mosadie.effectmc.core.effect.internal.Effect;

import java.lang.reflect.Type;

public class EffectSerializer implements JsonSerializer<Effect> {

@Override
public JsonElement serialize(Effect src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject object = new JsonObject();
object.addProperty("id", src.getEffectId());
object.addProperty("name", src.getEffectName());
object.addProperty("tooltip", src.getEffectTooltip());

// Serialize the property manager as normal
object.add("properties", context.serialize(src.getPropertyManager().getPropertiesList()));

System.out.println("Effect serialized: " + src.getEffectName());

return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,17 @@ public void handle(HttpExchange exchange) throws IOException {
return;
}

Map<String, Object> bodyParameters = new HashMap<>();

try {
Util.parseQuery(body, bodyParameters);
} catch (UnsupportedEncodingException e) {
core.getExecutor().log("Exception occurred parsing body query!");
String response = "Something went wrong parsing the body query.";
exchange.sendResponseHeaders(400, response.getBytes().length);
exchange.getResponseBody().write(response.getBytes());
exchange.getResponseBody().close();
return;
}

// Handle no device (send unauthorized)
if (!parameters.containsKey("device") && !bodyParameters.containsKey("device")) {
if (!parameters.containsKey("device")) {
String message = "Missing device property";
exchange.sendResponseHeaders(401, message.getBytes().length);
exchange.getResponseBody().write(message.getBytes());
exchange.getResponseBody().close();
return;
}

// Combine the parameters, where any specified in the body overwrite the query parameters
for (String key : bodyParameters.keySet()) {
parameters.put(key, bodyParameters.get(key));
}

// Check for request parameter, if not present, send 400
if (!parameters.containsKey("request")) {
String message = "Missing request property";
exchange.sendResponseHeaders(400, message.getBytes().length);
exchange.getResponseBody().write(message.getBytes());
exchange.getResponseBody().close();
return;
}

// Create EffectRequest
EffectRequest request = core.requestFromJson(parameters.get("request").toString());
EffectRequest request = core.requestFromJson(body);

if (request == null) {
String message = "Invalid request JSON, check game logs for more information";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@ public abstract class EffectProperty {
final boolean required;
final String label;

final String sdPropType;

EffectProperty(PropertyType type, String id, boolean required, String label) {
this.TYPE = type;
this.id = id;
this.required = required;
this.label = label;

switch (type) {
case FLOAT:
case DOUBLE:
case INTEGER:
this.sdPropType = "number";
break;

case BOOLEAN:
this.sdPropType = "boolean";
break;

case BODY:
case STRING:
case SELECTION:
case COMMENT:
default:
this.sdPropType = "string";
break;
}
}

public String getId() {
Expand All @@ -35,6 +57,7 @@ public String getLabel() {

public abstract String getAsString(Object input);
public abstract String getHTMLInput();

public abstract String getSDHTMLInput();

public abstract boolean getAsBoolean(Object input);
Expand Down
3 changes: 0 additions & 3 deletions StreamDeckPlugin/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions StreamDeckPlugin/.idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions StreamDeckPlugin/.idea/compiler.xml

This file was deleted.

20 changes: 0 additions & 20 deletions StreamDeckPlugin/.idea/gradle.xml

This file was deleted.

25 changes: 0 additions & 25 deletions StreamDeckPlugin/.idea/jarRepositories.xml

This file was deleted.

Loading

0 comments on commit a7f998f

Please sign in to comment.