Example #1
0
void EntityIdentifier::parseCategoryDefinition(JSONObject *data, int packID) {
  QString category;
  if (data->has("category"))
    category = data->at("category")->asString();
  else
    category = "Unknown";

  QColor catcolor;
  if (data->has("catcolor")) {
    QString colorname = data->at("catcolor")->asString();
    catcolor.setNamedColor(colorname);
    assert(catcolor.isValid());
  } else {  // use hashed by name instead
    quint32 hue = qHash(category);
    catcolor.setHsv(hue % 360, 255, 255);
  }
  addCategory(qMakePair(category, catcolor));

  if (data->has("entity")) {
    JSONArray *entities = dynamic_cast<JSONArray *>(data->at("entity"));
    int len = entities->length();

    for (int e = 0; e < len; e++)
      parseEntityDefinition(dynamic_cast<JSONObject *>(entities->at(e)),
                            category, catcolor, packID);
  }
}
Example #2
0
void EntityIdentifier::parseEntityDefinition(JSONObject *entity,
                                             QString const &category,
                                             QColor catcolor, int packID) {
  QString id("unknown");
  if (entity->has("id"))
    id = entity->at("id")->asString().toLower();

  if (entity->has("catcolor")) {
    QString colorname = entity->at("catcolor")->asString();
    catcolor.setNamedColor(colorname);
    assert(catcolor.isValid());
  }

  QColor color;
  if (entity->has("color")) {
    QString colorname = entity->at("color")->asString();
    color.setNamedColor(colorname);
    assert(color.isValid());
  } else {  // use hashed by name instead
    quint32 hue = qHash(id);
    color.setHsv(hue % 360, 255, 255);
  }

  QString name;
  if (entity->has("name")) {
    // use provided name
    name = entity->at("name")->asString();
  } else {
    // or try to build name automatically
    // split at underscores
    QStringList tokens = id.toLower().replace('_',' ').split(" ");
    // make first character uppercase
    for (QList<QString>::iterator tokItr = tokens.begin(); tokItr != tokens.end(); ++tokItr) {
      (*tokItr) = (*tokItr).at(0).toUpper() + (*tokItr).mid(1);
    }
    name = tokens.join(" ");
  }

  // enter entity into manager
  TentityMap& map = getMapForPackID(packID);
  map.insert(id, EntityInfo(name, category, catcolor, color));

  // add duplicates: when new 1.11+ or 1.13+ id definitions are available
  // legacy id is stored in own definition element (duplicates automatically)
  if (entity->has("idlist")) {
    JSONArray *idlist = dynamic_cast<JSONArray *>(entity->at("idlist"));
    int len = idlist->length();
    for (int j = 0; j < len; j++) {
      QString idl = entity->at("idlist")->at(j)->asString().toLower();
      map.insert(idl, EntityInfo(name, category, catcolor, color));
    }
  }
}
void OuyaPlugin_asyncOuyaRequestProducts(const char* productsJson, s3eCallback onSuccess, s3eCallback onFailure, s3eCallback onCancel)
{
    IwTrace(ODK, ("ODK_platform: OuyaPlugin_asyncOuyaRequestProducts"));

    std::string msg = "OuyaPlugin_asyncOuyaRequestProducts: productsJson=";
    msg.append(productsJson);
    IwTrace(ODK, (msg.c_str()));

    //convert JSON to product id array
    JSONArray jsonArray = JSONArray(productsJson);

    std::vector<std::string> productIds;

    for (int i = 0; i < jsonArray.length(); i++)
    {
        std::string productId = jsonArray.getString(i);
        productIds.push_back(productId);
    }

    OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);

    g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}
Example #4
0
void FlatteningConverter::parseDefinition(
        JSONObject *b,
        int *parentID,
        int pack) {

  // get the ancient block ID
  int bid, data(0);
  if (parentID == NULL) {
    bid = b->at("id")->asNumber();
  } else {
    bid = *parentID;
    data = b->at("data")->asNumber();
    bid |= data << 8;
  }

  // try to translate old block name into new flatname
  QString flatname;
  if (b->has("name")) {
    flatname = "minecraft:" + b->at("name")->asString().toLower().replace(" ", "_");
  } else if (parentID != NULL) {
    flatname = palette[*parentID].name;
  } else {
    flatname = "Unknown";
  }

  // or use provided flatname instead
  if (b->has("flatname"))
    flatname = b->at("flatname")->asString();

  palette[bid].name = flatname;
  palette[bid].hid  = qHash(palette[bid].name);
  if ((parentID == NULL) && (data == 0)) {
    // spread main block type for data == 0
    for (int d=1; d<16; d++) {
      int sid = bid | (d<<8);
      palette[sid].name = flatname;
      palette[sid].hid  = palette[bid].hid;
    }
  }
  //  packs[pack].append(block);

  // get optional mask value (or guess default)
  int mask = 0;
  if (b->has("mask")) {
    mask = b->at("mask")->asNumber();
  } else if (b->has("variants")) {
    mask = 0x0f;
  }

  // recursive parsing of variants (with data)
  if (b->has("variants")) {
    JSONArray *variants = dynamic_cast<JSONArray *>(b->at("variants"));
    int vlen = variants->length();
    for (int j = 0; j < vlen; j++) {
      parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), &bid, pack);
    }
    // spread variants in masked bid
    for (int j = vlen; j < 16; j++) {
      int id  = bid | (j << 8);
      int mid = bid | ((j & mask) << 8);
      palette[id].name = palette[mid].name;
      palette[id].hid  = palette[mid].hid;
    }
  }
}
Example #5
0
void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent,
                                      int pack) {
  int id;
  if (parent == NULL) {
    id = b->at("id")->asNumber();
  } else {
    id = parent->id;
    int data = b->at("data")->asNumber();
    id |= data << 12;
  }
  BlockInfo *block = new BlockInfo();
  block->id = id;

  if (b->has("name"))
    block->setName(b->at("name")->asString());
  else if (parent != NULL)
    block->setName(parent->getName());
  else
    block->setName("Unknown");
  block->enabled = true;

  if (b->has("transparent")) {
    block->transparent = b->at("transparent")->asBool();
    block->rendernormal = false;  // for most cases except the following
    if (b->has("rendercube"))
      block->rendernormal = b->at("rendercube")->asBool();
    block->spawninside = false;  // for most cases except the following
    if (b->has("spawninside"))
      block->spawninside = b->at("spawninside")->asBool();
  } else if (parent != NULL) {
    block->transparent = parent->transparent;
    block->rendernormal = parent->rendernormal;
    block->spawninside = parent->spawninside;
  } else {
    block->transparent = false;
    block->rendernormal = true;
    block->spawninside = false;
  }

  if (b->has("liquid"))
    block->liquid = b->at("liquid")->asBool();
  else if (parent != NULL)
    block->liquid = parent->liquid;
  else
    block->liquid = false;

  if (b->has("canProvidePower"))
    block->providepower = b->at("canProvidePower")->asBool();
  else if (parent != NULL)
    block->providepower = parent->providepower;
  else
    block->providepower = false;

  if (b->has("alpha"))
    block->alpha = b->at("alpha")->asNumber();
  else if (parent != NULL)
    block->alpha = parent->alpha;
  else
    block->alpha = 1.0;

  QColor blockcolor;
  if (b->has("color")) {
    QString colorname = b->at("color")->asString();
    if (colorname.length() == 6) {
      // check if this is an old color definition with missing '#'
      bool ok;
      colorname.toInt(&ok,16);
      if (ok)
        colorname.push_front('#');
    }
    blockcolor.setNamedColor(colorname);
    assert(blockcolor.isValid());
  } else if (parent != NULL) {
    // copy brightest color from parent
    blockcolor = parent->colors[15];
  } else {
    // use hashed by name instead
    quint32 hue = qHash(block->getName());
    blockcolor.setHsv(hue % 360, 255, 255);
  }

  // pre-calculate light spectrum
  for (int i = 0; i < 16; i++) {
    // calculate light attenuation similar to Minecraft
    // except base 90% here, were Minecraft is using 80% per level
    double light_factor = pow(0.90,15-i);
    block->colors[i].setRgb(light_factor*blockcolor.red(),
                            light_factor*blockcolor.green(),
                            light_factor*blockcolor.blue(),
                            255*block->alpha );
  }

  if (b->has("mask"))
    block->mask = b->at("mask")->asNumber();
  else if (b->has("variants"))
    block->mask = 0x0f;
  else
    block->mask = 0x00;

  if (b->has("variants")) {
    JSONArray *variants = dynamic_cast<JSONArray *>(b->at("variants"));
    int vlen = variants->length();
    for (int j = 0; j < vlen; j++)
      parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), block, pack);
  }

  blocks[id].append(block);
  packs[pack].append(block);
}