Placement config code cleanup

This commit is contained in:
Anuken
2020-09-05 20:41:50 -04:00
parent c483ae2c23
commit f87bd78674
14 changed files with 67 additions and 92 deletions

View File

@@ -374,6 +374,13 @@ public class Block extends UnlockableContent{
return this;
}
public Object nextConfig(){
if(saveConfig && lastConfig != null){
return lastConfig;
}
return null;
}
public void drawRequest(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime(), 6f, 0.28f));
@@ -389,7 +396,7 @@ public class Block extends UnlockableContent{
TextureRegion reg = getRequestRegion(req, list);
Draw.rect(reg, req.drawx(), req.drawy(), !rotate ? 0 : req.rotation * 90);
if(req.hasConfig){
if(req.config != null){
drawRequestConfig(req, list);
}
}

View File

@@ -48,26 +48,35 @@ public class BuildBlock extends Block{
}
@Remote(called = Loc.server)
public static void deconstructFinish(Tile tile, Block block, int builderID){
public static void deconstructFinish(Tile tile, Block block, Unit builder){
Team team = tile.team();
Fx.breakBlock.at(tile.drawx(), tile.drawy(), block.size);
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, true));
Events.fire(new BlockBuildEndEvent(tile, builder, team, true, null));
tile.remove();
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
}
@Remote(called = Loc.server)
public static void constructFinish(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
public static void constructFinish(Tile tile, Block block, Unit builder, byte rotation, Team team, Object config){
if(tile == null) return;
float healthf = tile.build == null ? 1f : tile.build.healthf();
tile.setBlock(block, team, rotation);
if(tile.build != null) tile.build.health = block.health * healthf;
//last builder was this local client player, call placed()
if(tile.build != null && !headless && builderID == player.unit().id()){
if(!skipConfig){
tile.build.playerPlaced();
if(tile.build != null){
tile.build.health = block.health * healthf;
if(config != null){
tile.build.configured(builder, config);
}
}
//last builder was this local client player, call placed()
if(tile.build != null && !headless && builder == player.unit()){
tile.build.playerPlaced();
}
Fx.placeBlock.at(tile.drawx(), tile.drawy(), block.size);
}
@@ -95,11 +104,11 @@ public class BuildBlock extends Block{
}
}
public static void constructed(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
Call.constructFinish(tile, block, builderID, rotation, team, skipConfig);
public static void constructed(Tile tile, Block block, Unit builder, byte rotation, Team team, Object config){
Call.constructFinish(tile, block, builder, rotation, team, config);
tile.build.placed();
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false));
Events.fire(new BlockBuildEndEvent(tile, builder, team, false, config));
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));
}
@@ -122,7 +131,7 @@ public class BuildBlock extends Block{
* If a non-recipe block is being deconstructed, this is the block that is being deconstructed.
*/
public Block previous;
public int builderID = -1;
public Object lastConfig;
private float[] accumulator;
private float[] totalAccumulator;
@@ -154,7 +163,7 @@ public class BuildBlock extends Block{
if(control.input.buildWasAutoPaused && !control.input.isBuilding && player.isBuilder()){
control.input.isBuilding = true;
}
player.builder().addBuild(new BuildPlan(tile.x, tile.y, rotation, cblock), false);
player.builder().addBuild(new BuildPlan(tile.x, tile.y, rotation, cblock, lastConfig), false);
}
}
@@ -190,12 +199,14 @@ public class BuildBlock extends Block{
});
}
public boolean construct(Unit builder, @Nullable Building core, float amount, boolean configured){
public void construct(Unit builder, @Nullable Building core, float amount, Object config){
if(cblock == null){
kill();
return false;
return;
}
lastConfig = config;
if(cblock.requirements.length != accumulator.length || totalAccumulator.length != cblock.requirements.length){
setConstruct(previous, cblock);
}
@@ -211,16 +222,13 @@ public class BuildBlock extends Block{
maxProgress = core == null || team.rules().infiniteResources ? maxProgress : checkRequired(core.items, maxProgress, true);
progress = Mathf.clamp(progress + maxProgress);
builderID = builder.id;
if(progress >= 1f || state.rules.infiniteResources){
constructed(tile, cblock, builderID, (byte)rotation, builder.team, configured);
return true;
constructed(tile, cblock, builder, (byte)rotation, builder.team, config);
}
return false;
}
public void deconstruct(Unitc builder, @Nullable Building core, float amount){
public void deconstruct(Unit builder, @Nullable Building core, float amount){
float deconstructMultiplier = state.rules.deconstructRefundMultiplier;
if(cblock != null){
@@ -253,10 +261,8 @@ public class BuildBlock extends Block{
progress = Mathf.clamp(progress - amount);
builderID = builder.id();
if(progress <= 0 || state.rules.infiniteResources){
Call.deconstructFinish(tile, this.cblock == null ? previous : this.cblock, builderID);
Call.deconstructFinish(tile, this.cblock == null ? previous : this.cblock, builder);
}
}

View File

@@ -51,7 +51,7 @@ public class Sorter extends Block{
public @Nullable Item sortItem;
@Override
public void configured(Player player, Object value){
public void configured(Unit player, Object value){
super.configured(player, value);
if(!headless){