📄 worldmanager.java
字号:
/*
* Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
* Copyright (C) 2001-2002 WOTLAS Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package wotlas.common;
import wotlas.common.universe.*;
import wotlas.common.router.*;
import wotlas.common.objects.inventories.*;
import wotlas.utils.Debug;
import java.io.File;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import wotlas.editor.*;
/** A WorldManager provides all the methods needed to handle & manage the game world
* from its root.<p><br>
*
* This class IS NOT directly persistent. The WorldMap instances are made persistent
* by calling saveUniverse() & loadUniverse() methods. The files are saved separatly.
* This is why a WorldManager is not directly persistent : we don't want to save
* all its data in one huge file.
*
* @author Petrus, Aldiss, Diego
* @see wotlas.common.universe.WorldMap
* @see wotlas.libs.persistence.PropertiesConverter
*/
public class WorldManager {
/*------------------------------------------------------------------------------------*/
public static byte PRELOADER_STATUS = PreloaderEnabled.LOAD_ALL;
/** Game Universe Name Format
*/
public final static String DEFAULT_UNIVERSE = "default";
public final static String UNIVERSE_PREFIX = "universe-save-";
public final static String UNIVERSE_SUFFIX = "";
public final static String WORLD_FILE = "world.cfg";
public final static String TOWN_FILE = "town.cfg";
public final static String BUILDING_FILE = "building.cfg";
public final static String MAP_SUFFIX = "-map.cfg";
public final static String TILEMAP_FILE = "tilemap.bin";
public final static String TOWN_DIR_EXT = ".town";
public final static String TILEMAP_DIR_EXT = ".tilemap";
public final static String AREA_EXT = ".area";
public final static String TILEMAP_EXT = ".bin";
public final static String DEFAULT_UNIVERSE_OBJECTS = "objects";
public final static String INVENTORY_PREFIX = "room-inventory-";
public final static String INVENTORY_SUFFIX = ".cfg";
/*------------------------------------------------------------------------------------*/
/** array of WorldMap
*/
protected WorldMap[] worldMaps;
/** Our resource manager.
*/
protected ResourceManager rManager;
/*------------------------------------------------------------------------------------*/
/** Constructor with resource Manager. We do not load universe data.
* @param rManager resource manager to get the data from.
*/
public WorldManager( ResourceManager rManager ) {
this.rManager = rManager;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Constructor with resource manager. We attempt to load the local universe data.
* Any error at this step will stop the program.
*
* @param rManager resource manager to get the data from.
* @param loadDefault do we have to load the default universe data (true) or the
* current one ?
*/
public WorldManager( ResourceManager rManager, boolean loadDefault ) {
this(rManager,loadDefault,true);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Constructor with resource manager. We attempt to load the local universe data.
* Any error at this step will stop the program if failureIfNoData==true.
*
* @param rManager resource manager to get the data from.
* @param loadDefault do we have to load the default universe data (true) or the
* current one ?
* @param failureIfNoData if true we'll produce a Debug.FAILURE+Debug.exit if no universe
* data is found, if false we'll just print a FAILURE message.
*/
public WorldManager( ResourceManager rManager, boolean loadDefault, boolean failureIfNoData ) {
this.rManager = rManager;
loadUniverse(loadDefault);
if(worldMaps==null) {
Debug.signal( Debug.FAILURE, this, "No universe data available !" );
if(failureIfNoData)
Debug.exit();
}
}
public WorldManager( boolean loadForEditor, ResourceManager rManager ) {
this.rManager = rManager;
loadUniverse(false,loadForEditor);
if(worldMaps==null) {
Debug.signal( Debug.FAILURE, this, "No universe data available !" );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Constructor with a pre-loaded list of World Maps.
* @param worldMaps list of worlds...
*/
public WorldManager( WorldMap worldMaps[], ResourceManager rManager ) {
this.rManager = rManager;
this.worldMaps = worldMaps;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To initialize this whole universe ( it rebuilds shortcuts ). This method calls
* recursively the init() method of the WorldMaps, TownMaps, buildings, interiorMaps
* and rooms.
*
* IMPORTANT: You must ONLY call this method ONE time when ALL the world data has been
* loaded...
*/
protected void init() {
// 1 - any data ?
if(worldMaps==null) {
Debug.signal(Debug.WARNING, this, "Universe inits failed: No WorldMaps.");
return;
}
// 2 - we transmit the init() call
for( int i=0; i<worldMaps.length; i++ )
if( worldMaps[i]!=null )
worldMaps[i].init();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To init this worldmap for message routing. We create an appropriate message router
* for the world/towns/rooms via the provided factory. This method should be called once
* on the WorldManager at start-up. It's your job to create the factory.
*
* If you don't call this method you won't be able to manage message routing among
* the different locations.
*
* @param msgRouterFactory our router factory for MessageRouter creation.
*/
public void initMessageRouting( MessageRouterFactory msgRouterFactory ){
// 1 - any data ?
if(worldMaps==null) {
Debug.signal(Debug.WARNING, this, "Universe routing inits failed: No WorldMaps.");
return;
}
// 2 - we transmit the initMessageRouting() call
for( int i=0; i<worldMaps.length; i++ )
if( worldMaps[i]!=null )
worldMaps[i].initMessageRouting( msgRouterFactory, this );
}
/*------------------------------------------------------------------------------------*/
/** To Get a World by its ID.
*
* @param id worldMapID
* @return corresponding worldMap, null if ID does not exist.
*/
public WorldMap getWorldMapFromID( int id ) {
if(worldMaps==null) {
Debug.signal( Debug.ERROR, this, "No World data available." );
return null;
}
if(id>=worldMaps.length || id<0) {
Debug.signal( Debug.ERROR, this, "getWorldMapFromID : Bad world ID "+id );
return null;
}
return worldMaps[id];
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a World list (some entries might be null).
* @return worldMaps possessed by this WorldManager.
*/
public WorldMap[] getWorldMaps() {
return worldMaps;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a World from a Wotlas location.
*
* @param location wotlas location
* @return corresponding worldMap, null if ID does not exist.
*/
public WorldMap getWorldMap( WotlasLocation location ) {
return getWorldMapFromID( location.getWorldMapID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a TileMap from a WotlasLocation. IMPORTANT: we assume the WotlasLocation object
* points out at least a tileMap...
*
* @param location wotlas location
* @return corresponding tileMap, null if the map does not exist.
*/
public TileMap getTileMap( WotlasLocation location ) {
WorldMap wMap = getWorldMapFromID( location.getWorldMapID() );
if(wMap==null)
return null;
return wMap.getTileMapFromID( location.getTileMapID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a Town from a WotlasLocation. IMPORTANT: we assume the WotlasLocation object
* points out at least a townMap...
*
* @param location wotlas location
* @return corresponding townMap, null if the map does not exist.
*/
public TownMap getTownMap( WotlasLocation location ) {
WorldMap wMap = getWorldMapFromID( location.getWorldMapID() );
if(wMap==null)
return null;
return wMap.getTownMapFromID( location.getTownMapID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a Building from a WotlasLocation. IMPORTANT: we assume the
* WotlasLocation object points out at least a building...
*
* @param location wotlas location
* @return corresponding building, null if the map does not exist.
*/
public Building getBuilding( WotlasLocation location ) {
TownMap tMap = getTownMap( location );
if(tMap==null)
return null;
return tMap.getBuildingFromID( location.getBuildingID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get an InteriorMap from a WotlasLocation. IMPORTANT: we assume the
* WotlasLocation object points out at least an interiorMap...
*
* @param location wotlas location
* @return corresponding interiorMap, null if the map does not exist.
*/
public InteriorMap getInteriorMap( WotlasLocation location ) {
Building bMap = getBuilding( location );
if(bMap==null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -