From f888b3b77e18f4c7ec281de7ac93cb4c131fa945 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 22 Aug 2024 06:54:07 -0400 Subject: [PATCH] Automatic planet detection for content --- core/src/mindustry/ClientLauncher.java | 4 ++- core/src/mindustry/content/Blocks.java | 31 ------------------- core/src/mindustry/core/ContentLoader.java | 1 + core/src/mindustry/core/GameState.java | 2 +- core/src/mindustry/ctype/Content.java | 3 ++ .../mindustry/ctype/UnlockableContent.java | 20 +++--------- .../mindustry/ui/dialogs/DatabaseDialog.java | 4 +-- .../ui/dialogs/LaunchLoadoutDialog.java | 2 +- core/src/mindustry/world/Block.java | 16 ++++++++++ 9 files changed, 32 insertions(+), 51 deletions(-) diff --git a/core/src/mindustry/ClientLauncher.java b/core/src/mindustry/ClientLauncher.java index 2e8d7396c1..c68681b7a9 100644 --- a/core/src/mindustry/ClientLauncher.java +++ b/core/src/mindustry/ClientLauncher.java @@ -62,7 +62,9 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform } long ram = Runtime.getRuntime().maxMemory(); boolean gb = ram >= 1024 * 1024 * 1024; - Log.info("[RAM] Available: @ @", Strings.fixed(gb ? ram / 1024f / 1024 / 1024f : ram / 1024f / 1024f, 1), gb ? "GB" : "MB"); + if(!OS.isIos){ + Log.info("[RAM] Available: @ @", Strings.fixed(gb ? ram / 1024f / 1024 / 1024f : ram / 1024f / 1024f, 1), gb ? "GB" : "MB"); + } Time.setDeltaProvider(() -> { float result = Core.graphics.getDeltaTime() * 60f; diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 912e1ecb09..03c6cf3f2e 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1513,27 +1513,23 @@ public class Blocks{ requirements(Category.defense, with(Items.copper, 6)); health = 80 * wallHealthMultiplier; researchCostMultiplier = 0.1f; - envDisabled |= Env.scorching; }}; copperWallLarge = new Wall("copper-wall-large"){{ requirements(Category.defense, ItemStack.mult(copperWall.requirements, 4)); health = 80 * 4 * wallHealthMultiplier; size = 2; - envDisabled |= Env.scorching; }}; titaniumWall = new Wall("titanium-wall"){{ requirements(Category.defense, with(Items.titanium, 6)); health = 110 * wallHealthMultiplier; - envDisabled |= Env.scorching; }}; titaniumWallLarge = new Wall("titanium-wall-large"){{ requirements(Category.defense, ItemStack.mult(titaniumWall.requirements, 4)); health = 110 * wallHealthMultiplier * 4; size = 2; - envDisabled |= Env.scorching; }}; plastaniumWall = new Wall("plastanium-wall"){{ @@ -1542,7 +1538,6 @@ public class Blocks{ insulated = true; absorbLasers = true; schematicPriority = 10; - envDisabled |= Env.scorching; }}; plastaniumWallLarge = new Wall("plastanium-wall-large"){{ @@ -1552,20 +1547,17 @@ public class Blocks{ insulated = true; absorbLasers = true; schematicPriority = 10; - envDisabled |= Env.scorching; }}; thoriumWall = new Wall("thorium-wall"){{ requirements(Category.defense, with(Items.thorium, 6)); health = 200 * wallHealthMultiplier; - envDisabled |= Env.scorching; }}; thoriumWallLarge = new Wall("thorium-wall-large"){{ requirements(Category.defense, ItemStack.mult(thoriumWall.requirements, 4)); health = 200 * wallHealthMultiplier * 4; size = 2; - envDisabled |= Env.scorching; }}; phaseWall = new Wall("phase-wall"){{ @@ -1573,7 +1565,6 @@ public class Blocks{ health = 150 * wallHealthMultiplier; chanceDeflect = 10f; flashHit = true; - envDisabled |= Env.scorching; }}; phaseWallLarge = new Wall("phase-wall-large"){{ @@ -1582,14 +1573,12 @@ public class Blocks{ size = 2; chanceDeflect = 10f; flashHit = true; - envDisabled |= Env.scorching; }}; surgeWall = new Wall("surge-wall"){{ requirements(Category.defense, with(Items.surgeAlloy, 6)); health = 230 * wallHealthMultiplier; lightningChance = 0.05f; - envDisabled |= Env.scorching; }}; surgeWallLarge = new Wall("surge-wall-large"){{ @@ -1597,13 +1586,11 @@ public class Blocks{ health = 230 * 4 * wallHealthMultiplier; size = 2; lightningChance = 0.05f; - envDisabled |= Env.scorching; }}; door = new Door("door"){{ requirements(Category.defense, with(Items.titanium, 6, Items.silicon, 4)); health = 100 * wallHealthMultiplier; - envDisabled |= Env.scorching; }}; doorLarge = new Door("door-large"){{ @@ -1612,14 +1599,12 @@ public class Blocks{ closefx = Fx.doorcloselarge; health = 100 * 4 * wallHealthMultiplier; size = 2; - envDisabled |= Env.scorching; }}; scrapWall = new Wall("scrap-wall"){{ requirements(Category.defense, BuildVisibility.sandboxOnly, with(Items.scrap, 6)); health = 60 * wallHealthMultiplier; variants = 5; - envDisabled |= Env.scorching; }}; scrapWallLarge = new Wall("scrap-wall-large"){{ @@ -1627,7 +1612,6 @@ public class Blocks{ health = 60 * 4 * wallHealthMultiplier; size = 2; variants = 4; - envDisabled |= Env.scorching; }}; scrapWallHuge = new Wall("scrap-wall-huge"){{ @@ -1635,21 +1619,18 @@ public class Blocks{ health = 60 * 9 * wallHealthMultiplier; size = 3; variants = 3; - envDisabled |= Env.scorching; }}; scrapWallGigantic = new Wall("scrap-wall-gigantic"){{ requirements(Category.defense, BuildVisibility.sandboxOnly, ItemStack.mult(scrapWall.requirements, 16)); health = 60 * 16 * wallHealthMultiplier; size = 4; - envDisabled |= Env.scorching; }}; thruster = new Thruster("thruster"){{ requirements(Category.defense, BuildVisibility.sandboxOnly, with(Items.scrap, 96)); health = 55 * 16 * wallHealthMultiplier; size = 4; - envDisabled |= Env.scorching; }}; berylliumWall = new Wall("beryllium-wall"){{ @@ -5755,51 +5736,43 @@ public class Blocks{ requirements(Category.power, BuildVisibility.sandboxOnly, with()); powerProduction = 1000000f / 60f; alwaysUnlocked = true; - allDatabaseTabs = true; }}; powerVoid = new PowerVoid("power-void"){{ requirements(Category.power, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; - allDatabaseTabs = true; }}; itemSource = new ItemSource("item-source"){{ requirements(Category.distribution, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; - allDatabaseTabs = true; }}; itemVoid = new ItemVoid("item-void"){{ requirements(Category.distribution, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; - allDatabaseTabs = true; }}; liquidSource = new LiquidSource("liquid-source"){{ requirements(Category.liquid, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; - allDatabaseTabs = true; }}; liquidVoid = new LiquidVoid("liquid-void"){{ requirements(Category.liquid, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; - allDatabaseTabs = true; }}; payloadSource = new PayloadSource("payload-source"){{ requirements(Category.units, BuildVisibility.sandboxOnly, with()); size = 5; alwaysUnlocked = true; - allDatabaseTabs = true; }}; payloadVoid = new PayloadVoid("payload-void"){{ requirements(Category.units, BuildVisibility.sandboxOnly, with()); size = 5; alwaysUnlocked = true; - allDatabaseTabs = true; }}; heatSource = new HeatProducer("heat-source"){{ @@ -5953,7 +5926,6 @@ public class Blocks{ size = 1; maxInstructionsPerTick = 1000; range = Float.MAX_VALUE; - allDatabaseTabs = true; }}; worldCell = new MemoryBlock("world-cell"){{ @@ -5963,7 +5935,6 @@ public class Blocks{ privileged = true; memoryCapacity = 128; forceDark = true; - allDatabaseTabs = true; }}; worldMessage = new MessageBlock("world-message"){{ @@ -5971,7 +5942,6 @@ public class Blocks{ targetable = false; privileged = true; - allDatabaseTabs = true; }}; worldSwitch = new SwitchBlock("world-switch"){{ @@ -5979,7 +5949,6 @@ public class Blocks{ targetable = false; privileged = true; - allDatabaseTabs = true; }}; //endregion diff --git a/core/src/mindustry/core/ContentLoader.java b/core/src/mindustry/core/ContentLoader.java index 1e2afa02de..5dfa75d09a 100644 --- a/core/src/mindustry/core/ContentLoader.java +++ b/core/src/mindustry/core/ContentLoader.java @@ -88,6 +88,7 @@ public class ContentLoader{ /** Calls Content#init() on everything. Use only after all modules have been created. */ public void init(){ initialize(Content::init); + initialize(Content::postInit); if(logicVars != null) logicVars.init(); Events.fire(new ContentInitEvent()); } diff --git a/core/src/mindustry/core/GameState.java b/core/src/mindustry/core/GameState.java index 17d3b3bfe9..1066e6d2a6 100644 --- a/core/src/mindustry/core/GameState.java +++ b/core/src/mindustry/core/GameState.java @@ -78,7 +78,7 @@ public class GameState{ } public @Nullable Planet getPlanet(){ - return rules.sector != null ? rules.sector.planet : null; + return rules.sector != null ? rules.sector.planet : rules.planet; } public boolean isEditor(){ diff --git a/core/src/mindustry/ctype/Content.java b/core/src/mindustry/ctype/Content.java index 58a75b4dc8..97816377e2 100644 --- a/core/src/mindustry/ctype/Content.java +++ b/core/src/mindustry/ctype/Content.java @@ -25,6 +25,9 @@ public abstract class Content implements Comparable{ /** Called after all content and modules are created. Do not use to load regions or texture data! */ public void init(){} + /** Called after init(). */ + public void postInit(){} + /** * Called after all content is created, only on non-headless versions. * Use for loading regions or other image data. diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index 4b7157b05d..6cbe82e287 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -9,7 +9,6 @@ import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; import mindustry.annotations.Annotations.*; -import mindustry.content.*; import mindustry.content.TechTree.*; import mindustry.game.EventType.*; import mindustry.graphics.*; @@ -47,7 +46,7 @@ public abstract class UnlockableContent extends MappableContent{ /** If true, this content will appear in all database tabs. */ public boolean allDatabaseTabs = false; /** - * Planets that this content is made for. If empty, it is shown on all planets. + * Planets that this content is made for. If empty, a planet is decided based on item requirements. * Currently, this is only meaningful for blocks. * */ public ObjectSet shownPlanets = new ObjectSet<>(); @@ -55,7 +54,6 @@ public abstract class UnlockableContent extends MappableContent{ * Content - usually a planet - that dictates which database tab(s) this content will appear in. * If nothing is defined, it will use the values in shownPlanets. * If shownPlanets is also empty, it will use Serpulo as the "default" tab. - * Note: When reading, use {@link #getDatabaseTabs} instead. * */ public ObjectSet databaseTabs = new ObjectSet<>(); /** The tech tree node for this content, if applicable. Null if not part of a tech tree. */ @@ -64,7 +62,6 @@ public abstract class UnlockableContent extends MappableContent{ public Seq techNodes = new Seq<>(); /** Unlock state. Loaded from settings. Do not modify outside the constructor. */ protected boolean unlocked; - private boolean initializedDatabaseTabs; public UnlockableContent(String name){ super(name); @@ -75,18 +72,11 @@ public abstract class UnlockableContent extends MappableContent{ this.unlocked = Core.settings != null && Core.settings.getBool(this.name + "-unlocked", false); } - public ObjectSet getDatabaseTabs(){ - //the problem here is that the planet hasn't initialized yet in init(), which means it hasn't assigned the shownPlanets yet. - //initialization has to be deferred to a getter - if(!initializedDatabaseTabs){ - initializedDatabaseTabs = true; + @Override + public void postInit(){ + super.postInit(); - databaseTabs.addAll(shownPlanets); - if(databaseTabs.isEmpty()){ - databaseTabs.add(Planets.serpulo); - } - } - return databaseTabs; + databaseTabs.addAll(shownPlanets); } @Override diff --git a/core/src/mindustry/ui/dialogs/DatabaseDialog.java b/core/src/mindustry/ui/dialogs/DatabaseDialog.java index 1951bf61cf..e8ffe18778 100644 --- a/core/src/mindustry/ui/dialogs/DatabaseDialog.java +++ b/core/src/mindustry/ui/dialogs/DatabaseDialog.java @@ -66,7 +66,7 @@ public class DatabaseDialog extends BaseDialog{ for(var contents : allContent){ for(var content : contents){ if(content instanceof UnlockableContent u){ - all.addAll(u.getDatabaseTabs()); + all.addAll(u.databaseTabs); } } } @@ -101,7 +101,7 @@ public class DatabaseDialog extends BaseDialog{ ContentType type = ContentType.all[j]; Seq array = allContent[j] - .select(c -> c instanceof UnlockableContent u && !u.isHidden() && (tab == Planets.sun || u.allDatabaseTabs || u.getDatabaseTabs().contains(tab)) && + .select(c -> c instanceof UnlockableContent u && !u.isHidden() && (tab == Planets.sun || u.allDatabaseTabs || u.databaseTabs.contains(tab)) && (text.isEmpty() || u.localizedName.toLowerCase().contains(text))).as(); if(array.size == 0) continue; diff --git a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java index 86ca0c8e16..1b309e05b6 100644 --- a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java +++ b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java @@ -172,7 +172,7 @@ public class LaunchLoadoutDialog extends BaseDialog{ Cons handler = s -> { if(s.tiles.contains(tile -> !tile.block.supportsEnv(sector.planet.defaultEnv) || //make sure block can be built here. - tile.block.isOnPlanet(sector.planet))){ + !tile.block.isOnPlanet(sector.planet))){ return; } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 64cc26af00..c324ae4978 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -1160,6 +1160,22 @@ public class Block extends UnlockableContent implements Senseable{ return buildVisibility != BuildVisibility.hidden; } + @Override + public void postInit(){ + //usually, an empty set of planets is a configuration error. auto-assign based on requirements + if(requirements.length > 0 && shownPlanets.isEmpty()){ + for(Planet planet : content.planets()){ + if(planet.isLandable()){ + if(!Structs.contains(requirements, s -> !s.item.isOnPlanet(planet))){ + shownPlanets.add(planet); + } + } + } + } + + super.postInit(); + } + /** Called after all blocks are created. */ @Override @CallSuper