Package VASSAL.build
Class GameModule
java.lang.Object
VASSAL.build.AbstractBuildable
VASSAL.build.AbstractConfigurable
VASSAL.build.GameModule
- All Implemented Interfaces:
AutoConfigurable,Buildable,Configurable,GpIdSupport,MutablePropertiesContainer,PropertyNameSource,PropertySource,CommandEncoder,ValidityChecker,Translatable,ToolBarComponent
- Direct Known Subclasses:
BasicModule
public abstract class GameModule extends AbstractConfigurable implements CommandEncoder, ToolBarComponent, PropertySource, MutablePropertiesContainer, GpIdSupport
The GameModule class is the base class for a VASSAL module. It is
the root of the
Buildable containment hierarchy, although
BasicModule actually stands in as the root node in the Editor's
ConfigureTree and contains the root node's own encoder and
a certain amount of its build logic, in order to allow the root node
to be easily configured in the Editor without fully building/activating
the module.
Components which are added directly to the GameModule are contained
in the VASSAL.build.module package.
It is a singleton, and contains access points for many other classes,
such as DataArchive, ServerConnection, Logger,
and Prefs.
-
Nested Class Summary
Nested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.UtilNested classes/interfaces inherited from interface VASSAL.build.module.properties.MutablePropertiesContainer
MutablePropertiesContainer.Impl -
Field Summary
Fields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, localizedName, myI18nData, nameFields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validatorFields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY -
Constructor Summary
Constructors Modifier Constructor Description protectedGameModule(DataArchive archive) -
Method Summary
Modifier and Type Method Description voidaddCommandEncoder(CommandEncoder ce)This method adds aCommandEncoderto the list of objects that will attempt to decode/encode a commandvoidaddIdChangeListener(PropertyChangeListener l)voidaddKeyStrokeListener(KeyStrokeListener l)The GameModule acts as the mediator for hotkey events.voidaddKeyStrokeSource(KeyStrokeSource src)The GameModule acts as the mediator for hotkey events.voidaddMutableProperty(String key, MutableProperty p)Add a property under the given keyvoidaddSideChangeListenerToPlayerRoster(PlayerRoster.SideChangeListener l)voidaddTo(Buildable b)Adds this component to its parent.voidappendToTitle(String s)Append the string to the title of the controls window and all Map windowsprotected abstract voidbuild()Initialize the moduleprotected LongbuildCrc()protected StringbuildString()protected voidcheckGpIds()Check every PieceSlot and PlaceMarker trait for duplicate, illegal or Missing GamePiece id's and update them if necessaryvoidclearPausedCommands()Clear outstanding Commands Use where the calling level handles the sending of outstanding commandsstatic intcompareVersions(String v1, String v2)Deprecated, for removal: This API element is subject to removal in a future version.GamePiececreatePiece(String type)Central location to create any type of GamePiece from within VASSALGamePiececreatePiece(String type, GamePiece inner)Commanddecode(String command)Uses the registeredCommandEncoders to decode a String into aCommand.Stringencode(Command c)Uses the registeredCommandEncoders to encode aCommandinto a String objectvoidfireKeyStroke(KeyStroke stroke)Deprecated, for removal: This API element is subject to removal in a future version.voidfireKeyStroke(NamedKeyStroke stroke)StringgenerateGpId()Generate a new PieceSlot Id, unique to this top-level component.Class<?>[]getAllowableConfigureComponents()Return a list of valid sub-component Classes.ArchiveWritergetArchiveWriter()If the module is being edited, return the writeable archive for the moduleString[]getAttributeDescriptions()Return an array of Strings describing the attributes of this object.String[]getAttributeNames()Lists all the buildFile (XML) attribute names for this component.Class<?>[]getAttributeTypes()Return the Class for the buildFile (XML) attributes of this component.StringgetAttributeValueString(String name)Called by theBuildable.getBuildElement(org.w3c.dom.Document)method to write the attributes into an XML elementChattergetChatter()static StringgetConfigureTypeName()JComponentgetControlPanel()longgetCrc()DataArchivegetDataArchive()FileChoosergetFileChooser()FileDialoggetFileDialog()Deprecated, for removal: This API element is subject to removal in a future version.UsegetFileChooser()instead.JFramegetFrame()Deprecated, for removal: This API element is subject to removal in a future version.static GameModulegetGameModule()StringgetGameName()GameStategetGameState()Return the object responsible for tracking the state of a game.StringgetGameVersion()PrefsgetGlobalPrefs()Deprecated, for removal: This API element is subject to removal in a future version.GpIdSupportgetGpIdSupport()HelpFilegetHelpFile()ComponentI18nDatagetI18nData()ImageTileSourcegetImageTileSource()StringgetLocalizedGameName()ObjectgetLocalizedProperty(Object key)LoggergetLogger()StringgetMutablePropertiesContainerId()Return a unique Id for the containerMutablePropertygetMutableProperty(String name)Find a GlobalProperty object with the given nameintgetNextGpId()Accessors to check and update the next GpId if necessary.PlayerRostergetPlayerRoster()PlayerWindowgetPlayerWindow()PrefsgetPrefs()ObjectgetProperty(Object key)Return values of Global propertiesRandomgetRNG()ServerConnectiongetServer()JToolBargetToolBar()static StringgetUserId()WizardSupportgetWizardSupport()static voidinit(GameModule module)Set the singleton GameModule and invokebuild()on it.voidinitFrameTitle()booleanisLocalizationEnabled()Is the module being translated into the user's Locale? Localization is disabled when editing a modulebooleanpauseLogging()Pause logging and return true if successful.voidquit()Exit the application, prompting user to save if necessaryvoidrefreshKeyStrokeListeners()If our keyboard mapping paradigm changes (example: Mac Legacy preference checked/unchecked), we need to reregister all of our KeyStrokeListenersvoidremoveCommandEncoder(CommandEncoder ce)This method removes aCommandEncoderfrom the list of objects that will attempt to decode/encode a commandvoidremoveFrom(Buildable parent)Remove this component from its parentvoidremoveIdChangeListener(PropertyChangeListener l)MutablePropertyremoveMutableProperty(String key)Remove the property with the given keyCommandresumeLogging()Restart logging and return any outstanding commandsvoidsave()If the module is being edited, write the module dataprotected voidsave(boolean saveAs)voidsaveAs()voidsendAndLog(Command c)Encode theCommand, send it to the server and write it to a logfile (if any is open)voidsetAttribute(String name, Object value)Sets a buildFile (XML) attribute value for this component.voidsetChatter(Chatter c)Set the object that displays chat text.voidsetGlobalPrefs(Prefs p)Deprecated, for removal: This API element is subject to removal in a future version.no replacementvoidsetGpIdSupport(GpIdSupport s)voidsetNextGpId(int id)voidsetPrefs(Prefs p)static voidsetUserId(String newId)Set the identifier for the userbooleanshutDown()Prompt user to save open game and modules/extensions being editedstatic voidunload()Unload the modulevoidupdateLastSave()voidwarn(String s)Display the given text in the control window's status line.Methods inherited from class VASSAL.build.AbstractConfigurable
add, addPropertyChangeListener, getAttributeVisibility, getConfigureComponents, getConfigureName, getConfigurer, getI18nPrefix, getLocalizedConfigureName, remove, removePropertyChangeListener, setAllAttributesUntranslatable, setAttributeTranslatable, setConfigureNameMethods inherited from class VASSAL.build.AbstractBuildable
build, getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getPropertyNames, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface VASSAL.build.Buildable
build, getBuildElement
-
Field Details
-
DEFAULT_NAME
- See Also:
- Constant Field Values
-
MODULE_NAME
- See Also:
- Constant Field Values
-
MODULE_VERSION
- See Also:
- Constant Field Values
-
DESCRIPTION
- See Also:
- Constant Field Values
-
VASSAL_VERSION_CREATED
- See Also:
- Constant Field Values
-
VASSAL_VERSION_RUNNING
The System property of this name will return a version identifier for the version of VASSAL being run- See Also:
- Constant Field Values
-
NEXT_PIECESLOT_ID
- See Also:
- Constant Field Values
-
BUILDFILE
- See Also:
- Constant Field Values
-
moduleVersion
-
vassalVersionCreated
-
gameName
-
localizedGameName
-
description
-
lastSavedConfiguration
-
fileChooser
-
fileDialog
-
propsContainer
-
repaintOnPropertyChange
-
frame
-
controlPanel
Deprecated, for removal: This API element is subject to removal in a future version.usegetPlayerWindow()andPlayerWindow.getControlPanel()instead. -
theState
-
archive
-
preferences
-
logger
-
chat
-
RNG
-
server
-
tcache
-
wizardSupport
-
idChangeSupport
-
keyStrokeSources
-
keyStrokeListeners
-
commandEncoders
-
deferredChat
-
nextGpId
protected int nextGpId -
loggingPaused
protected boolean loggingPaused -
loggingLock
-
pausedCommands
-
gpidSupport
-
crc
-
REAL_NAME
ThePrefskey for the user's real name- See Also:
- Constant Field Values
-
SECRET_NAME
ThePrefskey for the user's secret name- See Also:
- Constant Field Values
-
PERSONAL_INFO
ThePrefskey for the user's personal info- See Also:
- Constant Field Values
-
-
Constructor Details
-
GameModule
-
-
Method Details
-
getFrame
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the top-level frame of the controls window
-
getPlayerWindow
-
initFrameTitle
public void initFrameTitle() -
getWizardSupport
-
build
Initialize the module- Throws:
IOException
-
setAttribute
Description copied from class:AbstractBuildableSets a buildFile (XML) attribute value for this component. Thekeyparameter will be one of those listed inAbstractBuildable.getAttributeNames(). If thevalueparameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)for the samekey. If the implementing class extendsAbstractConfigurable, thenvaluewill be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()- Specified by:
setAttributein interfaceAutoConfigurable- Specified by:
setAttributein interfaceTranslatable- Specified by:
setAttributein classAbstractBuildable- Parameters:
name- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()value- If thevalueparameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)for the samekey. If the implementing class extendsAbstractConfigurable, thenvaluecan also be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
-
getAttributeValueString
Description copied from interface:AutoConfigurableCalled by theBuildable.getBuildElement(org.w3c.dom.Document)method to write the attributes into an XML element- Specified by:
getAttributeValueStringin interfaceAutoConfigurable- Specified by:
getAttributeValueStringin interfaceTranslatable- Specified by:
getAttributeValueStringin classAbstractBuildable- Parameters:
name- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()- Returns:
- a String representation of the attribute with the given name. When initializing a module, this String value will be passed to
AbstractBuildable.setAttribute(java.lang.String, java.lang.Object).
-
compareVersions
@Deprecated(since="2020-08-06", forRemoval=true) public static int compareVersions(String v1, String v2)Deprecated, for removal: This API element is subject to removal in a future version.A valid verson format is "w.x.y[bz]", where 'w','x','y', and 'z' are integers.- Returns:
- a negative number if
v2is a later version thev1, a positive number if an earlier version, or zero if the versions are the same.
-
addTo
Description copied from interface:BuildableAdds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class. -
getConfigureTypeName
-
removeFrom
Description copied from interface:ConfigurableRemove this component from its parent- Specified by:
removeFromin interfaceConfigurable
-
getHelpFile
- Specified by:
getHelpFilein interfaceConfigurable- Returns:
- a HelpFilte describing how to use and configure this component
-
getAttributeNames
Description copied from class:AbstractBuildableLists all the buildFile (XML) attribute names for this component. If this component is ALSO anAbstractConfigurable, then this list of attributes determines the appropriate attribute order forAbstractConfigurable.getAttributeDescriptions()andAbstractConfigurable.getAttributeTypes().- Specified by:
getAttributeNamesin interfaceAutoConfigurable- Specified by:
getAttributeNamesin classAbstractBuildable- Returns:
- a list of all buildFile (XML) attribute names for this component
-
getAttributeDescriptions
Description copied from interface:AutoConfigurableReturn an array of Strings describing the attributes of this object. These strings are used as prompts in the Properties window for this object.- Specified by:
getAttributeDescriptionsin interfaceAutoConfigurable- Specified by:
getAttributeDescriptionsin classAbstractConfigurable- Returns:
- an array of Strings describing the buildFile (XML) attributes of this component. These strings are used as prompts in the
Properties window for this object, when the component is configured in the Editor. The order of descriptions should
be the same as the order of names in
AbstractBuildable.getAttributeNames()
-
getAttributeTypes
Description copied from class:AbstractConfigurableReturn the Class for the buildFile (XML) attributes of this component. Valid classes include: String, Integer, Double, Boolean, Image, Color, and KeyStroke, along with any class for which a Configurer exists in VASSAL.configure. The class determines, among other things, which type ofAutoConfigurerwill be used to configure the attribute when the object is configured in the Editor. The order of classes should be the same as the order of names inAbstractBuildable.getAttributeNames()- Specified by:
getAttributeTypesin interfaceAutoConfigurable- Specified by:
getAttributeTypesin classAbstractConfigurable
-
getAllowableConfigureComponents
Description copied from interface:ConfigurableReturn a list of valid sub-component Classes. If a Class appears in this list, then instances of that class may be added to this component from the Configuration Window.- Specified by:
getAllowableConfigureComponentsin interfaceConfigurable
-
addKeyStrokeSource
The GameModule acts as the mediator for hotkey events. Components that wish to fire hotkey events when they have the focus should register themselves using this method. These events will be forwarded to all listeners that have registered themselves withaddKeyStrokeListener(VASSAL.tools.KeyStrokeListener) -
addKeyStrokeListener
The GameModule acts as the mediator for hotkey events. Objects that react to hotkey events should register themselves using this method. Any component that has been registered withaddKeyStrokeSource(VASSAL.tools.KeyStrokeSource)will forward hotkey events to listeners registered with this method. -
refreshKeyStrokeListeners
public void refreshKeyStrokeListeners()If our keyboard mapping paradigm changes (example: Mac Legacy preference checked/unchecked), we need to reregister all of our KeyStrokeListeners -
fireKeyStroke
Deprecated, for removal: This API element is subject to removal in a future version. -
fireKeyStroke
-
getGameName
- Returns:
- the name of the game for this module
-
getLocalizedGameName
-
getGameVersion
-
addIdChangeListener
-
removeIdChangeListener
-
getPrefs
- Returns:
- the preferences for this module
-
getGlobalPrefs
Deprecated, for removal: This API element is subject to removal in a future version.A set of preferences that applies to all modules -
addCommandEncoder
This method adds aCommandEncoderto the list of objects that will attempt to decode/encode a command -
removeCommandEncoder
This method removes aCommandEncoderfrom the list of objects that will attempt to decode/encode a command -
createPiece
Central location to create any type of GamePiece from within VASSAL- Parameters:
type- Type for Piece- Returns:
- Created Piece
-
createPiece
-
warn
Display the given text in the control window's status line. Save the messages for later if the Chatter has not been initialised yet -
getRNG
- Returns:
- a single Random number generator that all objects may share
-
getLogger
- Returns:
- the object responsible for logging commands to a logfile
-
setChatter
Set the object that displays chat text. Display any warning messages deferred during earlier initialisation -
getControlPanel
-
getChatter
- Returns:
- the object that displays chat text
-
setPrefs
-
setGlobalPrefs
Deprecated, for removal: This API element is subject to removal in a future version.no replacement -
decode
Uses the registeredCommandEncoders to decode a String into aCommand.- Specified by:
decodein interfaceCommandEncoder
-
encode
Uses the registeredCommandEncoders to encode aCommandinto a String object- Specified by:
encodein interfaceCommandEncoder
-
getFileChooser
- Returns:
- a common FileChooser so that recent file locations can be remembered
-
getFileDialog
Deprecated, for removal: This API element is subject to removal in a future version.UsegetFileChooser()instead. -
getToolBar
- Specified by:
getToolBarin interfaceToolBarComponent- Returns:
- the JToolBar of the command window
-
appendToTitle
Append the string to the title of the controls window and all Map windows- Parameters:
s- If null, set the title to the default.
-
quit
public void quit()Exit the application, prompting user to save if necessary -
shutDown
public boolean shutDown()Prompt user to save open game and modules/extensions being edited- Returns:
- true if shutDown should proceed, i.e. user did not cancel
-
sendAndLog
Encode theCommand, send it to the server and write it to a logfile (if any is open)- See Also:
encode(VASSAL.command.Command)
-
pauseLogging
public boolean pauseLogging()Pause logging and return true if successful. Return false if logging already paused While Paused, commands are accumulated into pausedCommands so that they can all be logged at the same time, and generate a single UNDO command.- Returns:
- Current logging pause status, false if logging currently paused
-
resumeLogging
Restart logging and return any outstanding commands -
clearPausedCommands
public void clearPausedCommands()Clear outstanding Commands Use where the calling level handles the sending of outstanding commands -
getUserId
- Returns:
- a String that uniquely identifies the user
-
setUserId
Set the identifier for the user -
getServer
- Returns:
- the object reponsible for sending messages to the server
-
init
Set the singleton GameModule and invokebuild()on it.- Throws:
IOException
-
unload
public static void unload()Unload the module -
updateLastSave
public void updateLastSave() -
generateGpId
Description copied from interface:GpIdSupportGenerate a new PieceSlot Id, unique to this top-level component.- Specified by:
generateGpIdin interfaceGpIdSupport- Returns:
- PieceSlot Id
-
getNextGpId
public int getNextGpId()Description copied from interface:GpIdSupportAccessors to check and update the next GpId if necessary.- Specified by:
getNextGpIdin interfaceGpIdSupport
-
setNextGpId
public void setNextGpId(int id)- Specified by:
setNextGpIdin interfaceGpIdSupport
-
setGpIdSupport
-
getGpIdSupport
-
checkGpIds
protected void checkGpIds()Check every PieceSlot and PlaceMarker trait for duplicate, illegal or Missing GamePiece id's and update them if necessary -
getDataArchive
- Returns:
- the object which stores data for the module
-
getArchiveWriter
If the module is being edited, return the writeable archive for the module -
getImageTileSource
-
isLocalizationEnabled
public boolean isLocalizationEnabled()Is the module being translated into the user's Locale? Localization is disabled when editing a module- Returns:
- true if the module/extension has been localized
-
getGameModule
- Returns:
- the singleton instance of GameModule
-
getGameState
Return the object responsible for tracking the state of a game. Only one game in progress is allowed; -
saveAs
public void saveAs() -
save
public void save()If the module is being edited, write the module data -
save
protected void save(boolean saveAs) -
buildString
-
getProperty
Return values of Global properties- Specified by:
getPropertyin interfacePropertySource
-
getMutableProperty
Description copied from interface:MutablePropertiesContainerFind a GlobalProperty object with the given name- Specified by:
getMutablePropertyin interfaceMutablePropertiesContainer
-
addMutableProperty
Description copied from interface:MutablePropertiesContainerAdd a property under the given key- Specified by:
addMutablePropertyin interfaceMutablePropertiesContainer
-
removeMutableProperty
Description copied from interface:MutablePropertiesContainerRemove the property with the given key- Specified by:
removeMutablePropertyin interfaceMutablePropertiesContainer
-
getMutablePropertiesContainerId
Description copied from interface:MutablePropertiesContainerReturn a unique Id for the container- Specified by:
getMutablePropertiesContainerIdin interfaceMutablePropertiesContainer
-
getLocalizedProperty
- Specified by:
getLocalizedPropertyin interfacePropertySource
-
getCrc
public long getCrc() -
buildCrc
-
getI18nData
- Specified by:
getI18nDatain interfaceTranslatable- Overrides:
getI18nDatain classAbstractConfigurable- Returns:
- the i18n data for this component
-
getPlayerRoster
- Returns:
- the
PlayerRosterinstance, ornullif noPlayerRosterexists within thisGameModule
-
addSideChangeListenerToPlayerRoster
-
getPlayerWindow()andPlayerWindow.getControlPanel()instead.