Skip to content

Commit

Permalink
Reverted lone cell check, added post-processing mutators
Browse files Browse the repository at this point in the history
  • Loading branch information
ThizThizzyDizzy committed Oct 2, 2024
1 parent 79d5308 commit 7c3bd1d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public long getValue(){
public ArrayList<GeneratorMutator<T>> steps = new ArrayList<>();
public ArrayList<StageTransition<T>> stageTransitions = new ArrayList<>();
public ArrayList<Priority<T>> priorities = new ArrayList<>();
public ArrayList<GeneratorMutator<T>> postProcessing = new ArrayList<>();
public void run(T multiblock, Random rand){
hits++;
STEP:for(GeneratorMutator<T> mutator : steps){
Expand All @@ -29,6 +30,16 @@ public void run(T multiblock, Random rand){
mutator.run(multiblock, rand);
}
}
public void runPostProcessing(T multiblock, Random rand){
STEP:for(GeneratorMutator<T> mutator : postProcessing){
for(Condition c : mutator.conditions){
c.hits++;
if(!c.check(rand))continue STEP;
}
mutator.hits++;
mutator.run(multiblock, rand);
}
}
@Override
public int getVariableCount(){
return vars.length;
Expand All @@ -48,20 +59,26 @@ public void reset(){
for(Priority<T> priority : priorities){
priority.reset();
}
for(GeneratorMutator<T> step : postProcessing){
step.reset();
}
}
@Override
public void convertFromObject(NCPFObject ncpf){
steps = ncpf.getRegisteredNCPFList("steps", GeneratorMutator.getRegisteredMutators());
stageTransitions = ncpf.getDefinedNCPFList("stage_transitions", StageTransition<T>::new);
priorities = ncpf.getDefinedNCPFList("priorities", Priority<T>::new);
postProcessing = ncpf.getRegisteredNCPFList("post_processing", GeneratorMutator.getRegisteredMutators());
}
@Override
public void convertToObject(NCPFObject ncpf){
ncpf.setRegisteredNCPFList("steps", steps);
ncpf.setDefinedNCPFList("stage_transitions", stageTransitions);
ncpf.setDefinedNCPFList("priorities", priorities);
ncpf.setRegisteredNCPFList("post_processing", postProcessing);
}
public void setIndicies(T multiblock){
for(GeneratorMutator<T> step : steps)step.setIndicies(multiblock);
for(GeneratorMutator<T> step : postProcessing)step.setIndicies(multiblock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void run(T multiblock, Random rand, T original, T priorityMultiblock, Con
condition.hits++;
if(!condition.check(rand))continue TRANSITION;
}
currentStage.runPostProcessing(multiblock, rand);
transition.hits++;
lastUpdate = System.nanoTime();
if(transition.store.get()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ public void run(LiteOverhaulSFR multiblock, Random rand){
}
}
}
//now check for fully-insulated fuel cells.
for(int x = 0; x<multiblock.dims[0]; x++){
for(int y = 0; y<multiblock.dims[1]; y++){
for(int z = 0; z<multiblock.dims[2]; z++){
if(!multiblock.configuration.blockFuelCell[multiblock.blocks[x][y][z]])continue;//check for fuel cells only
int adjacentSpaces = 6;
if(x==0)adjacentSpaces--;
if(y==0)adjacentSpaces--;
if(z==0)adjacentSpaces--;
if(x==multiblock.dims[0]-1)adjacentSpaces--;
if(y==multiblock.dims[1]-1)adjacentSpaces--;
if(z==multiblock.dims[2]-1)adjacentSpaces--;
if(multiblock.moderatorLines[x][y][z]>=adjacentSpaces)multiblock.blocks[x][y][z] = -1;
}
}
}
}
@Override
public int getSettingCount(){
Expand Down
35 changes: 20 additions & 15 deletions src/net/ncplanner/plannerator/ncpf/io/NCPFObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void setDefinedNCPFObject(String key, DefinedNCPFObject object){
object.convertToObject(ncpf);
setNCPFObject(key, ncpf);
}

public <T extends DefinedNCPFObject, V extends List<T>> V getDefinedNCPFList(String key, Supplier<T> objectSupplier){
return (V)getDefinedNCPFList(key, new ArrayList<>(), objectSupplier);
}
Expand All @@ -48,7 +48,7 @@ public <T extends DefinedNCPFObject> void setDefinedNCPFList(String key, List<T>
}
setNCPFList(key, ncpf);
}

public <T extends DefinedNCPFObject> void getDefined3DArray(String name, T[][][] array, List<T> indicies){
NCPFList list3 = getNCPFList(name);
for(int x = 0; x<array.length; x++){
Expand Down Expand Up @@ -77,28 +77,31 @@ public <T extends NCPFElement> void setDefined3DArray(String name, T[][][] array
}
setNCPFList(name, list3);
}

public <T extends RegisteredNCPFObject> T getRegisteredNCPFObject(String key, HashMap<String, Supplier<T>> registry){
String type = getNCPFObject(key).getString("type");
Supplier<T> supplier = registry.get(type);
if(supplier==null)throw new IllegalArgumentException("Cannot load unregistered object: "+type+"!");
if(supplier==null)
throw new IllegalArgumentException("Cannot load unregistered object: "+type+"!");
return getDefinedNCPFObject(key, supplier);
}
public void setRegisteredNCPFObject(String key, RegisteredNCPFObject object){
setDefinedNCPFObject(key, object);
getNCPFObject(key).setString("type", object.type);
}

public <T extends RegisteredNCPFObject, V extends List<T>> V getRegisteredNCPFList(String key, HashMap<String, Supplier<T>> registry){
return (V)getRegisteredNCPFList(key, new ArrayList<>(), registry);
}
public <T extends RegisteredNCPFObject, V extends List<T>> V getRegisteredNCPFList(String key, V list, HashMap<String, Supplier<T>> registry){
NCPFList ncpf = getNCPFList(key);
if(ncpf==null)return list;
for(int i = 0; i<ncpf.size(); i++){
NCPFObject obj = ncpf.getNCPFObject(i);
String type = obj.getString("type");
Supplier<T> supplier = registry.get(type);
if(supplier==null)throw new IllegalArgumentException("Cannot load unregistered object: "+type+"!");
if(supplier==null)
throw new IllegalArgumentException("Cannot load unregistered object: "+type+"!");
T object = supplier.get();
list.add(object);
object.convertFromObject(obj);
Expand All @@ -115,7 +118,7 @@ public <T extends RegisteredNCPFObject> void setRegisteredNCPFList(String key, L
}
setNCPFList(key, ncpf);
}

public <T extends DefinedNCPFModularObject> void getRecipe3DArray(String name, NCPFElement[][][] array, T[][][] design){
NCPFList list3 = getNCPFList(name);
int X = -1;
Expand All @@ -141,7 +144,8 @@ public <T extends DefinedNCPFModularObject> void getRecipe3DArray(String name, N
Z++;
}
int idx = list3.getNCPFList(X).getNCPFList(Y).getInteger(Z);
if(idx>-1)array[x][y][z] = design[x][y][z].getModule(NCPFBlockRecipesModule::new).recipes.get(idx);
if(idx>-1)
array[x][y][z] = design[x][y][z].getModule(NCPFBlockRecipesModule::new).recipes.get(idx);
}
}
}
Expand All @@ -165,27 +169,27 @@ public <T extends DefinedNCPFModularObject> void setRecipe3DArray(String name, N
}
setNCPFList(name, list3);
}

public void getVariable(String key, SettingVariable setting){
setting.set(setting.convertFromObject(getNCPFObject(key)));
}
public void setVariable(String key, SettingVariable setting){
setNCPFObject(key, setting.convertToObject());
}

public int[] getIntArray(String key){
NCPFList list = getNCPFList(key);
int[] arr = new int[list.size()];
for(int i = 0; i<arr.length; i++)arr[i] = list.getInteger(i);
return arr;
}

public void setIntArray(String key, int[] value){
NCPFList<Integer> list = new NCPFList<>();
for(int i : value)list.add(i);
setNCPFList(key, list);
}

public NCPFObject getNCPFObject(String key){
Object o = get(key);
if(o instanceof NCPFObject)return (NCPFObject)o;
Expand Down Expand Up @@ -231,7 +235,7 @@ public Object set(String key, Object value){
if(value==null)return remove(key);//never hold nulls!
return put(key, value);
}

//just so I don't change types accidentally
public void setNCPFObject(String key, NCPFObject value){
set(key, value);
Expand Down Expand Up @@ -274,7 +278,8 @@ public <T extends NCPFElement> void setIndex(String name, T element, List<T> ind
}
public NCPFElementReference getDefinedModuleOrElementReference(String block){
NCPFElementReference reference = getDefinedNCPFObject(block, NCPFElementReference::new);
if(reference.definition.typeMatches(NCPFModuleElement::new))return reference.copyTo(NCPFModuleReference::new);
if(reference.definition.typeMatches(NCPFModuleElement::new))
return reference.copyTo(NCPFModuleReference::new);
return reference;
}
}
}
26 changes: 26 additions & 0 deletions src/net/ncplanner/plannerator/planner/gui/menu/MenuGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,32 @@ public void draw(double deltaTime){
stage.priorities.add(new Priority<>());
rebuildGUI();
}));
stageSettings.add(new Label(0, 0, 0, 36, "Post-Processing Mutators", true));
for(GeneratorMutator<T> mutator : stage.postProcessing){
if(expand(stageSettings.add(new Label(0, 0, 0, 32, mutator.mutator.getTitle()){
Button del = add(new Button(0, 0, height, height, "X", true, true).addAction(() -> {
stage.postProcessing.remove(mutator);
rebuildGUI();
}));
@Override
public void draw(double deltaTime){
del.x = width-del.width;
super.draw(deltaTime);
}
}.setTooltip(mutator.getTooltip())), mutator)){
addConditionSettings(mutator.conditions);
addExpandedSettings(mutator);
addSettings(stageSettings.add(new Label(0, 0, 0, 30, "Mutator Settings").setTooltip(mutator.mutator.getTooltip())), mutator.mutator);
}
}
stageSettings.add(new Button(0, 0, 0, 32, "Add Post-Processing Mutator", true).addAction(() -> {
new MenuPickMutator<>(gui, this, multiblock, (mutator)->{
new MenuPickGeneratorMutator<>(gui, this, mutator, (genMutator)->{
stage.postProcessing.add(genMutator);
rebuildGUI();
}).open();
}).open();
}));
stageSettings.add(new Label(0, 0, 0, 36, "Stage Transitions", true));
for(int i = 0; i<stage.stageTransitions.size(); i++){
StageTransition<T> transition = stage.stageTransitions.get(i);
Expand Down

0 comments on commit 7c3bd1d

Please sign in to comment.