Package net.sf.colossus.server
Class VariantSupport
- java.lang.Object
-
- net.sf.colossus.server.VariantSupport
-
public final class VariantSupport extends java.lang.Object
Class VariantSupport hold the members and functions required to support Variants in Colossus TODO this should probably move into the variant package sooner or later, possibly into theVariant
class itself- Author:
- Romain Dolbeau
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
VariantSupport.VariantLoadException
A helper class to store the exception that happened during VariantLoading together with the task during which that happened.
-
Field Summary
Fields Modifier and Type Field Description private static IVariantHint
aihl
private static Variant
CURRENT_VARIANT
private static java.util.List<java.lang.String>
dependUpon
private static java.lang.String
hintName
private static java.util.List<java.lang.String>
lCreaturesName
private static boolean
loadedVariant
whether or not there is currently a valid variant loaded.private static java.util.logging.Logger
LOGGER
private static java.lang.String
mapName
private static java.util.Properties
markerNames
private static int
maxPlayers
private static java.lang.String
recruitsFileName
private static java.util.Map<java.lang.String,java.lang.String>
rememberCustomDirs
private static java.lang.String
varDirectory
private static java.lang.String
varFilename
private static java.lang.String
variantName
private static javax.swing.text.Document
varREADME
-
Constructor Summary
Constructors Constructor Description VariantSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.String>
getBattlelandsDirectoriesList()
static java.util.List<java.lang.String>
getCreaturesNames()
static Variant
getCurrentVariant()
Retrieves the currently loaded variant.static java.lang.String
getFullPathFileForVariantName(java.lang.String varName)
static int
getHintedRecruitmentValueOffset(CreatureType creature)
static int
getHintedRecruitmentValueOffset(CreatureType creature, java.util.List<IVariantHint.AIStyle> aiStyles)
static java.util.List<java.lang.String>
getImagesDirectoriesList()
static java.util.List<CreatureType>
getInitialSplitHint(MasterHex hex)
static java.util.List<CreatureType>
getInitialSplitHint(MasterHex hex, java.util.List<IVariantHint.AIStyle> aiStyles)
static java.lang.String
getMapName()
static java.util.Properties
getMarkerNamesProperties()
static int
getMaxPlayers()
get maximum number of players in that variantprivate static javax.swing.text.Document
getMissingReadmeNotification()
static CreatureType
getRecruitHint(MasterBoardTerrain terrain, IOracleLegion legion, java.util.List<CreatureType> recruits, IHintOracle oracle)
static CreatureType
getRecruitHint(MasterBoardTerrain terrain, IOracleLegion legion, java.util.List<CreatureType> recruits, IHintOracle oracle, java.util.List<IVariantHint.AIStyle> aiStyles)
static java.util.List<java.lang.String>
getVarDirectoriesList()
static java.util.List<java.lang.String>
getVarDirectoriesList(java.lang.String suffixPath)
static java.lang.String
getVarDirectory()
static java.lang.String
getVarFilename()
static java.lang.String
getVariantName()
private static java.lang.String
getVariantNameFromFilename(java.lang.String varFilename)
static AllCreatureType
loadCreatures()
Call immediately after loading variant, before using creatures.private static void
loadHints(Variant variant)
private static java.util.Properties
loadMarkerNamesProperties()
static IVariantInitializer
loadTerrainsAndRecruits(AllCreatureType creatureTypes)
static Variant
loadVariant(java.lang.String tempVariantName, java.lang.String tempVarFilename, java.lang.String tempVarDirectory, boolean serverSide)
Try to load a Colossus Variant from the specified filename in the specified path.static Variant
loadVariantByFile(java.io.File varFile, boolean serverSide)
Load a Colossus Variant from the specified Filestatic Variant
loadVariantByName(java.lang.String variantName, boolean serverSide)
Load a Colossus Variant by name.static void
rememberFullPathFileForVariantName(java.lang.String varName, java.lang.String varFullPathFilename)
private static Variant
tryLoadVariant(java.lang.String tempVariantName, java.lang.String tempVarFilename, java.lang.String tempVarDirectory, boolean serverSide)
This does the actual work forloadVariant(String, String, String, boolean)
This here is private and should be called only from the synchronized before-mentioned method.static void
unloadVariant()
Remove all variant data, so that next variant loading attempt is guaranteed to load it freshly (e.g.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
varDirectory
private static java.lang.String varDirectory
-
varFilename
private static java.lang.String varFilename
-
variantName
private static java.lang.String variantName
-
mapName
private static java.lang.String mapName
-
recruitsFileName
private static java.lang.String recruitsFileName
-
hintName
private static java.lang.String hintName
-
lCreaturesName
private static java.util.List<java.lang.String> lCreaturesName
-
varREADME
private static javax.swing.text.Document varREADME
-
dependUpon
private static java.util.List<java.lang.String> dependUpon
-
loadedVariant
private static boolean loadedVariant
whether or not there is currently a valid variant loaded. TODO: perhaps superfluous - check CURRENT_VARIANT for null instead?
-
CURRENT_VARIANT
private static Variant CURRENT_VARIANT
-
maxPlayers
private static int maxPlayers
-
aihl
private static IVariantHint aihl
-
markerNames
private static java.util.Properties markerNames
-
rememberCustomDirs
private static java.util.Map<java.lang.String,java.lang.String> rememberCustomDirs
-
-
Method Detail
-
unloadVariant
public static void unloadVariant()
Remove all variant data, so that next variant loading attempt is guaranteed to load it freshly (e.g. to get XML data from remote server even if currently loaded was same name, but, well, from local files).
-
rememberFullPathFileForVariantName
public static void rememberFullPathFileForVariantName(java.lang.String varName, java.lang.String varFullPathFilename)
-
getFullPathFileForVariantName
public static java.lang.String getFullPathFileForVariantName(java.lang.String varName)
-
loadVariantByName
public static Variant loadVariantByName(java.lang.String variantName, boolean serverSide)
Load a Colossus Variant by name.- Parameters:
variantName
- The name of the variant.serverSide
- We're loading on a server.- Returns:
- The loaded variant.
-
loadVariantByFile
public static Variant loadVariantByFile(java.io.File varFile, boolean serverSide)
Load a Colossus Variant from the specified File- Parameters:
varFile
- The File to load as a Variant, probably selected by user in a FileSelectionDialog, with full absolute path.serverSide
- We're loading on a server.- Returns:
- The loaded variant.
-
getVariantNameFromFilename
private static java.lang.String getVariantNameFromFilename(java.lang.String varFilename) throws java.lang.Exception
- Throws:
java.lang.Exception
-
loadVariant
public static Variant loadVariant(java.lang.String tempVariantName, java.lang.String tempVarFilename, java.lang.String tempVarDirectory, boolean serverSide)
Try to load a Colossus Variant from the specified filename in the specified path. If loading fails, inform user with a message dialog and try to load Default variant instead. If that fails as well, do a system.exit after another message dialog. Synchronized to avoid concurrent threads running into it at same time (probably not possible so far, but if one day Public Server game can run with one local human and several AIs (on user's computer) this would become an issue.- Parameters:
tempVarFilename
- The name of the file holding the Variant definition.tempVarDirectory
- The path to the directory holding the Variant.tempVariantName
- The actual plain name of the variantserverSide
- We're loading on a server.- Returns:
- A variant object, perhaps newly created, perhaps re-used if same variant was used before. TODO right now variant name might sometimes be null, then we try a hack to retrieve the variant name from the variant file name.
-
tryLoadVariant
private static Variant tryLoadVariant(java.lang.String tempVariantName, java.lang.String tempVarFilename, java.lang.String tempVarDirectory, boolean serverSide) throws VariantSupport.VariantLoadException
This does the actual work forloadVariant(String, String, String, boolean)
This here is private and should be called only from the synchronized before-mentioned method.- Parameters:
tempVariantName
-tempVarFilename
-tempVarDirectory
-serverSide
-- Returns:
- A variant object, perhaps newly created, perhaps re-used if same variant was used before.
- Throws:
VariantSupport.VariantLoadException
-
loadCreatures
public static AllCreatureType loadCreatures()
Call immediately after loading variant, before using creatures.
-
getMissingReadmeNotification
private static javax.swing.text.Document getMissingReadmeNotification()
-
getVarDirectory
public static java.lang.String getVarDirectory()
-
getVarFilename
public static java.lang.String getVarFilename()
-
getVariantName
public static java.lang.String getVariantName()
-
getMapName
public static java.lang.String getMapName()
-
getCreaturesNames
public static java.util.List<java.lang.String> getCreaturesNames()
-
getVarDirectoriesList
public static java.util.List<java.lang.String> getVarDirectoriesList()
-
getVarDirectoriesList
public static java.util.List<java.lang.String> getVarDirectoriesList(java.lang.String suffixPath)
-
getImagesDirectoriesList
public static java.util.List<java.lang.String> getImagesDirectoriesList()
-
getBattlelandsDirectoriesList
public static java.util.List<java.lang.String> getBattlelandsDirectoriesList()
-
loadTerrainsAndRecruits
public static IVariantInitializer loadTerrainsAndRecruits(AllCreatureType creatureTypes)
-
loadMarkerNamesProperties
private static java.util.Properties loadMarkerNamesProperties()
-
getMarkerNamesProperties
public static java.util.Properties getMarkerNamesProperties()
-
loadHints
private static void loadHints(Variant variant)
-
getRecruitHint
public static CreatureType getRecruitHint(MasterBoardTerrain terrain, IOracleLegion legion, java.util.List<CreatureType> recruits, IHintOracle oracle)
-
getRecruitHint
public static CreatureType getRecruitHint(MasterBoardTerrain terrain, IOracleLegion legion, java.util.List<CreatureType> recruits, IHintOracle oracle, java.util.List<IVariantHint.AIStyle> aiStyles)
-
getInitialSplitHint
public static java.util.List<CreatureType> getInitialSplitHint(MasterHex hex)
-
getInitialSplitHint
public static java.util.List<CreatureType> getInitialSplitHint(MasterHex hex, java.util.List<IVariantHint.AIStyle> aiStyles)
-
getHintedRecruitmentValueOffset
public static int getHintedRecruitmentValueOffset(CreatureType creature)
-
getHintedRecruitmentValueOffset
public static int getHintedRecruitmentValueOffset(CreatureType creature, java.util.List<IVariantHint.AIStyle> aiStyles)
-
getMaxPlayers
public static int getMaxPlayers()
get maximum number of players in that variant
-
getCurrentVariant
public static Variant getCurrentVariant()
Retrieves the currently loaded variant. TODO this is a helper method to introduce the Variant objects into the code, in the long run they should be passed around instead of being in a static member here.
-
-