acmerobotics / ftc-dashboard

React-based web dashboard designed for FTC
https://acmerobotics.github.io/ftc-dashboard
Other
168 stars 125 forks source link

Add array config support #144

Closed MafteiAlbert-Alexandru closed 10 months ago

MafteiAlbert-Alexandru commented 10 months ago

As it says, this config adds the ability to edit array values in the Config window of the dashboard. This is achieved by using different ValueProvider implementation(which accesses the values from the array) when creating nested CustomVariables, and using indices as the names for those variables. This modification is safe, since resizing the array doesn't cause any exceptions, but should ideally somehow cause a refresh of the config variables.

rbrott commented 10 months ago

I put together a test config class.

package com.acmerobotics.dashboard.testopmode;

public class TestConfig {
    public static int[] NUM_ARRAY = {1, 2, 3};
    public static int[] EMPTY_ARRAY = {};
    public static int[] NULL_ARRAY = null;

    public static int[][] NESTED_ARRAY = {{1, 2}, {3, 4}};
    public static int[][] NESTED_EMPTY_ARRAY = {{}, {}};

    public static int[][] RAGGED_ARRAY = {{1, 2}, {3, 4, 5}};

    public static class NestedClass {
        public int[] numArray = {1, 2, 3};
        public int[] emptyArray = {};
        public int[] nullArray = null;

        public int[][] nestedArray = {{1, 2}, {3, 4}};
        public int[][] nestedEmptyArray = {{}, {}};

        public int[][] raggedArray = {{1, 2}, {3, 4, 5}};
    }
    public static NestedClass NESTED_CLASS = new NestedClass();
}

And this PR seems to handle the one-dimensional arrays great (:tada:) and recurses infinitely on the two-dimensional ones.

rbrott commented 10 months ago

I'm testing with TestServer and the following patch

diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java
index 3fb819e..2a3fe56 100644
--- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java
+++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java
@@ -5,11 +5,13 @@ import com.acmerobotics.dashboard.RobotStatus;
 import com.acmerobotics.dashboard.SendFun;
 import com.acmerobotics.dashboard.SocketHandler;
 import com.acmerobotics.dashboard.config.ValueProvider;
+import com.acmerobotics.dashboard.config.reflection.ReflectionConfig;
 import com.acmerobotics.dashboard.message.Message;
 import com.acmerobotics.dashboard.message.redux.InitOpMode;
 import com.acmerobotics.dashboard.message.redux.ReceiveOpModeList;
 import com.acmerobotics.dashboard.message.redux.ReceiveRobotStatus;
 import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
+import com.acmerobotics.dashboard.testopmode.TestConfig;
 import com.acmerobotics.dashboard.testopmode.TestOpMode;
 import com.acmerobotics.dashboard.testopmode.TestOpModeManager;

@@ -181,6 +183,9 @@ public class TestDashboardInstance {
             }
         });

+        core.withConfigRoot(configRoot ->
+            configRoot.putVariable("TestConfig", ReflectionConfig.createVariableFromClass(TestConfig.class)));
+

         try {
             server.start();

Maybe that can help speed up your workflow.

MafteiAlbert-Alexandru commented 10 months ago

Worked on nested/multidimensional arrays and they work now.