Extra mod field parsing (untested)

This commit is contained in:
Anuken
2020-10-07 11:00:02 -04:00
parent d4513fab19
commit be66a15287
10 changed files with 215 additions and 134 deletions
+35 -25
View File
@@ -15,6 +15,7 @@ import static mindustry.type.ItemStack.*;
public class TechTree implements ContentList{
static ObjectMap<UnlockableContent, TechNode> map = new ObjectMap<>();
static TechNode context = null;
public static Seq<TechNode> all;
public static TechNode root;
@@ -543,36 +544,46 @@ public class TechTree implements ContentList{
}
public static void setup(){
TechNode.context = null;
context = null;
map = new ObjectMap<>();
all = new Seq<>();
}
public static TechNode node(UnlockableContent content, Runnable children){
//all the "node" methods are hidden, because they are for internal context-dependent use only
//for custom research, just use the TechNode constructor
static TechNode node(UnlockableContent content, Runnable children){
return node(content, content.researchRequirements(), children);
}
public static TechNode node(UnlockableContent content, ItemStack[] requirements, Runnable children){
return new TechNode(content, requirements, children);
static TechNode node(UnlockableContent content, ItemStack[] requirements, Runnable children){
return node(content, requirements, null, children);
}
public static TechNode node(UnlockableContent content, Seq<Objective> objectives, Runnable children){
TechNode node = new TechNode(content, content.researchRequirements(), children);
node.objectives = objectives;
static TechNode node(UnlockableContent content, ItemStack[] requirements, Seq<Objective> objectives, Runnable children){
TechNode node = new TechNode(context, content, requirements);
if(objectives != null){
node.objectives = objectives;
}
TechNode prev = context;
context = node;
children.run();
context = prev;
return node;
}
public static TechNode node(UnlockableContent block){
static TechNode node(UnlockableContent content, Seq<Objective> objectives, Runnable children){
return node(content, content.researchRequirements(), objectives, children);
}
static TechNode node(UnlockableContent block){
return node(block, () -> {});
}
public static TechNode create(UnlockableContent parent, UnlockableContent block){
TechNode.context = all.find(t -> t.content == parent);
return node(block, () -> {});
}
public static @Nullable
TechNode get(UnlockableContent content){
@Nullable
public static TechNode get(UnlockableContent content){
return map.get(content);
}
@@ -581,8 +592,6 @@ public class TechTree implements ContentList{
}
public static class TechNode{
static TechNode context;
/** Depth in tech tree. */
public int depth;
/** Requirement node. */
@@ -600,10 +609,10 @@ public class TechTree implements ContentList{
/** Nodes that depend on this node. */
public final Seq<TechNode> children = new Seq<>();
TechNode(@Nullable TechNode ccontext, UnlockableContent content, ItemStack[] requirements, Runnable children){
if(ccontext != null) ccontext.children.add(this);
public TechNode(@Nullable TechNode parent, UnlockableContent content, ItemStack[] requirements){
if(parent != null) parent.children.add(this);
this.parent = ccontext;
this.parent = parent;
this.content = content;
this.requirements = requirements;
this.depth = parent == null ? 0 : parent.depth + 1;
@@ -619,14 +628,15 @@ public class TechTree implements ContentList{
content.getDependencies(d -> objectives.add(new Research(d)));
map.put(content, this);
context = this;
children.run();
context = ccontext;
all.add(this);
}
TechNode(UnlockableContent content, ItemStack[] requirements, Runnable children){
this(context, content, requirements, children);
/** Removes this node from the tech tree. */
public void remove(){
all.remove(this);
if(parent != null){
parent.children.remove(this);
}
}
/** Flushes research progress to settings. */