Skip to content

Commit

Permalink
Add basic support for long, float (#150)
Browse files Browse the repository at this point in the history
* feat: support long types in configurations

* feat: support float types in configurations
  • Loading branch information
BD103 authored Dec 12, 2023
1 parent 82b536f commit 26920d6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ private static ConfigVariable<?> createVariableFromArrayField(Field field, Class
switch (type) {
case BOOLEAN:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case STRING:
case ENUM:
Expand Down Expand Up @@ -88,6 +90,8 @@ private static ConfigVariable<?> createVariableFromField(Field field, Object par
switch (type) {
case BOOLEAN:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case STRING:
case ENUM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public ConfigVariable<?> deserialize(JsonElement jsonElement, Type type,
case INT:
return new BasicVariable<>(varType,
new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsInt()));
case LONG:
return new BasicVariable<>(varType,
new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsLong()));
case FLOAT:
return new BasicVariable<>(varType,
new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsFloat()));
case DOUBLE:
return new BasicVariable<>(varType,
new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsDouble()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public enum VariableType {
@SerializedName("int")
INT,

@SerializedName("long")
LONG,

@SerializedName("float")
FLOAT,

@SerializedName("double")
DOUBLE,

Expand All @@ -34,6 +40,10 @@ public static VariableType fromClass(Class<?> klass) {
return BOOLEAN;
} else if (klass == Integer.class || klass == int.class) {
return INT;
} else if (klass == Long.class || klass == long.class) {
return LONG;
} else if (klass == Float.class || klass == float.class) {
return FLOAT;
} else if (klass == Double.class || klass == double.class) {
return DOUBLE;
} else if (klass == String.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ public void set(TestEnum value) {
}
});

core.addConfigVariable("More Primitives", "Long", new ValueProvider<Long>() {
private long value = 10L;

@Override
public Long get() {
return this.value;
}

@Override
public void set(Long value) {
this.value = value;
}
});
core.addConfigVariable("More Primitives", "Float", new ValueProvider<Float>() {
private float value = 10L;

@Override
public Float get() {
return this.value;
}

@Override
public void set(Float value) {
this.value = value;
}
});

try {
server.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class BasicVariable extends React.Component<Props> {
} else {
switch (state.__type) {
case 'int':
case 'long':
input = (
<TextInput
id={path}
Expand All @@ -72,6 +73,7 @@ class BasicVariable extends React.Component<Props> {
/>
);
break;
case 'float':
case 'double':
if (typeof state.__value === 'string') {
input = <p>{state.__value}</p>;
Expand Down
4 changes: 2 additions & 2 deletions FtcDashboard/dash/src/store/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type BasicVar =
__enumValues: string[];
}
| {
__type: 'boolean' | 'int' | 'double' | 'string';
__type: 'boolean' | 'int' | 'long' | 'float' | 'double' | 'string';
__value: boolean | number | string | null;
};

Expand All @@ -33,7 +33,7 @@ export type BasicVarState = (
__enumValues: string[];
}
| {
__type: 'boolean' | 'int' | 'double' | 'string';
__type: 'boolean' | 'int' | 'long' | 'float' | 'double' | 'string';
__value: boolean | number | string | null;
__newValue: boolean | number | string | null;
}
Expand Down

0 comments on commit 26920d6

Please sign in to comment.