コード例 #1
0
  @Override
  public boolean execute(Sprite sprite) {
    final Vector<BroadcastScript> receiver =
        Stage.getInstance().getMessageContainer().getReceiverOfMessage(message);

    CatrobatDebug.debug("BroadcastWait - message: " + message);

    if (receiver == null) {
      CatrobatDebug.debug("receiver is null");
      return false;
    }

    if (receiver.size() == 0) {
      CatrobatDebug.debug("no receivers");
      return true;
    }

    CatThread executiveThread = CatScheduler.get().getThread(script.getExecutor());

    WaitCount signaler = new WaitCount(executiveThread);

    for (BroadcastScript receiverScript : receiver) {

      receiverScript.resetBroadcastScript();

      receiverScript.executeBroadcastWait(signaler);

      CatrobatDebug.debug(
          "BroadcastWait - receiver, script: "
              + receiverScript.getName()
              + ", sprite: "
              + receiverScript.getSprite().getName());
    }

    executiveThread.awaitSignal(signaler);

    return true;
  }
コード例 #2
0
 public WaitBrickTest() {
   stage = Stage.getInstance();
   scene = Scene.get();
   spriteManager = stage.getSpriteManager();
   scheduler = CatScheduler.get();
 }
コード例 #3
0
 public void gwtTearDown() {
   stage.setCanvas(null);
   stage.getSpriteManager().reset();
   CatScheduler.get().clear();
 }
コード例 #4
0
  public void testForeverNextCostume() {

    CatScheduler.get().clear();

    String spriteName = "spriteName";
    Sprite sprite = stage.getSpriteManager().getSprite(spriteName, true);

    String costumeName1 = "costume1";
    String costumeName2 = "costume2";
    String costumeName3 = "costume3";

    LookData costumeData1 = createCostumeData(costumeName1);
    LookData costumeData2 = createCostumeData(costumeName2);
    LookData costumeData3 = createCostumeData(costumeName3);

    sprite.addLookData(costumeData1);
    sprite.addLookData(costumeData2);
    sprite.addLookData(costumeData3);

    String scriptName = "scriptName";
    StartScript startScript = new StartScript(sprite, scriptName);

    NextLookBrick nextLookBrick = new NextLookBrick(spriteName);
    ForeverBrick repeatBrick = new ForeverBrick(spriteName);
    LoopEndBrick loopEndBrick = new LoopEndBrick(spriteName, repeatBrick);
    repeatBrick.setLoopEndBrick(loopEndBrick);

    startScript.addBrick(repeatBrick);
    startScript.addBrick(nextLookBrick);
    startScript.addBrick(loopEndBrick);

    sprite.addScript(startScript);

    // simulate SetLookBrick
    sprite.getLook().setLookData(costumeData1);
    sprite.getLook().hide();

    CatThread thread = new CatThread("threadName", startScript);
    CatScheduler.get().schedule(thread);

    CatScheduler.get().execute(); // repeat

    CatScheduler.get().execute(); // next
    CatScheduler.get().execute(); // loop end

    assertEquals(costumeName2, sprite.getLook().getLookData().getName());

    CatScheduler.get().execute(); // next
    CatScheduler.get().execute(); // loop end

    assertEquals(costumeName3, sprite.getLook().getLookData().getName());

    CatScheduler.get().execute(); // next
    CatScheduler.get().execute(); // loop end

    assertEquals(costumeName1, sprite.getLook().getLookData().getName());

    CatScheduler.get().execute(); // next
    CatScheduler.get().execute(); // loop end

    assertEquals(costumeName2, sprite.getLook().getLookData().getName());

    assertEquals(LoopEndBrick.FOREVER, loopEndBrick.getTimesToRepeat());

    assertEquals(1, CatScheduler.get().getThreadCount());

    CatScheduler.get().clear();
  }