Class ExpressionInterpreter
java.lang.Object
bsh.Interpreter
VASSAL.script.AbstractInterpreter
VASSAL.script.ExpressionInterpreter
- All Implemented Interfaces:
bsh.ConsoleInterface
,Serializable
,Runnable
,Auditable
,RecursionLimiter.Loopable
A BeanShell Interpreter customised to evaluate a single Vassal
expression containing Vassal property references.
All traits with the same expression will share the same Interpreter
Each ExpressionInterpreter has 2 levels of NameSpace:
1. Top level is a single global NameSpace that contains utility methods
available to all ExpressionInterpreters. It is the parent of all
level 2 NameSpaces.
2. Level 2 is a NameSpace for each unique expression that contains the
parsed expression. All expressions in all traits that are the same
will use the one Expression NameSpace.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected AuditTrail
protected Auditable
protected static final String
protected String
protected bsh.NameSpace
protected static final String
protected static final String
protected static final String
protected static final String
protected PropertySource
protected static final String
protected static final String
protected static bsh.NameSpace
Fields inherited from class VASSAL.script.AbstractInterpreter
myNameSpace
Fields inherited from class bsh.Interpreter
DEBUG, evalOnly, interactive, LOCALSCOPING, TRACE, VERSION
-
Constructor Summary
ConstructorDescriptionExpressionInterpreter
(String expr) Private constructor to build an ExpressionInterpreter. -
Method Summary
Modifier and TypeMethodDescriptionaudit
(Object message, Object conditionOrOptionList, Object optionList, PropertySource ps) Audit Write a message to the errorlogcountAttachment
(Object attachment, Object property, Object expression, PropertySource ps) countAttachment
(Object attachment, Object propertyOrExpression, PropertySource ps) CountAttach Beanshell function implementationcountCurrentZone
(Object propertyName, Object expression, PropertySource ps) countLocation
(Object propertyOrLocation, Object expressionOrMap, PropertySource ps) countLocation
(Object propertyOrExpression, PropertySource ps) BeanShell CountLocation implementation Return count of pieces in the same location as the current piececountMap
(Object map, Object property, Object expression, PropertySource ps) countMap
(Object propertyOrMap, Object expressionOrProperty, PropertySource ps) countMap
(Object propertyOrExpressionOrMap, PropertySource ps) countMapLocation
(Object locationName, Object mapName, Object property, Object expression, PropertySource ps) countMapLocation
(Object locationName, Object mapName, Object propertyOrExpression, PropertySource ps) countMat
(Object property, Object expression, PropertySource ps) countMat
(Object propertyOrExpression, PropertySource ps) CountMat(property) function Return the total number of counters with a non-blank value for the specified property among the Mat-and-MatCargo grouping of the current piececountRange
(Object propertyOrExpression, Object expression, Object minRange, Object maxRange, Boolean asPixels, PropertySource ps) Implementation of all flavours of CountRange and CounrRangePx functionscountStack
(Object property, Object expression, PropertySource ps) countStack
(Object propertyOrExpression, PropertySource ps) CountStack(property) and CountStack(expression) function count the number of pieces in the same stack which have any non-blank value for the specified property.countZone
(Object zoneName, Object mapName, Object propertyOrExpression, PropertySource ps) countZone
(Object propertyOrZone, Object expressionOrMap, PropertySource ps) countZone
(Object propertyOrExpression, PropertySource ps) CountZone() function.evaluate()
Evaluate the expression, setting the value of any undefined values to the matching Vassal property value.evaluate
(PropertySource ps, boolean localized) evaluate
(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit) evaluate
(PropertySource ps, Map<String, String> properties, boolean localized, Auditable owner, AuditTrail audit) getAttachmentProperty
(Object attachment, Object property, Object indexOrNameOrexpression, PropertySource ps) Callback for Beanshell getAttachProperty functionsReturn the name of the trait or Component an Auditable isReturn a description of the Type of trait or Component an Auditable isReturn the current expressiongetLocalizedProperty
(Object name) getMapProperty
(Object propertyName, Object mapName) getProperty
(Object name) Callbacks from BeanShell Expressions to VassalgetProperty minus the wrapgetZoneProperty
(Object propertyName, Object zoneName) getZoneProperty
(Object propertyName, Object zoneName, Object mapName) protected void
Initialise the static elements of this class.maxAttachment
(Object attachment, Object property, PropertySource ps) MaxAttachment(attachment, property) function Highest value of the named property among all pieces attached, or 0 if no pieces are attachedminAttachment
(Object attachment, Object property, PropertySource ps) MinAttachment(attachment, property) function Lowest value of the named property among all pieces attached, or 0 if no pieces are attachedrangeAttach
(Object attachmentName, Object expression, boolean asPixels, PropertySource ps) Implementation of Range functionsrangeInCells
(Object x1, Object y1, Object x2, Object y2, Object mapName, PropertySource ps) rangeInCells
(Object x1, Object y1, Object x2, Object y2, PropertySource ps) rangeInCells
(Object x, Object y, PropertySource ps) rangeInPixels
(Object x1, Object y1, Object x2, Object y2, Object mapName, PropertySource ps) rangeInPixels
(Object x1, Object y1, Object x2, Object y2, PropertySource ps) rangeInPixels
(Object x, Object y, PropertySource ps) sleep
(Object ms, PropertySource ps) Refresh the screen, then delay for the specified number of milliseconds This is not pretty, but is the only way I have found to force a proper UI refresh - Open a modal dialog box way offscreen.protected static String
sumAttachment
(Object attachment, Object property, Object expression, PropertySource ps) sumAttachment
(Object attachment, Object property, PropertySource ps) SumAttach Beanshell function implementationsumLocation
(Object property, Object location, Object map, Object expression, PropertySource ps) SumMapLocation(property, location, map, expression) function Total the value of the named property in all counters in the specified map and location that match the supplied expressionsumLocation
(Object property, Object location, Object map, PropertySource ps) SumMapLocation(property, location, map) function Total the value of the named property in all counters in the specified map and locationsumLocation
(Object property, Object expression, PropertySource ps) SumLocation(property, expression) function Total the value of the named property in all counters in the same location as the specified piece that meet the supplied expression.sumLocation
(Object property, PropertySource ps) SumLocation(property) function Total the value of the named property in all counters in the same location as the specified piece.sumMap
(Object property, Object map, Object expression, PropertySource ps) sumMap
(Object property, Object mapOrExpression, PropertySource ps) sumMap
(Object property, PropertySource ps) sumMat
(Object property, Object expression, PropertySource ps) sumMat
(Object propertyOrExpression, PropertySource ps) SumMat(property) function Total the value of the named property in all counters among the Mat-and-MatCargo grouping of the current piecesumRange
(Object propertyName, Object expression, Object minRange, Object maxRange, Boolean asPixels, PropertySource ps) Implementation of all flavours of SumRange and SumRangePx functionssumStack
(Object property, Object expression, PropertySource ps) SumStack(property, expression) function Total the value of the named property in all counters in the same stack as the specified piece that meet the specified expressionsumStack
(Object property, PropertySource ps) SumStack(property) function Total the value of the named property in all counters in the same stack as the specified piece.SumZone(property, location, map, expression) function Total the value of the named property in all counters in the specified map and zone that match the supplied expressionWrap a possibly already wrapped value.Convert a String value into a wrapped primitive object if possible.Methods inherited from class VASSAL.script.AbstractInterpreter
alert, alert, findMap, getModuleProperty, globalHotKey, isAccessible, setModuleProperty, setVar, setVar, setVar, setVar, setVar
Methods inherited from class bsh.Interpreter
debug, error, eval, eval, eval, eval, get, getClassManager, getErr, getIn, getInterface, getNameSpace, getOut, getParent, getShowResults, getSourceFileInfo, getStrictJava, invokeMain, main, pathToFile, print, println, redirectOutputToFile, run, set, set, set, set, set, set, setClassLoader, setConsole, setErr, setExitOnEOF, setNameSpace, setOut, setShowResults, setStrictJava, source, source, unset
-
Field Details
-
INIT_SCRIPT
- See Also:
-
THIS
- See Also:
-
SOURCE
- See Also:
-
MAGIC1
- See Also:
-
MAGIC2
- See Also:
-
MAGIC3
- See Also:
-
ERROR_PREFIX
- See Also:
-
topLevelNameSpace
protected static bsh.NameSpace topLevelNameSpace -
expressionNameSpace
protected bsh.NameSpace expressionNameSpace -
expression
-
variables
-
stringVariables
-
source
-
currentAudit
-
currentOwner
-
-
Constructor Details
-
ExpressionInterpreter
Private constructor to build an ExpressionInterpreter. Interpreters can only be created by createInterpreter.- Parameters:
expr
- Expression- Throws:
ExpressionException
- Invalid Expression details
-
-
Method Details
-
getComponentTypeName
Description copied from interface:Auditable
Return a description of the Type of trait or Component an Auditable is- Specified by:
getComponentTypeName
in interfaceAuditable
- Returns:
- Component Type
-
getComponentName
Description copied from interface:Auditable
Return the name of the trait or Component an Auditable is- Specified by:
getComponentName
in interfaceAuditable
- Returns:
- Component name
-
strip
-
initialiseStatic
protected void initialiseStatic()Initialise the static elements of this class. Create a Top Level NameSpace using the Vassal class loader, load useful classes and read and process the init_expression.bsh file to load scripted methods available to expressions. -
getExpression
-
evaluate
Evaluate the expression, setting the value of any undefined values to the matching Vassal property value. Primitives must be wrapped.- Returns:
- result
- Throws:
ExpressionException
-
evaluate
- Throws:
ExpressionException
-
evaluate
public String evaluate(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit) throws ExpressionException - Throws:
ExpressionException
-
evaluate
public String evaluate(PropertySource ps, Map<String, String> properties, boolean localized, Auditable owner, AuditTrail audit) throws ExpressionException- Throws:
ExpressionException
-
evaluate
- Throws:
ExpressionException
-
wrap
Convert a String value into a wrapped primitive object if possible. Note this is a non-static copy of BeanShell.wrap(). Callbacks from beanshell (e.g. getProperty) fail if an attempt is made to call a static method.- Parameters:
value
- Value to wrap- Returns:
- wrapped value
-
wrap
-
getProperty
-
getLocalizedProperty
-
getString
-
getZoneProperty
-
getZoneProperty
-
getMapProperty
-
getAttachmentProperty
public Object getAttachmentProperty(Object attachment, Object property, Object indexOrNameOrexpression, PropertySource ps) Callback for Beanshell getAttachProperty functions- Parameters:
attachment
- Attachment nameproperty
- Property nameindexOrNameOrexpression
- An index number, a piece Basic Name or an Expressionps
- Source Piece- Returns:
- Property value
-
sumStack
SumStack(property) function Total the value of the named property in all counters in the same stack as the specified piece.- Parameters:
property
- Property Nameps
- GamePiece- Returns:
- total
-
sumStack
SumStack(property, expression) function Total the value of the named property in all counters in the same stack as the specified piece that meet the specified expression- Parameters:
property
- Property Nameexpression
- Expressionps
- GamePiece- Returns:
- total
-
countStack
CountStack(property) and CountStack(expression) function count the number of pieces in the same stack which have any non-blank value for the specified property.- Parameters:
propertyOrExpression
- Property Name or Expressionps
- GamePiece- Returns:
- total
-
countStack
-
maxAttachment
MaxAttachment(attachment, property) function Highest value of the named property among all pieces attached, or 0 if no pieces are attached- Parameters:
attachment
- Attachment Nameproperty
- Property Nameps
- GamePiece- Returns:
- total
-
minAttachment
MinAttachment(attachment, property) function Lowest value of the named property among all pieces attached, or 0 if no pieces are attached- Parameters:
attachment
- Attachment Nameproperty
- Property Nameps
- GamePiece- Returns:
- total
-
sumAttachment
SumAttach Beanshell function implementation -
sumAttachment
public Object sumAttachment(Object attachment, Object property, Object expression, PropertySource ps) -
countAttachment
CountAttach Beanshell function implementation -
countAttachment
public Object countAttachment(Object attachment, Object property, Object expression, PropertySource ps) -
sumMat
SumMat(property) function Total the value of the named property in all counters among the Mat-and-MatCargo grouping of the current piece- Parameters:
propertyOrExpression
- Property Nameps
- GamePiece- Returns:
- total
-
sumMat
-
countMat
CountMat(property) function Return the total number of counters with a non-blank value for the specified property among the Mat-and-MatCargo grouping of the current piece- Parameters:
propertyOrExpression
- Property Nameps
- GamePiece- Returns:
- total
-
countMat
-
countMat
-
sumLocation
SumLocation(property) function Total the value of the named property in all counters in the same location as the specified piece.- Parameters:
property
- Property Nameps
- GamePiece- Returns:
- total
-
sumLocation
SumLocation(property, expression) function Total the value of the named property in all counters in the same location as the specified piece that meet the supplied expression.- Parameters:
property
- Property Nameexpression
- Expressionps
- GamePiece Source- Returns:
- total
-
sumLocation
SumMapLocation(property, location, map) function Total the value of the named property in all counters in the specified map and location- Parameters:
property
- Property Namelocation
- Location Namemap
- Map Nameps
- GamePiece source- Returns:
- total
-
sumLocation
public Object sumLocation(Object property, Object location, Object map, Object expression, PropertySource ps) SumMapLocation(property, location, map, expression) function Total the value of the named property in all counters in the specified map and location that match the supplied expression- Parameters:
property
- Property Namelocation
- Location Namemap
- Map Nameexpression
- Expressionps
- GamePiece source- Returns:
- total
-
countLocation
BeanShell CountLocation implementation Return count of pieces in the same location as the current piece- Returns:
- Piece Count
-
countLocation
-
countLocation
-
countMapLocation
public Object countMapLocation(Object locationName, Object mapName, Object propertyOrExpression, PropertySource ps) -
countMapLocation
-
sumZone
public Object sumZone(Object property, Object zone, Object map, Object expression, PropertySource ps) SumZone(property, location, map, expression) function Total the value of the named property in all counters in the specified map and zone that match the supplied expression- Parameters:
property
- Property Namezone
- Zone Namemap
- Map Nameexpression
- Expressionps
- GamePiece source- Returns:
- total
-
countZone
CountZone() function. Return count of pieces in the same zone as the current piece- Returns:
- Piece Count
-
countZone
-
countZone
-
countCurrentZone
-
countZone
public Object countZone(Object zoneName, Object mapName, Object propertyOrExpression, PropertySource ps) -
countZone
-
sumMap
-
sumMap
-
sumMap
-
countMap
-
countMap
-
countMap
-
countMap
-
rangeAttach
public Object rangeAttach(Object attachmentName, Object expression, boolean asPixels, PropertySource ps) Implementation of Range functions -
rangeInPixels
-
rangeInCells
-
rangeInPixels
-
rangeInCells
-
rangeInPixels
-
rangeInCells
-
sumRange
public Object sumRange(Object propertyName, Object expression, Object minRange, Object maxRange, Boolean asPixels, PropertySource ps) Implementation of all flavours of SumRange and SumRangePx functions- Parameters:
propertyName
- Property name to sumexpression
- Optional expression to select targetsminRange
- minimum RangemaxRange
- maximum rangeasPixels
- true to force range check to be pixelsps
- Source piece- Returns:
- Sum of properties
-
countRange
public Object countRange(Object propertyOrExpression, Object expression, Object minRange, Object maxRange, Boolean asPixels, PropertySource ps) Implementation of all flavours of CountRange and CounrRangePx functions- Parameters:
propertyOrExpression
- Property name to sum OR Expression if no property suppliedexpression
- Optional expression to select targetsminRange
- minimum RangemaxRange
- maximum rangeasPixels
- true to force range check to be pixelsps
- Source piece- Returns:
- Count of matching pieces
-
random
-
isRandom
-
sum
-
sum
-
count
-
count
-
audit
public Object audit(Object message, Object conditionOrOptionList, Object optionList, PropertySource ps) Audit Write a message to the errorlog- Parameters:
message
- Message to display. Can be an ExpressionconditionOrOptionList
- If provided, is an expression that will be evaluated and the message will only be written if trueoptionList
- A String containing any of the following letters to invoke various options 'F' - Include full audit of the current expression 'C' - Display in Chatter 'S' - Suppress logging to errorLog- Returns:
- Returns a blank string
-
sleep
Refresh the screen, then delay for the specified number of milliseconds This is not pretty, but is the only way I have found to force a proper UI refresh - Open a modal dialog box way offscreen. This forces a an actual real Swing UI refresh, then hangs the UI - Start a new thread that closes the dialog box after a specified delay- Parameters:
ms
- Milliseconds to delayps
- A Property source- Returns:
- blank String
-