Misc cleanup & fixes
This commit is contained in:
@@ -32,6 +32,11 @@ public interface Payload{
|
||||
return size() / tilesize <= s;
|
||||
}
|
||||
|
||||
/** @return rotation of this payload. */
|
||||
default float rotation(){
|
||||
return 0f;
|
||||
}
|
||||
|
||||
/** writes the payload for saving. */
|
||||
void write(Writes write);
|
||||
|
||||
|
||||
@@ -35,7 +35,12 @@ public class UnitPayload implements Payload{
|
||||
@Override
|
||||
public void set(float x, float y, float rotation){
|
||||
unit.set(x, y);
|
||||
unit.rotation(rotation);
|
||||
unit.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float rotation(){
|
||||
return unit.rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,7 @@ import mindustry.world.blocks.payloads.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class PayloadAcceptor extends Block{
|
||||
public float payloadSpeed = 0.5f;
|
||||
public float payloadSpeed = 0.5f, payloadRotateSpeed = 5f;
|
||||
|
||||
public @Load(value = "@-top", fallback = "factory-top-@size") TextureRegion topRegion;
|
||||
public @Load(value = "@-out", fallback = "factory-out-@size") TextureRegion outRegion;
|
||||
@@ -66,7 +66,7 @@ public class PayloadAcceptor extends Block{
|
||||
public void handlePayload(Building source, Payload payload){
|
||||
this.payload = (T)payload;
|
||||
this.payVector.set(source).sub(this).clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
||||
this.payRotation = source.angleTo(this);
|
||||
this.payRotation = payload.rotation();
|
||||
|
||||
updatePayload();
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class PayloadAcceptor extends Block{
|
||||
|
||||
updatePayload();
|
||||
|
||||
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
||||
payRotation = Angles.moveToward(payRotation, rotate ? rotdeg() : 90f, payloadRotateSpeed * edelta());
|
||||
payVector.approach(Vec2.ZERO, payloadSpeed * delta());
|
||||
|
||||
return hasArrived();
|
||||
@@ -126,10 +126,12 @@ public class PayloadAcceptor extends Block{
|
||||
|
||||
updatePayload();
|
||||
|
||||
payVector.trns(rotdeg(), payVector.len() + delta() * payloadSpeed);
|
||||
payRotation = rotdeg();
|
||||
Vec2 dest = Tmp.v1.trns(rotdeg(), size* tilesize/2f);
|
||||
|
||||
if(payVector.len() >= size * tilesize/2f){
|
||||
payRotation = Angles.moveToward(payRotation, rotdeg(), payloadRotateSpeed * edelta());
|
||||
payVector.approach(dest, payloadSpeed * delta());
|
||||
|
||||
if(payVector.within(dest, 0.001f)){
|
||||
payVector.clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
|
||||
|
||||
Building front = front();
|
||||
@@ -155,7 +157,7 @@ public class PayloadAcceptor extends Block{
|
||||
|
||||
public void drawPayload(){
|
||||
if(payload != null){
|
||||
payload.set(x + payVector.x, y + payVector.y, payRotation);
|
||||
updatePayload();
|
||||
|
||||
Draw.z(Layer.blockOver);
|
||||
payload.draw();
|
||||
|
||||
@@ -142,13 +142,12 @@ public class Reconstructor extends UnitBlock{
|
||||
if(constructing() && hasArrived()){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
Draw.alpha(1f - progress/ constructTime);
|
||||
Draw.rect(payload.unit.type.icon(Cicon.full), x, y, rotdeg() - 90);
|
||||
Draw.rect(payload.unit.type.icon(Cicon.full), x, y, payload.rotation() - 90);
|
||||
Draw.reset();
|
||||
Drawf.construct(this, upgrade(payload.unit.type), rotdeg() - 90f, progress / constructTime, speedScl, time);
|
||||
Drawf.construct(this, upgrade(payload.unit.type), payload.rotation() - 90f, progress / constructTime, speedScl, time);
|
||||
});
|
||||
}else{
|
||||
Draw.z(Layer.blockOver);
|
||||
payRotation = rotdeg();
|
||||
|
||||
drawPayload();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user