Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetaMacro Functionality for GM & Campaign Panel Buttons #4531

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading