Beispiel #1
0
bool GdaJson::findValue(const json_spirit::Value& input,
						json_spirit::Value& output,
						const wxString& name)
{
	if (input.type() != json_spirit::obj_type) return false;
	return GdaJson::findValue(input.get_obj(), output, name);
}
Beispiel #2
0
bool
jsonGetMember(const json_spirit::Value& value, const char* name, T& out)
{
    using namespace json_spirit;

    if (value.type() == obj_type) {
        // yeah, only objects have values.
        BOOST_FOREACH(const Pair& pair, value.get_obj()) {
            if (pair.name_ == name) {
                out = pair.value_.get_value<T>();
                return true;
            }
        }
    }
Simulation::Simulation(json_spirit::Value &jsonData)
{
	reset();

	json_spirit::Object jsonObject = jsonData.get_obj();
	
	// It is crucial that the teams are setup before the rules.
	// To achieve that, we just delay rule initialization.
	json_spirit::Array ruleData;

	for (json_spirit::Pair &pair : jsonObject)
	{
		std::string &key = pair.name_;

		if (key == "thread_count") numberOfThreads = pair.value_.get_int();
		else if (key == "run_count") numberOfRuns = pair.value_.get_int();
		else if (key == "tournament_id") tournamentID = pair.value_.get_int();
		else if (key == "tournament_type") tournamentType = pair.value_.get_str();
		else if (key == "teams") setupTeams(pair.value_.get_array());
		else if (key == "rules") ruleData = pair.value_.get_array();
		else if (key == "match_database") setupKnownMatches(pair.value_.get_array());
		else
			std::cerr << "sim::Simulation: invalid property \"" << key << "\"" << std::endl;
	}

	// Finally (after the teams are setup) init the rules.
	if (!ruleData.empty())
		setupRules(ruleData);
}
Beispiel #4
0
Script::Script(json_spirit::Value jsonString)
: owner(NULL)
{
    /*
        JSON TEMPLATE FOR SCRIPT COMPONENT
        {
            "name": "Script"
            "scripts":
            [
                "Assets/Scripts/script1.lua",
                "Assets/Scripts/script2.lua"
            ]
        }
    */
    std::string scriptPath;
    std::string className;

    json_spirit::Array scriptsArray;
    scriptsArray = jsonString.getObject().at("scripts").getArray();

    for (unsigned int index = 0; index < scriptsArray.size(); ++index)
    {
        scriptPath = Game::resourceManager->GetPath(scriptsArray[index].getString());

        className = scriptPath.substr(scriptPath.find_last_of('/') + 1);
        className = className.erase(className.find_last_of('.'));

        scripts.push_back(scriptPath);
        classNames.push_back(className);
    }
}
Beispiel #5
0
void ConvertTo(json_spirit::Value& value, bool fAllowNull=false)
{
    if (fAllowNull && value.type() == json_spirit::null_type)
        return;
    if (value.type() == json_spirit::str_type)
    {
        // reinterpret string as unquoted json value
        json_spirit::Value value2;
        std::string strJSON = value.get_str();
        if (!read_string(strJSON, value2))
            throw std::runtime_error(std::string("Error parsing JSON:")+strJSON);
        ConvertTo<T>(value2, fAllowNull);
        value = value2;
    }
    else
    {
        value = value.get_value<T>();
    }
}
Beispiel #6
0
json_spirit::Object JSONRPCReplyObj(const json_spirit::Value& result, const json_spirit::Value& error, const json_spirit::Value& id)
{
    json_spirit::Object reply;
    if (error.type() != json_spirit::null_type)
        reply.push_back(json_spirit::Pair("result", json_spirit::Value::null));
    else
        reply.push_back(json_spirit::Pair("result", result));
    reply.push_back(json_spirit::Pair("error", error));
    reply.push_back(json_spirit::Pair("id", id));
    return reply;
}
Beispiel #7
0
// Convert from a JSON to an AtNode
static AtSmartPtr<AtNode> ConvertNode(json_spirit::Value node)
{
	AtSmartPtr<AtNode> obj (new AtNode());
	
	if (node.type() == json_spirit::str_type)
	{
		obj->value = std::wstring(node.get_str().begin(),node.get_str().end());
	}
	else if (node.type() == json_spirit::int_type || node.type() == json_spirit::real_type)
	{
		std::wstringstream stream;
		if (node.type() == json_spirit::int_type)
			stream << node.get_int();
		if (node.type() == json_spirit::real_type)
			stream << node.get_real();
		
		obj->value = stream.str().c_str();
		obj->children.insert(AtNode::child_pairtype(
			"@number", AtSmartPtr<AtNode>(new AtNode())
		));
	}
	else if (node.type() == json_spirit::bool_type)
	{
		if (node.get_bool())
			obj->value = L"true";
		else
			obj->value = L"false";
		
		obj->children.insert(AtNode::child_pairtype(
			"@boolean", AtSmartPtr<AtNode>(new AtNode())
		));
	}
	else if (node.type() == json_spirit::array_type)
	{
		obj->children.insert(AtNode::child_pairtype(
			"@array", AtSmartPtr<AtNode>(new AtNode())
		));

		json_spirit::Array nodeChildren = node.get_array();
		json_spirit::Array::iterator itr = nodeChildren.begin();
		
		for (; itr != nodeChildren.end(); itr++)
		{
			obj->children.insert(AtNode::child_pairtype(
				"item", ConvertNode(*itr)
			));
		}
	}
	else if (node.type() == json_spirit::obj_type)
	{
		json_spirit::Object objectProperties = node.get_obj();
		json_spirit::Object::iterator itr = objectProperties.begin();
		for (; itr != objectProperties.end(); itr++)
		{
			obj->children.insert(AtNode::child_pairtype(
				itr->name_, ConvertNode(itr->value_)
			));
		}
	}
	else if (node.type() == json_spirit::null_type)
	{
		return obj;
	}
	else
	{
		assert(! "Unimplemented type found when parsing JSON!");
	}
	
	return obj;
}
Beispiel #8
0
bool GdaJson::hasName(const json_spirit::Value& val, const wxString& name)
{
	if (val.type() != json_spirit::obj_type) return false;
	return GdaJson::hasName(val.get_obj(), name);
}
Beispiel #9
0
wxString GdaJson::getStrValFromObj(const json_spirit::Value& val,
								   const wxString& name)
{
	if (val.type() != json_spirit::obj_type) return "";
	return getStrValFromObj(val.get_obj(), name);
}
Beispiel #10
0
Physics::Physics(json_spirit::Value jsonString)
:   velocity(),
    aceleration(),
    mass(1.0f),
    linearDrag(0.0f),
    angularDrag(0.0f),
    isKinematic(false)
{
    /*
     * JSON TEMPLATE FOR PHYSICS COMPONENT
     * {
     *  "name": "Physics",
     *  "velocity":
     *  {
     *      "x": 0,
     *      "y": 0,
     *      "z": 0
     *  },
     *  "aceleration":
     *  {
     *      "x": 0,
     *      "y": 0,
     *      "z": 0
     *  },
     *  "mass": 1.0,
     *  "linear_drag": 1.0,
     *  "angular_drag": 1.0,
     *  "kinematic": false
     *
     * }
     */
     json_spirit::Value v, a;

    if (jsonString.contains("velocity"))
    {
        v = jsonString.getObject().at("velocity");
        velocity.x = v.getObject().at("x").getReal();
        velocity.y = v.getObject().at("y").getReal();
        velocity.z = v.getObject().at("z").getReal();
    }

    if (jsonString.contains("aceleration"))
    {
        a = jsonString.getObject().at("aceleration");

        aceleration.x = v.getObject().at("x").getReal();
        aceleration.y = v.getObject().at("y").getReal();
        aceleration.z = v.getObject().at("z").getReal();
    }

    if (jsonString.contains("mass"))
    {
        mass = jsonString.getObject().at("mass").getReal();
    }

    if (jsonString.contains("linear_drag"))
    {
        linearDrag = jsonString.getObject().at("linear_drag").getReal();
    }

    if (jsonString.contains("angular_drag"))
    {
        angularDrag = jsonString.getObject().at("angular_drag").getReal();
    }

    if (jsonString.contains("kinematic"))
    {
        isKinematic = jsonString.getObject().at("kinematic").getBool();
    }
}