Class package refactoring

This commit is contained in:
Anuken
2018-07-14 12:11:48 -04:00
parent 59ade6cf09
commit cfecdae970
47 changed files with 318 additions and 333 deletions

View File

@@ -0,0 +1,200 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.SaveMeta;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.ThreadArray;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class Saves{
private int nextSlot;
private Array<SaveSlot> saves = new ThreadArray<>();
private SaveSlot current;
private boolean saving;
private float time;
public Saves(){
Events.on(StateChangeEvent.class, (prev, state) -> {
if(state == State.menu){
threads.run(() -> current = null);
}
});
}
public void load(){
saves.clear();
for(int i = 0; i < saveSlots; i++){
if(SaveIO.isSaveValid(i)){
SaveSlot slot = new SaveSlot(i);
saves.add(slot);
slot.meta = SaveIO.getData(i);
nextSlot = i + 1;
}
}
}
public SaveSlot getCurrent(){
return current;
}
public void update(){
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
time += Timers.delta();
if(time > Settings.getInt("saveinterval") * 60){
saving = true;
Timers.run(2f, () -> {
try{
SaveIO.saveToSlot(current.index);
current.meta = SaveIO.getData(current.index);
}catch(Exception e){
e.printStackTrace();
}
saving = false;
});
time = 0;
}
}else{
time = 0;
}
}
public void resetSave(){
current = null;
}
public boolean isSaving(){
return saving;
}
public boolean canAddSave(){
return nextSlot < saveSlots;
}
public void addSave(String name){
SaveSlot slot = new SaveSlot(nextSlot);
nextSlot++;
slot.setName(name);
saves.add(slot);
SaveIO.saveToSlot(slot.index);
slot.meta = SaveIO.getData(slot.index);
current = slot;
}
public SaveSlot importSave(FileHandle file) throws IOException{
SaveSlot slot = new SaveSlot(nextSlot);
slot.importFile(file);
nextSlot++;
slot.setName(file.nameWithoutExtension());
saves.add(slot);
slot.meta = SaveIO.getData(slot.index);
current = slot;
return slot;
}
public Array<SaveSlot> getSaveSlots(){
return saves;
}
public class SaveSlot{
public final int index;
SaveMeta meta;
public SaveSlot(int index){
this.index = index;
}
public void load(){
SaveIO.loadFromSlot(index);
meta = SaveIO.getData(index);
current = this;
}
public void save(){
SaveIO.saveToSlot(index);
meta = SaveIO.getData(index);
current = this;
}
public String getDate(){
return meta.date;
}
public Map getMap(){
return meta.map;
}
public String getName(){
return Settings.getString("save-" + index + "-name", "untittled");
}
public void setName(String name){
Settings.putString("save-" + index + "-name", name);
Settings.save();
}
public int getBuild(){
return meta.build;
}
public int getWave(){
return meta.wave;
}
public Difficulty getDifficulty(){
return meta.difficulty;
}
public GameMode getMode(){
return meta.mode;
}
public boolean isAutosave(){
return Settings.getBool("save-" + index + "-autosave", !gwt);
}
public void setAutosave(boolean save){
Settings.putBool("save-" + index + "-autosave", save);
Settings.save();
}
public void importFile(FileHandle file) throws IOException{
try{
file.copyTo(SaveIO.fileFor(index));
}catch(Exception e){
throw new IOException(e);
}
}
public void exportFile(FileHandle file) throws IOException{
try{
if(!file.extension().equals(saveExtension)){
file = file.parent().child(file.nameWithoutExtension() + "." + saveExtension);
}
SaveIO.fileFor(index).copyTo(file);
}catch(Exception e){
throw new IOException(e);
}
}
public void delete(){
SaveIO.fileFor(index).delete();
saves.removeValue(this, true);
if(this == current){
current = null;
}
}
}
}

View File

@@ -0,0 +1,35 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.PropertiesUtils;
import io.anuke.ucore.util.Strings;
import java.io.IOException;
public class Version{
public static String name;
public static String type;
public static String code;
public static int build = 0;
public static String buildName;
public static void init(){
try{
FileHandle file = Gdx.files.internal("version.properties");
ObjectMap<String, String> map = new ObjectMap<>();
PropertiesUtils.load(map, file.reader());
name = map.get("name");
type = map.get("version");
code = map.get("code");
build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1;
buildName = build == -1 ? map.get("build") : "build " + build;
}catch(IOException e){
throw new RuntimeException(e);
}
}
}

View File

@@ -1,190 +0,0 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.UnitTypes;
import io.anuke.mindustry.content.Weapons;
import io.anuke.mindustry.type.ItemStack;
public class WaveCreator{
public static Array<SpawnGroup> getSpawns(){
return Array.with(
new SpawnGroup(UnitTypes.scout){{
end = 8;
unitScaling = 2;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 12;
end = 14;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 11;
unitScaling = 2;
spacing = 2;
max = 4;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 9;
spacing = 3;
unitScaling = 2;
end = 30;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 10;
unitScaling = 2;
unitAmount = 1;
spacing = 2;
ammoItem = Items.tungsten;
end = 30;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 28;
spacing = 3;
unitScaling = 2;
weapon = Weapons.flamethrower;
end = 40;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 45;
spacing = 3;
unitScaling = 2;
weapon = Weapons.flamethrower;
effect = StatusEffects.overdrive;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 120;
spacing = 2;
unitScaling = 3;
unitAmount = 5;
weapon = Weapons.flakgun;
effect = StatusEffects.overdrive;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 16;
unitScaling = 2;
spacing = 2;
end = 39;
max = 7;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 82;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
unitScaling = 3;
effect = StatusEffects.overdrive;
ammoItem = Items.silicon;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 41;
spacing = 5;
unitAmount = 1;
unitScaling = 3;
effect = StatusEffects.shielded;
ammoItem = Items.thorium;
max = 10;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 35;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
effect = StatusEffects.overdrive;
items = new ItemStack(Items.blastCompound, 60);
end = 60;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 42;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
effect = StatusEffects.overdrive;
items = new ItemStack(Items.pyratite, 100);
end = 130;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 40;
ammoItem = Items.blastCompound;
unitAmount = 2;
spacing = 2;
unitScaling = 3;
max = 8;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 50;
unitAmount = 4;
unitScaling = 3;
spacing = 5;
groupAmount = 2;
effect = StatusEffects.overdrive;
max = 8;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 53;
ammoItem = Items.pyratite;
unitAmount = 2;
unitScaling = 3;
spacing = 4;
max = 8;
end = 74;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 53;
ammoItem = Items.coal;
unitAmount = 2;
unitScaling = 3;
spacing = 4;
max = 8;
end = 74;
}}
);
}
public static void testWaves(int from, int to){
Array<SpawnGroup> spawns = getSpawns();
for(int i = from; i <= to; i++){
System.out.print(i + ": ");
int total = 0;
for(SpawnGroup spawn : spawns){
int a = spawn.getUnitsSpawned(i) * spawn.getGroupsSpawned(i);
total += a;
if(a > 0){
System.out.print(a + "x" + spawn.type.name);
if(spawn.weapon != null){
System.out.print(":" + spawn.weapon.name);
}
if(spawn.ammoItem != null){
System.out.print(":" + spawn.ammoItem.name);
}
System.out.print(" ");
}
}
System.out.print(" (" + total + ")");
System.out.println();
}
}
}

View File

@@ -0,0 +1,190 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.UnitTypes;
import io.anuke.mindustry.content.Weapons;
import io.anuke.mindustry.type.ItemStack;
public class Waves{
public static Array<SpawnGroup> getSpawns(){
return Array.with(
new SpawnGroup(UnitTypes.scout){{
end = 8;
unitScaling = 2;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 12;
end = 14;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 11;
unitScaling = 2;
spacing = 2;
max = 4;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 9;
spacing = 3;
unitScaling = 2;
end = 30;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 10;
unitScaling = 2;
unitAmount = 1;
spacing = 2;
ammoItem = Items.tungsten;
end = 30;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 28;
spacing = 3;
unitScaling = 2;
weapon = Weapons.flamethrower;
end = 40;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 45;
spacing = 3;
unitScaling = 2;
weapon = Weapons.flamethrower;
effect = StatusEffects.overdrive;
}},
new SpawnGroup(UnitTypes.titan){{
begin = 120;
spacing = 2;
unitScaling = 3;
unitAmount = 5;
weapon = Weapons.flakgun;
effect = StatusEffects.overdrive;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 16;
unitScaling = 2;
spacing = 2;
end = 39;
max = 7;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 82;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
unitScaling = 3;
effect = StatusEffects.overdrive;
ammoItem = Items.silicon;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 41;
spacing = 5;
unitAmount = 1;
unitScaling = 3;
effect = StatusEffects.shielded;
ammoItem = Items.thorium;
max = 10;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 35;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
effect = StatusEffects.overdrive;
items = new ItemStack(Items.blastCompound, 60);
end = 60;
}},
new SpawnGroup(UnitTypes.scout){{
begin = 42;
spacing = 3;
unitAmount = 4;
groupAmount = 2;
effect = StatusEffects.overdrive;
items = new ItemStack(Items.pyratite, 100);
end = 130;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 40;
ammoItem = Items.blastCompound;
unitAmount = 2;
spacing = 2;
unitScaling = 3;
max = 8;
}},
new SpawnGroup(UnitTypes.vtol){{
begin = 50;
unitAmount = 4;
unitScaling = 3;
spacing = 5;
groupAmount = 2;
effect = StatusEffects.overdrive;
max = 8;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 53;
ammoItem = Items.pyratite;
unitAmount = 2;
unitScaling = 3;
spacing = 4;
max = 8;
end = 74;
}},
new SpawnGroup(UnitTypes.monsoon){{
begin = 53;
ammoItem = Items.coal;
unitAmount = 2;
unitScaling = 3;
spacing = 4;
max = 8;
end = 74;
}}
);
}
public static void testWaves(int from, int to){
Array<SpawnGroup> spawns = getSpawns();
for(int i = from; i <= to; i++){
System.out.print(i + ": ");
int total = 0;
for(SpawnGroup spawn : spawns){
int a = spawn.getUnitsSpawned(i) * spawn.getGroupsSpawned(i);
total += a;
if(a > 0){
System.out.print(a + "x" + spawn.type.name);
if(spawn.weapon != null){
System.out.print(":" + spawn.weapon.name);
}
if(spawn.ammoItem != null){
System.out.print(":" + spawn.ammoItem.name);
}
System.out.print(" ");
}
}
System.out.print(" (" + total + ")");
System.out.println();
}
}
}