Exemplo n.º 1
0
static json_t *btRace_toJson(const void *vbr)
{
	btRace_t	*br = (btRace_t *)vbr;
	json_t		*root;

	root = json_object();

	JSON_NUMBER(root, "base_st", br->base_st);
	JSON_NUMBER(root, "base_iq", br->base_iq);
	JSON_NUMBER(root, "base_dx", br->base_dx);
	JSON_NUMBER(root, "base_cn", br->base_cn);
	JSON_NUMBER(root, "base_lk", br->base_lk);
	JSON_BTSTRING(root, "name", br->name);
	json_object_set_new(root, "starting_classes", 
			cnvList_toJsonArray(br->startingClasses));

	return root;
}
Exemplo n.º 2
0
static json_t *btcity_toJson(const void *vc)
{
	btcity_t	*btc = (btcity_t *)vc;
	json_t		*root;
	json_t		*node;

	root = json_object();

	JSON_BTSTRING(root, "title", btc->title);
	JSON_BTSTRING(root, "guildExitSquare", btc->guildExitSquare);
	JSON_BTSTRING(root, "guildExitDir", btc->guildExitDir);
	json_object_set_new(root, "squares", cnvList_toJsonObject(btc->sqs));
	json_object_set_new(root, "buildings", cnvList_toJsonObject(btc->bls));

	node = json_object();
	json_object_set_new(node, "items",
				cnvList_toJsonArray(btc->day->items));
	json_object_set_new(node, "monsters",
				cnvList_toJsonArray(btc->day->monsters));
	JSON_NUMBER(node, "poisonDamage", btc->day->poisonDmg);
	JSON_NUMBER(node, "level", btc->day->level);
	if (btc->params)
		json_object_update(node, paramList_toJson(btc->params));

	json_object_set_new(root, "day", node);

	if (btc->night->level) {
		node = json_object();
		json_object_set_new(node, "items",
				cnvList_toJsonArray(btc->night->items));
		json_object_set_new(node, "monsters",
				cnvList_toJsonArray(btc->night->monsters));
		JSON_NUMBER(node, "poisonDamage", btc->night->poisonDmg);
		JSON_NUMBER(node, "level", btc->night->level);
		json_object_set_new(root, "night", node);
	}

	return root;
}
/* ****************************************************************************
*
* toJson -
*/
std::string CompoundValueNode::toJson(bool isLastElement)
{
  std::string  out       = "";
  bool         jsonComma = siblingNo < (int) container->childV.size() - 1;
  std::string  tagName   = (container->valueType == orion::ValueTypeVector)? "item" : name;

  // No "comma after" if toplevel
  if (container == this)
  {
    jsonComma = false;
  }

  if (valueType == orion::ValueTypeString)
  {
    LM_T(LmtCompoundValueRender, ("I am a String (%s)", name.c_str()));
    if (container->valueType == orion::ValueTypeVector)
    {
      out = JSON_STR(stringValue);
    }
    else
    {
      out = JSON_STR(tagName) + ":" + JSON_STR(stringValue);
    }
  }
  else if (valueType == orion::ValueTypeNumber)
  {
    char  num[32];

    LM_T(LmtCompoundValueRender, ("I am a Number (%s)", name.c_str()));
    snprintf(num, sizeof(num), "%f", numberValue);

    if (container->valueType == orion::ValueTypeVector)
    {
      out = JSON_NUMBER(num);
    }
    else
    {
      out = JSON_STR(tagName) + ":" + JSON_NUMBER(num);
    }
  }
  else if (valueType == orion::ValueTypeBoolean)
  {
    LM_T(LmtCompoundValueRender, ("I am a Bool (%s)", name.c_str()));

    if (container->valueType == orion::ValueTypeVector)
    {
      out = JSON_BOOL(boolValue);
    }
    else
    {
      out = JSON_STR(tagName) + ":" + JSON_BOOL(boolValue);
    }
  }
  else if ((valueType == orion::ValueTypeVector) && (container == this))
  {
    //
    // NOTE: Here, the '[]' are already added in the calling function
    //
    LM_T(LmtCompoundValueRender, ("I am a Vector (%s) and my container is TOPLEVEL", name.c_str()));
    for (uint64_t ix = 0; ix < childV.size(); ++ix)
    {
      out += childV[ix]->toJson(ix == childV.size() - 1);
    }
  }
  else if ((valueType == orion::ValueTypeVector) && (container->valueType == orion::ValueTypeVector))
  {
    out += "[";

    for (uint64_t ix = 0; ix < childV.size(); ++ix)
    {
      out += childV[ix]->toJson(false);
    }

    out += "]";
  }
  else if (valueType == orion::ValueTypeVector)
  {
    LM_T(LmtCompoundValueRender, ("I am a Vector (%s)", name.c_str()));
    out += JSON_STR(name) + ":[";
    for (uint64_t ix = 0; ix < childV.size(); ++ix)
    {
      out += childV[ix]->toJson(false);
    }

    out += "]";
  }
  else if ((valueType == orion::ValueTypeObject) && (container->valueType == orion::ValueTypeVector))
  {
    LM_T(LmtCompoundValueRender, ("I am an Object (%s) and my container is a Vector", name.c_str()));
    out += "{";
    for (uint64_t ix = 0; ix < childV.size(); ++ix)
    {
      out += childV[ix]->toJson(ix == childV.size() - 1);
    }

    out += "}";
  }
  else if (valueType == orion::ValueTypeObject)
  {
    if (rootP != this)
    {
      LM_T(LmtCompoundValueRender, ("I am an Object (%s) and my container is NOT a Vector", name.c_str()));
      out += JSON_STR(name) + ":{";

      for (uint64_t ix = 0; ix < childV.size(); ++ix)
      {
        out += childV[ix]->toJson(ix == childV.size() - 1);
      }

      out += "}";
    }
    else
    {
      LM_T(LmtCompoundValueRender, ("I am the TREE ROOT (%s: %d children)", name.c_str(), childV.size()));
      for (uint64_t ix = 0; ix < childV.size(); ++ix)
      {
        out += childV[ix]->toJson(true);
      }
    }
  }

  out += jsonComma? "," : "";

  return out;
}
Exemplo n.º 4
0
static json_t *monster_toJson(const void *vm)
{
	json_t		*monRoot;
	monster_t	*m = (monster_t *)vm;
	uint32_t	i;

	monRoot = json_object();

	JSON_BTSTRING(monRoot, "singular",	m->singular);
	JSON_BTSTRING(monRoot, "plural",	m->plural);
	JSON_BTSTRING(monRoot, "picture",	m->picture);
	JSON_STRING(monRoot, "pronoun",		getPronounString(m->pronoun));
	JSON_NUMBER(monRoot, "hpBase",		m->hpBase);
	JSON_NUMBER(monRoot, "hpRndDie",	m->hpRndDie);
	JSON_NUMBER(monRoot, "hpRndNDice",	m->hpRndNdice);
	JSON_NUMBER(monRoot, "reward",		m->reward);
	JSON_NUMBER(monRoot, "ac",		m->baseAC);
	JSON_NUMBER(monRoot, "breathSaveLo",	m->breathSaveLo);
	JSON_NUMBER(monRoot, "breathSaveHi",	m->breathSaveHi);
	JSON_NUMBER(monRoot, "spellSaveLo",	m->spellSaveLo);
	JSON_NUMBER(monRoot, "spellSaveHi",	m->spellSaveHi);
	JSON_NUMBER(monRoot, "toHitLo",		m->toHitLo);
	JSON_NUMBER(monRoot, "toHitHi",		m->toHitHi);
	JSON_NUMBER(monRoot, "priorityLo",	m->priorityLo);
	JSON_NUMBER(monRoot, "priorityHi",	m->priorityHi);
	JSON_BOOL(monRoot, "rndGroupSize",	m->rndGroupSize);
	JSON_NUMBER(monRoot, "groupSize",	m->groupSize);
	JSON_NUMBER(monRoot, "numAttacks",	m->numAttacks);
	/* XXX PRONOUN Handling */
	JSON_BOOL(monRoot, "willAdvance",	m->willAdvance);
	JSON_NUMBER(monRoot, "distance",	m->distance);
	JSON_NUMBER(monRoot, "advanceSpeed",	m->advSpeed);
	JSON_BOOL(monRoot, "isIllusion",	m->isIllusion);

	json_object_update(monRoot, repel_toJson(&m->repel));
	json_object_set_new(monRoot, "attacks", cnvList_toJsonArray(m->attacks));
	
	return monRoot;
}