Пример #1
0
/* EntryOperations::openMapDB2
 * Opens the map at [entry] with Doom Builder 2, including all open
 * resource archives. Sets up a FileMonitor to update the map in the
 * archive if any changes are made to it in DB2
 *******************************************************************/
bool EntryOperations::openMapDB2(ArchiveEntry* entry)
{
#ifdef __WXMSW__	// Windows only
	string path = path_db2;

	if (path.IsEmpty())
	{
		// Check for DB2 location registry key
		wxRegKey key(wxRegKey::HKLM, "SOFTWARE\\CodeImp\\Doom Builder");
		key.QueryValue("Location", path);

		// Can't proceed if DB2 isn't installed
		if (path.IsEmpty())
		{
			wxMessageBox("Doom Builder 2 must be installed to use this feature.", "Doom Builder 2 Not Found");
			return false;
		}

		// Add default executable name
		path += "\\Builder.exe";
	}

	// Get map info for entry
	Archive::mapdesc_t map = entry->getParent()->getMapInfo(entry);

	// Check valid map
	if (map.format == MAP_UNKNOWN)
		return false;

	// Export the map to a temp .wad file
	string filename = appPath(entry->getParent()->getFilename(false) + "-" + entry->getName(true) + ".wad", DIR_TEMP);
	filename.Replace("/", "-");
	if (map.archive)
	{
		entry->exportFile(filename);
		entry->lock();
	}
	else
	{
		// Write map entries to temporary wad archive
		if (map.head)
		{
			WadArchive archive;

			// Add map entries to archive
			ArchiveEntry* e = map.head;
			while (true)
			{
				archive.addEntry(e, "", true);
				e->lock();
				if (e == map.end) break;
				e = e->nextEntry();
			}

			// Write archive to file
			archive.save(filename);
		}
	}

	// Generate Doom Builder command line
	string cmd = S_FMT("%s \"%s\" -map %s", path, filename, entry->getName());

	// Add base resource archive to command line
	Archive* base = theArchiveManager->baseResourceArchive();
	if (base)
	{
		if (base->getType() == ARCHIVE_WAD)
			cmd += S_FMT(" -resource wad \"%s\"", base->getFilename());
		else if (base->getType() == ARCHIVE_ZIP)
			cmd += S_FMT(" -resource pk3 \"%s\"", base->getFilename());
	}

	// Add resource archives to command line
	for (int a = 0; a < theArchiveManager->numArchives(); ++a)
	{
		Archive* archive = theArchiveManager->getArchive(a);

		// Check archive type (only wad and zip supported by db2)
		if (archive->getType() == ARCHIVE_WAD)
			cmd += S_FMT(" -resource wad \"%s\"", archive->getFilename());
		else if (archive->getType() == ARCHIVE_ZIP)
			cmd += S_FMT(" -resource pk3 \"%s\"", archive->getFilename());
	}

	// Run DB2
	FileMonitor* fm = new DB2MapFileMonitor(filename, entry->getParent(), entry->getName(true));
	wxExecute(cmd, wxEXEC_ASYNC, fm->getProcess());

	return true;
#else
	return false;
#endif//__WXMSW__
}
Пример #2
0
/* MapEditorWindow::writeMap
 * Writes the current map as [name] to a wad archive and returns it
 *******************************************************************/
WadArchive* MapEditorWindow::writeMap(string name, bool nodes)
{
	// Get map data entries
	vector<ArchiveEntry*> new_map_data;
	SLADEMap& map = editor.getMap();
	if (mdesc_current.format == MAP_DOOM)
		map.writeDoomMap(new_map_data);
	else if (mdesc_current.format == MAP_HEXEN)
		map.writeHexenMap(new_map_data);
	else if (mdesc_current.format == MAP_UDMF)
	{
		ArchiveEntry* udmf = new ArchiveEntry("TEXTMAP");
		map.writeUDMFMap(udmf);
		new_map_data.push_back(udmf);
	}
	else // TODO: doom64
		return NULL;

	// Check script language
	bool acs = false;
	if (theGameConfiguration->scriptLanguage() == "acs_hexen" ||
		theGameConfiguration->scriptLanguage() == "acs_zdoom")
		acs = true;
	// Force ACS on for Hexen map format, and off for Doom map format
	if (mdesc_current.format == MAP_DOOM) acs = false;
	if (mdesc_current.format == MAP_HEXEN) acs = true;
	bool dialogue = false;
	if (theGameConfiguration->scriptLanguage() == "usdf" ||
		theGameConfiguration->scriptLanguage() == "zsdf")
		dialogue = true;

	// Add map data to temporary wad
	WadArchive* wad = new WadArchive();
	wad->addNewEntry(name);
	// Handle fragglescript and similar content in the map header
	if (mdesc_current.head && mdesc_current.head->getSize() && !mdesc_current.archive)
	{
		wad->getEntry(name)->importMemChunk(mdesc_current.head->getMCData());
	}
	for (unsigned a = 0; a < new_map_data.size(); a++)
		wad->addEntry(new_map_data[a]);
	if (acs) // BEHAVIOR
		wad->addEntry(panel_script_editor->compiledEntry(), "", true);
	if (acs && panel_script_editor->scriptEntry()->getSize() > 0) // SCRIPTS (if any)
		wad->addEntry(panel_script_editor->scriptEntry(), "", true);
	if (mdesc_current.format == MAP_UDMF)
	{
		// Add extra UDMF entries
		for (unsigned a = 0; a < map.udmfExtraEntries().size(); a++)
			wad->addEntry(map.udmfExtraEntries()[a], -1, NULL, true);

		wad->addNewEntry("ENDMAP");
	}

	// Build nodes
	if (nodes)
		buildNodes(wad);

	// Clear current map data
	for (unsigned a = 0; a < map_data.size(); a++)
		delete map_data[a];
	map_data.clear();

	// Update map data
	for (unsigned a = 0; a < wad->numEntries(); a++)
		map_data.push_back(new ArchiveEntry(*(wad->getEntry(a))));

	return wad;
}