Modded techtree bugfixes
This commit is contained in:
@@ -709,7 +709,7 @@ public class TechTree implements ContentList{
|
|||||||
/** Item requirements for this content. */
|
/** Item requirements for this content. */
|
||||||
public ItemStack[] requirements;
|
public ItemStack[] requirements;
|
||||||
/** Requirements that have been fulfilled. Always the same length as the requirement array. */
|
/** Requirements that have been fulfilled. Always the same length as the requirement array. */
|
||||||
public final ItemStack[] finishedRequirements;
|
public ItemStack[] finishedRequirements;
|
||||||
/** Extra objectives needed to research this. */
|
/** Extra objectives needed to research this. */
|
||||||
public Seq<Objective> objectives = new Seq<>();
|
public Seq<Objective> objectives = new Seq<>();
|
||||||
/** Nodes that depend on this node. */
|
/** Nodes that depend on this node. */
|
||||||
@@ -720,14 +720,8 @@ public class TechTree implements ContentList{
|
|||||||
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.requirements = requirements;
|
|
||||||
this.depth = parent == null ? 0 : parent.depth + 1;
|
this.depth = parent == null ? 0 : parent.depth + 1;
|
||||||
this.finishedRequirements = new ItemStack[requirements.length];
|
setupRequirements(requirements);
|
||||||
|
|
||||||
//load up the requirements that have been finished if settings are available
|
|
||||||
for(int i = 0; i < requirements.length; i++){
|
|
||||||
finishedRequirements[i] = new ItemStack(requirements[i].item, Core.settings == null ? 0 : Core.settings.getInt("req-" + content.name + "-" + requirements[i].item.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
var used = new ObjectSet<Content>();
|
var used = new ObjectSet<Content>();
|
||||||
|
|
||||||
@@ -742,6 +736,16 @@ public class TechTree implements ContentList{
|
|||||||
all.add(this);
|
all.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupRequirements(ItemStack[] requirements){
|
||||||
|
this.requirements = requirements;
|
||||||
|
this.finishedRequirements = new ItemStack[requirements.length];
|
||||||
|
|
||||||
|
//load up the requirements that have been finished if settings are available
|
||||||
|
for(int i = 0; i < requirements.length; i++){
|
||||||
|
finishedRequirements[i] = new ItemStack(requirements[i].item, Core.settings == null ? 0 : Core.settings.getInt("req-" + content.name + "-" + requirements[i].item.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Resets finished requirements and saves. */
|
/** Resets finished requirements and saves. */
|
||||||
public void reset(){
|
public void reset(){
|
||||||
for(ItemStack stack : finishedRequirements){
|
for(ItemStack stack : finishedRequirements){
|
||||||
|
|||||||
@@ -247,12 +247,12 @@ public class Control implements ApplicationListener, Loadable{
|
|||||||
saves.load();
|
saves.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Automatically unlocks things with no requirements. */
|
/** Automatically unlocks things with no requirements and no locked parents. */
|
||||||
void checkAutoUnlocks(){
|
void checkAutoUnlocks(){
|
||||||
if(net.client()) return;
|
if(net.client()) return;
|
||||||
|
|
||||||
for(TechNode node : TechTree.all){
|
for(TechNode node : TechTree.all){
|
||||||
if(!node.content.unlocked() && node.requirements.length == 0 && !node.objectives.contains(o -> !o.complete())){
|
if(!node.content.unlocked() && (node.parent == null || node.parent.content.unlocked()) && node.requirements.length == 0 && !node.objectives.contains(o -> !o.complete())){
|
||||||
node.content.unlock();
|
node.content.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,11 @@ public class ContentParser{
|
|||||||
return sound;
|
return sound;
|
||||||
});
|
});
|
||||||
put(Objectives.Objective.class, (type, data) -> {
|
put(Objectives.Objective.class, (type, data) -> {
|
||||||
|
if(data.isString()){
|
||||||
|
var cont = locateAny(data.asString());
|
||||||
|
if(cont == null) throw new IllegalArgumentException("Unknown objective content: " + data.asString());
|
||||||
|
return new Research((UnlockableContent)cont);
|
||||||
|
}
|
||||||
var oc = resolve(data.getString("type", ""), SectorComplete.class);
|
var oc = resolve(data.getString("type", ""), SectorComplete.class);
|
||||||
data.remove("type");
|
data.remove("type");
|
||||||
Objectives.Objective obj = make(oc);
|
Objectives.Objective obj = make(oc);
|
||||||
@@ -544,6 +549,16 @@ public class ContentParser{
|
|||||||
return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name);
|
return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends MappableContent> T locateAny(String name){
|
||||||
|
for(ContentType t : ContentType.all){
|
||||||
|
var out = locate(t, name);
|
||||||
|
if(out != null){
|
||||||
|
return (T)out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
<T> T make(Class<T> type){
|
<T> T make(Class<T> type){
|
||||||
try{
|
try{
|
||||||
Constructor<T> cons = type.getDeclaredConstructor();
|
Constructor<T> cons = type.getDeclaredConstructor();
|
||||||
@@ -680,18 +695,26 @@ public class ContentParser{
|
|||||||
lastNode.remove();
|
lastNode.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
TechNode node = new TechNode(null, unlock, customRequirements == null ? unlock.researchRequirements() : customRequirements);
|
TechNode node = new TechNode(null, unlock, customRequirements == null ? ItemStack.empty : customRequirements);
|
||||||
LoadedMod cur = currentMod;
|
LoadedMod cur = currentMod;
|
||||||
|
|
||||||
postreads.add(() -> {
|
postreads.add(() -> {
|
||||||
currentContent = unlock;
|
currentContent = unlock;
|
||||||
currentMod = cur;
|
currentMod = cur;
|
||||||
|
|
||||||
|
//add custom objectives
|
||||||
|
if(research.has("objectives")){
|
||||||
|
node.objectives.addAll(parser.readValue(Objective[].class, research.get("objectives")));
|
||||||
|
}
|
||||||
|
|
||||||
//remove old node from parent
|
//remove old node from parent
|
||||||
if(node.parent != null){
|
if(node.parent != null){
|
||||||
node.parent.children.remove(node);
|
node.parent.children.remove(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(customRequirements == null){
|
||||||
|
node.setupRequirements(unlock.researchRequirements());
|
||||||
|
}
|
||||||
|
|
||||||
//find parent node.
|
//find parent node.
|
||||||
TechNode parent = TechTree.all.find(t -> t.content.name.equals(researchName) || t.content.name.equals(currentMod.name + "-" + researchName));
|
TechNode parent = TechTree.all.find(t -> t.content.name.equals(researchName) || t.content.name.equals(currentMod.name + "-" + researchName));
|
||||||
|
|||||||
Reference in New Issue
Block a user