Ejemplo n.º 1
0
  @Override
  public Object childEvaluate(Parser parser, String functionName, List<Object> parameters)
      throws ParserException {

    Object numArgs = parser.getVariable("macro.args.num");
    int argCount = 0;

    if (numArgs instanceof BigDecimal) {
      argCount = ((BigDecimal) numArgs).intValue();
    }

    if (functionName.equals("argCount")) {
      return BigDecimal.valueOf(argCount);
    }

    if (parameters.size() != 1 || !(parameters.get(0) instanceof BigDecimal)) {
      throw new ParserException(I18N.getText("macro.function.args.incorrectParam", "arg"));
    }

    int argNo = ((BigDecimal) parameters.get(0)).intValue();

    if (argCount == 0 && argNo == 0) {
      return parser.getVariable("macro.args");
    }

    if (argNo < 0 || argNo >= argCount) {
      throw new ParserException(
          I18N.getText("macro.function.args.outOfRange", "arg", argNo, argCount - 1));
    }

    return parser.getVariable("macro.args." + argNo);
  }
Ejemplo n.º 2
0
  /**
   * Gets the label of the token
   *
   * @param parser The parser that called the Object.
   * @param args The arguments passed.
   * @return the name of the token.
   * @throws ParserException when an error occurs.
   */
  private Object getLabel(Parser parser, List<Object> args) throws ParserException {
    Token token;

    if (args.size() == 1) {
      if (!MapTool.getParser().isMacroTrusted()) {
        throw new ParserException(I18N.getText("macro.function.general.noPermOther", "getLabel"));
      }

      token = FindTokenFunctions.findToken(args.get(0).toString(), null);
      if (token == null) {
        throw new ParserException(
            I18N.getText(
                "macro.function.general.unknownToken", "getLabel", args.get(0).toString()));
      }
    } else if (args.isEmpty()) {
      MapToolVariableResolver res = (MapToolVariableResolver) parser.getVariableResolver();
      token = res.getTokenInContext();
      if (token == null) {
        throw new ParserException(
            I18N.getText("macro.function.general.noImpersonated", "getLabel"));
      }
    } else {
      throw new ParserException(
          I18N.getText("macro.function.general.tooManyParam", "getLabel", 1, args.size()));
    }
    return getLabel(token);
  }
Ejemplo n.º 3
0
  /**
   * Sets the label of the token.
   *
   * @param parser The parser that called the Object.
   * @param args The arguments passed.
   * @return the new name of the token.
   * @throws ParserException when an error occurs.
   */
  private Object setLabel(Parser parser, List<Object> args) throws ParserException {
    Token token;

    if (args.size() == 2) {
      if (!MapTool.getParser().isMacroTrusted()) {
        throw new ParserException(I18N.getText("macro.function.general.noPermOther", "setLabel"));
      }
      token = FindTokenFunctions.findToken(args.get(1).toString(), null);
      if (token == null) {
        throw new ParserException(
            I18N.getText(
                "macro.function.general.unknownToken", "setLabel", args.get(1).toString()));
      }
    } else if (args.size() == 1) {
      MapToolVariableResolver res = (MapToolVariableResolver) parser.getVariableResolver();
      token = res.getTokenInContext();
      if (token == null) {
        throw new ParserException(
            I18N.getText("macro.function.general.noImpersonated", "setLabel"));
      }
    } else if (args.isEmpty()) {
      throw new ParserException(
          I18N.getText("macro.function.general.notEnoughParam", "setLabel", 1, args.size()));
    } else {
      throw new ParserException(
          I18N.getText("macro.function.general.tooManyParam", "setLabel", 2, args.size()));
    }
    setLabel(token, args.get(0).toString());
    Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
    MapTool.serverCommand().putToken(zone.getId(), token);
    zone.putToken(token);
    return args.get(0);
  }
Ejemplo n.º 4
0
 public void execute(MacroContext context, String macro, MapToolMacroContext executionContext) {
   String result = roll(macro);
   if (result != null) {
     if (!MapTool.getPlayer().isGM()) {
       MapTool.addMessage(
           new TextMessage(
               TextMessage.Channel.GM,
               null,
               MapTool.getPlayer().getName(),
               "* " + I18N.getText("rollsecret.gm.string", MapTool.getPlayer().getName(), result),
               context.getTransformationHistory()));
       MapTool.addMessage(
           new TextMessage(
               TextMessage.Channel.ME,
               null,
               MapTool.getPlayer().getName(),
               I18N.getText("rollsecret.self.string"),
               context.getTransformationHistory()));
     } else {
       MapTool.addMessage(
           new TextMessage(
               TextMessage.Channel.GM,
               null,
               MapTool.getPlayer().getName(),
               "* " + I18N.getText("rollsecret.gmself.string", result),
               context.getTransformationHistory()));
     }
   }
 }
Ejemplo n.º 5
0
  protected String roll(String roll) {

    try {
      String text = roll + " => " + MapTool.getParser().expandRoll(roll);

      return text;
    } catch (Exception e) {
      MapTool.addLocalMessage("<b>" + I18N.getText("roll.general.unknown", roll) + "</b>");
      return null;
    }
  }
Ejemplo n.º 6
0
    public EditLabelDialog(Label label) {
      super(MapTool.getFrame(), I18N.getText("tool.label.dialogtitle"), true);
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);

      EditLabelPanel panel = new EditLabelPanel(this);
      panel.bind(label);

      add(panel);
      getRootPane().setDefaultButton(panel.getOKButton());
      pack();
    }
Ejemplo n.º 7
0
  /**
   * Set the name of this token to the provided string. There is a potential exposure of information
   * to the player in this method: through repeated attempts to name a token they own to another
   * name, they could determine which token names the GM is already using. Fortunately, the
   * showError() call makes this extremely unlikely due to the interactive nature of a failure.
   *
   * @param name
   * @throws IOException
   */
  public void setName(String name) throws IllegalArgumentException {
    // Let's see if there is another Token with that name (only if Player is not GM)
    if (!MapTool.getPlayer().isGM() && !MapTool.getParser().isMacroTrusted()) {
      Zone curZone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
      List<Token> tokensList = curZone.getTokens();

      for (int i = 0; i < tokensList.size(); i++) {
        String curTokenName = tokensList.get(i).getName();
        if (curTokenName.equalsIgnoreCase(name)) {
          MapTool.showError(I18N.getText("Token.error.unableToRename", name));
          throw new IllegalArgumentException("Player dropped token with duplicate name");
        }
      }
    }
    this.name = name;
    fireModelChangeEvent(new ModelChangeEvent(this, ChangeEvent.name, name));
  }
Ejemplo n.º 8
0
 @Override
 public LuaValue call(LuaValue pnts, LuaValue p) {
   Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
   if (!token.isSelfOrTrusted()) {
     throw new LuaError(
         new ParserException(
             I18N.getText("macro.function.general.noPerm", "token.movedOverPoints")));
   }
   String points = pnts.checkjstring();
   if (p.isnil()) {
     Path<?> path = token.getToken().getLastPath();
     return LuaConverters.fromJson(
         TokenMoveFunctions.pathPointsToJSONArray(
             TokenMoveFunctions.crossedPoints(
                 zone, token.getToken(), points, TokenMoveFunctions.getLastPathList(path, true))));
   } else {
     String jsonPath = ObjectUtils.toString(LuaConverters.toJson(p));
     return LuaConverters.fromJson(
         TokenMoveFunctions.pathPointsToJSONArray(
             TokenMoveFunctions.crossedPoints(zone, token.getToken(), points, jsonPath)));
   }
 }
  /**
   * Given a string (normally from the JTextArea which holds the properties for a Property Type)
   * this method converts those lines into a List of EditTokenProperty objects. It checks for
   * duplicates along the way, ignoring any it finds. (Should produce a list of warnings to indicate
   * which ones are duplicates. See the Light/Sight code for examples.)
   *
   * @param propertyText
   * @return
   */
  private List<TokenProperty> parseTokenProperties(String propertyText)
      throws IllegalArgumentException {
    List<TokenProperty> propertyList = new ArrayList<TokenProperty>();
    BufferedReader reader = new BufferedReader(new StringReader(propertyText));
    CaseInsensitiveHashMap<String> caseCheck = new CaseInsensitiveHashMap<String>();
    List<String> errlog = new LinkedList<String>();
    try {
      String original, line;
      while ((original = reader.readLine()) != null) {
        line = original = original.trim();
        if (line.length() == 0) {
          continue;
        }

        TokenProperty property = new TokenProperty();

        // Prefix
        while (true) {
          if (line.startsWith("*")) {
            property.setShowOnStatSheet(true);
            line = line.substring(1);
            continue;
          }
          if (line.startsWith("@")) {
            property.setOwnerOnly(true);
            line = line.substring(1);
            continue;
          }
          if (line.startsWith("#")) {
            property.setGMOnly(true);
            line = line.substring(1);
            continue;
          }

          // Ran out of special characters
          break;
        }

        // default value
        // had to do this here since the short name is not built
        // to take advantage of multiple opening/closing parenthesis
        // in a single property line
        int indexDefault = line.indexOf(":");
        if (indexDefault > 0) {
          String defaultVal = line.substring(indexDefault + 1).trim();
          if (defaultVal.length() > 0) {
            property.setDefaultValue(defaultVal);
          }

          // remove the default value from the end of the string...
          line = line.substring(0, indexDefault);
        }
        // Suffix
        // (Really should handle nested parens here)
        int index = line.indexOf("(");
        if (index > 0) {
          String shortName = line.substring(index + 1, line.lastIndexOf(")")).trim();
          if (shortName.length() > 0) {
            property.setShortName(shortName);
          }
          line = line.substring(0, index).trim();
        }
        property.setName(line);
        // Since property names are not case-sensitive, let's make sure that we don't
        // already have this name represented somewhere in the list.
        String old = caseCheck.get(line);
        if (old != null) {
          // Perhaps these properties should produce warnings at all, but what it someone
          // is actually <b>using them as property names!</b>
          if (old.startsWith("---"))
            errlog.add(
                I18N.getText("msg.error.mtprops.properties.duplicateComment", original, old));
          else errlog.add(I18N.getText("msg.error.mtprops.properties.duplicate", original, old));
        } else {
          propertyList.add(property);
          caseCheck.put(line, original);
        }
      }

    } catch (IOException ioe) {
      // If this happens, I'll check into the nearest insane asylum
      MapTool.showError("IOException during parsing of properties?!", ioe);
    }
    caseCheck.clear();
    if (!errlog.isEmpty()) {
      errlog.add(0, I18N.getText("msg.error.mtprops.properties.title", editingType));
      errlog.add(I18N.getText("msg.error.mtprops.properties.ending"));
      MapTool.showFeedback(errlog.toArray());
      errlog.clear();
      throw new IllegalArgumentException(); // Don't save the properties...
    }
    return propertyList;
  }
Ejemplo n.º 10
0
  public ToolbarPanel(Toolbox tbox) {
    setRollover(true);

    toolbox = tbox;
    optionPanel = new JPanel(new CardLayout());

    final OptionPanel pointerGroupOptionPanel = createPointerPanel();
    final JToggleButton pointerGroupButton =
        createButton(
            "net/rptools/maptool/client/image/tool/pointer-blue.png",
            "net/rptools/maptool/client/image/tool/pointer-blue-off.png",
            pointerGroupOptionPanel,
            I18N.getText("tools.interaction.tooltip"));

    pointerGroupButton.setSelected(true);
    pointerGroupOptionPanel.activate();

    final JSeparator vertSplit = new JSeparator(JSeparator.VERTICAL);
    final Component vertSpacer = Box.createHorizontalStrut(10);

    final JSeparator horizontalSplit = new JSeparator(JSeparator.HORIZONTAL);
    horizontalSplit.setVisible(false);
    final Component horizontalSpacer = Box.createVerticalStrut(10);
    horizontalSpacer.setVisible(false);

    add(pointerGroupButton);
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/draw-blue.png",
            "net/rptools/maptool/client/image/tool/draw-blue-off.png",
            createDrawPanel(),
            I18N.getText("tools.drawing.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/temp-blue.png",
            "net/rptools/maptool/client/image/tool/temp-blue-off.png",
            createTemplatePanel(),
            I18N.getText("tools.template.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/fog-blue.png",
            "net/rptools/maptool/client/image/tool/fog-blue-off.png",
            createFogPanel(),
            I18N.getText("tools.fog.tooltip")));
    add(
        createButton(
            "net/rptools/maptool/client/image/tool/eye-blue.png",
            "net/rptools/maptool/client/image/tool/eye-blue-off.png",
            createTopologyPanel(),
            I18N.getText("tools.topo.tooltip")));
    add(vertSplit);
    add(horizontalSplit);
    add(vertSpacer);
    add(horizontalSpacer);
    add(optionPanel);
    add(Box.createGlue());
    add(createZoneSelectionButton());

    // Non visible tools
    tbox.createTool(GridTool.class);
    tbox.createTool(BoardTool.class);
    tbox.createTool(FacingTool.class);
    tbox.createTool(StampTool.class);

    addPropertyChangeListener(
        "orientation",
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            int orientation = (Integer) evt.getNewValue();

            horizontalSplit.setVisible(orientation == JToolBar.VERTICAL);
            horizontalSpacer.setVisible(orientation == JToolBar.VERTICAL);

            vertSplit.setVisible(orientation == JToolBar.HORIZONTAL);
            vertSpacer.setVisible(orientation == JToolBar.HORIZONTAL);
          }
        });
  }