Exemplo n.º 1
0
void AddFxContextMenu::loadFxGroup(TIStream *is) {
  while (!is->eos()) {
    std::string tagName;
    if (is->matchTag(tagName)) {
      QString groupName = QString::fromStdString(tagName);

      std::unique_ptr<QMenu> insertFxGroup(new QMenu(groupName, m_insertMenu));
      std::unique_ptr<QMenu> addFxGroup(new QMenu(groupName, m_addMenu));
      std::unique_ptr<QMenu> replaceFxGroup(
          new QMenu(groupName, m_replaceMenu));

      loadFx(is, insertFxGroup.get(), addFxGroup.get(), replaceFxGroup.get());

      if (!insertFxGroup->isEmpty())
        m_insertMenu->addMenu(insertFxGroup.release());
      if (!addFxGroup->isEmpty()) m_addMenu->addMenu(addFxGroup.release());
      if (!replaceFxGroup->isEmpty())
        m_replaceMenu->addMenu(replaceFxGroup.release());

      is->closeChild();
    }
  }
}
Exemplo n.º 2
0
void GameLevel::load(const std::string &levelFile) {
  unload();

  std::string buffer = levelFile.empty() ? sTemplateMap : JsonParser::getBuffer(levelFile);
  if (buffer.empty()) {
    load("");
    return;
  }
  JsonParser parser(buffer);
  if (!parser) {
    CCLOG("%s", buffer.c_str());
    CCLOGERROR("Cannot load the level file: %s", levelFile.c_str());
  }

  CCLOG("Loading level file: %s", levelFile.empty() ? "Template" : levelFile.c_str());

  auto& doc = parser.getCurrentDocument();

  std::string paletteFile = doc[LEVEL_PALETTE_FILE].GetString();
  CC_SAFE_DELETE(mPalette);
  mPalette = new ColorPalette(paletteFile);

  // Shadows.
  if (doc.HasMember(SHADOW_GROUP)) {
    mNumShadowGroup = doc[SHADOW_GROUP].Size();
    parser.parseArray(doc, SHADOW_GROUP, [&](JsonSizeT i, JsonValueT &val) {
      addShadowGroup();
      mShadows[i]->load(val);
      initShadowGroup(i);
    });
  }

  // Sprites.
  CC_ASSERT(mSpriteList.empty());
  if (doc.HasMember(GAME_SPRITES)) {
    parser.parseArray(doc, GAME_SPRITES, [&](JsonSizeT i, JsonValueT &val) {
      mSpriteList.push_back(new GameSprite());
      mSpriteList.back()->load(val);
      mGameLayer->getBlockRoot()->addChild(mSpriteList.back()->getSprite(),
                                           mSpriteList.back()->ZOrder);
    });
  }

  // Effects.
  CC_ASSERT(mEffects.empty());
  if (doc.HasMember(GAME_FX)) {
    parser.parseArray(doc, GAME_FX, [&](JsonSizeT i, JsonValueT &val) {
      mEffects.push_back(val.GetString());
    });
  }
  loadFx();

  // Objects.
  mHeroSpawnPos = doc[LEVEL_SPAWN_POS].GetVec2();
  createHero(mHeroSpawnPos);
  parser.parseArray(doc, LEVEL_BLOCK_ARRAY, [&](JsonSizeT i, JsonValueT& val) {
    mObjectManager->createObject(val);
  });

  // Update shadow right after loading objects.
  for (auto sm : mShadows) {
    sm->update(0);
  }
  
  // Time events.
  CC_ASSERT(mTimeEvents.empty());
  if (doc.HasMember(TIME_EVENTS)) {
    parser.parseArray(doc, TIME_EVENTS, [&](JsonSizeT i, JsonValueT &val) {
      auto timeEvent = new TimeEvent();
      timeEvent->load(val);
      mTimeEvents.push_back(timeEvent);
    });
  }

  updateBounds();
  mBackground->clear();
  mBackground->drawSolidRect({mBounds.getMinX(), mBounds.getMinY()},
                             {mBounds.getMaxX(), mBounds.getMaxY()},
                             Color4F(mPalette->getBackgroundColor()));

  setCurrentFile(levelFile);

  mGameLayer->afterLoad();
}