Beispiel #1
0
void TilesetCategory::loadBrush(xmlNodePtr node, wxArrayString& warnings)
{
	std::string strVal;
	std::string brush_name;
	int intVal = 0;
	
	readXMLValue(node, "after", brush_name);
	if(readXMLValue(node, "afteritem", intVal))
	{
		ItemType& it = item_db[intVal];
		if(it.id != 0)// Verify that we have a valid item
		{
			brush_name = (it.raw_brush? it.raw_brush->getName() : "");
		}
	}

	if(xmlStrcmp(node->name,(const xmlChar*)"brush") == 0)
	{
		if(readXMLString(node, "name", strVal))
		{
			Brush* brush = tileset.brushes.getBrush(strVal);
			if(brush)
			{
				std::vector<Brush*>::iterator insert_here = brushlist.end();
				if(brush_name.size())
				{
					for(std::vector<Brush*>::iterator iter = brushlist.begin(); iter != brushlist.end(); ++iter)
					{
						if((*iter)->getName() == brush_name)
						{
							insert_here = ++iter;
							break;
						}
					}
				}
				brush->flagAsVisible();
				brushlist.insert(insert_here, brush);
			}
			else
			{
				warnings.push_back(wxT("Brush \"") + wxstr(strVal) + wxT("\" doesn't exist."));
			}
		}
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"item") == 0)
	{
		int fromid = 0, toid = 0;
		if(!readXMLInteger(node, "id", fromid))
		{
			if(!readXMLInteger(node, "fromid", fromid))
			{
				warnings.push_back(wxT("Couldn't read raw ids."));
			}
			readXMLInteger(node, "toid", toid);
		}
		toid = std::max(toid, fromid);
		
		std::vector<Brush*>::iterator insert_here = brushlist.end();
		if(brush_name.size())
		{
			for(std::vector<Brush*>::iterator iter = brushlist.begin(); iter != brushlist.end(); ++iter)
			{
				if((*iter)->getName() == brush_name) 
				{
					insert_here = ++iter;
					break;
				}
			}
		}
		
		std::vector<Brush*> temp_vec;
		for(int id = fromid; id <= toid; ++id)
		{
			ItemType& it = item_db[id];
			if(it.id == 0) // Verify that we have a valid item
			{
				warnings.push_back(wxT("Unknown item id #") + i2ws(id) + wxT("."));
			}
			else
			{
				RAWBrush* brush;
				if(it.raw_brush)
				{
					brush = it.raw_brush;
				}
				else
				{
					brush = it.raw_brush = newd RAWBrush(it.id);
					it.has_raw = true;
					tileset.brushes.addBrush(brush); // This will take care of cleaning up afterwards
				}

				if(it.doodad_brush == NULL && !isTrivial())
				{
					it.doodad_brush = brush;
				}

				brush->flagAsVisible();
				temp_vec.push_back(brush);
			}
		}
		brushlist.insert(insert_here, temp_vec.begin(), temp_vec.end());
	}
}
Beispiel #2
0
void Materials::createOtherTileset()
{
	Tileset* others;
	Tileset* npc_tileset;

	if(tilesets["Others"] != nullptr) {
		others = tilesets["Others"];
		others->clear();
	} else {
		others = newd Tileset(g_brushes, "Others");
		tilesets["Others"] = others;
	}

	if(tilesets["NPCs"] != nullptr) {
		npc_tileset = tilesets["NPCs"];
		npc_tileset->clear();
	} else {
		npc_tileset = newd Tileset(g_brushes, "NPCs");
		tilesets["NPCs"] = npc_tileset;
	}

	// There should really be an iterator to do this
	for(int32_t id = 0; id <= g_items.getMaxID(); ++id) {
		ItemType& it = g_items[id];
		if(it.id == 0) {
			continue;
		}

		if(!it.isMetaItem()) {
			Brush* brush;
			if(it.in_other_tileset) {
				others->getCategory(TILESET_RAW)->brushlist.push_back(it.raw_brush);
				continue;
			} else if(it.raw_brush == nullptr) {
				brush = it.raw_brush = newd RAWBrush(it.id);
				it.has_raw = true;
				g_brushes.addBrush(it.raw_brush);
			} else if(!it.has_raw) {
				brush = it.raw_brush;
			} else
				continue;

			brush->flagAsVisible();
			others->getCategory(TILESET_RAW)->brushlist.push_back(it.raw_brush);
			it.in_other_tileset = true;
		}
	}

	for(CreatureMap::iterator iter = g_creatures.begin(); iter != g_creatures.end(); ++iter) {
		CreatureType* type = iter->second;
		if(type->in_other_tileset) {
			if(type->isNpc) {
				npc_tileset->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			} else {
				others->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			}
		} else if(type->brush == nullptr) {
			type->brush = newd CreatureBrush(type);
			g_brushes.addBrush(type->brush);
			type->brush->flagAsVisible();
			type->in_other_tileset = true;
			if(type->isNpc) {
				npc_tileset->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			} else {
				others->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			}
		}
	}
}