Skip to content

Commit

Permalink
Merge pull request #4531 from bubblobill/gm_campaign_macro_functions
Browse files Browse the repository at this point in the history
MetaMacro Functionality for GM & Campaign Panel Buttons
  • Loading branch information
cwisniew authored Dec 7, 2023
2 parents d8b76e5 + d4217ef commit 4165ec9
Show file tree
Hide file tree
Showing 2 changed files with 764 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import net.rptools.maptool.client.functions.*;
import net.rptools.maptool.client.functions.json.JSONMacroFunctions;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.InitiativeList;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.TokenProperty;
import net.rptools.maptool.model.*;
import net.rptools.maptool.util.FunctionUtil;
import net.rptools.parser.ParserException;
import net.rptools.parser.VariableModifiers;
Expand All @@ -42,10 +40,19 @@ public class MapToolVariableResolver implements VariableResolver {
private static final Logger LOGGER = LogManager.getLogger(MapToolVariableResolver.class);

/** The prefix for querying and setting state values . */
public static final String STATE_PREFIX = "state.";
public static final String BAR_PREFIX = "bar.";

/** The variable name for querying and setting the current round in initiative. */
public static final String INITIATIVE_ROUND = "init.round";

/** The variable name for querying and setting the current initiative. */
public static final String INITIATIVE_CURRENT = "init.current";

public static final String CAMPAIGN_PANEL = "campaign";
public static final String GM_PANEL = "gm";

/** The prefix for querying and setting state values . */
public static final String BAR_PREFIX = "bar.";
public static final String STATE_PREFIX = "state.";

/** The variable name for querying and setting token halos. */
public static final String TOKEN_HALO = "token.halo";
Expand All @@ -65,23 +72,25 @@ public class MapToolVariableResolver implements VariableResolver {
/** The variable name for querying and setting the initiative of the current token. */
public static final String TOKEN_INITIATIVE_HOLD = "token.initHold";

/** The variable name for querying and setting the current round in initiative. */
public static final String INITIATIVE_ROUND = "init.round";

/** The variable name for querying and setting the current initiative. */
public static final String INITIATIVE_CURRENT = "init.current";

/** The variable name for querying and setting token visible state */
private static final String TOKEN_VISIBLE = "token.visible";

private static final Map<String, Object> CONSTANTS =
Map.of(
"true", BigDecimal.ONE,
"false", BigDecimal.ZERO,
"json.null", JsonNull.INSTANCE,
"json.true", new JsonPrimitive(true),
"json.false", new JsonPrimitive(false));

"true",
BigDecimal.ONE,
"false",
BigDecimal.ZERO,
"json.null",
JsonNull.INSTANCE,
"json.true",
new JsonPrimitive(true),
"json.false",
new JsonPrimitive(false),
"panel.campaign",
CAMPAIGN_PANEL,
"panel.gm",
GM_PANEL);
private final Map<String, Object> variables = new CaseInsensitiveHashMap<>();

private List<Runnable> delayedActionList;
Expand Down Expand Up @@ -110,7 +119,7 @@ public MapToolVariableResolver(Token tokenInContext) {
try {
setVariable(entry.getKey(), entry.getValue());
} catch (ParserException e) {
LOGGER.error("Error: Unable to set comstant " + entry.getKey() + " to " + entry.getValue());
LOGGER.error("Error: Unable to set constant " + entry.getKey() + " to " + entry.getValue());
}
}
}
Expand Down Expand Up @@ -166,7 +175,6 @@ public boolean containsVariable(String name) {

@Override
public boolean containsVariable(String name, VariableModifiers mods) {

// If we don't have the value then we'll prompt for it
return true;
}
Expand Down Expand Up @@ -197,7 +205,6 @@ public Object getVariable(String name, VariableModifiers mods) throws ParserExce

Object result = null;
if (tokenInContext != null) {

if (name.startsWith(STATE_PREFIX)) {
String stateName = name.substring(STATE_PREFIX.length());
return TokenStateFunction.getState(tokenInContext, stateName);
Expand Down
Loading

0 comments on commit 4165ec9

Please sign in to comment.