Search in sources :

Example 6 with WorldFile

use of mudmap2.backend.WorldFileReader.WorldFile in project mudmap2 by Neop.

the class WorldFileDefault method readFile.

/**
 * read world
 * @return
 * @throws FileNotFoundException
 * @throws Exception
 */
@Override
public World readFile() throws FileNotFoundException, Exception {
    World world = null;
    if (worldFile != null) {
        world = worldFile.readFile();
        world.setWorldFile(this);
    }
    if (world == null) {
        throw new Exception("Could not read world from file '" + filename);
    }
    return world;
}
Also used : World(mudmap2.backend.World) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with WorldFile

use of mudmap2.backend.WorldFileReader.WorldFile in project mudmap2 by Neop.

the class SaveWorldDialog method getWorldFile.

public WorldFile getWorldFile() {
    String file = getSelectedFile().getAbsolutePath();
    WorldFile worldFile;
    worldFile = new WorldFileJSON(file);
    return worldFile;
}
Also used : WorldFile(mudmap2.backend.WorldFileReader.WorldFile) WorldFileJSON(mudmap2.backend.WorldFileReader.current.WorldFileJSON)

Example 8 with WorldFile

use of mudmap2.backend.WorldFileReader.WorldFile in project mudmap2 by Neop.

the class WorldManager method deleteWorldFile.

/**
 * Checks if file is a world file and deletes it if so
 * @param filename
 * @return false on error
 */
public static Boolean deleteWorldFile(String filename) {
    Boolean error = false;
    WorldFileDefault worldFile = new WorldFileDefault(filename);
    if (worldFile.canRead()) {
        File file = new File(filename);
        if (!file.delete())
            error = true;
        WorldFileList.removeWorldFileEntry(filename);
    }
    return error;
}
Also used : WorldFileDefault(mudmap2.backend.WorldFileReader.current.WorldFileDefault) WorldFile(mudmap2.backend.WorldFileReader.WorldFile) File(java.io.File)

Example 9 with WorldFile

use of mudmap2.backend.WorldFileReader.WorldFile in project mudmap2 by Neop.

the class WorldManager method getWorld.

/**
 * Get loaded world or load world from file
 * @param file world file
 * @return
 * @throws Exception if world could not be loaded
 */
public static World getWorld(String file) throws Exception {
    World world = null;
    if (loadedWorlds.containsKey(file)) {
        // world in list
        world = loadedWorlds.get(file);
    } else {
        // world not loaded
        WorldFile worldFile = new WorldFileDefault(file);
        if (worldFile.canRead()) {
            world = worldFile.readFile();
            worldFile.backup();
            putWorld(file, world);
        } else {
            throw new Exception("Could not read world file");
        }
    }
    return world;
}
Also used : WorldFile(mudmap2.backend.WorldFileReader.WorldFile) WorldFileDefault(mudmap2.backend.WorldFileReader.current.WorldFileDefault)

Aggregations

WorldFileDefault (mudmap2.backend.WorldFileReader.current.WorldFileDefault)6 IOException (java.io.IOException)5 WorldFile (mudmap2.backend.WorldFileReader.WorldFile)5 FileNotFoundException (java.io.FileNotFoundException)4 File (java.io.File)3 WorldFileJSON (mudmap2.backend.WorldFileReader.current.WorldFileJSON)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JFileChooser (javax.swing.JFileChooser)1 World (mudmap2.backend.World)1 Test (org.junit.Test)1