Content mapping, part 1

This commit is contained in:
Anuken 2018-09-05 16:02:30 -04:00
parent be3147465d
commit eb3e507a11
57 changed files with 248 additions and 137 deletions

View file

@ -7,7 +7,7 @@ import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public class AmmoTypes implements ContentList{
public static AmmoType bulletCopper, bulletDense, bulletThorium, bulletSilicon, bulletPyratite,

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemType;

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Liquid;
public class Liquids implements ContentList{

View file

@ -17,7 +17,7 @@ import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Core;

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.blocks.*;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe;

View file

@ -5,7 +5,7 @@ import io.anuke.mindustry.content.fx.EnvironmentFx;
import io.anuke.mindustry.entities.StatusController.StatusEntry;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.StatusEffect;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;

View file

@ -6,7 +6,7 @@ import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.entities.units.types.*;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public class UnitTypes implements ContentList{
public static UnitType drone, alphaDrone, dagger, interceptor, monsoon, titan, fabricator;

View file

@ -4,7 +4,7 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Weapon;
public class Weapons implements ContentList{

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.blocks;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
public abstract class BlockList implements ContentList{

View file

@ -5,7 +5,7 @@ import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;

View file

@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.production.*;

View file

@ -7,7 +7,7 @@ import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Block;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.defense.*;

View file

@ -1,6 +1,6 @@
package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.distribution.*;

View file

@ -1,6 +1,6 @@
package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.distribution.*;
import io.anuke.mindustry.world.blocks.production.Pump;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.distribution.WarpGate;
import io.anuke.mindustry.world.blocks.power.*;

View file

@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.production.Cultivator;
import io.anuke.mindustry.world.blocks.production.Drill;

View file

@ -1,6 +1,6 @@
package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
import io.anuke.mindustry.world.blocks.storage.SortedUnloader;

View file

@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.content.AmmoTypes;
import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.defense.turrets.*;
import io.anuke.ucore.graphics.Draw;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.blocks;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.UnitTypes;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.units.*;

View file

@ -6,7 +6,7 @@ import io.anuke.mindustry.entities.bullet.ArtilleryBulletType;
import io.anuke.mindustry.entities.bullet.BasicBulletType;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public class ArtilleryBullets extends BulletList implements ContentList{
public static BulletType dense, plastic, plasticFrag, homing, incindiary, explosive, surge;

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content.bullets;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public abstract class BulletList implements ContentList{

View file

@ -6,7 +6,7 @@ import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.bullet.FlakBulletType;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.util.Mathf;
public class FlakBullets extends BulletList implements ContentList{

View file

@ -7,7 +7,7 @@ import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.bullet.MissileBulletType;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;

View file

@ -5,7 +5,7 @@ import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.entities.bullet.BasicBulletType;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public class StandardBullets extends BulletList implements ContentList{
public static BulletType copper, dense, thorium, homing, tracer, mechSmall, glaive;

View file

@ -15,7 +15,7 @@ import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.distribution.MassDriver.DriverBulletData;

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
public abstract class FxList implements ContentList{

View file

@ -3,7 +3,7 @@ package io.anuke.mindustry.content.fx;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -2,7 +2,7 @@ package io.anuke.mindustry.content.fx;
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;

View file

@ -1,9 +1,6 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import com.badlogic.gdx.utils.OrderedMap;
import com.badlogic.gdx.utils.OrderedSet;
import com.badlogic.gdx.utils.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.blocks.*;
import io.anuke.mindustry.content.bullets.*;
@ -18,6 +15,8 @@ import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.game.MappableContent;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.ColorMapper;
@ -32,7 +31,8 @@ import io.anuke.ucore.util.Log;
public class ContentLoader{
private static boolean loaded = false;
private static ObjectSet<Array<? extends Content>> contentSet = new OrderedSet<>();
private static OrderedMap<String, Array<Content>> contentMap = new OrderedMap<>();
private static OrderedMap<ContentType, Array<Content>> contentMap = new OrderedMap<>();
private static ObjectMap<ContentType, ObjectMap<String, MappableContent>> contentNameMap = new ObjectMap<>();
private static ObjectSet<Consumer<Content>> initialization = new ObjectSet<>();
private static ContentList[] content = {
//effects
@ -107,19 +107,25 @@ public class ContentLoader{
registerTypes();
for(ContentList list : content){
for(io.anuke.mindustry.game.ContentList list : content){
list.load();
}
for(ContentList list : content){
if(list.getAll().size != 0){
String type = list.getAll().first().getContentTypeName();
ContentType type = list.getAll().first().getContentType();
if(!contentMap.containsKey(type)){
contentMap.put(type, new Array<>());
contentNameMap.put(type, new ObjectMap<>());
}
contentMap.get(type).addAll(list.getAll());
for(Content c : list.getAll()){
if(c instanceof MappableContent){
contentNameMap.get(type).put(((MappableContent) c).getContentName(), (MappableContent) c);
}
}
}
contentSet.add(list.getAll());
}
@ -157,10 +163,17 @@ public class ContentLoader{
//TODO clear all content.
}
public static OrderedMap<String, Array<Content>> getContentMap(){
public static OrderedMap<ContentType, Array<Content>> getContentMap(){
return contentMap;
}
public static MappableContent getByName(ContentType type, String name){
if(!contentNameMap.containsKey(type)){
return null;
}
return contentNameMap.get(type).get(name);
}
/**
* Registers sync IDs for all types of sync entities.
* Do not register units here!

View file

@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.StatusEffect;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
@ -69,8 +70,8 @@ public abstract class BulletType extends BaseBulletType<Bullet> implements Conte
}
@Override
public String getContentTypeName(){
return "bullettype";
public ContentType getContentType(){
return ContentType.bullet;
}
@Override

View file

@ -10,6 +10,7 @@ import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.ui.ContentDisplay;
@ -77,6 +78,11 @@ public class UnitType implements UnlockableContent{
return types;
}
@Override
public int getID() {
return id;
}
@Override
public void displayInfo(Table table){
ContentDisplay.displayUnit(table, this);
@ -104,8 +110,8 @@ public class UnitType implements UnlockableContent{
}
@Override
public String getContentTypeName(){
return "unit-type";
public ContentType getContentType(){
return ContentType.unit;
}
@Override

View file

@ -1,6 +1,7 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.type.ContentType;
/**
* Base interface for a content type that is loaded in {@link io.anuke.mindustry.core.ContentLoader}.
@ -11,7 +12,7 @@ public interface Content{
* Returns the type name of this piece of content.
* This should return the same value for all instances of this content type.
*/
String getContentTypeName();
ContentType getContentType();
/**
* Returns a list of all instances of this content.

View file

@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.game.EventType.UnlockEvent;
import io.anuke.mindustry.type.ContentType;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Settings;
@ -12,19 +13,19 @@ import static io.anuke.mindustry.Vars.debug;
public class ContentDatabase{
/** Maps unlockable type names to a set of unlocked content.*/
private ObjectMap<String, ObjectSet<String>> unlocked = new ObjectMap<>();
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
/** Whether unlockables have changed since the last save.*/
private boolean dirty;
/** Returns whether or not this piece of content is unlocked yet.*/
public boolean isUnlocked(UnlockableContent content){
if(debug) return true;
if(!unlocked.containsKey(content.getContentTypeName())){
unlocked.put(content.getContentTypeName(), new ObjectSet<>());
if(!unlocked.containsKey(content.getContentType())){
unlocked.put(content.getContentType(), new ObjectSet<>());
}
ObjectSet<String> set = unlocked.get(content.getContentTypeName());
ObjectSet<String> set = unlocked.get(content.getContentType());
return set.contains(content.getContentName());
}
@ -39,11 +40,11 @@ public class ContentDatabase{
public boolean unlockContent(UnlockableContent content){
if(!content.canBeUnlocked()) return false;
if(!unlocked.containsKey(content.getContentTypeName())){
unlocked.put(content.getContentTypeName(), new ObjectSet<>());
if(!unlocked.containsKey(content.getContentType())){
unlocked.put(content.getContentType(), new ObjectSet<>());
}
boolean ret = unlocked.get(content.getContentTypeName()).add(content.getContentName());
boolean ret = unlocked.get(content.getContentType()).add(content.getContentName());
//fire unlock event so other classes can use it
if(ret){
@ -67,9 +68,9 @@ public class ContentDatabase{
}
public void load(){
ObjectMap<String, Array<String>> result = Settings.getJson("content-database", ObjectMap.class);
ObjectMap<ContentType, Array<String>> result = Settings.getJson("content-database", ObjectMap.class);
for(Entry<String, Array<String>> entry : result.entries()){
for(Entry<ContentType, Array<String>> entry : result.entries()){
ObjectSet<String> set = new ObjectSet<>();
set.addAll(entry.value);
unlocked.put(entry.key, set);
@ -80,9 +81,9 @@ public class ContentDatabase{
public void save(){
ObjectMap<String, Array<String>> write = new ObjectMap<>();
ObjectMap<ContentType, Array<String>> write = new ObjectMap<>();
for(Entry<String, ObjectSet<String>> entry : unlocked.entries()){
for(Entry<ContentType, ObjectSet<String>> entry : unlocked.entries()){
write.put(entry.key, entry.value.iterator().toArray());
}

View file

@ -0,0 +1,12 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
/**Interface for a list of content to be loaded in {@link io.anuke.mindustry.core.ContentLoader}.*/
public interface ContentList{
/**This method should create all the content.*/
void load();
/**This method should return the list of the content of this type, for further loading.*/
Array<? extends Content> getAll();
}

View file

@ -0,0 +1,13 @@
package io.anuke.mindustry.game;
public interface MappableContent extends 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();
int getID();
}

View file

@ -5,54 +5,31 @@ import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control;
/**
* Base interface for an unlockable content type.
*/
public interface UnlockableContent extends 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 localized name of this content.
*/
/**Base interface for an unlockable content type.*/
public interface UnlockableContent extends MappableContent{
/**Returns the localized name of this content.*/
String localizedName();
TextureRegion getContentIcon();
/**
* This should show all necessary info about this content in the specified table.
*/
/**This should show all necessary info about this content in the specified table.*/
void displayInfo(Table table);
/**
* Called when this content is unlocked. Use this to unlock other related content.
*/
/**Called when this content is unlocked. Use this to unlock other related content.*/
default void onUnlock(){
}
/**
* Whether this content is always hidden in the content info dialog.
*/
/**Whether this content is always hidden in the content info dialog.*/
default boolean isHidden(){
return false;
}
/**
* Lists the content that must be unlocked in order for this specific content to become unlocked. May return null.
*/
/**Lists the content that must be unlocked in order for this specific content to become unlocked. May return null.*/
default UnlockableContent[] getDependencies(){
return null;
}
/**
* Returns whether dependencies are satisfied for unlocking this content.
*/
/**Returns whether dependencies are satisfied for unlocking this content.*/
default boolean canBeUnlocked(){
UnlockableContent[] depend = getDependencies();
if(depend == null){

View file

@ -1,6 +1,14 @@
package io.anuke.mindustry.io;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entry;
import io.anuke.mindustry.core.ContentLoader;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.MappableContent;
import io.anuke.mindustry.type.ContentType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -25,6 +33,50 @@ public abstract class SaveFileVersion{
return new SaveMeta(version, time, playtime, build, sector, mode, map, wave, Difficulty.values()[difficulty]);
}
public ObjectMap<ContentType, IntMap<MappableContent>> readContentHeader(DataInputStream stream) throws IOException{
ObjectMap<ContentType, IntMap<MappableContent>> map = new ObjectMap<>();
byte mapped = stream.readByte();
for (int i = 0; i < mapped; i++) {
ContentType type = ContentType.values()[stream.readByte()];
map.put(type, new IntMap<>());
short total = stream.readShort();
for (int j = 0; j < total; j++) {
byte id = stream.readByte();
String name = stream.readUTF();
if(ContentLoader.getContentMap().get(type).size == 0) continue;
map.get(type).put(id, ContentLoader.getByName(type, name));
}
}
return map;
}
public void writeContentHeader(DataOutputStream stream) throws IOException{
ObjectMap<ContentType, Array<Content>> map = ContentLoader.getContentMap();
int mappable = 0;
for(Entry<ContentType, Array<Content>> entry : map.entries()){
if(entry.value.size > 0 && entry.value.first() instanceof MappableContent){
mappable ++;
}
}
stream.writeByte(mappable);
for(Entry<ContentType, Array<Content>> entry : map.entries()){
if(entry.value.size > 0 && entry.value.first() instanceof MappableContent){
stream.writeByte(entry.value.first().getContentType().ordinal());
stream.writeShort(entry.value.size);
for(Content c : entry.value){
MappableContent m = (MappableContent)c;
if(m.getID() >= 128) throw new RuntimeException("Content " + c + " has ID > 127!");
stream.writeByte(m.getID());
stream.writeUTF(m.getContentName());
}
}
}
}
public abstract void read(DataInputStream stream) throws IOException;
public abstract void write(DataOutputStream stream) throws IOException;

View file

@ -1,16 +1,16 @@
package io.anuke.mindustry.io.versions;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.entities.traits.SaveTrait;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BlockPart;
import io.anuke.ucore.core.Timers;
@ -56,6 +56,9 @@ public class Save16 extends SaveFileVersion{
state.wave = wave;
state.wavetime = wavetime;
ObjectMap<ContentType, IntMap<MappableContent>> contentMap = readContentHeader(stream);
//TODO implement
state.spawner.read(stream);
//entities
@ -168,7 +171,9 @@ public class Save16 extends SaveFileVersion{
stream.writeByte(state.difficulty.ordinal()); //difficulty ordinal
stream.writeFloat(state.wavetime); //wave countdown
state.spawner.write(stream);
writeContentHeader(stream);
state.spawner.write(stream); //spawnes
//--ENTITIES--

View file

@ -6,7 +6,7 @@ import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.game.Content;
import io.anuke.ucore.core.Effects.Effect;
public class AmmoType implements Content{
public class AmmoType implements Content {
private static int lastID = 0;
private static Array<AmmoType> allTypes = new Array<>(32);
@ -85,8 +85,8 @@ public class AmmoType implements Content{
}
@Override
public String getContentTypeName(){
return "ammotype";
public ContentType getContentType(){
return ContentType.ammo;
}
@Override

View file

@ -1,19 +0,0 @@
package io.anuke.mindustry.type;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Content;
/**
* Interface for a list of content to be loaded in {@link io.anuke.mindustry.core.ContentLoader}.
*/
public interface ContentList{
/**
* This method should create all the content.
*/
void load();
/**
* This method should return the list of the content of this type, for further loading.
*/
Array<? extends Content> getAll();
}

View file

@ -0,0 +1,16 @@
package io.anuke.mindustry.type;
/**Do not rearrange, ever!*/
public enum ContentType {
item,
recipe,
block,
mech,
bullet,
liquid,
weapon,
status,
unit,
ammo,
weather
}

View file

@ -69,6 +69,11 @@ public class Item implements Comparable<Item>, UnlockableContent{
this.region = Draw.region("item-" + name);
}
@Override
public int getID() {
return id;
}
@Override
public void displayInfo(Table table){
ContentDisplay.displayItem(table, this);
@ -100,8 +105,8 @@ public class Item implements Comparable<Item>, UnlockableContent{
}
@Override
public String getContentTypeName(){
return "item";
public ContentType getContentType(){
return ContentType.item;
}
@Override

View file

@ -79,6 +79,11 @@ public class Liquid implements UnlockableContent{
return liquids.get(id);
}
@Override
public int getID() {
return id;
}
@Override
public void load(){
iconRegion = Draw.region("liquid-icon-" + name);
@ -110,8 +115,8 @@ public class Liquid implements UnlockableContent{
}
@Override
public String getContentTypeName(){
return "liquid";
public ContentType getContentType(){
return ContentType.liquid;
}
@Override

View file

@ -87,6 +87,11 @@ public class Mech implements UnlockableContent{
return true;
}
@Override
public int getID() {
return id;
}
@Override
public boolean isHidden() {
return !flying && mobile;
@ -108,8 +113,8 @@ public class Mech implements UnlockableContent{
}
@Override
public String getContentTypeName(){
return "mech";
public ContentType getContentType(){
return ContentType.mech;
}
@Override

View file

@ -118,6 +118,11 @@ public class Recipe implements UnlockableContent{
return this;
}
@Override
public int getID() {
return id;
}
@Override
public boolean isHidden(){
return debugOnly || (desktopOnly && mobile);
@ -154,8 +159,8 @@ public class Recipe implements UnlockableContent{
}
@Override
public String getContentTypeName(){
return "recipe";
public ContentType getContentType(){
return ContentType.recipe;
}
@Override

View file

@ -85,8 +85,8 @@ public class StatusEffect implements Content{
}
@Override
public String getContentTypeName(){
return "statuseffect";
public ContentType getContentType(){
return ContentType.status;
}
@Override

View file

@ -120,8 +120,8 @@ public class Weapon implements Content{
}
@Override
public String getContentTypeName(){
return "weapon";
public ContentType getContentType(){
return ContentType.weapon;
}
@Override

View file

@ -27,8 +27,8 @@ public class WeatherEvent implements Content{
}
@Override
public String getContentTypeName(){
return "weatherevent";
public ContentType getContentType(){
return ContentType.weather;
}
@Override

View file

@ -7,6 +7,7 @@ import io.anuke.mindustry.core.ContentLoader;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.ContentType;
import io.anuke.ucore.scene.event.HandCursorListener;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.ScrollPane;
@ -34,9 +35,9 @@ public class UnlocksDialog extends FloatingDialog{
table.margin(20);
ScrollPane pane = new ScrollPane(table, "clear-black");
OrderedMap<String, Array<Content>> allContent = ContentLoader.getContentMap();
OrderedMap<ContentType, Array<Content>> allContent = ContentLoader.getContentMap();
for(String key : allContent.orderedKeys()){
for(ContentType key : allContent.orderedKeys()){
Array<Content> array = allContent.get(key);
if(array.size == 0 || !(array.first() instanceof UnlockableContent)) continue;

View file

@ -13,11 +13,13 @@ import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.effect.RubbleDecal;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.MappableContent;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.CursorType;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.meta.*;
@ -32,7 +34,7 @@ import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class Block extends BaseBlock implements Content{
public class Block extends BaseBlock implements MappableContent {
private static int lastid;
private static Array<Block> blocks = new Array<>(140);
private static ObjectMap<String, Block> map = new ObjectMap<>();
@ -209,6 +211,16 @@ public class Block extends BaseBlock implements Content{
}
}
@Override
public int getID() {
return id;
}
@Override
public String getContentName() {
return name;
}
/** Called after all blocks are created. */
@Override
public void init(){
@ -495,8 +507,8 @@ public class Block extends BaseBlock implements Content{
}
@Override
public String getContentTypeName(){
return "block";
public ContentType getContentType(){
return ContentType.block;
}
@Override

View file

@ -6,7 +6,7 @@ import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectIntMap;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.ContentList;
import io.anuke.mindustry.game.ContentList;
import io.anuke.ucore.util.Mathf;
public class ColorMapper implements ContentList{