New hint tutorial system (unfinished!)

This commit is contained in:
Anuken
2020-11-21 14:05:58 -05:00
parent 522a7f4728
commit 6fba84959c
23 changed files with 343 additions and 364 deletions

View File

@@ -37,6 +37,7 @@ import mindustry.world.draw.*;
import mindustry.world.meta.*;
import java.lang.reflect.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class ContentParser{
@@ -267,7 +268,13 @@ public class ContentParser{
UnitType unit;
if(locate(ContentType.unit, name) == null){
unit = new UnitType(mod + "-" + name);
unit.constructor = Reflect.cons(resolve(Strings.capitalize(getType(value)), "mindustry.gen"));
var typeVal = value.get("type");
if(typeVal != null && !typeVal.isString()){
throw new RuntimeException("Unit '" + name + "' has an incorrect type. Types must be strings.");
}
unit.constructor = unitType(typeVal);
}else{
unit = locate(ContentType.unit, name);
}
@@ -337,6 +344,18 @@ public class ContentParser{
//ContentType.sector, parser(ContentType.sector, SectorPreset::new)
);
private Prov<Unit> unitType(JsonValue value){
if(value == null) return UnitEntity::create;
return switch(value.asString()){
case "flying" -> UnitEntity::create;
case "mech" -> MechUnit::create;
case "legs" -> LegsUnit::create;
case "naval" -> UnitWaterMove::create;
case "payload" -> PayloadUnit::create;
default -> throw new RuntimeException("Invalid unit type: '" + value + "'. Must be 'flying/mech/legs/naval/payload'.");
};
}
private String getString(JsonValue value, String key){
if(value.has(key)){
return value.getString(key);