示例#1
0
void ResourceManager::loadAllResources(const std::string &fileName)
{
	CL_ResourceManager resourceManager = loadResourceFile(fileName);
	std::vector<CL_String> names = resourceManager.get_resource_names();
	for (std::vector<CL_String>::const_iterator it = names.begin(); it != names.end(); ++it)
		loadResource(*it, fileName);
}
示例#2
0
CarMotor::CarMotor(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp)
: CarOption(resources, carUp, 5, mainPath + "motorPrice", "Engine")
{
    std::string path = mainPath + "acceleration";
    m_acceleration = 6 * resources.get_integer_resource( path, 1 );

    path = mainPath + "maxSpeed";
    m_maxSpeed = 6 * resources.get_integer_resource( path, 1 );
}
示例#3
0
std::vector<CL_SharedPtr<Resource> > ResourceManager::createAllResources(const std::string &fileName)
{
	CL_ResourceManager resourceManager = loadResourceFile(fileName);
	std::vector<CL_String> names = resourceManager.get_resource_names();
	std::vector<CL_SharedPtr<Resource> > resources;
	for (std::vector<CL_String>::const_iterator it = names.begin(); it != names.end(); ++it)
		resources.push_back(createResource(*it, fileName));
	return resources;
}
示例#4
0
TileMap::TileMap(CL_GraphicContext& gc, CL_ResourceManager& resmgr, const CL_String& tileset)
: map_width(0), map_height(0), cur_map_x(0), cur_map_y(0) {
    CL_Resource res = resmgr.get_resource(tileset);

    if (res.get_type() != "tilemap")
        throw CL_Exception(cl_format("Resource %1 is not a tilemap", tileset));

    CL_DomElement element = res.get_element();
    levelname = element.get_attribute("name");
    CL_String resource_name = element.get_attribute("resource");
    map_width = element.get_attribute_int("width");
    map_height = element.get_attribute_int("height");

    tiles = CL_Sprite(gc, resource_name, &resmgr);
    float scalex, scaley;
    tiles.get_scale(scalex, scaley);
    tile_width = tiles.get_width() * scalex;
    tile_height = tiles.get_height() * scaley;

    auto layer_nodes = element.select_nodes("layer");
    for (CL_DomNode& idx : layer_nodes) {
        CL_DomElement layer_element = idx.to_element();

        CL_String layer_tiles = layer_element.get_first_child().get_node_value();
        std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");

        MapLayer layer;
        layer.map.reserve(tile_indices.size());
        for (auto& tile : tile_indices)
            layer.map.push_back(CL_StringHelp::text_to_int(tile));

        layers.push_back(layer);
    }
}
示例#5
0
CarOption::CarOption(CL_ResourceManager resources, CACarUpgrades* carUp, int maxOption, const std::string& pathPrice, const std::string& name)
:  m_carUp(carUp), m_current(0), m_maxOpt(maxOption), m_name(name)
{
    int pathPricei = resources.get_integer_resource(pathPrice,0);
    for (int i=0; i < m_maxOpt; i++)
        m_PriceList.push_back((i*pathPricei)/2+pathPricei);
}
示例#6
0
CL_SharedPtr<Resource> ResourceManager::createResource(const std::string &name, const std::string &fileName)
{
	ResourceMap::const_iterator it = mResources.find(name);
	if (it != mResources.end())
		return it->second;

	CL_ResourceManager resourceManager = loadResourceFile(fileName);
	CL_Resource resource = resourceManager.get_resource(name);

	CL_SharedPtr<Resource> ptr;
	std::string type = resource.get_type();
	if (type == "font")
		ptr = CL_SharedPtr<Resource>(new FontResource(resource));
	else if (type == "sprite")
		ptr = CL_SharedPtr<Resource>(new SpriteResource(resource));
	else if (type == "sample")
		ptr = CL_SharedPtr<Resource>(new SoundResource(resource));
	else
		throw Exception(cl_format("Resource '%1' has invalid or unsupported type '%2'", name, type));

	mResources.insert(std::make_pair(name, ptr));
	return ptr;
}
void CL_ResourceData_TextStyler::on_load()
{
    CL_Resource resource = get_resource();
    CL_ResourceManager manager = resource.get_manager();

    ts = CL_TextStyler();
    std::map<std::string, CL_Font>& fnt_map = ts.get_fonts();

    for (
        CL_DomNode cur_node = resource.get_element().get_first_child();
        !cur_node.is_null();
        cur_node = cur_node.get_next_sibling())
    {
        if (!cur_node.is_element()) continue;

        CL_DomElement cur_element = cur_node.to_element();
        if (
            cur_element.get_tag_name() == "font"
            && cur_element.has_attribute("name")
            && cur_element.has_attribute("font"))
        {
            if (manager.exists(cur_element.get_attribute("font")))
            {
                fnt_map[cur_element.get_attribute("name")] =
                    CL_Font(cur_element.get_attribute("font"), &manager);
            }
            else
            {
                throw CL_Error(std::string("CL_TextStyler: Unable to find sub-font named ") + cur_element.get_attribute("font"));
            }
        }
        else
        {
            throw CL_Error("CL_TextStyler: Unknown sub-element of a text_styler resource");
        }
    }
}
示例#8
0
void TileMap::load(CL_GraphicContext &gc, const CL_String &level, CL_ResourceManager &resources)
{
	CL_Resource resource = resources.get_resource(level);
	
	if (resource.get_type() != "tilemap")
		throw CL_Exception(cl_format("Resource %1 is not of type tilemap!", level));

	CL_DomElement element = resource.get_element();
	CL_String level_name = element.get_attribute("name");
	CL_String resource_name = element.get_attribute("resource");
	map_width = element.get_attribute_int("width");
	map_height = element.get_attribute_int("height");
	
	cl_log_event("Debug", "Loading level %1 (%2x%3)", level_name, map_width, map_height);

	sprite_tiles = CL_Sprite(gc, resource_name, &resources);

	tile_width = sprite_tiles.get_width();
	tile_height = sprite_tiles.get_height();

	cl_log_event("Debug", "Loaded resource %1 with %2 tiles", resource_name, sprite_tiles.get_frame_count());

	std::vector<CL_DomNode> layer_nodes = element.select_nodes("layer");
	for (size_t layer_index = 0; layer_index < layer_nodes.size(); layer_index++)
	{
		CL_DomElement layer_element = layer_nodes[layer_index].to_element();
		CL_String layer_name = layer_element.get_attribute("name");

		CL_String layer_tiles = layer_element.get_first_child().get_node_value();
		std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");

		TileMapLayer layer;
		layer.map.reserve(tile_indices.size());
		for(size_t i = 0; i < tile_indices.size(); ++i)
			layer.map.push_back(CL_StringHelp::text_to_int(tile_indices[i]));
	
		layers.push_back(layer);

		cl_log_event("Debug", "Loaded layer %1 with %2 tiles", layer_name, layer.map.size());
	}

	current_map_position_x = 0;
	current_map_position_y = 0;
}
示例#9
0
CarType::CarType(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp, const bool debug)
     :
         m_motor (mainPath, resources, carUp),
         m_tires (mainPath, resources, carUp),
         m_armor (mainPath, resources, carUp)
{
    if(debug) std::cout << "  name" << std::endl;

    std::string path = mainPath + "name";
    name = resources.get_string_resource( path, "name" );

    if(debug) std::cout << "  surface" << std::endl;

    path = mainPath + "surface";
    surface = CL_Texture( *CA_APP->graphicContext, path, &resources );

    if(debug) std::cout << "  surface3d" << std::endl;

    path = mainPath + "surface3d";
    surface3d = CL_Texture( *CA_APP->graphicContext, path, &resources );

    path = mainPath + "length";
    length = resources.get_integer_resource( path, 0 );
    path = mainPath + "width";
    width = resources.get_integer_resource( path, 0 );
    path = mainPath + "minSpeed";
    minSpeed = 6 * resources.get_integer_resource( path, 1 );
    path = mainPath + "maxTurbo";
    maxTurbo = resources.get_integer_resource( path, 1000 );
    path = mainPath + "acceleration";
    deceleration = 6 * resources.get_integer_resource( path, 1000 );
    path = mainPath + "steeringPower";
    steeringPower = resources.get_integer_resource( path, 1 );
    path = mainPath + "price";
    price = resources.get_integer_resource( path, 0 );


    radius = std::sqrt( (double)width/2 * (double)width/2 + (double)length/2 * (double)length/2 );
    angle = atan( (double)(width/2) / (double)(length/2) ) * ARAD;
}
示例#10
0
CarTires::CarTires(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp)
: CarOption(resources, carUp, 5, mainPath + "tiresPrice", "Tires")
{
    std::string path = mainPath + "slidingFactor";
    m_slidingFactor = 0.01 * resources.get_integer_resource( path, 1 );
}