From 006004fd701f6854ad3d4dff584c0aa12b8e95b8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 4 Feb 2020 09:39:12 -0500 Subject: [PATCH] Decal cleanup --- core/src/mindustry/core/Control.java | 14 +++--- core/src/mindustry/core/Logic.java | 7 ++- .../mindustry/entities/def/EntityComps.java | 12 +++++ .../mindustry/entities/def/EntityDefs.java | 3 ++ core/src/mindustry/entities/effect/Decal.java | 33 ------------- .../entities/effect/RubbleDecal.java | 46 ----------------- .../entities/effect/ScorchDecal.java | 49 ------------------- .../ui/fragments/PlacementFragment.java | 4 +- .../mindustry/world/blocks/BuildBlock.java | 4 +- 9 files changed, 31 insertions(+), 141 deletions(-) delete mode 100644 core/src/mindustry/entities/effect/Decal.java delete mode 100644 core/src/mindustry/entities/effect/RubbleDecal.java delete mode 100644 core/src/mindustry/entities/effect/ScorchDecal.java diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 231b249c65..c5016e09be 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -170,7 +170,7 @@ public class Control implements ApplicationListener, Loadable{ app.post(() -> ui.hudfrag.showLand()); renderer.zoomIn(Fx.coreLand.lifetime); - app.post(() -> Fx.coreLand.at(core.x, core.y, 0, core.block)); + app.post(() -> Fx.coreLand.at(core.getX(), core.getY(), 0, core.getBlock())); Time.run(Fx.coreLand.lifetime, () -> { Fx.launch.at(core); Effects.shake(5f, 5f, core); @@ -178,8 +178,8 @@ public class Control implements ApplicationListener, Loadable{ }); Events.on(UnitDestroyEvent.class, e -> { - if(e.unit instanceof BaseUnit && world.isZone()){ - data.unlockContent(((BaseUnit)e.unit).getType()); + if(world.isZone()){ + data.unlockContent(e.unit.getType()); } }); } @@ -259,7 +259,7 @@ public class Control implements ApplicationListener, Loadable{ state.rules.zone = zone; for(Tilec core : state.teams.playerCores()){ for(ItemStack stack : zone.getStartingItems()){ - core.items.add(stack.item, stack.amount); + core.getItems().add(stack.item, stack.amount); } } state.set(State.playing); @@ -308,11 +308,11 @@ public class Control implements ApplicationListener, Loadable{ state.rules.zone = zone; for(Tilec core : state.teams.playerCores()){ for(ItemStack stack : zone.getStartingItems()){ - core.items.add(stack.item, stack.amount); + core.getItems().add(stack.item, stack.amount); } } Tilec core = state.teams.playerCores().first(); - core.items.clear(); + core.getItems().clear(); logic.play(); state.rules.waveTimer = false; @@ -437,7 +437,7 @@ public class Control implements ApplicationListener, Loadable{ if(world.isZone()){ for(Tilec tile : state.teams.cores(player.getTeam())){ for(Item item : content.items()){ - if(tile.items.has(item)){ + if(tile.getItems().has(item)){ data.unlockContent(item); } } diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 6c47c616ae..b14ffe6f6a 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -210,7 +210,8 @@ public class Logic implements ApplicationListener{ if(!state.is(State.menu)){ if(!net.client()){ - state.enemies = unitGroup.count(b -> b.getTeam() == state.rules.waveTeam && b.countsAsEnemy()); + //TODO + //state.enemies = unitGroup.count(b -> b.getTeam() == state.rules.waveTeam && b.countsAsEnemy()); } if(!state.isPaused()){ @@ -226,6 +227,8 @@ public class Logic implements ApplicationListener{ runWave(); } + //TODO update groups + /* if(!headless){ effectGroup.update(); groundEffectGroup.update(); @@ -254,7 +257,7 @@ public class Logic implements ApplicationListener{ if(!state.isEditor()){ //bulletGroup collisions.collideGroups(bulletGroup, unitGroup); - } + }*/ } if(!net.client() && !world.isInvalidMap() && !state.isEditor() && state.rules.canGameOver){ diff --git a/core/src/mindustry/entities/def/EntityComps.java b/core/src/mindustry/entities/def/EntityComps.java index f8fda07959..4edc4e408e 100644 --- a/core/src/mindustry/entities/def/EntityComps.java +++ b/core/src/mindustry/entities/def/EntityComps.java @@ -801,6 +801,18 @@ public class EntityComps{ } } + @Component + abstract class DecalComp implements Drawc, Timedc, Rotc, Posc{ + Color color = new Color(1, 1, 1, 1); + TextureRegion region; + + public void draw(){ + Draw.color(color); + Draw.rect(region, getX(), getY(), getRotation()); + Draw.color(); + } + } + @Component abstract class DrawLightComp implements Drawc{ void drawLight(){} diff --git a/core/src/mindustry/entities/def/EntityDefs.java b/core/src/mindustry/entities/def/EntityDefs.java index 86c944ba1b..1c3c90a209 100644 --- a/core/src/mindustry/entities/def/EntityDefs.java +++ b/core/src/mindustry/entities/def/EntityDefs.java @@ -13,4 +13,7 @@ class EntityDefs{ @EntityDef({EffectComp.class}) class EffectDef{} + + @EntityDef({DecalComp.class}) + class DecalDef{} } diff --git a/core/src/mindustry/entities/effect/Decal.java b/core/src/mindustry/entities/effect/Decal.java deleted file mode 100644 index 29ef37052e..0000000000 --- a/core/src/mindustry/entities/effect/Decal.java +++ /dev/null @@ -1,33 +0,0 @@ -package mindustry.entities.effect; - -import arc.graphics.g2d.Draw; -import arc.math.Mathf; -import mindustry.entities.EntityGroup; -import mindustry.graphics.Pal; - -import static mindustry.Vars.groundEffectGroup; - -/** - * Class for creating block rubble on the ground. - */ -public abstract class Decal extends TimedEntity implements DrawTrait{ - - @Override - public float lifetime(){ - return 3600; - } - - @Override - public void draw(){ - Draw.color(Pal.rubble.r, Pal.rubble.g, Pal.rubble.b, 1f - Mathf.curve(fin(), 0.98f)); - drawDecal(); - Draw.color(); - } - - @Override - public EntityGroup targetGroup(){ - return groundEffectGroup; - } - - abstract void drawDecal(); -} diff --git a/core/src/mindustry/entities/effect/RubbleDecal.java b/core/src/mindustry/entities/effect/RubbleDecal.java deleted file mode 100644 index a7f7d2a323..0000000000 --- a/core/src/mindustry/entities/effect/RubbleDecal.java +++ /dev/null @@ -1,46 +0,0 @@ -package mindustry.entities.effect; - -import arc.Core; -import arc.graphics.g2d.Draw; -import arc.graphics.g2d.TextureRegion; -import arc.math.Mathf; - -import static mindustry.Vars.headless; - -public class RubbleDecal extends Decal{ - private TextureRegion region; - - /** Creates a rubble effect at a position. Provide a block size to use. */ - public static void create(float x, float y, int size){ - if(headless) return; - - RubbleDecal decal = new RubbleDecal(); - decal.region = Core.atlas.find("rubble-" + size + "-" + Mathf.randomSeed(decal.id, 0, 1)); - - if(!Core.atlas.isFound(decal.region)){ - return; - } - - decal.set(x, y); - decal.add(); - } - - @Override - public float lifetime(){ - return 8200f; - } - - @Override - public void drawDecal(){ - if(!Core.atlas.isFound(region)){ - remove(); - return; - } - Draw.rect(region, x, y, Mathf.randomSeed(id, 0, 4) * 90); - } - - @Override - public float drawSize(){ - return region.getWidth() * 3f; - } -} diff --git a/core/src/mindustry/entities/effect/ScorchDecal.java b/core/src/mindustry/entities/effect/ScorchDecal.java deleted file mode 100644 index e35cf7a7c0..0000000000 --- a/core/src/mindustry/entities/effect/ScorchDecal.java +++ /dev/null @@ -1,49 +0,0 @@ -package mindustry.entities.effect; - -import arc.Core; -import arc.graphics.g2d.Draw; -import arc.graphics.g2d.TextureRegion; -import arc.math.Angles; -import arc.math.Mathf; -import mindustry.world.Tile; - -import static mindustry.Vars.headless; -import static mindustry.Vars.world; - -public class ScorchDecal extends Decal{ - private static final int scorches = 5; - private static final TextureRegion[] regions = new TextureRegion[scorches]; - - public static void create(float x, float y){ - if(headless) return; - - if(regions[0] == null || regions[0].getTexture().isDisposed()){ - for(int i = 0; i < regions.length; i++){ - regions[i] = Core.atlas.find("scorch" + (i + 1)); - } - } - - Tile tile = world.tileWorld(x, y); - - if(tile == null || tile.floor().liquidDrop != null) return; - - ScorchDecal decal = new ScorchDecal(); - decal.set(x, y); - decal.add(); - } - - @Override - public void drawDecal(){ - for(int i = 0; i < 3; i++){ - TextureRegion region = regions[Mathf.randomSeed(id - i, 0, scorches - 1)]; - float rotation = Mathf.randomSeed(id + i, 0, 360); - float space = 1.5f + Mathf.randomSeed(id + i + 1, 0, 20) / 10f; - Draw.rect(region, - x + Angles.trnsx(rotation, space), - y + Angles.trnsy(rotation, space) + region.getHeight() / 2f * Draw.scl, - region.getWidth() * Draw.scl, - region.getHeight() * Draw.scl, - region.getWidth() / 2f * Draw.scl, 0, rotation - 90); - } - } -} diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index fb5a60d40e..ac03e5e727 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -221,7 +221,7 @@ public class PlacementFragment extends Fragment{ button.update(() -> { //color unplacable things gray Tilec core = player.getClosestCore(); - Color color = state.rules.infiniteResources || (core != null && (core.items.has(block.requirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray; + Color color = state.rules.infiniteResources || (core != null && (core.getItems().has(block.requirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray; button.forEach(elem -> elem.setColor(color)); button.setChecked(control.input.block == block); @@ -311,7 +311,7 @@ public class PlacementFragment extends Fragment{ Tilec core = player.getClosestCore(); if(core == null || state.rules.infiniteResources) return "*/*"; - int amount = core.items.get(stack.item); + int amount = core.getItems().get(stack.item); int stackamount = Math.round(stack.amount * state.rules.buildCostMultiplier); String color = (amount < stackamount / 2f ? "[red]" : amount < stackamount ? "[accent]" : "[white]"); diff --git a/core/src/mindustry/world/blocks/BuildBlock.java b/core/src/mindustry/world/blocks/BuildBlock.java index 184911c83b..4dc61ec3ae 100644 --- a/core/src/mindustry/world/blocks/BuildBlock.java +++ b/core/src/mindustry/world/blocks/BuildBlock.java @@ -228,7 +228,7 @@ public class BuildBlock extends Block{ setConstruct(previous, cblock); } - float maxProgress = core == null ? amount : checkRequired(core.items, amount, false); + float maxProgress = core == null ? amount : checkRequired(core.getItems(), amount, false); for(int i = 0; i < cblock.requirements.length; i++){ int reqamount = Math.round(state.rules.buildCostMultiplier * cblock.requirements[i].amount); @@ -236,7 +236,7 @@ public class BuildBlock extends Block{ totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount); } - maxProgress = core == null ? maxProgress : checkRequired(core.items, maxProgress, true); + maxProgress = core == null ? maxProgress : checkRequired(core.getItems(), maxProgress, true); progress = Mathf.clamp(progress + maxProgress); builderID = builder.getId();