added datatypes to Data
This commit is contained in:
parent
e4d090dbd9
commit
3857c64e41
|
@ -1,13 +1,18 @@
|
|||
package com.danitheskunk.skunkworks;
|
||||
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Data {
|
||||
static final String[] vectorSeperators = new String[]{"x", ",", " "};
|
||||
private final LinkedHashMap<String, LinkedHashMap<String, String>> data;
|
||||
private Runnable callback;
|
||||
private String currentCategory;
|
||||
private final LinkedHashMap<String, LinkedHashMap<String, String>> data;
|
||||
|
||||
public Data(ByteBuffer data) {
|
||||
this.data = new LinkedHashMap<>();
|
||||
|
@ -17,7 +22,57 @@ public class Data {
|
|||
}
|
||||
|
||||
public String get(String category, String key) {
|
||||
return data.get(category).get(key);
|
||||
var val = data.get(category).get(key);
|
||||
return val == null ? "" : val;
|
||||
}
|
||||
|
||||
public List<String> getCategories() {
|
||||
return new ArrayList<>(data.keySet());
|
||||
}
|
||||
|
||||
public Color getColor(String category, String key) {
|
||||
var str = get(category, key);
|
||||
if(str.equals("")) {
|
||||
return Color.WHITE;
|
||||
}
|
||||
if(str.startsWith("#") && (str.length() == 7 || str.length() == 9)) {
|
||||
var r = Integer.parseInt(str.substring(1, 3), 16);
|
||||
var g = Integer.parseInt(str.substring(3, 5), 16);
|
||||
var b = Integer.parseInt(str.substring(5, 7), 16);
|
||||
var a = str.length() == 9 ? Integer.parseInt(
|
||||
str.substring(7, 9),
|
||||
16
|
||||
) : 255;
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
for(var seperator : vectorSeperators) {
|
||||
if(str.contains(seperator)) {
|
||||
var posStr = str.split(seperator);
|
||||
return new Color(Integer.parseInt(posStr[0].strip()),
|
||||
Integer.parseInt(posStr[1].strip()),
|
||||
Integer.parseInt(posStr[2].strip())
|
||||
);
|
||||
}
|
||||
}
|
||||
return Color.WHITE;
|
||||
|
||||
}
|
||||
|
||||
public Vec2i getVec2i(String category, String key) {
|
||||
var str = get(category, key);
|
||||
if(str.equals("")) {
|
||||
return Vec2i.ZERO;
|
||||
}
|
||||
for(var seperator : vectorSeperators) {
|
||||
if(str.contains(seperator)) {
|
||||
var posStr = str.split(seperator);
|
||||
return new Vec2i(Integer.parseInt(posStr[0].strip()),
|
||||
Integer.parseInt(posStr[1].strip())
|
||||
);
|
||||
}
|
||||
}
|
||||
return Vec2i.ZERO;
|
||||
}
|
||||
|
||||
public void onReload(Runnable callback) {
|
||||
|
|
Loading…
Reference in New Issue