Search in sources :

Example 1 with OrderedPair

use of pcgen.base.math.OrderedPair in project pcgen by PCGen.

the class FaceToken method getSquaresToken.

/**
	 * Get squares sub token
	 * 
	 * @param display
	 * @return squares sub token
	 */
public static String getSquaresToken(CharacterDisplay display) {
    OrderedPair face = getFace(display.getCharID());
    String retString = "";
    double squareSize = SettingsHandler.getGame().getSquareSize();
    if (CoreUtility.doublesEqual(face.getPreciseY().doubleValue(), 0.0)) {
        retString = new DecimalFormat("#.#").format(face.getPreciseX().doubleValue() / squareSize);
    } else {
        retString = new DecimalFormat("#.#").format(face.getPreciseX().doubleValue() / squareSize) + " x " + new DecimalFormat("#.#").format(face.getPreciseY().doubleValue() / squareSize);
    }
    return retString;
}
Also used : OrderedPair(pcgen.base.math.OrderedPair) DecimalFormat(java.text.DecimalFormat)

Example 2 with OrderedPair

use of pcgen.base.math.OrderedPair in project pcgen by PCGen.

the class FaceToken method getFace.

public static OrderedPair getFace(CharID id) {
    String varName = ControlUtilities.getControlToken(Globals.getContext(), CControl.FACE);
    if (varName == null) {
        varName = "Face";
    }
    ResultFacet resultFacet = FacetLibrary.getFacet(ResultFacet.class);
    return (OrderedPair) resultFacet.getGlobalVariable(id, varName);
}
Also used : ResultFacet(pcgen.cdom.facet.analysis.ResultFacet) OrderedPair(pcgen.base.math.OrderedPair)

Example 3 with OrderedPair

use of pcgen.base.math.OrderedPair in project pcgen by PCGen.

the class FaceToken method getShortToken.

/**
	 * Get SHORT sub token
	 * 
	 * @param display
	 * @return SHORT sub toke
	 */
public static String getShortToken(CharacterDisplay display) {
    OrderedPair face = getFace(display.getCharID());
    String retString = "";
    if (CoreUtility.doublesEqual(face.getPreciseY().doubleValue(), 0.0)) {
        retString = Globals.getGameModeUnitSet().displayDistanceInUnitSet(face.getPreciseX().doubleValue()) + Globals.getGameModeUnitSet().getDistanceUnit();
    } else {
        retString = Globals.getGameModeUnitSet().displayDistanceInUnitSet(face.getPreciseX().doubleValue()) + Globals.getGameModeUnitSet().getDistanceUnit() + " x " + Globals.getGameModeUnitSet().displayDistanceInUnitSet(face.getPreciseY().doubleValue()) + Globals.getGameModeUnitSet().getDistanceUnit();
    }
    return retString;
}
Also used : OrderedPair(pcgen.base.math.OrderedPair)

Example 4 with OrderedPair

use of pcgen.base.math.OrderedPair in project pcgen by PCGen.

the class FaceToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier " + MOD_IDENTIFICATION + " had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    if (!context.getVariableContext().isLegalVariableID(scope, VAR_NAME)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid var name: " + VAR_NAME + ", Modified on " + race.getClass().getSimpleName() + ' ' + race.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(VAR_NAME, scope, modifier);
    context.getObjectContext().addToList(race, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) OrderedPair(pcgen.base.math.OrderedPair) FormatManager(pcgen.base.util.FormatManager)

Example 5 with OrderedPair

use of pcgen.base.math.OrderedPair in project pcgen by PCGen.

the class FaceToken method parseFace.

protected ParseResult parseFace(LoadContext context, PCTemplate fObj, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    @SuppressWarnings("unchecked") FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier SET had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    String varName = VAR_NAME;
    if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid fact name: " + varName + ", Modified on " + fObj.getClass().getSimpleName() + ' ' + fObj.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(varName, scope, modifier);
    context.getObjectContext().addToList(fObj, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) OrderedPair(pcgen.base.math.OrderedPair) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) FormatManager(pcgen.base.util.FormatManager)

Aggregations

OrderedPair (pcgen.base.math.OrderedPair)8 Test (org.junit.Test)2 LegalScope (pcgen.base.formula.base.LegalScope)2 ScopeInstance (pcgen.base.formula.base.ScopeInstance)2 FormatManager (pcgen.base.util.FormatManager)2 VarModifier (pcgen.cdom.content.VarModifier)2 ParseResult (pcgen.rules.persistence.token.ParseResult)2 DecimalFormat (java.text.DecimalFormat)1 ManagerFactory (pcgen.base.formula.base.ManagerFactory)1 ResultFacet (pcgen.cdom.facet.analysis.ResultFacet)1