[vassalengine-svn] SF.net SVN: vassalengine:[8665] VASSAL-src/trunk/src/VASSAL
Brought to you by:
rodneykinney,
uckelman
From: <uck...@us...> - 2013-04-29 21:46:58
|
Revision: 8665 http://sourceforge.net/p/vassalengine/svn/8665 Author: uckelman Date: 2013-04-29 21:46:54 +0000 (Mon, 29 Apr 2013) Log Message: ----------- Merged Brent-3.2-p2p@8661. Fixed Bug 10128: Slow Follow Property handling in Embellishment Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/counters/Embellishment.java Added Paths: ----------- VASSAL-src/trunk/src/VASSAL/script/expression/SinglePropertyExpression.java Modified: VASSAL-src/trunk/src/VASSAL/counters/Embellishment.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/counters/Embellishment.java 2013-04-29 13:11:27 UTC (rev 8664) +++ VASSAL-src/trunk/src/VASSAL/counters/Embellishment.java 2013-04-29 21:46:54 UTC (rev 8665) @@ -60,9 +60,9 @@ import VASSAL.i18n.PieceI18nData; import VASSAL.i18n.Resources; import VASSAL.i18n.TranslatablePiece; -import VASSAL.script.expression.BeanShellExpression; import VASSAL.script.expression.Expression; import VASSAL.script.expression.ExpressionException; +import VASSAL.script.expression.SinglePropertyExpression; import VASSAL.tools.FormattedString; import VASSAL.tools.NamedKeyStroke; import VASSAL.tools.SequenceEncoder; @@ -107,6 +107,7 @@ protected boolean followProperty; protected String propertyName = ""; + protected Expression followPropertyExpression; protected int firstLevelValue; // random layers @@ -495,12 +496,15 @@ */ protected void checkPropertyLevel() { if (!followProperty || propertyName.length() == 0) return; + + if (followPropertyExpression == null) { + followPropertyExpression = new SinglePropertyExpression(propertyName); + } - final Expression ex = BeanShellExpression.createExpression(BeanShellExpression.convertProperty(propertyName)); String val = ""; try { - val = ex.evaluate(Decorator.getOutermost(this)); + val = followPropertyExpression.evaluate(Decorator.getOutermost(this)); if (val == null || val.length() == 0) val = String.valueOf(firstLevelValue); int v = Integer.parseInt(val) - firstLevelValue + 1; @@ -739,6 +743,7 @@ public Object getProperty(Object key) { if (key.equals(name + IMAGE)) { + System.out.println(name + IMAGE); checkPropertyLevel(); if (value > 0) { return imageName[Math.abs(value) - 1]; @@ -747,6 +752,7 @@ return ""; } else if (key.equals(name + NAME)) { + System.out.println(name + NAME); checkPropertyLevel(); if (value > 0) { return strip(commonName[Math.abs(value) - 1]); @@ -755,13 +761,16 @@ return ""; } else if (key.equals(name + LEVEL)) { + System.out.println(name + LEVEL); checkPropertyLevel(); return String.valueOf(value); } else if (key.equals(name + ACTIVE)) { + System.out.println(name + ACTIVE); return String.valueOf(isActive()); } else if (key.equals(Properties.VISIBLE_STATE)) { + System.out.println(name + Properties.VISIBLE_STATE); String s = String.valueOf(super.getProperty(key)); if (drawUnderneathWhenSelected) { s += getProperty(Properties.SELECTED); Copied: VASSAL-src/trunk/src/VASSAL/script/expression/SinglePropertyExpression.java (from rev 8661, VASSAL-src/branches/Brent-3.2-p2p/src/VASSAL/script/expression/SinglePropertyExpression.java) =================================================================== --- VASSAL-src/trunk/src/VASSAL/script/expression/SinglePropertyExpression.java (rev 0) +++ VASSAL-src/trunk/src/VASSAL/script/expression/SinglePropertyExpression.java 2013-04-29 21:46:54 UTC (rev 8665) @@ -0,0 +1,62 @@ +/* + * $Id: SinglePropertyExpression.java 7725 2011-07-31 18:51:43Z uckelman $ + * + * Copyright (c) 2013 Brent Easton + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License (LGPL) as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, copies are available + * at http://www.opensource.org. + */ + +package VASSAL.script.expression; + +import java.util.Map; + +import VASSAL.build.module.properties.PropertySource; + +/** + * An expression consisting of a single property name + * + */ +public class SinglePropertyExpression extends Expression { + + public SinglePropertyExpression (String ex) { + setExpression(ex); + } + + public String evaluate(PropertySource ps, Map<String, String> properties, boolean localized) + throws ExpressionException { + String value = null; + try { + if (properties != null) { + value = properties.get(getExpression()); + } + if (value == null && ps != null) { + if (localized) { + value = (String) ps.getLocalizedProperty(getExpression()); + } + else { + value = (String) ps.getProperty(getExpression()); + } + } + } + catch (Exception ex) { + throw new ExpressionException(getExpression(), ex.getMessage()); + } + return value == null ? "" : value; + } + + public String toBeanShellString() { + return BeanShellExpression.convertProperty(getExpression()); + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |