From ce68c2a3e94fc92a32219ff8ed809dc7f1dd0bd6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 28 May 2018 15:20:46 -0400 Subject: [PATCH] Documentation, added Content/ContentDatabase classes --- .../io/anuke/mindustry/content/AmmoTypes.java | 4 +- .../src/io/anuke/mindustry/content/Items.java | 2 +- .../io/anuke/mindustry/content/Recipes.java | 42 +++++++++---------- .../mindustry/content/UpgradeRecipes.java | 4 +- .../content/blocks/CraftingBlocks.java | 4 +- .../mindustry/content/blocks/DebugBlocks.java | 2 +- .../anuke/mindustry/core/ContentLoader.java | 4 +- core/src/io/anuke/mindustry/core/Control.java | 11 ++++- core/src/io/anuke/mindustry/core/Logic.java | 2 +- core/src/io/anuke/mindustry/game/Content.java | 14 +++++++ .../anuke/mindustry/game/ContentDatabase.java | 27 ++++++++++++ .../io/anuke/mindustry/type/AmmoEntry.java | 5 ++- .../src/io/anuke/mindustry/type/AmmoType.java | 22 ++++++++-- core/src/io/anuke/mindustry/type/Item.java | 15 ++++++- core/src/io/anuke/mindustry/type/Liquid.java | 16 +++++-- core/src/io/anuke/mindustry/type/Mech.java | 2 +- core/src/io/anuke/mindustry/type/Recipe.java | 25 +++++++---- core/src/io/anuke/mindustry/type/Upgrade.java | 26 +++++++++--- core/src/io/anuke/mindustry/type/Weapon.java | 10 ++--- .../io/anuke/mindustry/type/WeatherEvent.java | 21 +++++++++- .../ui/fragments/BlocksFragment.java | 2 +- .../io/anuke/mindustry/world/BaseBlock.java | 2 +- core/src/io/anuke/mindustry/world/Block.java | 4 +- .../blocks/types/distribution/Conveyor.java | 4 +- .../blocks/types/distribution/Sorter.java | 4 +- .../blocks/types/modules/InventoryModule.java | 2 +- .../types/production/WeaponFactory.java | 2 +- .../blocks/types/storage/SortedUnloader.java | 4 +- 28 files changed, 207 insertions(+), 75 deletions(-) create mode 100644 core/src/io/anuke/mindustry/game/Content.java create mode 100644 core/src/io/anuke/mindustry/game/ContentDatabase.java diff --git a/core/src/io/anuke/mindustry/content/AmmoTypes.java b/core/src/io/anuke/mindustry/content/AmmoTypes.java index 682af78289..f1e8f6ab00 100644 --- a/core/src/io/anuke/mindustry/content/AmmoTypes.java +++ b/core/src/io/anuke/mindustry/content/AmmoTypes.java @@ -57,7 +57,7 @@ public class AmmoTypes { smokeEffect = ShootFx.shootSmallSmoke; }}, - flakSurge = new AmmoType(Items.densealloy, FlakBullets.surge, 5){{ + flakSurge = new AmmoType(Items.surgealloy, FlakBullets.surge, 5){{ shootEffect = ShootFx.shootSmall; smokeEffect = ShootFx.shootSmallSmoke; }}, @@ -96,7 +96,7 @@ public class AmmoTypes { smokeEffect = ShootFx.shootBigSmoke2; }}, - missileSurge = new AmmoType(Items.densealloy, MissileBullets.surge, 1){{ + missileSurge = new AmmoType(Items.surgealloy, MissileBullets.surge, 1){{ shootEffect = ShootFx.shootBig2; smokeEffect = ShootFx.shootBigSmoke2; }}, diff --git a/core/src/io/anuke/mindustry/content/Items.java b/core/src/io/anuke/mindustry/content/Items.java index 14e6e4670a..4ddc13e25f 100644 --- a/core/src/io/anuke/mindustry/content/Items.java +++ b/core/src/io/anuke/mindustry/content/Items.java @@ -52,7 +52,7 @@ public class Items { explosiveness = 0.1f; }}, - densealloy = new Item("densealloy", Color.valueOf("b4d5c7")){{ + surgealloy = new Item("surgealloy", Color.valueOf("b4d5c7")){{ type = ItemType.material; }}, diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index e425bc5f2b..64345dc9f3 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -10,17 +10,17 @@ public class Recipes { new Recipe(defense, DefenseBlocks.ironwall, new ItemStack(Items.iron, 12)); new Recipe(defense, DefenseBlocks.steelwall, new ItemStack(Items.steel, 12)); new Recipe(defense, DefenseBlocks.titaniumwall, new ItemStack(Items.titanium, 12)); - new Recipe(defense, DefenseBlocks.diriumwall, new ItemStack(Items.densealloy, 12)); + new Recipe(defense, DefenseBlocks.diriumwall, new ItemStack(Items.surgealloy, 12)); new Recipe(defense, DefenseBlocks.steelwalllarge, new ItemStack(Items.steel, 12 * 4)); new Recipe(defense, DefenseBlocks.titaniumwalllarge, new ItemStack(Items.titanium, 12 * 4)); - new Recipe(defense, DefenseBlocks.diriumwall, new ItemStack(Items.densealloy, 12 * 4)); + new Recipe(defense, DefenseBlocks.diriumwall, new ItemStack(Items.surgealloy, 12 * 4)); new Recipe(defense, DefenseBlocks.door, new ItemStack(Items.steel, 3), new ItemStack(Items.iron, 3 * 4)); new Recipe(defense, DefenseBlocks.largedoor, new ItemStack(Items.steel, 3 * 4), new ItemStack(Items.iron, 3 * 4 * 4)); new Recipe(defense, DefenseBlocks.titaniumshieldwall, new ItemStack(Items.titanium, 16)); new Recipe(distribution, DistributionBlocks.conveyor, new ItemStack(Items.iron, 1)); new Recipe(distribution, DistributionBlocks.steelconveyor, new ItemStack(Items.steel, 1)); - new Recipe(distribution, DistributionBlocks.pulseconveyor, new ItemStack(Items.densealloy, 1)); + new Recipe(distribution, DistributionBlocks.pulseconveyor, new ItemStack(Items.surgealloy, 1)); new Recipe(distribution, DistributionBlocks.router, new ItemStack(Items.iron, 2)); new Recipe(distribution, DistributionBlocks.multiplexer, new ItemStack(Items.iron, 8)); new Recipe(distribution, DistributionBlocks.junction, new ItemStack(Items.iron, 2)); @@ -40,12 +40,12 @@ public class Recipes { new Recipe(weapon, WeaponBlocks.wave, new ItemStack(Items.iron, 15), new ItemStack(Items.steel, 10)); new Recipe(weapon, WeaponBlocks.lancer, new ItemStack(Items.steel, 12), new ItemStack(Items.titanium, 12)); new Recipe(weapon, WeaponBlocks.crux, new ItemStack(Items.steel, 25), new ItemStack(Items.titanium, 15)); - new Recipe(weapon, WeaponBlocks.arc, new ItemStack(Items.steel, 20), new ItemStack(Items.titanium, 25), new ItemStack(Items.densealloy, 15)); - new Recipe(weapon, WeaponBlocks.swarmer, new ItemStack(Items.steel, 80), new ItemStack(Items.titanium, 70), new ItemStack(Items.densealloy, 60)); - new Recipe(weapon, WeaponBlocks.ripple, new ItemStack(Items.steel, 80), new ItemStack(Items.titanium, 70), new ItemStack(Items.densealloy, 60)); - new Recipe(weapon, WeaponBlocks.fuse, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.densealloy, 55)); - new Recipe(weapon, WeaponBlocks.spectre, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.densealloy, 55)); - new Recipe(weapon, WeaponBlocks.meltdown, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.densealloy, 55)); + new Recipe(weapon, WeaponBlocks.arc, new ItemStack(Items.steel, 20), new ItemStack(Items.titanium, 25), new ItemStack(Items.surgealloy, 15)); + new Recipe(weapon, WeaponBlocks.swarmer, new ItemStack(Items.steel, 80), new ItemStack(Items.titanium, 70), new ItemStack(Items.surgealloy, 60)); + new Recipe(weapon, WeaponBlocks.ripple, new ItemStack(Items.steel, 80), new ItemStack(Items.titanium, 70), new ItemStack(Items.surgealloy, 60)); + new Recipe(weapon, WeaponBlocks.fuse, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.surgealloy, 55)); + new Recipe(weapon, WeaponBlocks.spectre, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.surgealloy, 55)); + new Recipe(weapon, WeaponBlocks.meltdown, new ItemStack(Items.steel, 70), new ItemStack(Items.titanium, 50), new ItemStack(Items.surgealloy, 55)); new Recipe(crafting, CraftingBlocks.smelter, new ItemStack(Items.iron, 40)); new Recipe(crafting, CraftingBlocks.alloysmelter, new ItemStack(Items.titanium, 50), new ItemStack(Items.steel, 50)); @@ -68,12 +68,12 @@ public class Recipes { new Recipe(production, ProductionBlocks.reinforcedDrill, new ItemStack(Items.iron, 25)); new Recipe(production, ProductionBlocks.steelDrill, new ItemStack(Items.iron, 25)); new Recipe(production, ProductionBlocks.titaniumDrill, new ItemStack(Items.iron, 25)); - new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); - new Recipe(production, ProductionBlocks.nucleardrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); - new Recipe(production, ProductionBlocks.plasmadrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); - new Recipe(production, ProductionBlocks.cultivator, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); - new Recipe(production, ProductionBlocks.waterextractor, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); - new Recipe(production, ProductionBlocks.oilextractor, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40)); + new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); + new Recipe(production, ProductionBlocks.nucleardrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); + new Recipe(production, ProductionBlocks.plasmadrill, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); + new Recipe(production, ProductionBlocks.cultivator, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); + new Recipe(production, ProductionBlocks.waterextractor, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); + new Recipe(production, ProductionBlocks.oilextractor, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40)); new Recipe(power, PowerBlocks.powernode, new ItemStack(Items.steel, 3), new ItemStack(Items.iron, 3)); new Recipe(power, PowerBlocks.powernodelarge, new ItemStack(Items.steel, 3), new ItemStack(Items.iron, 3)); @@ -85,12 +85,12 @@ public class Recipes { new Recipe(power, PowerBlocks.rtgenerator, new ItemStack(Items.titanium, 20), new ItemStack(Items.steel, 20)); new Recipe(power, PowerBlocks.solarpanel, new ItemStack(Items.iron, 30), new ItemStack(Items.silicon, 20)); new Recipe(power, PowerBlocks.largesolarpanel, new ItemStack(Items.iron, 30), new ItemStack(Items.silicon, 20)); - new Recipe(power, PowerBlocks.nuclearReactor, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40), new ItemStack(Items.steel, 50)); - new Recipe(power, PowerBlocks.fusionReactor, new ItemStack(Items.titanium, 40), new ItemStack(Items.densealloy, 40), new ItemStack(Items.steel, 50)); + new Recipe(power, PowerBlocks.nuclearReactor, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40), new ItemStack(Items.steel, 50)); + new Recipe(power, PowerBlocks.fusionReactor, new ItemStack(Items.titanium, 40), new ItemStack(Items.surgealloy, 40), new ItemStack(Items.steel, 50)); - new Recipe(power, PowerBlocks.shieldgenerator, new ItemStack(Items.titanium, 30), new ItemStack(Items.densealloy, 30)); + new Recipe(power, PowerBlocks.shieldgenerator, new ItemStack(Items.titanium, 30), new ItemStack(Items.surgealloy, 30)); - new Recipe(distribution, PowerBlocks.teleporter, new ItemStack(Items.steel, 30), new ItemStack(Items.densealloy, 40)); + new Recipe(distribution, PowerBlocks.teleporter, new ItemStack(Items.steel, 30), new ItemStack(Items.surgealloy, 40)); new Recipe(power, PowerBlocks.repairturret, new ItemStack(Items.iron, 30)); new Recipe(power, PowerBlocks.megarepairturret, new ItemStack(Items.iron, 20), new ItemStack(Items.steel, 30)); @@ -104,7 +104,7 @@ public class Recipes { new Recipe(liquid, LiquidBlocks.laserconduit, new ItemStack(Items.titanium, 2), new ItemStack(Items.steel, 2)); new Recipe(liquid, LiquidBlocks.pump, new ItemStack(Items.steel, 10)); - new Recipe(liquid, LiquidBlocks.fluxpump, new ItemStack(Items.steel, 10), new ItemStack(Items.densealloy, 5)); + new Recipe(liquid, LiquidBlocks.fluxpump, new ItemStack(Items.steel, 10), new ItemStack(Items.surgealloy, 5)); new Recipe(units, UnitBlocks.repairPoint, new ItemStack(Items.steel, 10)); new Recipe(units, UnitBlocks.resupplyPoint, new ItemStack(Items.steel, 10)); @@ -119,6 +119,6 @@ public class Recipes { new Recipe(units, DebugBlocks.itemVoid, new ItemStack(Items.steel, 10)).setDebug(); new Recipe(units, DebugBlocks.liquidSource, new ItemStack(Items.steel, 10)).setDebug(); new Recipe(units, DebugBlocks.powerVoid, new ItemStack(Items.steel, 10)).setDebug(); - new Recipe(units, DebugBlocks.powerInfinite, new ItemStack(Items.steel, 10), new ItemStack(Items.densealloy, 5)).setDebug(); + new Recipe(units, DebugBlocks.powerInfinite, new ItemStack(Items.steel, 10), new ItemStack(Items.surgealloy, 5)).setDebug(); } } diff --git a/core/src/io/anuke/mindustry/content/UpgradeRecipes.java b/core/src/io/anuke/mindustry/content/UpgradeRecipes.java index bfaf3309eb..5813e52e48 100644 --- a/core/src/io/anuke/mindustry/content/UpgradeRecipes.java +++ b/core/src/io/anuke/mindustry/content/UpgradeRecipes.java @@ -13,8 +13,8 @@ public class UpgradeRecipes { Weapons.triblaster, list(stack(Items.iron, 60), stack(Items.steel, 80)), Weapons.clustergun, list(stack(Items.iron, 300), stack(Items.steel, 80)), Weapons.vulcan, list(stack(Items.iron, 100), stack(Items.steel, 150), stack(Items.titanium, 80)), - Weapons.beam, list(stack(Items.steel, 260), stack(Items.titanium, 160), stack(Items.densealloy, 120)), - Weapons.shockgun, list(stack(Items.steel, 240), stack(Items.titanium, 160), stack(Items.densealloy, 160))*/ + Weapons.beam, list(stack(Items.steel, 260), stack(Items.titanium, 160), stack(Items.surgealloy, 120)), + Weapons.shockgun, list(stack(Items.steel, 240), stack(Items.titanium, 160), stack(Items.surgealloy, 160))*/ ); private static final ItemStack[] empty = {}; diff --git a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java index 5de9433d19..4c0a49d7dc 100644 --- a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java @@ -24,7 +24,7 @@ public class CraftingBlocks { health = 90; inputs = new Item[]{Items.titanium, Items.steel}; fuel = Items.coal; - result = Items.densealloy; + result = Items.surgealloy; burnDuration = 45f; craftTime = 25f; flameColor = Color.valueOf("fd896e"); @@ -46,7 +46,7 @@ public class CraftingBlocks { health = 90; craftEffect = BlockFx.smeltsmoke; inputs = new ItemStack[]{new ItemStack(Items.titanium, 4), new ItemStack(Items.thorium, 4)}; - result = Items.densealloy; + result = Items.surgealloy; powerUse = 0.3f; craftTime = 25f; size = 2; diff --git a/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java b/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java index f429a75406..aeb791eb9f 100644 --- a/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java @@ -92,7 +92,7 @@ public class DebugBlocks { public void buildTable(Tile tile, Table table){ LiquidSourceEntity entity = tile.entity(); - Array items = Liquid.getAllLiquids(); + Array items = Liquid.all(); ButtonGroup group = new ButtonGroup<>(); Table cont = new Table(); diff --git a/core/src/io/anuke/mindustry/core/ContentLoader.java b/core/src/io/anuke/mindustry/core/ContentLoader.java index 76a0712b6e..f1aa778275 100644 --- a/core/src/io/anuke/mindustry/core/ContentLoader.java +++ b/core/src/io/anuke/mindustry/core/ContentLoader.java @@ -70,8 +70,8 @@ public class ContentLoader { Log.info("--- CONTENT INFO ---"); Log.info("Blocks loaded: {0}\nItems loaded: {1}\nLiquids loaded: {2}\nUpgrades loaded: {3}\nUnits loaded: {4}\nAmmo types loaded: {5}\nBullet types loaded: {6}\nStatus effects loaded: {7}\nRecipes loaded: {8}\nTotal content classes: {9}", - Block.getAllBlocks().size, io.anuke.mindustry.type.Item.getAllItems().size, Liquid.getAllLiquids().size, - io.anuke.mindustry.type.Mech.getAllUpgrades().size, UnitType.getAllTypes().size, io.anuke.mindustry.type.AmmoType.getAllTypes().size, BulletType.all().size, StatusEffect.getAllEffects().size, io.anuke.mindustry.type.Recipe.getAllRecipes().size, content.length); + Block.getAllBlocks().size, io.anuke.mindustry.type.Item.all().size, Liquid.all().size, + io.anuke.mindustry.type.Mech.all().size, UnitType.getAllTypes().size, io.anuke.mindustry.type.AmmoType.all().size, BulletType.all().size, StatusEffect.getAllEffects().size, io.anuke.mindustry.type.Recipe.all().size, content.length); Log.info("-------------------"); } diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index ed3b31bc0d..c39505ed38 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.TimeUtils; import io.anuke.mindustry.content.Mechs; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; +import io.anuke.mindustry.game.ContentDatabase; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.input.AndroidInput; import io.anuke.mindustry.input.DefaultKeybinds; @@ -37,6 +38,7 @@ public class Control extends Module{ private boolean hiscore = false; private boolean wasPaused = false; private Saves saves; + private ContentDatabase db; private InputHandler[] inputs = {}; private ObjectMap soundMap = new ObjectMap<>(); @@ -46,6 +48,7 @@ public class Control extends Module{ public Control(){ saves = new Saves(); + db = new ContentDatabase(); Inputs.useControllers(!gwt); @@ -55,7 +58,7 @@ public class Control extends Module{ Core.atlas = new Atlas("sprites.atlas"); - for(Item item : Item.getAllItems()){ + for(Item item : Item.all()){ item.init(); } @@ -227,7 +230,11 @@ public class Control extends Module{ System.arraycopy(oldi, 0, inputs, 0, inputs.length); } - public Input gdxInput(){ + public ContentDatabase database() { + return db; + } + + public Input gdxInput(){ return gdxInput; } diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 68fa96073b..13648fb648 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -48,7 +48,7 @@ public class Logic extends Module { //fill inventory with items for debugging for(Tile tile : state.teams.get(players[0].team).cores){ - for(Item item : Item.getAllItems()){ + for(Item item : Item.all()){ if(item.type == ItemType.material){ tile.entity.items.addItem(item, 1000); } diff --git a/core/src/io/anuke/mindustry/game/Content.java b/core/src/io/anuke/mindustry/game/Content.java new file mode 100644 index 0000000000..75ded126d0 --- /dev/null +++ b/core/src/io/anuke/mindustry/game/Content.java @@ -0,0 +1,14 @@ +package io.anuke.mindustry.game; + +/**Base interface for an unlockable content type.*/ +public interface Content { + /**Returns the unqiue name of this piece of content. + * The name only needs to be unique for all content of this type. + * Do not use IDs for names! Make sure this string stays constant with each update unless removed. + * (e.g. having a recipe and a block, both with name "wall" is fine, as they are different types).*/ + String getContentName(); + + /**Returns the type name of this piece of content. + * This should return the same value for all instances of this content type.*/ + String getContentTypeName(); +} diff --git a/core/src/io/anuke/mindustry/game/ContentDatabase.java b/core/src/io/anuke/mindustry/game/ContentDatabase.java new file mode 100644 index 0000000000..78fa28b356 --- /dev/null +++ b/core/src/io/anuke/mindustry/game/ContentDatabase.java @@ -0,0 +1,27 @@ +package io.anuke.mindustry.game; + +import com.badlogic.gdx.utils.ObjectMap; +import com.badlogic.gdx.utils.ObjectSet; + +public class ContentDatabase { + private ObjectMap> unlocked = new ObjectMap<>(); + + public boolean isUnlocked(Content content){ + if(!unlocked.containsKey(content.getContentTypeName())){ + unlocked.put(content.getContentTypeName(), new ObjectSet<>()); + } + + ObjectSet set = unlocked.get(content.getContentTypeName()); + + return set.contains(content.getContentName()); + } + + private void load(){ + + } + + private void save(){ + + } + +} diff --git a/core/src/io/anuke/mindustry/type/AmmoEntry.java b/core/src/io/anuke/mindustry/type/AmmoEntry.java index f4deb909ce..fc14db1cce 100644 --- a/core/src/io/anuke/mindustry/type/AmmoEntry.java +++ b/core/src/io/anuke/mindustry/type/AmmoEntry.java @@ -1,10 +1,11 @@ package io.anuke.mindustry.type; +/**Used to store ammo amounts in units and turrets.*/ public class AmmoEntry{ - public io.anuke.mindustry.type.AmmoType type; + public AmmoType type; public int amount; - public AmmoEntry(io.anuke.mindustry.type.AmmoType type, int amount) { + public AmmoEntry(AmmoType type, int amount) { this.type = type; this.amount = amount; } diff --git a/core/src/io/anuke/mindustry/type/AmmoType.java b/core/src/io/anuke/mindustry/type/AmmoType.java index fcbcd7058f..4c82e10b7d 100644 --- a/core/src/io/anuke/mindustry/type/AmmoType.java +++ b/core/src/io/anuke/mindustry/type/AmmoType.java @@ -3,9 +3,10 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.entities.bullet.BulletType; +import io.anuke.mindustry.game.Content; import io.anuke.ucore.core.Effects.Effect; -public class AmmoType { +public class AmmoType implements Content{ private static int lastID = 0; private static Array allTypes = new Array<>(); @@ -14,7 +15,7 @@ public class AmmoType { public final Item item; /**The liquid used. Always null if item isn't.*/ public final Liquid liquid; - /**The resulting bullet.*/ + /**The resulting bullet. Never null.*/ public final BulletType bullet; /**For item ammo, this is amount given per ammo item. * For liquid ammo, this is amount used per shot.*/ @@ -33,6 +34,7 @@ public class AmmoType { allTypes.add(this); } + /**Creates an AmmoType with no liquid or item. Used for power-based ammo.*/ public AmmoType(BulletType result){ this.item = null; this.liquid = null; @@ -41,6 +43,7 @@ public class AmmoType { this.speedMultiplier = 1f; } + /**Creates an AmmoType with an item.*/ public AmmoType(Item item, BulletType result, float multiplier){ this.item = item; this.liquid = null; @@ -48,6 +51,7 @@ public class AmmoType { this.quantityMultiplier = multiplier; } + /**Creates an AmmoType with a liquid.*/ public AmmoType(Liquid liquid, BulletType result, float multiplier){ this.item = null; this.liquid = liquid; @@ -55,11 +59,23 @@ public class AmmoType { this.quantityMultiplier = multiplier; } + /**Returns maximum distance the bullet this ammo type has can travel.*/ public float getRange(){ return bullet.speed * bullet.lifetime; } - public static Array getAllTypes() { + //TODO implement content name? + @Override + public String getContentName() { + return "???"; + } + + @Override + public String getContentTypeName() { + return "ammotype"; + } + + public static Array all() { return allTypes; } diff --git a/core/src/io/anuke/mindustry/type/Item.java b/core/src/io/anuke/mindustry/type/Item.java index 5187ac4b3b..45011a8298 100644 --- a/core/src/io/anuke/mindustry/type/Item.java +++ b/core/src/io/anuke/mindustry/type/Item.java @@ -3,11 +3,12 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.game.Content; import io.anuke.mindustry.graphics.Palette; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Bundles; -public class Item implements Comparable{ +public class Item implements Comparable, Content{ private static final Array items = new Array<>(); public final int id; @@ -59,7 +60,17 @@ public class Item implements Comparable{ return Integer.compare(id, item.id); } - public static Array getAllItems() { + @Override + public String getContentName() { + return name; + } + + @Override + public String getContentTypeName() { + return "item"; + } + + public static Array all() { return Item.items; } diff --git a/core/src/io/anuke/mindustry/type/Liquid.java b/core/src/io/anuke/mindustry/type/Liquid.java index f5d7d12744..5ea0ac086d 100644 --- a/core/src/io/anuke/mindustry/type/Liquid.java +++ b/core/src/io/anuke/mindustry/type/Liquid.java @@ -4,10 +4,10 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.StatusEffects; import io.anuke.mindustry.entities.StatusEffect; +import io.anuke.mindustry.game.Content; import io.anuke.ucore.util.Bundles; -public class Liquid { - +public class Liquid implements Content{ private static final Array liquids = new Array<>(); public final Color color; @@ -47,7 +47,17 @@ public class Liquid { return localizedName(); } - public static Array getAllLiquids() { + @Override + public String getContentName() { + return name; + } + + @Override + public String getContentTypeName() { + return "liquid"; + } + + public static Array all() { return Liquid.liquids; } diff --git a/core/src/io/anuke/mindustry/type/Mech.java b/core/src/io/anuke/mindustry/type/Mech.java index cfcdad335c..16d6b95331 100644 --- a/core/src/io/anuke/mindustry/type/Mech.java +++ b/core/src/io/anuke/mindustry/type/Mech.java @@ -1,6 +1,6 @@ package io.anuke.mindustry.type; -public class Mech extends io.anuke.mindustry.type.Upgrade { +public class Mech extends Upgrade { public boolean flying; public float mass = 1f; diff --git a/core/src/io/anuke/mindustry/type/Recipe.java b/core/src/io/anuke/mindustry/type/Recipe.java index 7f9a0c99d3..767f0cdf5c 100644 --- a/core/src/io/anuke/mindustry/type/Recipe.java +++ b/core/src/io/anuke/mindustry/type/Recipe.java @@ -2,29 +2,30 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; +import io.anuke.mindustry.game.Content; import io.anuke.mindustry.world.Block; -public class Recipe { +public class Recipe implements Content{ private static int lastid; private static Array allRecipes = new Array<>(); private static ObjectMap recipeMap = new ObjectMap<>(); public final int id; public final Block result; - public final io.anuke.mindustry.type.ItemStack[] requirements; - public final io.anuke.mindustry.type.Section section; + public final ItemStack[] requirements; + public final Section section; public final float cost; public boolean desktopOnly = false, debugOnly = false; - public Recipe(io.anuke.mindustry.type.Section section, Block result, io.anuke.mindustry.type.ItemStack... requirements){ + public Recipe(Section section, Block result, ItemStack... requirements){ this.id = lastid ++; this.result = result; this.requirements = requirements; this.section = section; float timeToPlace = 0f; - for(io.anuke.mindustry.type.ItemStack stack : requirements){ + for(ItemStack stack : requirements){ timeToPlace += stack.amount * stack.item.cost; } @@ -44,7 +45,17 @@ public class Recipe { return this; } - public static Array getBySection(io.anuke.mindustry.type.Section section, Array r){ + @Override + public String getContentName() { + return result.name; + } + + @Override + public String getContentTypeName() { + return "recipe"; + } + + public static Array getBySection(Section section, Array r){ for(Recipe recipe : allRecipes){ if(recipe.section == section ) { r.add(recipe); @@ -54,7 +65,7 @@ public class Recipe { return r; } - public static Array getAllRecipes(){ + public static Array all(){ return allRecipes; } diff --git a/core/src/io/anuke/mindustry/type/Upgrade.java b/core/src/io/anuke/mindustry/type/Upgrade.java index 4c9e941b82..fba7b24c62 100644 --- a/core/src/io/anuke/mindustry/type/Upgrade.java +++ b/core/src/io/anuke/mindustry/type/Upgrade.java @@ -1,9 +1,10 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.game.Content; import io.anuke.ucore.util.Bundles; -public abstract class Upgrade { +public abstract class Upgrade implements Content{ private static Array upgrades = new Array<>(); private static byte lastid; @@ -23,11 +24,26 @@ public abstract class Upgrade { return Bundles.get("upgrade." + name + ".name"); } + @Override + public String toString(){ + return localized(); + } + + @Override + public String getContentName() { + return name; + } + + @Override + public String getContentTypeName() { + return "upgrade"; + } + + public static Array all() { + return upgrades; + } + public static T getByID(byte id){ return (T)upgrades.get(id); } - - public static Array getAllUpgrades() { - return upgrades; - } } diff --git a/core/src/io/anuke/mindustry/type/Weapon.java b/core/src/io/anuke/mindustry/type/Weapon.java index 9fd0ea3f1f..7aeea29c55 100644 --- a/core/src/io/anuke/mindustry/type/Weapon.java +++ b/core/src/io/anuke/mindustry/type/Weapon.java @@ -16,11 +16,11 @@ import io.anuke.ucore.util.Bits; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Translator; -public class Weapon extends io.anuke.mindustry.type.Upgrade { +public class Weapon extends Upgrade { /**minimum cursor distance from player, fixes 'cross-eyed' shooting.*/ protected static float minPlayerDist = 20f; /**ammo type map. set with setAmmo()*/ - protected ObjectMap ammoMap = new ObjectMap<>(); + protected ObjectMap ammoMap = new ObjectMap<>(); /**shell ejection effect*/ protected Effect ejectEffect = Fx.none; /**weapon reload in frames*/ @@ -83,11 +83,11 @@ public class Weapon extends io.anuke.mindustry.type.Upgrade { p.inventory.useAmmo(); } - public io.anuke.mindustry.type.AmmoType getAmmoType(io.anuke.mindustry.type.Item item){ + public AmmoType getAmmoType(io.anuke.mindustry.type.Item item){ return ammoMap.get(item); } - protected void setAmmo(io.anuke.mindustry.type.AmmoType... types){ + protected void setAmmo(AmmoType... types){ for(io.anuke.mindustry.type.AmmoType type : types){ ammoMap.put(type.item, type); } @@ -96,7 +96,7 @@ public class Weapon extends io.anuke.mindustry.type.Upgrade { void shootInternal(Player p, float x, float y, float rotation, boolean left){ Angles.shotgun(shots, spacing, rotation, f -> bullet(p, x, y, f + Mathf.range(inaccuracy))); - io.anuke.mindustry.type.AmmoType type = p.inventory.getAmmo(); + AmmoType type = p.inventory.getAmmo(); tr.trns(rotation + 180f, type.recoil); diff --git a/core/src/io/anuke/mindustry/type/WeatherEvent.java b/core/src/io/anuke/mindustry/type/WeatherEvent.java index 0d6b20336e..727e38c8e6 100644 --- a/core/src/io/anuke/mindustry/type/WeatherEvent.java +++ b/core/src/io/anuke/mindustry/type/WeatherEvent.java @@ -1,8 +1,10 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.game.Content; -public class WeatherEvent { +//TODO implement this class +public class WeatherEvent implements Content{ private static final Array all = new Array<>(); private static int lastid; @@ -16,4 +18,21 @@ public class WeatherEvent { all.add(this); } + @Override + public String getContentName() { + return name; + } + + @Override + public String getContentTypeName() { + return "weatherevent"; + } + + public static Array all(){ + return all; + } + + public static WeatherEvent getByID(int id){ + return all.get(id); + } } diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index 99c45cd6b1..10003af718 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -43,7 +43,7 @@ public class BlocksFragment implements Fragment{ { int size = 0; - for(Item ignored : Item.getAllItems()){ + for(Item ignored : Item.all()){ size ++; } diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index 6a2f5cd055..a9f4c511df 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -190,7 +190,7 @@ public abstract class BaseBlock { Tile other; Tile in; - for(Item item : Item.getAllItems()){ + for(Item item : Item.all()){ other = tile.getNearby(nearby[i]); in = tile.getNearby(Edges.getInsideEdges(size)[i]); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index f0ef61b610..3565266403 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -253,7 +253,7 @@ public class Block extends BaseBlock { tempColor.set(Palette.darkFlame); if(hasItems){ - for(Item item : Item.getAllItems()){ + for(Item item : Item.all()){ int amount = tile.entity.items.getItem(item); explosiveness += item.explosiveness*amount; flammability += item.flammability*amount; @@ -314,7 +314,7 @@ public class Block extends BaseBlock { return 0; }else{ float result = 0f; - for(Item item : Item.getAllItems()){ + for(Item item : Item.all()){ int amount = tile.entity.items.getItem(item); result += item.flammability*amount; } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java index 672525396e..4717705354 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java @@ -322,10 +322,10 @@ public class Conveyor extends Block{ ItemPos set(long lvalue, short[] values){ Bits.getShorts(lvalue, values); - if(values[0] >= Item.getAllItems().size || values[0] < 0) + if(values[0] >= Item.all().size || values[0] < 0) item = null; else - item = Item.getAllItems().get(values[0]); + item = Item.all().get(values[0]); x = values[1] / (float)Short.MAX_VALUE; y = ((float)values[2]) / Short.MAX_VALUE + 1f; diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Sorter.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Sorter.java index 9eef97fbf6..fb2260c7d1 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Sorter.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Sorter.java @@ -110,7 +110,7 @@ public class Sorter extends Block{ public void buildTable(Tile tile, Table table){ SorterEntity entity = tile.entity(); - Array items = Item.getAllItems(); + Array items = Item.all(); ButtonGroup group = new ButtonGroup<>(); Table cont = new Table(); @@ -151,7 +151,7 @@ public class Sorter extends Block{ @Override public void read(DataInputStream stream) throws IOException{ - sortItem = Item.getAllItems().get(stream.readByte()); + sortItem = Item.all().get(stream.readByte()); } } } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/modules/InventoryModule.java b/core/src/io/anuke/mindustry/world/blocks/types/modules/InventoryModule.java index 9200d242fe..4d9d4f03a0 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/modules/InventoryModule.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/modules/InventoryModule.java @@ -10,7 +10,7 @@ import java.io.IOException; import java.util.Arrays; public class InventoryModule extends BlockModule{ - public int[] items = new int[Item.getAllItems().size]; + public int[] items = new int[Item.all().size]; //TODO optimize! public int totalItems(){ diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java b/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java index 4e6c2d40a2..ff61137f1d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java @@ -45,7 +45,7 @@ public class WeaponFactory extends Block{ Table content = new Table(); /* - for(Upgrade upgrade : Upgrade.getAllUpgrades()){ + for(Upgrade upgrade : Upgrade.all()){ if(!(upgrade instanceof Weapon)) continue; Weapon weapon = (Weapon)upgrade; diff --git a/core/src/io/anuke/mindustry/world/blocks/types/storage/SortedUnloader.java b/core/src/io/anuke/mindustry/world/blocks/types/storage/SortedUnloader.java index 7f09546fea..8babd3d103 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/storage/SortedUnloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/storage/SortedUnloader.java @@ -69,7 +69,7 @@ public class SortedUnloader extends Unloader { public void buildTable(Tile tile, Table table){ SortedUnloaderEntity entity = tile.entity(); - Array items = Item.getAllItems(); + Array items = Item.all(); ButtonGroup group = new ButtonGroup<>(); Table cont = new Table(); @@ -111,7 +111,7 @@ public class SortedUnloader extends Unloader { @Override public void read(DataInputStream stream) throws IOException{ - sortItem = Item.getAllItems().get(stream.readByte()); + sortItem = Item.all().get(stream.readByte()); } } }