Skip to content

Commit

Permalink
Add config to all the StreamDeck+ actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cazzar committed Jan 11, 2024
1 parent 5fe5096 commit df154da
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 22 deletions.
5 changes: 3 additions & 2 deletions streamdeck-vtubestudio/Actions/MoveModelX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ protected override void SettingsUpdated(MoveSettings oldSettings, MoveSettings n

public void DialRotate(DialRotatePayload dialRotatePayload)
{
_currentPosition = Math.Clamp(_currentPosition + (dialRotatePayload.Ticks * (Settings.StepSize / 200d)), -2, 2);

Vts.Send(new MoveModelRequest
{
PositionX = Math.Clamp(_currentPosition + (dialRotatePayload.Ticks * Settings.StepSize), -2, 2),
PositionX = _currentPosition,
TimeInSeconds = 0.01d,
});
}
Expand All @@ -81,7 +83,6 @@ public void UseCurrent(PluginPayload pl)

public void Dispose()
{
GC.SuppressFinalize(this);
VTubeStudioWebsocketClient.OnModelMove -= ModelMove;
}
}
5 changes: 3 additions & 2 deletions streamdeck-vtubestudio/Actions/MoveModelY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ protected override void SettingsUpdated(MoveModelX.MoveSettings oldSettings, Mov

public void DialRotate(DialRotatePayload dialRotatePayload)
{
_currentPosition = Math.Clamp(_currentPosition + (dialRotatePayload.Ticks * (Settings.StepSize / 200d)), -2, 2);

Vts.Send(new MoveModelRequest
{
PositionY = Math.Clamp(_currentPosition + (dialRotatePayload.Ticks * Settings.StepSize), -2, 2),
PositionY = _currentPosition,
TimeInSeconds = 0.05d,
});
}
Expand All @@ -71,7 +73,6 @@ public void UseCurrent(PluginPayload pl)

public void Dispose()
{
GC.SuppressFinalize(this);
VTubeStudioWebsocketClient.OnModelMove -= ModelMove;
}
}
24 changes: 20 additions & 4 deletions streamdeck-vtubestudio/Actions/RotateModelAction.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
using System;
using Cazzar.StreamDeck.VTubeStudio.Models;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Events;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using StreamDeckLib;
using StreamDeckLib.Models;
using StreamDeckLib.Models.StreamDeckPlus;

namespace Cazzar.StreamDeck.VTubeStudio.Actions;

[StreamDeckAction("dev.cazzar.vtubestudio.rotatemodel")]
public class RotateModelAction : BaseAction<RotateModelAction.Settings>, IStreamDeckPlus, IDisposable
public class RotateModelAction : BaseAction<RotateModelAction.PluginSettings>, IStreamDeckPlus, IDisposable
{
private double _currentRotation = 0;

public class Settings;
public class PluginSettings
{
[JsonProperty("stepSize")]
public int StepSize { get; set; } = 2;
[JsonProperty("defaultRotation")]
public double DefaultRotation { get; set; } = 0.0d;
}

public RotateModelAction(GlobalSettingsManager gsm, VTubeStudioWebsocketClient vts, IStreamDeckConnection isd, ILogger<RotateModelAction> logger) : base(gsm, vts, isd, logger)
{
Expand Down Expand Up @@ -44,7 +52,7 @@ protected override void Released()
{
}

protected override void SettingsUpdated(Settings oldSettings, Settings newSettings)
protected override void SettingsUpdated(PluginSettings oldSettings, PluginSettings newSettings)
{
}
public void Touch(TouchTapPayload touchTap) => Pressed();
Expand All @@ -55,7 +63,7 @@ protected override void SettingsUpdated(Settings oldSettings, Settings newSettin

public void DialRotate(DialRotatePayload dialRotatePayload)
{
_currentRotation += dialRotatePayload.Ticks + ((Math.Sign(dialRotatePayload.Ticks) * Math.Pow(2, Math.Clamp(Math.Abs(dialRotatePayload.Ticks), 1, 8) - 1)) / 2);
_currentRotation += dialRotatePayload.Ticks * (Settings.StepSize / 10d);

Vts.Send(new MoveModelRequest
{
Expand All @@ -64,6 +72,14 @@ public void DialRotate(DialRotatePayload dialRotatePayload)
});
}

[PluginCommand("use-current")]
public void UseCurrent(PluginPayload pl)
{
Settings.DefaultRotation = _currentRotation;
SaveSettings();
}


public void Dispose()
{
VTubeStudioWebsocketClient.OnModelMove -= ModelMove;
Expand Down
25 changes: 19 additions & 6 deletions streamdeck-vtubestudio/Actions/ZoomModelAction.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using Cazzar.StreamDeck.VTubeStudio.Models;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Events;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests;
using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Responses;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using StreamDeckLib;
using StreamDeckLib.Models;
using StreamDeckLib.Models.StreamDeckPlus;
Expand Down Expand Up @@ -46,12 +48,18 @@ private async void UpdateFeedback(double percentage)
{"indicator", (int) (percentage * 100) },
} });
}

public class PluginSettings;

public class PluginSettings
{
[JsonProperty("stepSize")]
public int StepSize { get; set; } = 2;
[JsonProperty("defaultZoom")]
public double DefaultZoom { get; set; } = 0.0d;
}

protected override void Pressed()
{
Vts.Send(new MoveModelRequest() {Size = 0});
Vts.Send(new MoveModelRequest() {Size = Settings.DefaultZoom});
}
protected override void Released()
{
Expand All @@ -69,15 +77,20 @@ public void DialDown(DialPressPayload dialDown) { }

public void DialRotate(DialRotatePayload dialRotatePayload)
{
var offset = Math.Sign(dialRotatePayload.Ticks) * Math.Pow(2, Math.Clamp(Math.Abs(dialRotatePayload.Ticks), 1, 5)) / 2;

_currentSize = Math.Clamp(_currentSize + offset, -100, 100);
_currentSize = Math.Clamp(_currentSize + (dialRotatePayload.Ticks * Settings.StepSize), -100, 100);

Vts.Send(new MoveModelRequest() {Size = _currentSize, TimeInSeconds = 0.05d});

UpdateFeedback((_currentSize + 100d) / 200d);
}

[PluginCommand("use-current")]
public void UseCurrent(PluginPayload pl)
{
Settings.DefaultZoom = _currentSize;
SaveSettings();
}

public void Dispose()
{
VTubeStudioWebsocketClient.OnCurrentModelInformation -= CurrentModelInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<NotConnected v-if="!websocketConnected" />
<div v-else>
<div class="sdpi-item">
<div class="sdpi-item-label">Size ({{ defaultPosition ?? '0' }})</div>
<div class="sdpi-item-label">Position ({{ currentPos }})</div>
<span class="sdpi-item-value">
<input type="range" min="-1" max="1" step="0.01" v-model="defaultPosition">
</span>
Expand All @@ -11,13 +11,13 @@
<div class="sdpi-item">
<div class="sdpi-item-label">Step Size ({{ stepSize ?? '0' }})</div>
<span class="sdpi-item-value">
<input type="range" min="-1" max="1" step="0.01" v-model="stepSize">
<input type="range" min="1" max="10" step="1" v-model="stepSize">
</span>
</div>

<div class="sdpi-item">
<div class="sdpi-item-label">Tools</div>
<button class="sdpi-item-value" id="force-refresh" @click="sendAction('use-current', null)">Refresh</button>
<button class="sdpi-item-value" id="use-current" @click="sendAction('use-current', null)">Current Pos</button>
<button class="sdpi-item-value" id="force-refresh" @click="sendAction('refresh', null)">Refresh</button>
</div>
</div>
Expand All @@ -38,6 +38,13 @@ export default {
stepSize: 2
}
},
computed: {
currentPos() {
let pos = Number(this.defaultPosition) ?? 0
return ((pos + 1) / 2.0).toLocaleString(undefined, { style: "percent" });
}
},
watch: {
defaultPosition() {
this.saveSettings()
Expand All @@ -60,7 +67,14 @@ export default {
}
},
mounted() {
this.$store.state.streamDeck.on('didReceiveSettings', settings => console.log(settings))
this.$store.state.streamDeck.on('didReceiveSettings', payload =>
{
console.log(payload)
let settings = payload?.payload?.settings ?? this.settings
this.defaultPosition = settings.defaultPosition ?? 0.0
this.stepSize = settings.stepSize ?? 2
})
this.$store.state.streamDeck.on('connected', payload => {
let settings = payload?.payload?.settings ?? this.settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<NotConnected v-if="!websocketConnected" />
<div v-else>
<div class="sdpi-item">
<div class="sdpi-item-label">Rotation ({{ currentRotation }})</div>
<span class="sdpi-item-value">
<input type="range" min="0" max="360" step="0.01" v-model="defaultRotation">
</span>
</div>

<div class="sdpi-item">
<div class="sdpi-item-label">Step Size ({{ stepSize ?? '0' }})</div>
<span class="sdpi-item-value">
<input type="range" min="1" max="10" step="1" v-model="stepSize">
</span>
</div>

<div class="sdpi-item">
<div class="sdpi-item-label">Tools</div>
<button class="sdpi-item-value" id="use-current" @click="sendAction('use-current', null)">Current Pos</button>
<button class="sdpi-item-value" id="force-refresh" @click="sendAction('refresh', null)">Refresh</button>
</div>
</div>
</template>

<script>
import NotConnected from "../../components/NotConnected.vue";
export default {
name: 'App',
components: {
NotConnected
},
data() {
return {
websocketConnected: false,
defaultRotation: 0.0,
stepSize: 2
}
},
computed: {
currentRotation() {
let pos = Number(this.defaultRotation) ?? 0
return pos.toLocaleString(undefined, { maximumFractionDigits: 2 }) + "°";
}
},
watch: {
defaultRotation() {
this.saveSettings()
},
stepSize() {
this.saveSettings()
}
},
methods: {
sendAction(command, payload) {
this.$store.state.streamDeck.sendToPlugin({
command, payload
})
},
saveSettings() {
this.$store.state.streamDeck.saveSettings({
defaultRotation: this.defaultPosition,
stepSize: this.stepSize
});
}
},
mounted() {
this.$store.state.streamDeck.on('didReceiveSettings', payload =>
{
let settings = payload?.payload?.settings ?? this.settings
this.defaultRotation = settings.defaultRotation ?? 0.0
this.stepSize = settings.stepSize ?? 2
})
this.$store.state.streamDeck.on('connected', payload => {
let settings = payload?.payload?.settings ?? this.settings
this.defaultRotation = settings.defaultRotation ?? 0.0
this.stepSize = settings.stepSize ?? 2
})
this.$store.state.streamDeck.on('sendToPropertyInspector', e => {
this.websocketConnected = e.connected ?? false
})
},
}
</script>
<style>
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createApp } from 'vue'
import StreamDeck from '../../utils/streamdeck';
import App from './App.vue'
import { createStore } from 'vuex';

window.connectElgatoStreamDeckSocket = function (inPort, inPluginUUID, inRegisterEvent, inInfo, inActionInfo) {
let streamDeck = new StreamDeck(inPort, inPluginUUID, inRegisterEvent, inInfo, inActionInfo);
console.log("Connected to stream deck")

let store = createStore({
state: {
streamDeck,
},
mutations: {
},
actions: {
},
modules: {
}
})

createApp(App).use(store).mount('#app')
}



Loading

0 comments on commit df154da

Please sign in to comment.