Initial support for arbitrary types of content in tech tree
This commit is contained in:
@@ -328,21 +328,29 @@ public class TechTree implements ContentList{
|
||||
});
|
||||
}
|
||||
|
||||
private static TechNode node(Block block, Runnable children){
|
||||
ItemStack[] requirements = new ItemStack[block.requirements.length];
|
||||
for(int i = 0; i < requirements.length; i++){
|
||||
requirements[i] = new ItemStack(block.requirements[i].item, 40 + Mathf.round(Mathf.pow(block.requirements[i].amount, 1.25f) * 6, 10));
|
||||
private static TechNode node(UnlockableContent content, Runnable children){
|
||||
ItemStack[] requirements;
|
||||
|
||||
if(content instanceof Block){
|
||||
Block block = (Block)content;
|
||||
|
||||
requirements = new ItemStack[block.requirements.length];
|
||||
for(int i = 0; i < requirements.length; i++){
|
||||
requirements[i] = new ItemStack(block.requirements[i].item, 40 + Mathf.round(Mathf.pow(block.requirements[i].amount, 1.25f) * 6, 10));
|
||||
}
|
||||
}else{
|
||||
requirements = ItemStack.empty;
|
||||
}
|
||||
|
||||
return new TechNode(block, requirements, children);
|
||||
return new TechNode(content, requirements, children);
|
||||
}
|
||||
|
||||
private static TechNode node(Block block){
|
||||
return node(block, () -> {});
|
||||
}
|
||||
|
||||
public static TechNode create(Block parent, Block block){
|
||||
TechNode.context = all.find(t -> t.block == parent);
|
||||
public static TechNode create(UnlockableContent parent, UnlockableContent block){
|
||||
TechNode.context = all.find(t -> t.content == parent);
|
||||
return node(block, () -> {});
|
||||
}
|
||||
|
||||
@@ -350,17 +358,17 @@ public class TechTree implements ContentList{
|
||||
static TechNode context;
|
||||
|
||||
public TechNode parent;
|
||||
public final Block block;
|
||||
public final UnlockableContent content;
|
||||
public final ItemStack[] requirements;
|
||||
public final Array<TechNode> children = new Array<>();
|
||||
|
||||
TechNode(TechNode ccontext, Block block, ItemStack[] requirements, Runnable children){
|
||||
TechNode(TechNode ccontext, UnlockableContent content, ItemStack[] requirements, Runnable children){
|
||||
if(ccontext != null){
|
||||
ccontext.children.add(this);
|
||||
}
|
||||
|
||||
this.parent = ccontext;
|
||||
this.block = block;
|
||||
this.content = content;
|
||||
this.requirements = requirements;
|
||||
|
||||
context = this;
|
||||
@@ -369,8 +377,8 @@ public class TechTree implements ContentList{
|
||||
all.add(this);
|
||||
}
|
||||
|
||||
TechNode(Block block, ItemStack[] requirements, Runnable children){
|
||||
this(context, block, requirements, children);
|
||||
TechNode(UnlockableContent content, ItemStack[] requirements, Runnable children){
|
||||
this(context, content, requirements, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user