Better organization

This commit is contained in:
Anuken
2019-10-21 21:22:35 -04:00
parent bb593af463
commit d7ebbbf2b6
102 changed files with 206 additions and 170 deletions

View File

@@ -1,23 +0,0 @@
package io.anuke.mindustry.game;
import java.util.*;
/** Defines sizes of a content's preview icon. */
public enum Cicon{
/** Full size. */
full(0),
tiny(8 * 2),
small(8 * 3),
medium(8 * 4),
large(8 * 5),
xlarge(8 * 6);
public static final Cicon[] all = values();
public static final Cicon[] scaled = Arrays.copyOfRange(all, 1, all.length);
public final int size;
Cicon(int size){
this.size = size;
}
}

View File

@@ -1,49 +0,0 @@
package io.anuke.mindustry.game;
import io.anuke.arc.files.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.mod.Mods.*;
import io.anuke.mindustry.type.*;
/** Base class for a content type that is loaded in {@link io.anuke.mindustry.core.ContentLoader}. */
public abstract class Content implements Comparable<Content>{
public final short id;
/** The mod that loaded this piece of content. */
public @Nullable LoadedMod mod;
/** File that this content was loaded from. */
public @Nullable FileHandle sourceFile;
public Content(){
this.id = (short)Vars.content.getBy(getContentType()).size;
Vars.content.handleContent(this);
}
/**
* Returns the type name of this piece of content.
* This should return the same value for all instances of this content type.
*/
public abstract ContentType getContentType();
/** Called after all content and modules are created. Do not use to load regions or texture data! */
public void init(){
}
/**
* Called after all content is created, only on non-headless versions.
* Use for loading regions or other image data.
*/
public void load(){
}
@Override
public int compareTo(Content c){
return Integer.compare(id, c.id);
}
@Override
public String toString(){
return getContentType().name() + "#" + id;
}
}

View File

@@ -1,7 +0,0 @@
package io.anuke.mindustry.game;
/** 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();
}

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry.game;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.ctype.UnlockableContent;
import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.entities.units.*;
@@ -173,15 +174,15 @@ public class EventType{
}
public static class UnlockEvent{
public final UnlockableContent content;
public final io.anuke.mindustry.ctype.UnlockableContent content;
public UnlockEvent(UnlockableContent content){
public UnlockEvent(io.anuke.mindustry.ctype.UnlockableContent content){
this.content = content;
}
}
public static class ResearchEvent{
public final UnlockableContent content;
public final io.anuke.mindustry.ctype.UnlockableContent content;
public ResearchEvent(UnlockableContent content){
this.content = content;

View File

@@ -6,6 +6,7 @@ import io.anuke.arc.files.*;
import io.anuke.arc.util.io.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.ctype.UnlockableContent;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.type.*;
@@ -131,7 +132,7 @@ public class GlobalData{
}
/** Returns whether or not this piece of content is unlocked yet. */
public boolean isUnlocked(UnlockableContent content){
public boolean isUnlocked(io.anuke.mindustry.ctype.UnlockableContent content){
return content.alwaysUnlocked() || unlocked.getOr(content.getContentType(), ObjectSet::new).contains(content.name);
}

View File

@@ -1,17 +0,0 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.*;
public abstract class MappableContent extends Content{
public final String name;
public MappableContent(String name){
this.name = name;
Vars.content.handleMappableContent(this);
}
@Override
public String toString(){
return name;
}
}

View File

@@ -1,19 +0,0 @@
package io.anuke.mindustry.game;
import io.anuke.arc.function.Supplier;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.type.ContentType;
public class TypeID extends MappableContent{
public final Supplier<? extends TypeTrait> constructor;
public TypeID(String name, Supplier<? extends TypeTrait> constructor){
super(name);
this.constructor = constructor;
}
@Override
public ContentType getContentType(){
return ContentType.typeid;
}
}

View File

@@ -1,72 +0,0 @@
package io.anuke.mindustry.game;
import io.anuke.annotations.Annotations.*;
import io.anuke.arc.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.mindustry.*;
/** Base interface for an unlockable content type. */
public abstract class UnlockableContent extends MappableContent{
/** Localized, formal name. Never null. Set to block name if not found in bundle. */
public String localizedName;
/** Localized description. May be null. */
public String description;
/** Icons by Cicon ID.*/
protected TextureRegion[] cicons = new TextureRegion[Cicon.all.length];
public UnlockableContent(String name){
super(name);
this.localizedName = Core.bundle.get(getContentType() + "." + name + ".name", name);
this.description = Core.bundle.getOrNull(getContentType() + "." + name + ".description");
}
/** Generate any special icons for this content. Called asynchronously.*/
@CallSuper
public void createIcons(PixmapPacker out, PixmapPacker editor){
}
/** Returns a specific content icon, or the region {contentType}-{name} if not found.*/
public TextureRegion icon(Cicon icon){
if(cicons[icon.ordinal()] == null){
cicons[icon.ordinal()] = Core.atlas.find(getContentType().name() + "-" + name + "-" + icon.name(),
Core.atlas.find(getContentType().name() + "-" + name + "-full",
Core.atlas.find(getContentType().name() + "-" + name,
Core.atlas.find(name,
Core.atlas.find(name + "1")))));
}
return cicons[icon.ordinal()];
}
/** Returns the localized name of this content. */
public abstract String localizedName();
//public abstract TextureRegion getContentIcon();
/** This should show all necessary info about this content in the specified table. */
public abstract void displayInfo(Table table);
/** Called when this content is unlocked. Use this to unlock other related content. */
public void onUnlock(){
}
/** Whether this content is always hidden in the content info dialog. */
public boolean isHidden(){
return false;
}
/** Override to make content always unlocked. */
public boolean alwaysUnlocked(){
return false;
}
public final boolean unlocked(){
return Vars.data.isUnlocked(this);
}
public final boolean locked(){
return !unlocked();
}
}

View File

@@ -1,54 +0,0 @@
package io.anuke.mindustry.game;
import io.anuke.arc.*;
import io.anuke.arc.Files.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.io.*;
import java.io.*;
public class Version{
/** Build type. 'official' for official releases; 'custom' or 'bleeding edge' are also used. */
public static String type;
/** Build modifier, e.g. 'alpha' or 'release' */
public static String modifier;
/** Number specifying the major version, e.g. '4' */
public static int number;
/** Build number, e.g. '43'. set to '-1' for custom builds. */
public static int build = 0;
/** Revision number. Used for hotfixes. Does not affect server compatibility. */
public static int revision = 0;
/** Whether version loading is enabled. */
public static boolean enabled = true;
public static void init(){
if(!enabled) return;
try{
FileHandle file = OS.isAndroid || OS.isIos ? Core.files.internal("version.properties") : new FileHandle("version.properties", FileType.Internal);
ObjectMap<String, String> map = new ObjectMap<>();
PropertiesUtils.load(map, file.reader());
type = map.get("type");
number = Integer.parseInt(map.get("number", "4"));
modifier = map.get("modifier");
if(map.get("build").contains(".")){
String[] split = map.get("build").split("\\.");
try{
build = Integer.parseInt(split[0]);
revision = Integer.parseInt(split[1]);
}catch(Throwable e){
e.printStackTrace();
build = -1;
}
}else{
build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1;
}
}catch(IOException e){
throw new RuntimeException(e);
}
}
}