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.Util
Nested 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, name
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validator
Fields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY
-
Constructor Summary
Constructors Modifier Constructor Description protected
GameModule(DataArchive archive)
-
Method Summary
Modifier and Type Method Description void
addCommandEncoder(CommandEncoder ce)
This method adds aCommandEncoder
to the list of objects that will attempt to decode/encode a commandvoid
addIdChangeListener(PropertyChangeListener l)
void
addKeyStrokeListener(KeyStrokeListener l)
The GameModule acts as the mediator for hotkey events.void
addKeyStrokeSource(KeyStrokeSource src)
The GameModule acts as the mediator for hotkey events.void
addMutableProperty(String key, MutableProperty p)
Add a property under the given keyvoid
addSideChangeListenerToPlayerRoster(PlayerRoster.SideChangeListener l)
void
addTo(Buildable b)
Adds this component to its parent.void
appendToTitle(String s)
Append the string to the title of the controls window and all Map windowsprotected abstract void
build()
Initialize the moduleprotected Long
buildCrc()
protected String
buildString()
protected void
checkGpIds()
Check every PieceSlot and PlaceMarker trait for duplicate, illegal or Missing GamePiece id's and update them if necessaryvoid
clearPausedCommands()
Clear outstanding Commands Use where the calling level handles the sending of outstanding commandsstatic int
compareVersions(String v1, String v2)
Deprecated, for removal: This API element is subject to removal in a future version.GamePiece
createPiece(String type)
Central location to create any type of GamePiece from within VASSALGamePiece
createPiece(String type, GamePiece inner)
Command
decode(String command)
Uses the registeredCommandEncoder
s to decode a String into aCommand
.String
encode(Command c)
Uses the registeredCommandEncoder
s to encode aCommand
into a String objectvoid
fireKeyStroke(KeyStroke stroke)
Deprecated, for removal: This API element is subject to removal in a future version.void
fireKeyStroke(NamedKeyStroke stroke)
String
generateGpId()
Generate a new PieceSlot Id, unique to this top-level component.Class<?>[]
getAllowableConfigureComponents()
Return a list of valid sub-component Classes.ArchiveWriter
getArchiveWriter()
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.String
getAttributeValueString(String name)
Called by theBuildable.getBuildElement(org.w3c.dom.Document)
method to write the attributes into an XML elementChatter
getChatter()
static String
getConfigureTypeName()
JComponent
getControlPanel()
long
getCrc()
DataArchive
getDataArchive()
FileChooser
getFileChooser()
FileDialog
getFileDialog()
Deprecated, for removal: This API element is subject to removal in a future version.UsegetFileChooser()
instead.JFrame
getFrame()
Deprecated, for removal: This API element is subject to removal in a future version.static GameModule
getGameModule()
String
getGameName()
GameState
getGameState()
Return the object responsible for tracking the state of a game.String
getGameVersion()
Prefs
getGlobalPrefs()
Deprecated, for removal: This API element is subject to removal in a future version.GpIdSupport
getGpIdSupport()
HelpFile
getHelpFile()
ComponentI18nData
getI18nData()
ImageTileSource
getImageTileSource()
String
getLocalizedGameName()
Object
getLocalizedProperty(Object key)
Logger
getLogger()
String
getMutablePropertiesContainerId()
Return a unique Id for the containerMutableProperty
getMutableProperty(String name)
Find a GlobalProperty object with the given nameint
getNextGpId()
Accessors to check and update the next GpId if necessary.PlayerRoster
getPlayerRoster()
PlayerWindow
getPlayerWindow()
Prefs
getPrefs()
Object
getProperty(Object key)
Return values of Global propertiesRandom
getRNG()
ServerConnection
getServer()
JToolBar
getToolBar()
static String
getUserId()
WizardSupport
getWizardSupport()
static void
init(GameModule module)
Set the singleton GameModule and invokebuild()
on it.void
initFrameTitle()
boolean
isLocalizationEnabled()
Is the module being translated into the user's Locale? Localization is disabled when editing a moduleboolean
pauseLogging()
Pause logging and return true if successful.void
quit()
Exit the application, prompting user to save if necessaryvoid
refreshKeyStrokeListeners()
If our keyboard mapping paradigm changes (example: Mac Legacy preference checked/unchecked), we need to reregister all of our KeyStrokeListenersvoid
removeCommandEncoder(CommandEncoder ce)
This method removes aCommandEncoder
from the list of objects that will attempt to decode/encode a commandvoid
removeFrom(Buildable parent)
Remove this component from its parentvoid
removeIdChangeListener(PropertyChangeListener l)
MutableProperty
removeMutableProperty(String key)
Remove the property with the given keyCommand
resumeLogging()
Restart logging and return any outstanding commandsvoid
save()
If the module is being edited, write the module dataprotected void
save(boolean saveAs)
void
saveAs()
void
sendAndLog(Command c)
Encode theCommand
, send it to the server and write it to a logfile (if any is open)void
setAttribute(String name, Object value)
Sets a buildFile (XML) attribute value for this component.void
setChatter(Chatter c)
Set the object that displays chat text.void
setGlobalPrefs(Prefs p)
Deprecated, for removal: This API element is subject to removal in a future version.no replacementvoid
setGpIdSupport(GpIdSupport s)
void
setNextGpId(int id)
void
setPrefs(Prefs p)
static void
setUserId(String newId)
Set the identifier for the userboolean
shutDown()
Prompt user to save open game and modules/extensions being editedstatic void
unload()
Unload the modulevoid
updateLastSave()
void
warn(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, setConfigureName
Methods inherited from class VASSAL.build.AbstractBuildable
build, getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getPropertyNames, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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
ThePrefs
key for the user's real name- See Also:
- Constant Field Values
-
SECRET_NAME
ThePrefs
key for the user's secret name- See Also:
- Constant Field Values
-
PERSONAL_INFO
ThePrefs
key 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:AbstractBuildable
Sets a buildFile (XML) attribute value for this component. Thekey
parameter will be one of those listed inAbstractBuildable.getAttributeNames()
. If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
will be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
- Specified by:
setAttribute
in interfaceAutoConfigurable
- Specified by:
setAttribute
in interfaceTranslatable
- Specified by:
setAttribute
in classAbstractBuildable
- Parameters:
name
- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()
value
- If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
can also be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
-
getAttributeValueString
Description copied from interface:AutoConfigurable
Called by theBuildable.getBuildElement(org.w3c.dom.Document)
method to write the attributes into an XML element- Specified by:
getAttributeValueString
in interfaceAutoConfigurable
- Specified by:
getAttributeValueString
in interfaceTranslatable
- Specified by:
getAttributeValueString
in 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
v2
is a later version thev1
, a positive number if an earlier version, or zero if the versions are the same.
-
addTo
Description copied from interface:Buildable
Adds 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:Configurable
Remove this component from its parent- Specified by:
removeFrom
in interfaceConfigurable
-
getHelpFile
- Specified by:
getHelpFile
in interfaceConfigurable
- Returns:
- a HelpFilte describing how to use and configure this component
-
getAttributeNames
Description copied from class:AbstractBuildable
Lists 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:
getAttributeNames
in interfaceAutoConfigurable
- Specified by:
getAttributeNames
in classAbstractBuildable
- Returns:
- a list of all buildFile (XML) attribute names for this component
-
getAttributeDescriptions
Description copied from interface:AutoConfigurable
Return 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:
getAttributeDescriptions
in interfaceAutoConfigurable
- Specified by:
getAttributeDescriptions
in 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:AbstractConfigurable
Return 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 ofAutoConfigurer
will 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:
getAttributeTypes
in interfaceAutoConfigurable
- Specified by:
getAttributeTypes
in classAbstractConfigurable
-
getAllowableConfigureComponents
Description copied from interface:Configurable
Return 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:
getAllowableConfigureComponents
in 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 aCommandEncoder
to the list of objects that will attempt to decode/encode a command -
removeCommandEncoder
This method removes aCommandEncoder
from 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 registeredCommandEncoder
s to decode a String into aCommand
.- Specified by:
decode
in interfaceCommandEncoder
-
encode
Uses the registeredCommandEncoder
s to encode aCommand
into a String object- Specified by:
encode
in 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:
getToolBar
in 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:GpIdSupport
Generate a new PieceSlot Id, unique to this top-level component.- Specified by:
generateGpId
in interfaceGpIdSupport
- Returns:
- PieceSlot Id
-
getNextGpId
public int getNextGpId()Description copied from interface:GpIdSupport
Accessors to check and update the next GpId if necessary.- Specified by:
getNextGpId
in interfaceGpIdSupport
-
setNextGpId
public void setNextGpId(int id)- Specified by:
setNextGpId
in 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:
getProperty
in interfacePropertySource
-
getMutableProperty
Description copied from interface:MutablePropertiesContainer
Find a GlobalProperty object with the given name- Specified by:
getMutableProperty
in interfaceMutablePropertiesContainer
-
addMutableProperty
Description copied from interface:MutablePropertiesContainer
Add a property under the given key- Specified by:
addMutableProperty
in interfaceMutablePropertiesContainer
-
removeMutableProperty
Description copied from interface:MutablePropertiesContainer
Remove the property with the given key- Specified by:
removeMutableProperty
in interfaceMutablePropertiesContainer
-
getMutablePropertiesContainerId
Description copied from interface:MutablePropertiesContainer
Return a unique Id for the container- Specified by:
getMutablePropertiesContainerId
in interfaceMutablePropertiesContainer
-
getLocalizedProperty
- Specified by:
getLocalizedProperty
in interfacePropertySource
-
getCrc
public long getCrc() -
buildCrc
-
getI18nData
- Specified by:
getI18nData
in interfaceTranslatable
- Overrides:
getI18nData
in classAbstractConfigurable
- Returns:
- the i18n data for this component
-
getPlayerRoster
- Returns:
- the
PlayerRoster
instance, ornull
if noPlayerRoster
exists within thisGameModule
-
addSideChangeListenerToPlayerRoster
-
getPlayerWindow()
andPlayerWindow.getControlPanel()
instead.