Actual map conversion, loading of saves
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -210,9 +210,9 @@ public class Control implements ApplicationListener{
|
||||
public void playZone(Zone zone){
|
||||
ui.loadAnd(() -> {
|
||||
logic.reset();
|
||||
world.loadGenerator(zone.generator);
|
||||
state.rules = zone.rules.get();
|
||||
state.rules.zone = zone;
|
||||
world.loadGenerator(zone.generator);
|
||||
for(Tile core : state.teams.get(defaultTeam).cores){
|
||||
for(ItemStack stack : zone.getStartingItems()){
|
||||
core.entity.items.add(stack.item, stack.amount);
|
||||
|
||||
@@ -35,9 +35,12 @@ public class World implements ApplicationListener{
|
||||
private boolean generating, invalidMap;
|
||||
|
||||
public World(){
|
||||
//TODO swap
|
||||
Core.app.post(maps::load);
|
||||
//maps.load();
|
||||
maps.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
maps.loadLegacyMaps();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import io.anuke.arc.util.serialization.Json;
|
||||
import io.anuke.arc.util.serialization.JsonValue;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.game.Rules;
|
||||
import io.anuke.mindustry.game.SpawnGroup;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Zone;
|
||||
|
||||
public class JsonIO{
|
||||
private static Json json = new Json(){{
|
||||
setIgnoreUnknownFields(true);
|
||||
setElementType(Rules.class, "spawns", SpawnGroup.class);
|
||||
|
||||
setSerializer(Zone.class, new Serializer<Zone>(){
|
||||
@Override
|
||||
public void write(Json json, Zone object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zone read(Json json, JsonValue jsonData, Class type){
|
||||
return Vars.content.getByName(ContentType.zone, jsonData.asString());
|
||||
}
|
||||
});
|
||||
}};
|
||||
|
||||
public static String write(Object object){
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import io.anuke.arc.util.serialization.JsonValue;
|
||||
|
||||
public interface JsonTypeReader<T>{
|
||||
T read(JsonValue json, String name);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import io.anuke.arc.util.serialization.Json;
|
||||
|
||||
public interface JsonTypeWriter<T>{
|
||||
void write(Json json, T object, String name);
|
||||
}
|
||||
@@ -59,16 +59,6 @@ public class Maps implements Disposable{
|
||||
/** Load all maps. Should be called at application start. */
|
||||
public void load(){
|
||||
try{
|
||||
//TODO remove, this is only for testing
|
||||
|
||||
for(FileHandle in : Core.files.absolute("/home/anuke/Projects/Mindustry/core/assets/maps").list()){
|
||||
if(in.extension().equalsIgnoreCase(oldMapExtension)){
|
||||
Log.info("Converting {0}...", in);
|
||||
LegacyMapIO.convertMap(in, in.sibling(in.nameWithoutExtension() + "." + mapExtension));
|
||||
Log.info("Converted {0}", in);
|
||||
}
|
||||
}
|
||||
|
||||
for(String name : defaultMapNames){
|
||||
FileHandle file = Core.files.internal("maps/" + name + "." + mapExtension);
|
||||
loadMap(file, false);
|
||||
@@ -167,6 +157,34 @@ public class Maps implements Disposable{
|
||||
return str == null ? null : str.equals("[]") ? new Array<>() : Array.with(json.fromJson(SpawnGroup[].class, str));
|
||||
}
|
||||
|
||||
public void loadLegacyMaps(){
|
||||
boolean convertedAny = false;
|
||||
for(FileHandle file : customMapDirectory.list()){
|
||||
if(file.extension().equalsIgnoreCase(oldMapExtension)){
|
||||
try{
|
||||
LegacyMapIO.convertMap(file, file.sibling(file.nameWithoutExtension() + "." + mapExtension));
|
||||
//delete old, converted file; it is no longer useful
|
||||
file.delete();
|
||||
convertedAny = true;
|
||||
Log.info("Converted file {0}", file);
|
||||
}catch(IOException e){
|
||||
//rename the file to a 'mmap_conversion_failed' extension to keep it there just in case
|
||||
//but don't delete it
|
||||
file.copyTo(file.sibling(file.name() + "_conversion_failed"));
|
||||
file.delete();
|
||||
Log.err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//free up any potential memory that was used up during conversion
|
||||
if(convertedAny){
|
||||
world.createTiles(0, 0);
|
||||
//reload maps to load the converted ones
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
/** Find a new filename to put a map to. */
|
||||
private FileHandle findFile(){
|
||||
//find a map name that isn't used.
|
||||
@@ -193,26 +211,6 @@ public class Maps implements Disposable{
|
||||
}
|
||||
|
||||
private void loadCustomMaps(){
|
||||
boolean convertedAny = false;
|
||||
for(FileHandle file : customMapDirectory.list()){
|
||||
if(file.extension().equalsIgnoreCase(oldMapExtension)){
|
||||
convertedAny = true;
|
||||
try{
|
||||
LegacyMapIO.convertMap(file, file.sibling(file.nameWithoutExtension() + "." + mapExtension));
|
||||
//TODO delete so conversion doesn't happen again
|
||||
//file.delete();
|
||||
}catch(IOException e){
|
||||
//don't convert
|
||||
Log.err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//free up any potential memory that was used up during conversion
|
||||
if(convertedAny){
|
||||
world.createTiles(0, 0);
|
||||
}
|
||||
|
||||
for(FileHandle file : customMapDirectory.list()){
|
||||
try{
|
||||
if(file.extension().equalsIgnoreCase(mapExtension)){
|
||||
|
||||
@@ -13,7 +13,6 @@ import io.anuke.mindustry.game.EventType.ZoneConfigureCompleteEvent;
|
||||
import io.anuke.mindustry.game.EventType.ZoneRequireCompleteEvent;
|
||||
import io.anuke.mindustry.game.Rules;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.gen.Serialization;
|
||||
import io.anuke.mindustry.maps.generators.Generator;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
@@ -39,12 +38,6 @@ public class Zone extends UnlockableContent{
|
||||
|
||||
private Array<ItemStack> defaultStartingItems = new Array<>();
|
||||
|
||||
static{
|
||||
Serialization.setSerializer(Zone.class,
|
||||
(json, zone, name) -> json.writeValue(name, zone.name),
|
||||
(json, name) -> content.getByName(ContentType.zone, json.getString(name)));
|
||||
}
|
||||
|
||||
public Zone(String name, Generator generator){
|
||||
super(name);
|
||||
this.generator = generator;
|
||||
|
||||
Reference in New Issue
Block a user