Files
RidgeScout/app/src/main/java/com/astatin3/scoutingapp2025/scoutingData/fields.java
T

146 lines
5.0 KiB
Java
Raw Normal View History

2024-06-27 22:12:36 -06:00
package com.astatin3.scoutingapp2025.scoutingData;
2024-06-26 13:31:31 -06:00
import com.astatin3.scoutingapp2025.types.input.dropdownType;
import com.astatin3.scoutingapp2025.types.input.inputType;
import com.astatin3.scoutingapp2025.types.input.notesType;
import com.astatin3.scoutingapp2025.types.input.sliderType;
2024-06-28 15:44:38 -06:00
import com.astatin3.scoutingapp2025.utility.fileEditor;
2024-06-27 22:12:36 -06:00
import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder;
import java.util.ArrayList;
2024-06-26 13:31:31 -06:00
public class fields {
// public static ScoutingVersion sv = new ScoutingVersion();
2024-06-28 15:44:38 -06:00
public static final String matchFieldsFilename = "matches.fields";
2024-06-29 17:51:40 -06:00
public static final String pitsFieldsFilename = "pits.fields";
public static final inputType[][] default_match_fields = new inputType[][] {
2024-06-27 22:12:36 -06:00
{
new sliderType("How good is robot", 5, 1, 10),
new notesType("notes", "<no-notes>"),
2024-06-28 15:44:38 -06:00
},{
new sliderType("How good is robot", 5, 1, 10),
new sliderType("Test", 128, 64, 256),
new notesType("notes", "<no-notes>"),
},{
new sliderType("How good is robot", 5, 1, 10),
new sliderType("Test", 128, 64, 256),
new dropdownType("test-dropdown", new String[]{"Test1", "test2", "Three"}, 1),
new notesType("notes", "<no-notes>"),
2024-06-27 22:12:36 -06:00
}
};
public static final inputType[][] default_pit_fields = new inputType[][] {
2024-06-28 15:44:38 -06:00
{
new sliderType("How good is robot", 5, 0, 10),
new notesType("notes", "<no-notes>"),
2024-06-28 15:44:38 -06:00
},{
new sliderType("How good is robot", 5, 0, 10),
new sliderType("Test", 1, 0, 10),
new notesType("notes", "<no-notes>"),
2024-06-28 15:44:38 -06:00
}
};
public static boolean save(String filename, inputType[][] values){
try {
ByteBuilder bb = new ByteBuilder();
for (int i = 0; i < values.length; i++) {
bb.addRaw(127, save_version(values[i]));
}
2024-06-28 15:44:38 -06:00
fileEditor.writeFile(filename, bb.build());
return true;
}catch (ByteBuilder.buildingException e) {
e.printStackTrace();
return false;
// throw new RuntimeException(e);
}
}
private static byte[] save_version(inputType[] values) throws ByteBuilder.buildingException {
ByteBuilder bb = new ByteBuilder();
for(int i =0; i < values.length; i++){
bb.addRaw(values[i].get_byte_id(), values[i].encode());
}
return bb.build();
}
public static inputType[][] load(String filename){
2024-06-28 15:44:38 -06:00
byte[] bytes = fileEditor.readFile(filename);
2024-06-27 22:12:36 -06:00
System.out.println(bytes);
try {
BuiltByteParser bbp = new BuiltByteParser(bytes);
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
inputType[][] values = new inputType[objects.size()][];
for(int i = 0 ; i < objects.size(); i++){
values[i] = load_version((byte[]) objects.get(i).get());
}
2024-06-28 15:44:38 -06:00
return values;
// return true;
2024-06-27 22:12:36 -06:00
} catch (Exception e) {
e.printStackTrace();
2024-06-28 15:44:38 -06:00
return null;
// return false;
}
}
private static inputType[] load_version(byte[] bytes) throws BuiltByteParser.byteParsingExeption{
BuiltByteParser bbp = new BuiltByteParser(bytes);
ArrayList<BuiltByteParser.parsedObject> objects = bbp.parse();
inputType[] output = new inputType[objects.size()];
for(int i = 0 ; i < objects.size(); i++){
BuiltByteParser.parsedObject obj = objects.get(i);
inputType t = null;
switch (obj.getType()){
case inputType.slider_type_id:
t = new sliderType();
break;
case inputType.dropdownType:
t = new dropdownType();
break;
case inputType.notesType:
t = new notesType();
break;
}
t.decode((byte[]) obj.get());
output[i] = t
;
}
return output;
}
2024-06-28 15:44:38 -06:00
// public static void test(){
// ScoutingVersion.transferType[][] transferValues = sv.get_transfer_values(values);
//
// ScoutingVersion.ScoutingArray msa = sv.new ScoutingArray(0, new ScoutingVersion.dataType[]{
// sv.new stringType("name", "test-username"),
// sv.new intType("How good is robot", 12)
// }, values, transferValues);
//
// msa.update();
//
// for(ScoutingVersion.dataType dt : msa.array){
// if(dt == null) continue;
// switch (dt.getValueType()){
// case NUM:
// System.out.println(dt.name + " " + (int) dt.get());
// break;
// case STRING:
// System.out.println(dt.name + " " + (String) dt.get());
// break;
// }
//
// }
// }
2024-06-26 13:31:31 -06:00
}