-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add expression toggle action and expression caching for Stream Deck plugin #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cazzar
wants to merge
2
commits into
main
Choose a base branch
from
expressions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| namespace StreamDeckLib.Models | ||
| { | ||
| public record StatePayload(uint Payload); | ||
| public record StatePayload(uint State); | ||
|
|
||
| record TitlePayload(string? Title, int Target, int State); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Events; | ||
|
|
||
| public class HotkeyTriggeredEvent | ||
| { | ||
| [JsonProperty("hotkeyID")] | ||
| public required string Id { get; set; } | ||
|
|
||
| [JsonProperty("hotkeyName")] | ||
| public required string Name { get; set; } | ||
|
|
||
| [JsonProperty("hotkeyAction")] | ||
| public required string Action { get; set; } | ||
|
|
||
| [JsonProperty("hotkeyFile")] | ||
| public required string File { get; set; } | ||
|
|
||
| [JsonProperty("hotkeyTriggeredByAPI")] | ||
| public bool ApiTriggered { get; set; } | ||
|
|
||
| [JsonProperty("modelID")] | ||
| public required string ModelId { get; set; } | ||
|
|
||
| [JsonProperty("modelName")] | ||
| public required string ModelName { get; set; } | ||
|
|
||
| [JsonProperty("isLive2DItem")] | ||
| public bool IsLive2DItem { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace VTubeStudioAPI.Models; | ||
|
|
||
| public class Expression | ||
| { | ||
| [JsonProperty("name")] | ||
| public required string Name { get; set; } | ||
|
|
||
| [JsonProperty("file")] | ||
| public required string File { get; set; } | ||
|
|
||
| [JsonProperty("active")] | ||
| public bool Active { get; set; } | ||
|
|
||
| [JsonProperty("deactivateWhenKeyIsLetGo")] | ||
| public bool DeactivateWhenKeyIsLetGo { get; set; } | ||
|
|
||
| [JsonProperty("autoDeactivateAfterSeconds")] | ||
| public bool AutoDeactivateAfterSeconds { get; set; } | ||
|
Cazzar marked this conversation as resolved.
|
||
|
|
||
| [JsonProperty("secondsRemaining")] | ||
| public int SecondsRemaining { get; set; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Responses; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests; | ||
|
|
||
| public abstract class ApiRequest | ||
| { | ||
| [JsonIgnore] | ||
| public abstract RequestType MessageType { get; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Responses; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests; | ||
|
|
||
| public class ExpressionActivationRequest(string? expressionFile = null, bool activate = true, float fadeTime = 0.5f) : ApiRequest | ||
| { | ||
| [JsonProperty("expressionFile")] | ||
| public string? ExpressionFile { get; set; } = expressionFile; | ||
| [JsonProperty("active")] | ||
| public bool? Activate { get; set; } = activate; | ||
| [JsonProperty("fadeTime")] | ||
| public float FadeTime { get; set; } = fadeTime; | ||
|
|
||
| public override RequestType MessageType { get; } = RequestType.ExpressionActivationRequest; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Responses; | ||
|
|
||
| namespace Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests; | ||
|
|
||
| public class ExpressionStateRequest(string? expressionFile = null) : ApiRequest | ||
| { | ||
| public string? ExpressionFile { get; set; } = expressionFile; | ||
|
|
||
| public override RequestType MessageType { get; } = RequestType.ExpressionStateRequest; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Newtonsoft.Json; | ||
| using VTubeStudioAPI.Models; | ||
|
|
||
| namespace VTubeStudioAPI.Responses; | ||
|
|
||
| public class ExpressionStateResponse | ||
| { | ||
| [JsonProperty("modelLoaded")] | ||
| public bool ModelLoaded { get; set; } | ||
|
|
||
| [JsonProperty("modelName")] | ||
| public required string ModelName { get; set; } | ||
|
|
||
| [JsonProperty("modelID")] | ||
| public required string ModelId { get; set; } | ||
|
|
||
| [JsonProperty("expressions")] | ||
| public required List<Expression> Expressions { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #nullable enable | ||
| using System.Linq; | ||
| using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi; | ||
| using Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi.Requests; | ||
| using Microsoft.Extensions.Logging; | ||
| using Newtonsoft.Json; | ||
| using StreamDeckLib; | ||
| using StreamDeckLib.Models; | ||
|
|
||
| namespace Cazzar.StreamDeck.VTubeStudio.Actions; | ||
|
|
||
|
|
||
| [StreamDeckAction("dev.cazzar.vtubestudio.expressiontoggle")] | ||
| public class ExpressionToggleAction : BaseAction<ExpressionToggleAction.ExpressionTogglePayload> | ||
| { | ||
| private readonly ExpressionCache _expressionCache; | ||
|
|
||
| public class ExpressionTogglePayload | ||
| { | ||
| [JsonProperty("expression")] | ||
| public string? Expression { get; set; } = "Cat Tail.exp3.json"; | ||
|
|
||
| [JsonProperty("fadeTime")] | ||
| public float FadeTime { get; set; } = 0.5f; | ||
| } | ||
|
|
||
| public ExpressionToggleAction(GlobalSettingsManager gsm, VTubeStudioWebsocketClient vts, IStreamDeckConnection isd, ILogger<ExpressionToggleAction> logger, ExpressionCache expressionCache) : base(gsm, vts, isd, logger) | ||
| { | ||
| _expressionCache = expressionCache; | ||
| } | ||
|
|
||
| protected override void Pressed() | ||
| { | ||
| if (!_expressionCache.ModelLoaded) | ||
| return; | ||
|
|
||
| var activate = !_expressionCache.Expressions.FirstOrDefault(e => e.File == Settings.Expression)?.Active ?? false; | ||
|
|
||
| Vts.Send(new ExpressionActivationRequest(Settings.Expression, activate, Settings.FadeTime)); | ||
|
|
||
| Connection.SendMessage(new SetStateRequest | ||
| { | ||
| Payload = new ((uint) (activate ? 1 : 0)), | ||
| Context = ContextId, | ||
| }); | ||
| } | ||
|
|
||
| public override void Tick() | ||
| { | ||
| base.Tick(); | ||
| var activate = !_expressionCache.Expressions.FirstOrDefault(e => e.File == Settings.Expression)?.Active ?? false; | ||
|
|
||
| Connection.SendMessage(new SetStateRequest | ||
| { | ||
| Payload = new ((uint) (activate ? 1 : 0)), | ||
| Context = ContextId, | ||
| }); | ||
| } | ||
|
|
||
| protected override object GetClientData() => new | ||
| { | ||
| expressions = _expressionCache.Expressions.DistinctBy(e => e.File).Select(e => new { e.Name, e.File }), | ||
| }; | ||
|
|
||
| protected override void Released() | ||
| { | ||
| } | ||
|
|
||
| protected override void SettingsUpdated(ExpressionTogglePayload oldSettings, ExpressionTogglePayload newSettings) | ||
| { | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent namespace naming.
The namespace
VTubeStudioAPI.Modelsdiffers from the convention used in other files (Cazzar.StreamDeck.VTubeStudio.VTubeStudioApi...). This inconsistency could cause confusion and potential import issues.Change the namespace to match the project convention:
🤖 Prompt for AI Agents