Package VASSAL.script
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
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected Stringprotected bsh.NameSpaceprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected PropertySourceprotected static final Stringprotected static final Stringprotected static bsh.NameSpaceFields inherited from class VASSAL.script.AbstractInterpreter
myNameSpaceFields inherited from class bsh.Interpreter
DEBUG, evalOnly, interactive, LOCALSCOPING, TRACE, VERSION -
Constructor Summary
ConstructorsConstructorDescriptionExpressionInterpreter(String expr) Private constructor to build an ExpressionInterpreter. -
Method Summary
Modifier and TypeMethodDescriptioncountAttachment(String attachment, String property, PropertySource ps) CountAttachment(property) function count the number of pieces attached to this piece via a named Attachment trait that *contain* the specified propertycountAttachmentExpression(String attachment, String expression, PropertySource ps) CountAttachmentExpression(attachment, expression) function count the number of pieces attached to this piece via a named Attachment trait for which the expression is truecountLocation(String property, String expression, PropertySource ps) CountLocation(property, expression) functions.countLocation(String propertyOrExpression, PropertySource ps) CountLocation(property) and CountLocation(expression) functions.CountLocation() function.countMapLocation(String locationName, String mapName, String property, String expression, PropertySource ps) countMapLocation(String locationName, String mapName, String propertyOrExpression, PropertySource ps) countMapLocation(String locationName, String mapName, PropertySource ps) countMapZone(String zoneName, String mapName, String property, String expression, PropertySource ps) CountMapZone(Zone, Map, property, expression) function Return the count of pieces in the specified Zone/Map that match the supplied expression AND have a non-blank value for the supplied property namecountMapZone(String zoneName, String mapName, String propertyOrExpression, PropertySource ps) CountMapZone(Zone, Map, property) and CountMapZone(Zone, Map, expression) function Return the count of pieces in the specified Zone/Map that match the supplied expression OR have a non-blank value for the supplied property namecountMapZone(String zoneName, String mapName, PropertySource ps) CountMapZone(Zone, Map) function Return the count of pieces in the specified Zone/MapcountMat(String property, 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 piececountStack(String property, PropertySource ps) CountStack(property) function count the number of pieces in the same stack which have any non-blank value for the specified property.countZone(String property, String expression, PropertySource ps) CountLocation(zone, expression) function Return count of pieces in the same zome as the current piece that have a non-blank value for a property and that match an expressioncountZone(String propertyOrExpression, PropertySource ps) CountZone(property) and CountZone(expression) functions.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(String attachment, String property, String indexOrName, PropertySource ps) Return 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(String name) getMapProperty(String propertyName, String mapName) getProperty(String name) Callbacks from BeanShell Expressions to VassalgetProperty minus the wrapgetZoneProperty(String propertyName, String zoneName) getZoneProperty(String propertyName, String zoneName, String mapName) protected voidInitialise the static elements of this class.maxAttachment(String attachment, String property, PropertySource ps) MaxAttachment(attachment, property) function Highest value of the named property among all pieces attached, or 0 if no pieces are attachedminAttachment(String attachment, String property, PropertySource ps) MinAttachment(attachment, property) function Lowest value of the named property among all pieces attached, or 0 if no pieces are attachedintrangeInCells(Object x1, Object y1, Object x2, Object y2, String mapName, PropertySource ps) intrangeInCells(Object x1, Object y1, Object x2, Object y2, PropertySource ps) intrangeInCells(Object x, Object y, PropertySource ps) intrangeInCells(String attachmentName, PropertySource ps) intrangeInPixels(Object x1, Object y1, Object x2, Object y2, String mapName, PropertySource ps) intrangeInPixels(Object x1, Object y1, Object x2, Object y2, PropertySource ps) intrangeInPixels(Object x, Object y, PropertySource ps) intrangeInPixels(String attachmentName, PropertySource ps) Implementation of Range functionsprotected static StringsumAttachment(String attachment, String property, PropertySource ps) SumAttachment(attachment, property) function Total the value of the named property in all pieces attachedsumLocation(String property, String 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(String property, PropertySource ps) SumLocation(property) function Total the value of the named property in all counters in the same location as the specified piece.sumMapLocation(String property, String location, String map, String 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 expressionsumMapLocation(String property, String location, String map, PropertySource ps) SumMapLocation(property, location, map) function Total the value of the named property in all counters in the specified map and locationsumMapZone(String property, String zoneName, String map, String expression, PropertySource ps) SumMapZone(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 expressionsumMapZone(String property, String zoneName, String map, PropertySource ps) SumMapZone(property, location, map) function Total the value of the named property in all counters in the specified map and zonesumMat(String property, PropertySource ps) SumMat(property) function Total the value of the named property in all counters among the Mat-and-MatCargo grouping of the current piecesumStack(String 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(String property, String expression, PropertySource ps) SumZone(property, expression) function Total the value of the named property in all counters in the same zone as the specified piece that meet the supplied expression.sumZone(String property, PropertySource ps) SumZone(property) function Total the value of the named property in all counters in the same zone as the specified piece.Convert a String value into a wrapped primitive object if possible.Methods inherited from class VASSAL.script.AbstractInterpreter
alert, findMap, getModuleProperty, globalHotKey, isAccessible, setModuleProperty, setVar, setVar, setVar, setVar, setVarMethods 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
-
-
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:AuditableReturn a description of the Type of trait or Component an Auditable is- Specified by:
getComponentTypeNamein interfaceAuditable- Returns:
- Component Type
-
getComponentName
Description copied from interface:AuditableReturn the name of the trait or Component an Auditable is- Specified by:
getComponentNamein 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
Return the current expression- Returns:
- expression
-
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
-
getProperty
Callbacks from BeanShell Expressions to Vassal -
getLocalizedProperty
-
getString
getProperty minus the wrap -
getZoneProperty
-
getZoneProperty
-
getMapProperty
-
getAttachmentProperty
public Object getAttachmentProperty(String attachment, String property, String indexOrName, PropertySource ps) -
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
-
countStack
CountStack(property) function count the number of pieces in the same stack which have any non-blank value for the specified property.- Parameters:
property- Property Nameps- GamePiece- Returns:
- total
-
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
SumAttachment(attachment, property) function Total the value of the named property in all pieces attached- Parameters:
attachment- Attachment Nameproperty- Property Nameps- GamePiece- Returns:
- total
-
countAttachment
CountAttachment(property) function count the number of pieces attached to this piece via a named Attachment trait that *contain* the specified property- Parameters:
attachment- Attachment Nameproperty- Property Nameps- GamePiece- Returns:
- total
-
countAttachmentExpression
CountAttachmentExpression(attachment, expression) function count the number of pieces attached to this piece via a named Attachment trait for which the expression is true- Parameters:
attachment- Attachment Name e.g. "MyTurrets"expression- Expression e.g. " { Ammo > 2 } "ps- GamePiece- Returns:
- total
-
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:
property- Property Nameps- GamePiece- Returns:
- total
-
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:
property- Property Nameps- GamePiece- Returns:
- total
-
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
-
sumMapLocation
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
-
sumMapLocation
public Object sumMapLocation(String property, String location, String map, String 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
CountLocation() function. Return count of pieces in the same location as the current piece- Returns:
- Piece Count
-
countLocation
CountLocation(property) and CountLocation(expression) functions. Return count of pieces in the same location as the current piece that have a non-nlank value for a property or that match an expression- Parameters:
propertyOrExpression- Property Name or Match Expression- Returns:
- Piece Count
-
countLocation
CountLocation(property, expression) functions. Return count of pieces in the same location as the current piece that have a non-nlank value for a property and that match an expression- Parameters:
property- Property Nameexpression- Match Expression- Returns:
- Piece Count
-
countMapLocation
-
countMapLocation
public Object countMapLocation(String locationName, String mapName, String propertyOrExpression, PropertySource ps) -
countMapLocation
-
sumZone
SumZone(property) function Total the value of the named property in all counters in the same zone as the specified piece.- Parameters:
property- Property Nameps- GamePiece- Returns:
- total
-
sumZone
SumZone(property, expression) function Total the value of the named property in all counters in the same zone as the specified piece that meet the supplied expression.- Parameters:
property- Property Nameexpression- Expressionps- GamePiece Source- Returns:
- total
-
sumMapZone
SumMapZone(property, location, map) function Total the value of the named property in all counters in the specified map and zone- Parameters:
property- Property NamezoneName- Zone Namemap- Map Nameps- GamePiece source- Returns:
- total
-
sumMapZone
public Object sumMapZone(String property, String zoneName, String map, String expression, PropertySource ps) SumMapZone(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 NamezoneName- 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(property) and CountZone(expression) functions. Return count of pieces in the same zone as the current piece that have a non-blank value for a property or that match an expression- Parameters:
propertyOrExpression- Property Name or Match Expression- Returns:
- Piece Count
-
countZone
CountLocation(zone, expression) function Return count of pieces in the same zome as the current piece that have a non-blank value for a property and that match an expression- Parameters:
property- property nameexpression- match expression- Returns:
- Piece Count
-
countMapZone
CountMapZone(Zone, Map) function Return the count of pieces in the specified Zone/Map- Parameters:
zoneName- Target Zone NamemapName- Target Map Nameps- Source Piece- Returns:
- Count
-
countMapZone
public Object countMapZone(String zoneName, String mapName, String propertyOrExpression, PropertySource ps) CountMapZone(Zone, Map, property) and CountMapZone(Zone, Map, expression) function Return the count of pieces in the specified Zone/Map that match the supplied expression OR have a non-blank value for the supplied property name- Parameters:
zoneName- Target Zone NamemapName- Target Map NamepropertyOrExpression- A Property Name or a Beanshell expressionps- Source Piece- Returns:
- Count
-
countMapZone
public Object countMapZone(String zoneName, String mapName, String property, String expression, PropertySource ps) CountMapZone(Zone, Map, property, expression) function Return the count of pieces in the specified Zone/Map that match the supplied expression AND have a non-blank value for the supplied property name- Parameters:
zoneName- Target Zone NamemapName- Target Map Nameproperty- A Property Nameexpression- A Beanshell expressionps- Source Piece- Returns:
- Count
-
rangeInPixels
Implementation of Range functions -
rangeInCells
-
rangeInPixels
-
rangeInCells
-
rangeInPixels
-
rangeInCells
-
rangeInPixels
-
rangeInCells
-
random
-
isRandom
-
sum
-
sum
-
count
-
count
-