コード例 #1
0
ファイル: WebTokenInfo.java プロジェクト: MalukuSeito/maptool
  void sendTokenRegisterdProperties(MTWebSocket mtws, String inResponseTo, JSONObject data) {
    String tokenId = data.getString("tokenId");
    Token token = findTokenFromId(tokenId);

    if (token == null) {
      System.out.println("DEBUG: sendTokenInfo(): Unable to find token " + tokenId);
      return;
      // FIXME: log this error
    }

    JSONObject jobj = new JSONObject();
    jobj.put("tokenId", tokenId);
    jobj.put("name", token.getName());
    jobj.put("label", token.getLabel());
    jobj.put("notes", token.getNotes());

    JSONObject jprop = new JSONObject();

    for (TokenProperty tp : MapTool.getCampaign().getTokenPropertyList(token.getPropertyType())) {
      JSONObject jp = new JSONObject();
      jp.put("name", tp.getName());
      if (tp.getShortName() != null) {
        jp.put("shortName", tp.getShortName());
      }
      if (tp.getDefaultValue() != null) {
        jp.put("defaultValue", tp.getDefaultValue());
      }
      jp.put("value", token.getProperty(tp.getName()));
      jp.put("showOnStatSheet", tp.isShowOnStatSheet());

      jprop.put(tp.getName(), jp);
    }

    jobj.put("properties", jprop);

    JSONArray jmacros = new JSONArray();

    for (MacroButtonProperties macro : token.getMacroList(false)) {
      JSONObject jmb = new JSONObject();
      jmb.put("label", macro.getLabel());
      jmb.put("tooltip", macro.getEvaluatedToolTip());
      jmb.put("index", macro.getIndex());
      jmb.put("fontColor", macro.getFontColorAsHtml());
      jmb.put("displayGroup", macro.getGroupForDisplay());
      jmb.put("group", macro.getGroup());
      jmb.put("index", macro.getIndex());
      jmb.put("autoExecute", macro.getAutoExecute());
      jmb.put("maxWidth", macro.getMaxWidth());
      jmb.put("minWidth", macro.getMinWidth());
      jmb.put("applyToTokens", macro.getApplyToTokens());

      jmacros.add(jmb);
    }

    jobj.put("macros", jmacros);

    mtws.sendMessage("tokenInfo", inResponseTo, jobj);
  }
コード例 #2
0
ファイル: WebTokenInfo.java プロジェクト: MalukuSeito/maptool
  void sendTokenProperties(MTWebSocket mtws, String inResponseTo, JSONObject data) {
    String tokenId = data.getString("tokenId");
    Token token = findTokenFromId(tokenId);

    if (token == null) {
      System.out.println("DEBUG: sendTokenInfo(): Unable to find token " + tokenId);
      return;
      // FIXME: log this error
    }

    JSONObject jobj = new JSONObject();
    jobj.put("tokenId", tokenId);

    JSONArray properties = new JSONArray();
    JSONObject propertiesMap = new JSONObject();

    JSONArray propToFetch = data.getJSONArray("propertyNames");
    for (int i = 0; i < propToFetch.size(); i++) {
      String pname = propToFetch.getString(i);
      String val;
      if (pname.startsWith(":")) {
        val = getTokenValue(token, pname);
      } else {

        val = token.getProperty(pname) == null ? null : token.getProperty(pname).toString();
      }
      JSONObject jprop = new JSONObject();
      jprop.put("name", pname);
      jprop.put("value", val);
      properties.add(jprop);
      propertiesMap.put(pname, val);
    }

    jobj.put("properties", properties);
    jobj.put("propertiesMap", propertiesMap);

    mtws.sendMessage("tokenProperties", inResponseTo, jobj);
  }