From d9b8335e0e2b14b8902c535950e64b5f53e12111 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 1 Oct 2019 21:47:02 -0400 Subject: [PATCH] Block tech tree mods --- core/src/io/anuke/mindustry/Vars.java | 2 +- .../io/anuke/mindustry/content/TechTree.java | 23 +++++++++++++------ .../io/anuke/mindustry/mod/ContentParser.java | 3 +++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index 36790a71d1..b4d01d579a 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -31,7 +31,7 @@ import static io.anuke.arc.Core.*; public class Vars implements Loadable{ /** Whether to load locales.*/ public static boolean loadLocales = true; - /** Maximum number of broken blocks.*/ + /** Maximum number of broken blocks. TODO implement or remove.*/ public static final int maxBrokenBlocks = 256; /** IO buffer size. */ public static final int bufferSize = 8192; diff --git a/core/src/io/anuke/mindustry/content/TechTree.java b/core/src/io/anuke/mindustry/content/TechTree.java index f22642e314..090257f468 100644 --- a/core/src/io/anuke/mindustry/content/TechTree.java +++ b/core/src/io/anuke/mindustry/content/TechTree.java @@ -13,6 +13,7 @@ public class TechTree implements ContentList{ @Override public void load(){ + TechNode.context = null; all = new Array<>(); root = node(coreShard, () -> { @@ -302,7 +303,7 @@ public class TechTree implements ContentList{ }); } - private TechNode node(Block block, Runnable children){ + 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, 30 + block.requirements[i].amount * 6); @@ -311,10 +312,15 @@ public class TechTree implements ContentList{ return new TechNode(block, requirements, children); } - private TechNode node(Block block){ + private static TechNode node(Block block){ return node(block, () -> {}); } + public static void create(Block parent, Block block){ + TechNode.context = all.find(t -> t.block == parent); + node(block, () -> {}); + } + public static class TechNode{ static TechNode context; @@ -322,19 +328,22 @@ public class TechTree implements ContentList{ public final ItemStack[] requirements; public final Array children = new Array<>(); - TechNode(Block block, ItemStack[] requirements, Runnable children){ - if(context != null){ - context.children.add(this); + TechNode(TechNode ccontext, Block block, ItemStack[] requirements, Runnable children){ + if(ccontext != null){ + ccontext.children.add(this); } this.block = block; this.requirements = requirements; - TechNode last = context; context = this; children.run(); - context = last; + context = ccontext; all.add(this); } + + TechNode(Block block, ItemStack[] requirements, Runnable children){ + this(context, block, requirements, children); + } } } diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java index 75728c884e..50f413f64d 100644 --- a/core/src/io/anuke/mindustry/mod/ContentParser.java +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -70,6 +70,9 @@ public class ContentParser{ Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name); read(() -> { readFields(block, value, true); + if(value.has("research")){ + TechTree.create(Vars.content.getByName(ContentType.block, value.get("research").asString()), block); + } //make block visible if(block.requirements != null){