Search in sources :

Example 46 with World

use of mudmap2.backend.World 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 47 with World

use of mudmap2.backend.World 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)

Example 48 with World

use of mudmap2.backend.World in project mudmap2 by Neop.

the class World method removeRiskLevel.

/**
 * Removes a risk level
 * @param rl
 * @throws java.lang.Exception
 */
public void removeRiskLevel(RiskLevel rl) throws Exception {
    if (!riskLevels.containsValue(rl))
        throw new Exception("Tried to remove risk level that does not belong to this world");
    // remode from risk level list
    riskLevels.remove(rl.getId());
    // removePlace from places
    for (Layer layer : getLayers()) {
        for (Place place : layer.getPlaces()) {
            if (place.getRiskLevel() == rl)
                place.setRiskLevel(null);
        }
    }
    callListeners(rl);
}
Also used : PlaceNotInsertedException(mudmap2.backend.Layer.PlaceNotInsertedException)

Aggregations

World (mudmap2.backend.World)31 Test (org.junit.Test)27 IOException (java.io.IOException)11 FileNotFoundException (java.io.FileNotFoundException)9 Place (mudmap2.backend.Place)9 File (java.io.File)7 WorldFileDefault (mudmap2.backend.WorldFileReader.current.WorldFileDefault)7 Layer (mudmap2.backend.Layer)6 Path (mudmap2.backend.Path)6 WorldCoordinate (mudmap2.backend.WorldCoordinate)6 Color (java.awt.Color)5 HashMap (java.util.HashMap)5 WorldFile (mudmap2.backend.WorldFileReader.WorldFile)5 PlaceGroup (mudmap2.backend.PlaceGroup)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 Map (java.util.Map)3 JLabel (javax.swing.JLabel)3 RiskLevel (mudmap2.backend.RiskLevel)3 BorderLayout (java.awt.BorderLayout)2