From 083c21ea3f18f5b1b7bd4b792e43701b0e69a1aa Mon Sep 17 00:00:00 2001 From: Matthew Peng <54301439+MEEPofFaith@users.noreply.github.com> Date: Mon, 27 Sep 2021 08:55:56 -0700 Subject: [PATCH] Effect Rotate With Parent (#5999) * Effect Rotate With Parent * Use Rotc * Wording * Base Rotation * Rotate effect rotation with parent. --- .../revisions/EffectStateComp/6.json | 1 + core/src/mindustry/content/Fx.java | 8 +++---- core/src/mindustry/entities/Effect.java | 21 ++++++++++++++++-- .../mindustry/entities/comp/ChildComp.java | 22 ++++++++++++++----- 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 annotations/src/main/resources/revisions/EffectStateComp/6.json diff --git a/annotations/src/main/resources/revisions/EffectStateComp/6.json b/annotations/src/main/resources/revisions/EffectStateComp/6.json new file mode 100644 index 0000000000..f8a361e105 --- /dev/null +++ b/annotations/src/main/resources/revisions/EffectStateComp/6.json @@ -0,0 +1 @@ +{version:6,fields:[{name:color,type:arc.graphics.Color},{name:data,type:java.lang.Object},{name:effect,type:mindustry.entities.Effect},{name:lifetime,type:float},{name:offsetPos,type:float},{name:offsetRot,type:float},{name:offsetX,type:float},{name:offsetY,type:float},{name:parent,type:mindustry.gen.Posc},{name:rotDirWithParent,type:boolean},{name:rotPosWithParent,type:boolean},{name:rotation,type:float},{name:time,type:float},{name:x,type:float},{name:y,type:float}]} \ No newline at end of file diff --git a/core/src/mindustry/content/Fx.java b/core/src/mindustry/content/Fx.java index dca9904588..9339df49ab 100644 --- a/core/src/mindustry/content/Fx.java +++ b/core/src/mindustry/content/Fx.java @@ -362,13 +362,13 @@ public class Fx{ Fill.circle(e.x, e.y, e.fin() * 10); Drawf.light(e.x, e.y, e.fin() * 20f, Pal.heal, 0.7f); - }).followParent(true), + }).followParent(true).rotWithParent(true), greenLaserChargeSmall = new Effect(40f, 100f, e -> { color(Pal.heal); stroke(e.fin() * 2f); Lines.circle(e.x, e.y, e.fout() * 50f); - }).followParent(true), + }).followParent(true).rotWithParent(true), greenCloud = new Effect(80f, e -> { color(Pal.heal); @@ -1943,7 +1943,7 @@ public class Fx{ } Lines.endLine(); - }).followParent(false), + }).followParent(false).rotWithParent(false), chainEmp = new Effect(30f, 300f, e -> { if(!(e.data instanceof Position p)) return; @@ -1980,5 +1980,5 @@ public class Fx{ } Lines.endLine(); - }).followParent(false); + }).followParent(false).rotWithParent(false); } diff --git a/core/src/mindustry/entities/Effect.java b/core/src/mindustry/entities/Effect.java index ba5def3822..4d298eb40f 100644 --- a/core/src/mindustry/entities/Effect.java +++ b/core/src/mindustry/entities/Effect.java @@ -30,8 +30,12 @@ public class Effect{ public float lifetime = 50f; /** Clip size. */ public float clip; + /** Amount added to rotation */ + public float baseRotation; /** If true, parent unit is data are followed. */ public boolean followParent; + /** If this and followParent are true, the effect will offset and rotate with the parent's rotation. */ + public boolean rotWithParent; public float layer = Layer.effect; public float layerDuration; @@ -61,11 +65,21 @@ public class Effect{ return this; } + public Effect rotWithParent(boolean follow){ + rotWithParent = follow; + return this; + } + public Effect layer(float l){ layer = l; return this; } + public Effect baseRotation(float d){ + baseRotation = d; + return this; + } + public Effect layer(float l, float duration){ layer = l; this.layerDuration = duration; @@ -156,12 +170,15 @@ public class Effect{ EffectState entity = EffectState.create(); entity.effect = effect; - entity.rotation = rotation; + entity.rotation = effect.baseRotation + rotation; entity.data = data; entity.lifetime = effect.lifetime; entity.set(x, y); entity.color.set(color); - if(effect.followParent && data instanceof Posc p) entity.parent = p; + if(effect.followParent && data instanceof Posc p){ + entity.parent = p; + entity.rotWithParent = effect.rotWithParent; + } entity.add(); } } diff --git a/core/src/mindustry/entities/comp/ChildComp.java b/core/src/mindustry/entities/comp/ChildComp.java index dae0c98814..f34a9198c9 100644 --- a/core/src/mindustry/entities/comp/ChildComp.java +++ b/core/src/mindustry/entities/comp/ChildComp.java @@ -1,29 +1,41 @@ package mindustry.entities.comp; +import arc.math.*; import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; @Component -abstract class ChildComp implements Posc{ - @Import float x, y; +abstract class ChildComp implements Posc, Rotc{ + @Import float x, y, rotation; @Nullable Posc parent; - float offsetX, offsetY; + boolean rotWithParent; + float offsetX, offsetY, offsetPos, offsetRot; @Override public void add(){ if(parent != null){ offsetX = x - parent.getX(); offsetY = y - parent.getY(); + if(rotWithParent && parent instanceof Rotc r){ + offsetPos = -r.rotation(); + offsetRot = rotation - r.rotation(); + } } } @Override public void update(){ if(parent != null){ - x = parent.getX() + offsetX; - y = parent.getY() + offsetY; + if(rotWithParent && parent instanceof Rotc r){ + x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY); + y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY); + rotation = r.rotation() + offsetRot; + }else{ + x = parent.getX() + offsetX; + y = parent.getY() + offsetY; + } } } }