Class 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 the Variant class itself
    Author:
    Romain Dolbeau
    • 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
      • markerNames

        private static java.util.Properties markerNames
      • rememberCustomDirs

        private static java.util.Map<java.lang.String,​java.lang.String> rememberCustomDirs
    • Constructor Detail

      • VariantSupport

        public VariantSupport()
    • 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 variant
        serverSide - 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 for loadVariant(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()
      • loadMarkerNamesProperties

        private static java.util.Properties loadMarkerNamesProperties()
      • getMarkerNamesProperties

        public static java.util.Properties getMarkerNamesProperties()
      • loadHints

        private static void loadHints​(Variant variant)
      • getInitialSplitHint

        public static java.util.List<CreatureType> getInitialSplitHint​(MasterHex hex)
      • 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.