Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject$Slot


  @Test
  public void joinBoard() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String userName = "one";
    ScriptableObject board1 = api.joinBoard(boardId, userName);
    assertEquals(32, board1.get("size"));

    board1 = api.save(board1);
    assertEquals(1L, board1.get("id"));

    ScriptableObject board2 = api.getBoard(1);
    assertEquals(1, board2.get("id"));

    assertEquals(1, ((ScriptableObject) board2.get("players")).size());

    api.joinBoard(board2, userName);
    assertEquals(1, ((ScriptableObject) board2.get("players")).size());
    api.joinBoard(board2, "two");
    assertEquals(2, ((ScriptableObject) board2.get("players")).size());
  }
View Full Code Here


  @Test
  public void queueSettlement() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String playerName = "one";
    ScriptableObject board = api.joinBoard(boardId, playerName);
    assertEquals(32, board.get("size"));

    board = api.save(board);

    String settlementPoint = "{\"r\":1,\"g\":1,\"b\":1}";
    String resources = "{\"WHEAT\":1,\"FUR\":1,\"STONE\":1}";
    String settlementName = "HAMLET";
    api.queueSettlement(board, playerName, settlementPoint, settlementName,
        resources);

    // see if the location got saved
    ScriptableObject queuedSettlements = (ScriptableObject) ((ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName)).get("queuedSettlements");
    assertEquals(1, queuedSettlements.size());
    assertEquals(settlementName, queuedSettlements.get(settlementPoint));

    // see if the queued resources got saved
    ScriptableObject queuedSettlementsResources = (ScriptableObject) ((ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName))
        .get("queuedSettlementsResources");
    assertEquals(1, queuedSettlementsResources.size());
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("WHEAT"));
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("FUR"));
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("STONE"));

    // see if the queued resources got removed from the player
    ScriptableObject player = (ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName);
    assertEquals(3.0,
        ((ScriptableObject) player.get("resources")).get("WHEAT"));
    assertEquals(2.0,
        ((ScriptableObject) player.get("resources")).get("FUR"));
    assertEquals(3.0,
        ((ScriptableObject) player.get("resources")).get("STONE"));
  }
View Full Code Here

  @Ignore
  public void processQueuedSettlement() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String playerName = "one";
    ScriptableObject board = api.joinBoard(boardId, playerName);
    assertEquals(32, board.get("size"));

    board = api.save(board);

    String settlementPoint = "{\"r\":1,\"g\":1,\"b\":1}";
    String resources = "{\"WHEAT\":1,\"FUR\":1,\"STONE\":1}";
    String settlementName = "HAMLET";
    api.queueSettlement(board, playerName, settlementPoint, settlementName,
        resources);

    api.endTurn(board);

    // see if the queued location got cleared
    ScriptableObject scriptableObject3 = (ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName);
    ScriptableObject queuedSettlements = (ScriptableObject) scriptableObject3
        .get("queuedSettlements");
    assertEquals(0, queuedSettlements.size());

    // see if the queued resources got cleared
    ScriptableObject queuedSettlementsResources = (ScriptableObject) scriptableObject3
        .get("queuedSettlementsResources");
    assertEquals(0, queuedSettlementsResources.size());

    // see if the settlement got built
    // board.settlementLocations
    assertEquals(1,
        ((ScriptableObject) board.get("settlementLocations")).size());
    assertEquals(settlementName,
        ((ScriptableObject) board.get("settlementLocations"))
            .get(settlementPoint));

    // board.settlementOwnership
    assertEquals(1,
        ((ScriptableObject) board.get("settlementOwnership")).size());
    assertEquals(playerName,
        ((ScriptableObject) board.get("settlementOwnership"))
            .get(settlementPoint));

    // board.players[playerName].settlements
    ScriptableObject scriptableObject2 = (ScriptableObject) scriptableObject3
        .get("settlements");
    assertEquals(1, scriptableObject2.size());
    ScriptableObject scriptableObject = (ScriptableObject) scriptableObject2
        .get(settlementPoint);
    assertEquals(settlementName, scriptableObject.get("name"));

  }
View Full Code Here

  void enterContext() {
    this.cx = Context.enter();
  }

  public ScriptableObject execute(String expresion) {
    ScriptableObject result = null;
    this.cx = Context.enter();
    try {
      result = (ScriptableObject) this.cx.evaluateString(this.scope,
          expresion, "", 1, null);
    } catch (RuntimeException rte) {
View Full Code Here

          json = (String) a;
        } else {
          json = a.toString();
        }

        ScriptableObject mementos = (ScriptableObject) table
            .get("mementos");
        Long mementoId = getLong(result.getProperty("mementoId"));

        Step step1 = MiniProfiler.step("putProperty,valueOf,ge.parse");
        ScriptableObject.putProperty(mementos,
View Full Code Here

  private void completePurchase(final ScriptableObject player)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.completePurchase");
    try {
      final ScriptableObject disks = (ScriptableObject) player
          .get("cart");

      for (final Object diskName : disks.getIds()) {
        final ScriptableObject disk = getDisk((String) diskName);
        // ScriptableObject info = (ScriptableObject)
        // disks.get(diskName);

        final int count = API.getInteger(disks.get(diskName));
        for (int i = 0; i < count; i++) {
View Full Code Here

  private String confirm(final String jwt, final String user)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.confirm");
    try {
      final String sd = deserialize(jwt);
      final ScriptableObject f = ge.execute("_=" + sd);
      final ScriptableObject jwtResponse = (ScriptableObject) f
          .get("response");
      final ScriptableObject jwtRequest = (ScriptableObject) f
          .get("request");
      final String u = (String) jwtRequest.get("sellerData");
      // make sure its still the same person
      if (user != u) {
        return "";
      }

      final String orderId = (String) jwtResponse.get("orderId");
      // add the disks to the player
      final ScriptableObject player = getPlayer(user);
      completePurchase(player);

      savePlayer(player);

      return orderId;
View Full Code Here

  }

  private ScriptableObject createDisk() throws GameEngineException {
    Step step = MiniProfiler.step("API.createDisk");
    try {
      final ScriptableObject disk = (ScriptableObject) ge.invoke("Disk");
      return disk;
    } finally {
      step.close();
    }
  }
View Full Code Here

    Step step = MiniProfiler.step("API.createDisk(...)");
    try {
      // name, attack, defense, toughness, movement, wounds, flying,
      // swashbuckler,cost,
      // faction, alignment, diameter, description, price
      final ScriptableObject disk = (ScriptableObject) ge.invoke("Disk",
          new Object[] { name, type, attack, defense, toughness,
              movement, wounds, flying, swashbuckler, archer,
              arrows, bolts, fireballs, boulders,
              missileImmunity, firstblow, spellcaster, limit,
              cost, faction, alignment, diameter, description,
View Full Code Here

      for (HashMap<String, Object> diskMap : disks.values()) {
        final String diskJson = (String) diskMap.get("json");

        // final ScriptableObject o = ge.execute("_=" + diskJson);

        final ScriptableObject disk = createDisk();

        update(disk, ge.parse(diskJson));

        // header
        if (header) {
          for (final Object id : disk.getIds()) {

            if (disk.get(id) instanceof String
                || disk.get(id) instanceof Number
                || disk.get(id) instanceof Boolean) {
              csv.append(id + ",");
            }
          }
          header = false;
          csv.append("\n");
        }

        // data
        for (final Object id : disk.getIds()) {

          if (disk.get(id) instanceof String) {
            csv.append("\""
                + ((String) disk.get(id)).replaceAll("\"",
                    "\"\"") + "\",");
          } else if (disk.get(id) instanceof Number
              || disk.get(id) instanceof Boolean) {
            csv.append(disk.get(id) + ",");
          }
        }

        csv.append("\n");
      }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject$Slot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.