Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feature-gdx
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
thelsing committed Nov 7, 2023
2 parents b81e7b5 + 7d89f48 commit 0dceaf2
Show file tree
Hide file tree
Showing 97 changed files with 8,016 additions and 558 deletions.
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sourceSets {
run {
args = ['-v=' + appSemVer]
applicationDefaultJvmArgs = ["-Xss8M", "-Dsun.java2d.d3d=false", "-Dsentry.environment=Development", "-Dfile.encoding=UTF-8",
"-Dpolyglot.engine.WarnInterpreterOnly=false",
"-Dpolyglot.engine.WarnInterpreterOnly=false","-DRUN_FROM_IDE=true",
"-DMAPTOOL_DATADIR=.maptool-" + vendor.toLowerCase(), "-XX:+ShowCodeDetailsInExceptionMessages",
"--add-opens=java.desktop/java.awt=ALL-UNNAMED", "--add-opens=java.desktop/java.awt.geom=ALL-UNNAMED",
"--add-opens=java.desktop/sun.awt.geom=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED",
Expand Down Expand Up @@ -219,7 +219,8 @@ runtime {
'jdk.unsupported.desktop',
'jdk.xml.dom',
'jdk.crypto.cryptoki',
'jdk.crypto.ec'
'jdk.crypto.ec',
'jdk.zipfs'
]


Expand All @@ -233,7 +234,8 @@ runtime {
"--add-opens=java.desktop/sun.awt.geom=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=javafx.web/javafx.scene.web=ALL-UNNAMED", "--add-opens=javafx.web/com.sun.webkit=ALL-UNNAMED", "--add-opens=javafx.web/com.sun.webkit.dom=ALL-UNNAMED",
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED","--add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED",
"--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED"]
"--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED"
]

imageOptions = []
imageName = project.name + developerRelease
Expand Down Expand Up @@ -499,7 +501,13 @@ dependencies {

implementation 'com.github.jknack:handlebars:4.3.1'
implementation 'com.github.jknack:handlebars-helpers:4.3.1'
implementation 'com.miglayout:miglayout-swing:11.0'


// Built In Add-on Libraries
implementation 'com.github.RPTools:maptool-builtin-addons:1.3'

// For advanced dice roller
implementation 'com.github.RPTools:advanced-dice-roller:1.0.3'

// libgdx
implementation 'com.github.thelsing:libgdx-jogl-backend:1.12.1'
Expand All @@ -516,8 +524,7 @@ dependencies {
implementation "com.badlogicgames.gdx-video:gdx-video-lwjgl3:1.3.2-SNAPSHOT"
implementation 'com.badlogicgames.box2dlights:box2dlights:1.5'
implementation 'com.badlogicgames.gdx:gdx-box2d:1.12.0'
implementation "com.badlogicgames.gdx:gdx-box2d-platform:1.12.0:natives-desktop"
}
implementation "com.badlogicgames.gdx:gdx-box2d-platform:1.12.0:natives-desktop"}


task configSentryRelease(type: Copy) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAME
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
30 changes: 30 additions & 0 deletions src/main/java/net/rptools/dicelib/expression/ExpressionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package net.rptools.dicelib.expression;

import java.util.List;
import java.util.regex.Pattern;
import net.rptools.dicelib.expression.function.ArsMagicaStress;
import net.rptools.dicelib.expression.function.CountSuccessDice;
import net.rptools.dicelib.expression.function.DropHighestRoll;
Expand All @@ -36,9 +38,11 @@
import net.rptools.dicelib.expression.function.ShadowRun5Dice;
import net.rptools.dicelib.expression.function.ShadowRun5ExplodeDice;
import net.rptools.dicelib.expression.function.UbiquityRoll;
import net.rptools.dicelib.expression.function.advanced.AdvancedDiceRolls;
import net.rptools.parser.*;
import net.rptools.parser.transform.RegexpStringTransformer;
import net.rptools.parser.transform.StringLiteralTransformer;
import org.javatuples.Pair;

public class ExpressionParser {
private static String[][] DICE_PATTERNS =
Expand Down Expand Up @@ -209,6 +213,11 @@ public class ExpressionParser {

private final Parser parser;

private final List<Pair<Pattern, String>> preprocessPatterns =
List.of(
new Pair<>(Pattern.compile("^([A-z]+)!\"([^\"]*)\"$"), "advancedRoll('$1', " + "'$2')"),
new Pair<>(Pattern.compile("^([A-z]+)!'([^']*)'$"), "advancedRoll('$1', " + "'$2')"));

public ExpressionParser() {
this(DICE_PATTERNS);
}
Expand Down Expand Up @@ -238,6 +247,7 @@ public ExpressionParser(String[][] regexpTransforms) {
parser.addFunction(new DropHighestRoll());
parser.addFunction(new KeepLowestRoll());
parser.addFunction(new ArsMagicaStress());
parser.addFunction(new AdvancedDiceRolls());

parser.addFunction(new If());

Expand Down Expand Up @@ -277,6 +287,9 @@ public Result evaluate(String expression, VariableResolver resolver, boolean mak
}
RunData.setCurrent(newRunData);

// Some patterns need pre-processing before the parser is called otherwise the parser
// creation will fail
expression = preProcess(expression);
synchronized (parser) {
final Expression xp =
makeDeterministic
Expand All @@ -292,4 +305,21 @@ public Result evaluate(String expression, VariableResolver resolver, boolean mak

return ret;
}

/**
* Pre-process the expression before it is parsed. This is used to convert some patterns into
* function calls that the parser can handle.
*
* @param expression The expression to pre-process
* @return The pre-processed expression
*/
private String preProcess(String expression) {
var trimmed = expression.trim();
for (Pair<Pattern, String> p : preprocessPatterns) {
if (p.getValue0().matcher(trimmed).find()) {
return p.getValue0().matcher(trimmed).replaceAll(p.getValue1());
}
}
return expression;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code 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.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.dicelib.expression.function.advanced;

import java.util.List;
import net.rptools.dicelib.expression.function.advanced.GenesysDiceRolls.DiceType;
import net.rptools.maptool.language.I18N;
import net.rptools.parser.Parser;
import net.rptools.parser.ParserException;
import net.rptools.parser.VariableResolver;
import net.rptools.parser.function.AbstractFunction;

/** Function to roll dice using the advanced dice roller. */
public class AdvancedDiceRolls extends AbstractFunction {

/** Constructor. */
public AdvancedDiceRolls() {
super(2, 2, false, "advancedRoll");
}

@Override
public Object childEvaluate(
Parser parser, VariableResolver resolver, String functionName, List<Object> parameters)
throws ParserException {
String diceName = parameters.get(0).toString().toLowerCase();
String diceExpression = parameters.get(1).toString();

try {
return switch (diceName) {
case "sw" -> new GenesysDiceRolls().roll(DiceType.StarWars, diceExpression, resolver);
case "gs" -> new GenesysDiceRolls().roll(DiceType.Genesys, diceExpression, resolver);
default -> throw new ParserException(
I18N.getText("advanced.roll.unknownDiceType", diceName));
};
} catch (IllegalArgumentException e) {
throw new ParserException(e.getMessage());
}
}
}
Loading

0 comments on commit 0dceaf2

Please sign in to comment.