Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,10 @@ FodyWeavers.xsd
*.msp

# JetBrains Rider
*.sln.iml
*.sln.iml

# config file created by Avalonia by error sometimes
config.json


!MacroPad.Core/BasePlugin/**
1 change: 1 addition & 0 deletions ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using MacroPad.Core;
using MacroPad.Core.Device;
using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Protocol;
using System.Reflection;
Expand Down
14 changes: 1 addition & 13 deletions MacroPad.Core/BasePlugin/BasePluginInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@ namespace MacroPad.Core.BasePlugin
{
public class BasePluginInfos : IPluginInfos
{
public string Name => "Base Plugin";

public string Description => "The usefulest plugin of MacroPad.";

public string Version => "1.0.0";

public string Author => "Piripe";

public string? AuthorUrl => null;

public string? SourceUrl => null;

public IProtocol[] Protocols => [];

public INodeCategory[] NodeCategories => [new BranchingCategory(), new ConditionsCategory() ,new ConstantsCategory(), new DebugCategory(), new TextCategory()];
public INodeCategory[] NodeCategories => [new BranchingCategory(), new ButtonCategory(), new ConditionsCategory(), new ConstantsCategory(), new DebugCategory(), new MathCategory(), new ProfileCategory(), new TextCategory(), new VariableCategory()];

public NodeType[] NodeTypes => [.. DefaultTypes.types];
public ISettingsComponent[] Settings => [];
Expand Down
4 changes: 2 additions & 2 deletions MacroPad.Core/BasePlugin/Branching/GetBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class GetBranch : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return new object[] { resource.GetValue((bool)resource.GetValue(0) ? 2 : 1) };
return [ resource.GetValue((bool)resource.GetValue(0) ? 2 : 1) ];
}
}
}
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Branching/RunBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SetPaletteColor : INodeRunner
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public NodeRunnerResult Run(IResourceManager resource)
public NodeRunnerResult Run(INodeResourceManager resource)
{
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = (bool)resource.GetValue(0) ? 1 : 0 };
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Button/GetCurrentValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GetCurrentValue : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => button.Type == ButtonType.Slider;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [(decimal)(NodeManager.CurrentDevice != null && NodeManager.CurrentButton != null ? NodeManager.CurrentDevice.ButtonsCurrentValue[NodeManager.CurrentButton.Id].Value : 0)];
}
Expand Down
7 changes: 4 additions & 3 deletions MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Button
{
Expand All @@ -22,9 +23,9 @@ public class SetCurrentPaletteColor : INodeRunner
public INodeComponent[] Components => [
new ComboBox()
{
GetItems = (IResourceManager resource, IDeviceLayoutButton button, IDeviceOutput output) =>
GetItems = (IResourceManager resource) =>
{
return output.Palette.Select(x=>x.Name).ToArray();
return resource.GetVirtual<IDeviceOutput>(VirtualDataKey.DeviceOutput)?.Palette.Select(x=>x.Name).ToArray() ?? [];
},
GetSelection = (IResourceManager resource) =>
{
Expand All @@ -38,7 +39,7 @@ public class SetCurrentPaletteColor : INodeRunner
];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => output.OutputType == OutputType.Palette;
public NodeRunnerResult Run(IResourceManager resource)
public NodeRunnerResult Run(INodeResourceManager resource)
{
if (NodeManager.CurrentButton != null) NodeManager.CurrentDevice?.SetButtonContent(NodeManager.CurrentButton, resource.GetData<int>("color"));
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
Expand Down
3 changes: 2 additions & 1 deletion MacroPad.Core/BasePlugin/Conditions/Condition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Conditions
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public class Condition : INodeGetter
private static decimal ObjectToDecimal(object x) => (decimal.TryParse(x.ToString(), out decimal val) ? val : 0m);

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [ _operations[resource.GetData<int>("o")](resource.GetValue(0), resource.GetValue(1)) ];
}
Expand Down
3 changes: 2 additions & 1 deletion MacroPad.Core/BasePlugin/Constants/Boolean.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Constants
{
Expand All @@ -23,7 +24,7 @@ internal class Boolean : INodeGetter
} ];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [resource.GetData<bool?>("v") ?? false];
}
Expand Down
5 changes: 3 additions & 2 deletions MacroPad.Core/BasePlugin/Constants/Number.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Constants
{
Expand All @@ -24,9 +25,9 @@ internal class Number : INodeGetter
} ];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return new object[] { resource.GetData<decimal?>("v") ?? 0m };
return [ resource.GetData<decimal?>("v") ?? 0m ];
}
}
}
3 changes: 2 additions & 1 deletion MacroPad.Core/BasePlugin/Constants/Text.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Constants
{
Expand All @@ -22,7 +23,7 @@ internal class Text : INodeGetter
} ];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [resource.GetData<string>("v") ?? ""];
}
Expand Down
30 changes: 30 additions & 0 deletions MacroPad.Core/BasePlugin/Debug/WriteLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;

namespace MacroPad.Core.BasePlugin.Debug
{
public class WriteLine : INodeRunner
{
public string Name => "Write Line";

public string Description => "Write a line in the console.";

public string Id => "WriteLine";

public TypeNamePair[] Inputs => [new(typeof(string), "Text")];

public TypeNamePair[] Outputs => [];

public int RunnerOutputCount => 1;
public string[] RunnerOutputsName => [];

public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public NodeRunnerResult Run(INodeResourceManager resource)
{
System.Diagnostics.Debug.WriteLine(resource.GetValue(0));
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
}
}
}
1 change: 0 additions & 1 deletion MacroPad.Core/BasePlugin/DefaultTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;

namespace MacroPad.Core.BasePlugin
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Absolute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Absolute : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Abs((decimal)resource.GetValue(0))];
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Floor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Floor : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Floor((decimal)resource.GetValue(0))];
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Map : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
decimal value = (decimal)resource.GetValue(0);
decimal minIn = (decimal)resource.GetValue(1);
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Max.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Max : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Max((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Min.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Min : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Min((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/MinMax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MinMax : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Min(System.Math.Max((decimal)resource.GetValue(0), (decimal)resource.GetValue(1)), (decimal)resource.GetValue(2))];
}
Expand Down
3 changes: 2 additions & 1 deletion MacroPad.Core/BasePlugin/Math/Operation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Math
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public class Operation : INodeGetter
];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [_operations[resource.GetData<int>("o")]((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
Expand Down
2 changes: 1 addition & 1 deletion MacroPad.Core/BasePlugin/Math/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Round : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Round((decimal)resource.GetValue(0))];
}
Expand Down
5 changes: 3 additions & 2 deletions MacroPad.Core/BasePlugin/Profile/SetProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using MacroPad.Shared.Plugin;

namespace MacroPad.Core.BasePlugin.Profile
{
Expand Down Expand Up @@ -33,7 +34,7 @@ private int GetProfileIndex(DeviceCore? device, IResourceManager resource)

public INodeComponent[] Components => [
new ComboBox() {
GetItems = (IResourceManager resource, IDeviceLayoutButton button, IDeviceOutput output) =>
GetItems = (IResourceManager resource) =>
{
return DeviceManager.SelectedDevice?.DeviceProfiles.Select(x=>x.Name).ToArray() ?? [];
},
Expand All @@ -47,7 +48,7 @@ private int GetProfileIndex(DeviceCore? device, IResourceManager resource)
];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public NodeRunnerResult Run(IResourceManager resource)
public NodeRunnerResult Run(INodeResourceManager resource)
{
if (NodeManager.CurrentDevice != null) NodeManager.CurrentDevice.SelectProfile(GetProfileIndex(NodeManager.CurrentDevice, resource));
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
Expand Down
7 changes: 1 addition & 6 deletions MacroPad.Core/BasePlugin/Text/Join.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MacroPad.Core.BasePlugin.Text
{
Expand All @@ -23,7 +18,7 @@ public class Join : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [string.Concat(resource.GetValue(0), resource.GetValue(1))];
}
Expand Down
7 changes: 1 addition & 6 deletions MacroPad.Core/BasePlugin/Text/Replace.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MacroPad.Core.BasePlugin.Text
{
Expand All @@ -23,7 +18,7 @@ public class Replace : INodeGetter
public INodeComponent[] Components => [];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
return [((string)resource.GetValue(0)).Replace((string)resource.GetValue(1), (string)resource.GetValue(2))];
}
Expand Down
7 changes: 4 additions & 3 deletions MacroPad.Core/BasePlugin/Variables/Get.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using Newtonsoft.Json.Linq;
using MacroPad.Shared.Plugin;
using System.Text.Json.Nodes;

namespace MacroPad.Core.BasePlugin.Variables
{
Expand All @@ -23,10 +24,10 @@ public class Get : INodeGetter
} ];

public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
public object[] GetOutputs(IResourceManager resource)
public object[] GetOutputs(INodeResourceManager resource)
{
string var = resource.GetData<string>("v") ?? "";
return [(DeviceManager.Config.Variables.TryGetValue(var, out JToken? value) ? value.Value<object>() : null) ?? ""];
return [(DeviceManager.Config.Variables.TryGetValue(var, out JsonValue? value) ? value.TryGetValue(out object? value2) ? value2 : null : null) ?? ""];
}
}
}
Loading