Documentation, added Content/ContentDatabase classes

This commit is contained in:
Anuken 2018-05-28 15:20:46 -04:00
parent 857f36e01a
commit ce68c2a3e9
28 changed files with 207 additions and 75 deletions

View File

@ -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;
}},

View File

@ -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;
}},

View File

@ -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();
}
}

View File

@ -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 = {};

View File

@ -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;

View File

@ -92,7 +92,7 @@ public class DebugBlocks {
public void buildTable(Tile tile, Table table){
LiquidSourceEntity entity = tile.entity();
Array<Liquid> items = Liquid.getAllLiquids();
Array<Liquid> items = Liquid.all();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Table cont = new Table();

View File

@ -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("-------------------");
}

View File

@ -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<Sound, Long> 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;
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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<String, ObjectSet<String>> unlocked = new ObjectMap<>();
public boolean isUnlocked(Content content){
if(!unlocked.containsKey(content.getContentTypeName())){
unlocked.put(content.getContentTypeName(), new ObjectSet<>());
}
ObjectSet<String> set = unlocked.get(content.getContentTypeName());
return set.contains(content.getContentName());
}
private void load(){
}
private void save(){
}
}

View File

@ -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;
}

View File

@ -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<AmmoType> 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<AmmoType> getAllTypes() {
//TODO implement content name?
@Override
public String getContentName() {
return "???";
}
@Override
public String getContentTypeName() {
return "ammotype";
}
public static Array<AmmoType> all() {
return allTypes;
}

View File

@ -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<Item>{
public class Item implements Comparable<Item>, Content{
private static final Array<Item> items = new Array<>();
public final int id;
@ -59,7 +60,17 @@ public class Item implements Comparable<Item>{
return Integer.compare(id, item.id);
}
public static Array<Item> getAllItems() {
@Override
public String getContentName() {
return name;
}
@Override
public String getContentTypeName() {
return "item";
}
public static Array<Item> all() {
return Item.items;
}

View File

@ -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<Liquid> liquids = new Array<>();
public final Color color;
@ -47,7 +47,17 @@ public class Liquid {
return localizedName();
}
public static Array<Liquid> getAllLiquids() {
@Override
public String getContentName() {
return name;
}
@Override
public String getContentTypeName() {
return "liquid";
}
public static Array<Liquid> all() {
return Liquid.liquids;
}

View File

@ -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;

View File

@ -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<Recipe> allRecipes = new Array<>();
private static ObjectMap<Block, Recipe> 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<Recipe> getBySection(io.anuke.mindustry.type.Section section, Array<Recipe> r){
@Override
public String getContentName() {
return result.name;
}
@Override
public String getContentTypeName() {
return "recipe";
}
public static Array<Recipe> getBySection(Section section, Array<Recipe> r){
for(Recipe recipe : allRecipes){
if(recipe.section == section ) {
r.add(recipe);
@ -54,7 +65,7 @@ public class Recipe {
return r;
}
public static Array<Recipe> getAllRecipes(){
public static Array<Recipe> all(){
return allRecipes;
}

View File

@ -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<Upgrade> 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<Upgrade> all() {
return upgrades;
}
public static <T extends Upgrade> T getByID(byte id){
return (T)upgrades.get(id);
}
public static Array<Upgrade> getAllUpgrades() {
return upgrades;
}
}

View File

@ -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<io.anuke.mindustry.type.Item, io.anuke.mindustry.type.AmmoType> ammoMap = new ObjectMap<>();
protected ObjectMap<Item, AmmoType> 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);

View File

@ -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<WeatherEvent> 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<WeatherEvent> all(){
return all;
}
public static WeatherEvent getByID(int id){
return all.get(id);
}
}

View File

@ -43,7 +43,7 @@ public class BlocksFragment implements Fragment{
{
int size = 0;
for(Item ignored : Item.getAllItems()){
for(Item ignored : Item.all()){
size ++;
}

View File

@ -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]);

View File

@ -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;
}

View File

@ -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;

View File

@ -110,7 +110,7 @@ public class Sorter extends Block{
public void buildTable(Tile tile, Table table){
SorterEntity entity = tile.entity();
Array<Item> items = Item.getAllItems();
Array<Item> items = Item.all();
ButtonGroup<ImageButton> 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());
}
}
}

View File

@ -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(){

View File

@ -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;

View File

@ -69,7 +69,7 @@ public class SortedUnloader extends Unloader {
public void buildTable(Tile tile, Table table){
SortedUnloaderEntity entity = tile.entity();
Array<Item> items = Item.getAllItems();
Array<Item> items = Item.all();
ButtonGroup<ImageButton> 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());
}
}
}