Search in sources :

Example 21 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class VAbilityTokenTest method testName.

/**
	 * Tests the name subtoken of VABILITY.
	 */
public void testName() {
    VAbilityToken tok = new VAbilityToken();
    ExportHandler eh = new ExportHandler(null);
    PlayerCharacter character = getCharacter();
    assertEquals("Perform (Dance)", tok.getToken("VABILITY.FEAT.0.NAME", character, eh));
    assertEquals("Skill Focus", tok.getToken("VABILITY.FEAT.1.NAME", character, eh));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler)

Example 22 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class VariableProcessor method getExportVariable.

/**
	 * Returns a float value representing a variable used by the
	 * export process, for example, any token that is used in an outputsheet.
	 *
	 * @param valString   The name of the token to process. i.e. "LOCK.CON"
	 * @return   The evaluated value of valString as a String.
	 */
public String getExportVariable(String valString) {
    final StringWriter sWriter = new StringWriter();
    final BufferedWriter aWriter = new BufferedWriter(sWriter);
    final ExportHandler aExport = new ExportHandler(new File(""));
    aExport.replaceTokenSkipMath(pc, valString, aWriter);
    sWriter.flush();
    try {
        aWriter.flush();
    } catch (IOException e) {
        Logging.errorPrint("Couldn't flush the StringWriter used in PlayerCharacter.getVariableValue.", e);
    }
    final String bString = sWriter.toString();
    String result;
    try {
        // Float values
        result = String.valueOf(Float.parseFloat(bString));
    } catch (NumberFormatException e) {
        // String values
        result = bString;
    }
    return result;
}
Also used : StringWriter(java.io.StringWriter) ExportHandler(pcgen.io.ExportHandler) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 23 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class PCHasVarFunctionTest method testExec.

/**
	 * Test method for {@link pcgen.io.freemarker.PCBooleanFunction#exec(java.util.List)}.
	 * @throws Exception 
	 */
@Test
public void testExec() throws Exception {
    PlayerCharacter pc = getCharacter();
    ExportHandler eh = new ExportHandler(new File(""));
    PCHasVarFunction pchv = new PCHasVarFunction(pc, eh);
    Boolean result = (Boolean) pchv.exec(Collections.singletonList("FooV"));
    assertFalse("Should not have var", result);
    addAbility(AbilityCategory.FEAT, fooFeat);
    pc.calcActiveBonuses();
    assertTrue("Should have var FooV", pc.hasVariable("FooV"));
    result = (Boolean) pchv.exec(Collections.singletonList("FooV"));
    assertTrue("PCHasVar could not see FooV", result);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler) File(java.io.File) Test(org.junit.Test)

Example 24 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class TextTokenTest method testNumSuffix.

/**
	 * Test the output for negative numbers with fractions.
	 */
public void testNumSuffix() {
    TextToken tok = new TextToken();
    ExportHandler eh = new ExportHandler(null);
    PlayerCharacter character = getCharacter();
    character.setPCAttribute(NumericPCAttribute.AGE, 1);
    assertEquals("Suffix 1", "st", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 2);
    assertEquals("Suffix 2", "nd", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 3);
    assertEquals("Suffix 3", "rd", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 4);
    assertEquals("Suffix 4", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 11);
    assertEquals("Suffix 11", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 12);
    assertEquals("Suffix 12", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 13);
    assertEquals("Suffix 13", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 14);
    assertEquals("Suffix 14", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 21);
    assertEquals("Suffix 21", "st", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 22);
    assertEquals("Suffix 22", "nd", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 23);
    assertEquals("Suffix 23", "rd", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 24);
    assertEquals("Suffix 24", "th", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
    character.setPCAttribute(NumericPCAttribute.AGE, 133);
    assertEquals("Suffix 133", "rd", tok.getToken("TEXT.NUMSUFFIX.AGE", getCharacter(), eh));
}
Also used : TextToken(plugin.exporttokens.TextToken) PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler)

Example 25 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class TextTokenTest method testNumSuffixDirect.

/**
	 * Test the output for negative numbers with fractions.
	 */
public void testNumSuffixDirect() {
    TextToken tok = new TextToken();
    ExportHandler eh = new ExportHandler(null);
    assertEquals("Suffix 1", "st", tok.getToken("TEXT.NUMSUFFIX.1", getCharacter(), eh));
    assertEquals("Suffix 2", "nd", tok.getToken("TEXT.NUMSUFFIX.2", getCharacter(), eh));
    assertEquals("Suffix 3", "rd", tok.getToken("TEXT.NUMSUFFIX.3", getCharacter(), eh));
    assertEquals("Suffix 4", "th", tok.getToken("TEXT.NUMSUFFIX.4", getCharacter(), eh));
    assertEquals("Suffix 12", "th", tok.getToken("TEXT.NUMSUFFIX.12", getCharacter(), eh));
    assertEquals("Suffix 133", "rd", tok.getToken("TEXT.NUMSUFFIX.133", getCharacter(), eh));
    assertEquals("Suffix 133", "rd", tok.getToken("TEXT.NUMSUFFIX.133.0", getCharacter(), eh));
}
Also used : TextToken(plugin.exporttokens.TextToken) ExportHandler(pcgen.io.ExportHandler)

Aggregations

ExportHandler (pcgen.io.ExportHandler)31 PlayerCharacter (pcgen.core.PlayerCharacter)24 File (java.io.File)7 BufferedWriter (java.io.BufferedWriter)6 StringWriter (java.io.StringWriter)4 IOException (java.io.IOException)3 TextToken (plugin.exporttokens.TextToken)3 OutputStreamWriter (java.io.OutputStreamWriter)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1 ExportException (pcgen.io.ExportException)1 PCGFile (pcgen.io.PCGFile)1