Skip to content

Commit

Permalink
bugfixes and updated payload for safety
Browse files Browse the repository at this point in the history
- issue occurred while add/remove monkey test, and fixed the bug; refinement did not occurred at index 0).

- updated payload structure and logics regarding the payload for safety.

- added DLogger class for Debugging. DLogger only works on DEBUG build version

- wrong expression of count of effect/function in main PI: minor-bug fixed when data array count is 0.
  • Loading branch information
artrointel committed Jun 29, 2021
1 parent a48847f commit a346585
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 40 deletions.
14 changes: 7 additions & 7 deletions ArtrointelPlugin/Control/AvengersKeyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AvengersKeyController(JObject settings, Action<SDCanvas> rendererUpdatedL
private void refineEffectConfigurations()
{
var effectCfgs = mSettings.EffectConfigurations;
for (int i = effectCfgs.Count - 1; i != 0; i--)
for (int i = effectCfgs.Count - 1; i != -1; i--)
{
if (!RendererFactory.IsSupported((EffectConfig)effectCfgs[i]))
{
Expand All @@ -58,7 +58,7 @@ private void refineEffectConfigurations()
private void refineFunctionConfigurations()
{
var functionCfgs = mSettings.FunctionConfigurations;
for (int i = functionCfgs.Count - 1; i != 0; i--)
for (int i = functionCfgs.Count - 1; i != -1; i--)
{
if (!FunctionFactory.IsSupported((FunctionConfig)functionCfgs[i]))
{
Expand Down Expand Up @@ -115,25 +115,25 @@ private void initializeRenderEngine()
public bool handlePayload(JObject payload)
{
// Handles Effect payload
int effectCount = PayloadReader.isEffectPayload(payload);
if(effectCount > 0)
if(PayloadReader.isEffectPayload(payload))
{
int effectCount = PayloadReader.getArrayCount(payload);
mSettings.EffectConfigurations = PayloadReader.LoadEffectDataFromPayload(payload, effectCount);
refineEffectConfigurations();
initializeRenderEngine();
return true;
}

// Handles Function payload
int functionCount = PayloadReader.isFunctionPayload(payload);
if (functionCount > 0)
if(PayloadReader.isFunctionPayload(payload))
{
int functionCount = PayloadReader.getArrayCount(payload);
mSettings.FunctionConfigurations = PayloadReader.LoadFunctionDataFromPayload(payload, functionCount);
refineFunctionConfigurations();
initializeFunctionExecutor();
return true;
}

// Handles Image update payload
String imgPath = PayloadReader.isImageUpdatePayload(payload);
if (imgPath != null && File.Exists(imgPath))
Expand Down
4 changes: 4 additions & 0 deletions ArtrointelPlugin/Control/Model/EffectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ public static EffectConfig Create(string trigger, string type, string hexRgb, st
return cfg;
}

public override string ToString() {
string ret = $"Trigger:{mTrigger}, Type:{mType}, HexRgb:{mHexRgb}, Alpha:{mAlpha}, Delay:{mDelay}, Duration:{mDuration}, Meta:{mMetadata}";
return ret;
}
}
}
6 changes: 5 additions & 1 deletion ArtrointelPlugin/Control/Model/FunctionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public static FunctionConfig Load(string trigger, string type, double delay, dou
cfg.mMetadata = metadata;
return cfg;
}

public override string ToString()
{
string ret = $"Trigger:{mTrigger}, Type:{mType}, Delay:{mDelay}, Alpha:{mInterval}, Duration:{mDuration}, Meta:{mMetadata}";
return ret;
}
}
}
35 changes: 26 additions & 9 deletions ArtrointelPlugin/Control/Payload/PayloadReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class PayloadReader
// constants from property inspector written in javascript.
public const string PAYLOAD_IMAGE_UPDATE_KEY = "payload_updateImage";
public const string PAYLOAD_EFFECT_KEY = "payload_updateEffects";
public const string PAYLOAD_FUNCTIONS_KEY = "payload_updateFunctions";
public const string PAYLOAD_FUNCTION_KEY = "payload_updateFunctions";

public const string PAYLOAD_COUNT = "payload_arrayCount";

public const string KEY_EFFECT_TRIGGER = "sEffectTrigger";
public const string KEY_EFFECT_TYPE = "sEffectType";
Expand All @@ -33,21 +35,36 @@ private PayloadReader()

}

public static int isEffectPayload(JObject payload)
public static bool isEffectPayload(JObject payload)
{
bool ret = false;
try
{
ret = bool.Parse(payload.Value<string>(PAYLOAD_EFFECT_KEY));
}
catch { }
return ret;
}

public static bool isFunctionPayload(JObject payload)
{
int effectCount = payload.Value<int>(PAYLOAD_EFFECT_KEY);
return effectCount;
bool ret = false;
try
{
ret = bool.Parse(payload.Value<string>(PAYLOAD_FUNCTION_KEY));
}
catch { }
return ret;
}

public static int isFunctionPayload(JObject payload)
public static int getArrayCount(JObject payload)
{
int functionCount = payload.Value<int>(PAYLOAD_FUNCTIONS_KEY);
return functionCount;
return payload.Value<int>(PAYLOAD_COUNT);
}

public static String isImageUpdatePayload(JObject payload)
public static string isImageUpdatePayload(JObject payload)
{
String imagePath = payload.Value<String>(PAYLOAD_IMAGE_UPDATE_KEY);
string imagePath = payload.Value<string>(PAYLOAD_IMAGE_UPDATE_KEY);
return imagePath;
}

Expand Down
3 changes: 2 additions & 1 deletion ArtrointelPlugin/PluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ArtrointelPlugin.Utils;

namespace ArtrointelPlugin
{
Expand Down Expand Up @@ -107,7 +108,7 @@ public override void OnTick() { }

public override void ReceivedSettings(ReceivedSettingsPayload payload)
{

DLogger.LogMessage(TracingLevel.DEBUG, "ReceivedSettings: " + payload.ToString());
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) { }
Expand Down
16 changes: 5 additions & 11 deletions ArtrointelPlugin/PropertyInspector/effectPI/effectPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,16 @@ function onBtnCancelClicked() {
function onBtnApplyClicked() {
// process saving all changes
var payload = buildEffectPayload();
if (payload == null) {
alert("Invalid data exists. cannot apply the effect.");
} else {
window.opener.sendPayloadToPlugin(payload);
window.close();
}
window.opener.sendPayloadToPlugin(payload);
window.close();
}

function buildEffectPayload() {
var payload = {};
var count = document.getElementsByName('effectItem').length;

payload['payload_updateEffects'] = 'true';
payload['payload_arrayCount'] = count;
if (count > 0) {
payload['payload_updateEffects'] = count;
for (var i = 1; i <= count; i++) {
payload['sEffectTrigger' + i] = getSelectValue('sEffectTrigger', i);
payload['sEffectType' + i] = getSelectValue('sEffectType', i);
Expand All @@ -204,8 +200,6 @@ function buildEffectPayload() {
payload['iEffectDuration' + i] = getValue('iEffectDuration', i);
payload['iEffectMetadata' + i] = getValue('iEffectMetadata', i);
}
return payload;
} else {
return null;
}
return payload;
}
16 changes: 5 additions & 11 deletions ArtrointelPlugin/PropertyInspector/functionPI/functionPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,16 @@ function onBtnCancelClicked() {
function onBtnApplyClicked() {
// process saving all changes
var payload = buildFunctionPayload();
if (payload == null) {
alert("Invalid data exists. cannot apply the effect.");
} else {
window.opener.sendPayloadToPlugin(payload);
window.close();
}
window.opener.sendPayloadToPlugin(payload);
window.close();
}

function buildFunctionPayload() {
var payload = {};
var count = document.getElementsByName('functionItem').length;

payload['payload_updateFunctions'] = 'true';
payload['payload_arrayCount'] = count;
if (count > 0) {
payload['payload_updateFunctions'] = count;
for (var i = 1; i <= count; i++) {
payload['sFunctionTrigger' + i] = getSelectValue('sFunctionTrigger', i);
payload['sFunctionType' + i] = getSelectValue('sFunctionType', i);
Expand All @@ -292,8 +288,6 @@ function buildFunctionPayload() {
payload['iFunctionDuration' + i] = getValue('iFunctionDuration', i);
payload['iFunctionMetadata' + i] = getValue('iFunctionMetadata', i);
}
return payload;
} else {
return null;
}
return payload;
}
4 changes: 4 additions & 0 deletions ArtrointelPlugin/PropertyInspector/mainPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ window.addEventListener('onSettingsUpdated', function (e) {

if (fCount > 0) {
document.getElementById('btnFunctionEdit').innerHTML = 'Edit (' + fCount + ')';
} else {
document.getElementById('btnFunctionEdit').innerHTML = 'Edit';
}
if (eCount > 0) {
document.getElementById('btnEffectEdit').innerHTML = 'Edit (' + eCount + ')';
} else {
document.getElementById('btnEffectEdit').innerHTML = 'Edit';
}
});

Expand Down
19 changes: 19 additions & 0 deletions ArtrointelPlugin/Utils/DLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BarRaider.SdTools;

namespace ArtrointelPlugin.Utils
{
class DLogger
{
public static void LogMessage(TracingLevel level, string msg)
{
#if DEBUG
Logger.Instance.LogMessage(level, msg);
#endif
}
}
}
39 changes: 39 additions & 0 deletions debug.sdPlugin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Rem yourPluginID
SET PLUGIN_NAME=com.artrointel.avengerskey



SET CURR_DIR=%~dp0
SET SDTOOLS_RELEASE_DIR=%CURR_DIR%\barraider-sdtools\bin\Release\netstandard2.0
SET PLUGIN_DIR=%PLUGIN_NAME%.sdPlugin

Rem packging all resource files
SET AVGKEY_DIR=%CURR_DIR%\ArtrointelPlugin
SET AVGKEY_DEBUG_DIR=%CURR_DIR%\ArtrointelPlugin\bin\Debug\%PLUGIN_DIR%
SET AVGKEY_IMG_DIR=%AVGKEY_DIR%\Images
SET AVGKEY_RES_DIR=%AVGKEY_DIR%\Res
SET AVGKEY_PI_DIR=%AVGKEY_DIR%\PropertyInspector

SET MANIFEST_FILE=manifest.json

SET TARGET_DIR=%PLUGIN_DIR%
SET RELEASE_DIR=Release\

rmdir /s /q %RELEASE_DIR%
rmdir /s /q %TARGET_DIR%
mkdir %RELEASE_DIR%
mkdir %TARGET_DIR%

robocopy %SDTOOLS_RELEASE_DIR%\ %TARGET_DIR%\
robocopy %AVGKEY_DEBUG_DIR%\ %TARGET_DIR%\
robocopy %AVGKEY_DIR%\ %TARGET_DIR%\ %MANIFEST_FILE%

robocopy %AVGKEY_PI_DIR%\ %TARGET_DIR%\PropertyInspector\ /E
robocopy %AVGKEY_IMG_DIR%\ %TARGET_DIR%\Images\ /E
robocopy %AVGKEY_RES_DIR%\ %TARGET_DIR%\Res\ /E

Rem disable your anti-virus system if it cannot release the your.streamDeckPlugin file.
DistributionTool.exe -b -i %TARGET_DIR% -o %RELEASE_DIR%

Rem remove belows for debugging
rmdir /s /q %TARGET_DIR%

0 comments on commit a346585

Please sign in to comment.