Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/levelset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
const TFilePath defaultRootFolder("Cast");
Toshihiro Shimizu 890ddd
const TFilePath defaultSoundRootFolder("Audio");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TLevelSet
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevelSet::TLevelSet()
Toshihiro Shimizu 890ddd
	: m_defaultFolder(defaultRootFolder)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_folders.push_back(defaultRootFolder);
Toshihiro Shimizu 890ddd
	m_folders.push_back(defaultSoundRootFolder);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevelSet::~TLevelSet()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::clear()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (std::vector<txshlevel *="">::iterator it = m_levels.begin();</txshlevel>
Toshihiro Shimizu 890ddd
		 it != m_levels.end(); ++it) {
Toshihiro Shimizu 890ddd
		TXshLevel *level = *it;
Toshihiro Shimizu 890ddd
		if (level->getSimpleLevel())
Toshihiro Shimizu 890ddd
			level->getSimpleLevel()->clearFrames();
Toshihiro Shimizu 890ddd
		(*it)->release();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_levelTable.clear();
Toshihiro Shimizu 890ddd
	m_levels.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_folderTable.clear();
Toshihiro Shimizu 890ddd
	m_folders.clear();
Toshihiro Shimizu 890ddd
	m_folders.push_back(defaultRootFolder);
Toshihiro Shimizu 890ddd
	m_folders.push_back(defaultSoundRootFolder);
Toshihiro Shimizu 890ddd
	m_defaultFolder = defaultRootFolder;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::removeLevel(TXshLevel *level, bool deleteIt)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//if(level->getSimpleLevel())
Toshihiro Shimizu 890ddd
	//  level->getSimpleLevel()->clearFrames();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_levels.erase(
Toshihiro Shimizu 890ddd
		std::remove(m_levels.begin(), m_levels.end(), level),
Toshihiro Shimizu 890ddd
		m_levels.end());
Toshihiro Shimizu 890ddd
	m_levelTable.erase(level->getName());
Toshihiro Shimizu 890ddd
	if (deleteIt)
Toshihiro Shimizu 890ddd
		level->release();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_folderTable.erase(level);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TLevelSet::renameLevel(TXshLevel *level, const std::wstring &newName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (level->getName() == newName)
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	if (m_levelTable.count(newName) > 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	m_levelTable.erase(level->getName());
Toshihiro Shimizu 890ddd
	level->setName(newName);
Toshihiro Shimizu 890ddd
	m_levelTable[newName] = level;
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TLevelSet::getLevelCount() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_levels.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshLevel *TLevelSet::getLevel(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0 <= index && index < getLevelCount());
Toshihiro Shimizu 890ddd
	return m_levels[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshLevel *TLevelSet::getLevel(const std::wstring &levelName) const
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::wstring, *="" txshlevel="">::const_iterator it;</std::wstring,>
Toshihiro Shimizu 890ddd
	it = m_levelTable.find(levelName);
Toshihiro Shimizu 890ddd
	if (it == m_levelTable.end())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshLevel *TLevelSet::getLevel(const ToonzScene &scene, const TFilePath &levelPath) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const TFilePath &decodedPath = scene.decodeFilePath(levelPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int l, lCount = getLevelCount();
Toshihiro Shimizu 890ddd
	for (l = 0; l != lCount; ++l) {
Toshihiro Shimizu 890ddd
		TXshLevel *level = getLevel(l);
Toshihiro Shimizu 890ddd
		if (decodedPath == scene.decodeFilePath(level->getPath()))
Toshihiro Shimizu 890ddd
			return level;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool TLevelSet::hasLevel(const std::wstring &levelName) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::vector<txshlevel *="">::const_iterator it = m_levels.begin();</txshlevel>
Toshihiro Shimizu 890ddd
	for (it; it != m_levels.end(); it++) {
Toshihiro Shimizu 890ddd
		TXshLevel *level = *it;
Toshihiro Shimizu 890ddd
		if (levelName == level->getName())
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TLevelSet::hasLevel(const ToonzScene &scene, const TFilePath &levelPath) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return getLevel(scene, levelPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::listLevels(std::vector<txshlevel *=""> &levels) const</txshlevel>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	levels = m_levels;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TLevelSet::insertLevel(TXshLevel *xl)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::wstring, *="" txshlevel="">::const_iterator it;</std::wstring,>
Toshihiro Shimizu 890ddd
	it = m_levelTable.find(xl->getName());
Toshihiro Shimizu 890ddd
	if (it != m_levelTable.end() && it->second == xl)
Toshihiro Shimizu 890ddd
		return it->second == xl;
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		xl->addRef();
Toshihiro Shimizu 890ddd
		m_levelTable[xl->getName()] = xl;
Toshihiro Shimizu 890ddd
		m_levels.push_back(xl);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFilePath folder = (xl->getSoundLevel()) ? defaultSoundRootFolder : m_defaultFolder;
Toshihiro Shimizu 890ddd
		m_folderTable[xl] = folder;
Toshihiro Shimizu 890ddd
		assert(std::find(m_folders.begin(), m_folders.end(), folder) != m_folders.end());
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::setDefaultFolder(TFilePath folder)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(std::find(m_folders.begin(), m_folders.end(), folder) != m_folders.end());
Toshihiro Shimizu 890ddd
	m_defaultFolder = folder;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath TLevelSet::getFolder(TXshLevel *xl) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::map<txshlevel *,="" tfilepath="">::const_iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
	it = m_folderTable.find(xl);
Toshihiro Shimizu 890ddd
	assert(it != m_folderTable.end());
Toshihiro Shimizu 890ddd
	return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath TLevelSet::renameFolder(const TFilePath &folder, const std::wstring &newName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// Impedisco la creazione di folder con nome "" che creano problemi
Toshihiro Shimizu 890ddd
	// (praticamente Ecome se avessero infinite sottocartelle)
Toshihiro Shimizu 890ddd
	if (newName == L"")
Toshihiro Shimizu 890ddd
		return folder;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath folder2 = folder.withName(newName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_folders.size(); i++) {
Toshihiro Shimizu 890ddd
		if (folder == m_folders[i])
Toshihiro Shimizu 890ddd
			m_folders[i] = folder2;
Toshihiro Shimizu 890ddd
		else if (folder.isAncestorOf(m_folders[i]))
Toshihiro Shimizu 890ddd
			m_folders[i] = folder2 + (m_folders[i] - folder);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_defaultFolder == folder)
Toshihiro Shimizu 890ddd
		m_defaultFolder = folder2;
Toshihiro Shimizu 890ddd
	std::map<txshlevel *,="" tfilepath="">::iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
	for (it = m_folderTable.begin(); it != m_folderTable.end(); ++it) {
Toshihiro Shimizu 890ddd
		if (folder == it->second)
Toshihiro Shimizu 890ddd
			it->second = folder2;
Toshihiro Shimizu 890ddd
		else if (folder.isAncestorOf(it->second))
Toshihiro Shimizu 890ddd
			it->second = folder2 + (it->second - folder);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return folder2;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath TLevelSet::createFolder(const TFilePath &parentFolder, const std::wstring &newName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath child = parentFolder + newName;
Toshihiro Shimizu 890ddd
	if (std::find(m_folders.begin(), m_folders.end(), child) == m_folders.end())
Toshihiro Shimizu 890ddd
		m_folders.push_back(child);
Toshihiro Shimizu 890ddd
	return child;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::removeFolder(const TFilePath &folder)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (folder == m_defaultFolder)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	std::vector<tfilepath> folders;</tfilepath>
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_folders.size(); i++)
Toshihiro Shimizu 890ddd
		if (!folder.isAncestorOf(m_folders[i]))
Toshihiro Shimizu 890ddd
			folders.push_back(m_folders[i]);
Toshihiro Shimizu 890ddd
	folders.swap(m_folders);
Toshihiro Shimizu 890ddd
	std::map<txshlevel *,="" tfilepath="">::iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
	for (it = m_folderTable.begin(); it != m_folderTable.end(); ++it) {
Toshihiro Shimizu 890ddd
		if (folder.isAncestorOf(it->second))
Toshihiro Shimizu 890ddd
			it->second = m_defaultFolder;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::listLevels(std::vector<txshlevel *=""> &levels, const TFilePath &folder) const</txshlevel>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::map<txshlevel *,="" tfilepath="">::const_iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
	for (it = m_folderTable.begin(); it != m_folderTable.end(); ++it)
Toshihiro Shimizu 890ddd
		if (folder == it->second)
Toshihiro Shimizu 890ddd
			levels.push_back(it->first);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::listFolders(std::vector<tfilepath> &folders, const TFilePath &folder) const</tfilepath>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_folders.size(); i++)
Toshihiro Shimizu 890ddd
		if (m_folders[i].getParentDir() == folder)
Toshihiro Shimizu 890ddd
			folders.push_back(m_folders[i]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::moveLevelToFolder(const TFilePath &fp, TXshLevel *level)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath folder(fp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (folder == TFilePath())
Toshihiro Shimizu 890ddd
		folder = m_defaultFolder;
Toshihiro Shimizu 890ddd
	if (std::find(m_folders.begin(), m_folders.end(), folder) == m_folders.end()) {
Toshihiro Shimizu 890ddd
		assert(0);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	std::map<txshlevel *,="" tfilepath="">::iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
	it = m_folderTable.find(level);
Toshihiro Shimizu 890ddd
	assert(it != m_folderTable.end());
Toshihiro Shimizu 890ddd
	if (it == m_folderTable.end())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	it->second = folder;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::saveFolder(TOStream &os, TFilePath folder)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::string, std::string=""> attr;</std::string,>
Toshihiro Shimizu 890ddd
	attr["name"] = folder.getName();
Toshihiro Shimizu 890ddd
	if (folder == getDefaultFolder())
Toshihiro Shimizu 890ddd
		attr["type"] = "default";
Toshihiro Shimizu 890ddd
	os.openChild("folder", attr);
Toshihiro Shimizu 890ddd
	std::vector<tfilepath> folders;</tfilepath>
Toshihiro Shimizu 890ddd
	listFolders(folders, folder);
Toshihiro Shimizu 890ddd
	if (!folders.empty()) {
Toshihiro Shimizu 890ddd
		for (int i = 0; i < (int)folders.size(); i++)
Toshihiro Shimizu 890ddd
			saveFolder(os, folders[i]);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	std::vector<txshlevel *=""> levels;</txshlevel>
Toshihiro Shimizu 890ddd
	listLevels(levels, folder);
Toshihiro Shimizu 890ddd
	if (!levels.empty()) {
Toshihiro Shimizu 890ddd
		os.openChild("levels");
Toshihiro Shimizu 890ddd
		for (int i = 0; i < (int)levels.size(); i++)
Toshihiro Shimizu 890ddd
			if (m_saveSet.empty() || m_saveSet.count(levels[i]) > 0)
Toshihiro Shimizu 890ddd
				os << levels[i];
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::loadFolder(TIStream &is, TFilePath folder)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::string s;
Toshihiro Shimizu 890ddd
	is.getTagParam("type", s);
Toshihiro Shimizu 890ddd
	if (s == "default")
Toshihiro Shimizu 890ddd
		setDefaultFolder(folder);
Toshihiro Shimizu 890ddd
	while (!is.eos()) {
Shinya Kitaoka 3bfa54
		std::string tagName;
Toshihiro Shimizu 890ddd
		is.matchTag(tagName);
Toshihiro Shimizu 890ddd
		if (tagName == "levels") {
Toshihiro Shimizu 890ddd
			while (!is.eos()) {
Toshihiro Shimizu 890ddd
				TPersist *p = 0;
Toshihiro Shimizu 890ddd
				is >> p;
Toshihiro Shimizu 890ddd
				TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Toshihiro Shimizu 890ddd
				if (xshLevel && !xshLevel->getChildLevel())
Toshihiro Shimizu 890ddd
					moveLevelToFolder(folder, xshLevel);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (tagName == "folder") {
Toshihiro Shimizu 890ddd
			is.getTagParam("name", s);
Toshihiro Shimizu 890ddd
			TFilePath child = createFolder(folder, toWideString(s));
Toshihiro Shimizu 890ddd
			loadFolder(is, child);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			throw TException("expected <levels> or <folder>");</folder></levels>
Toshihiro Shimizu 890ddd
		is.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int folderCount = 1;
Toshihiro Shimizu 890ddd
	while (!is.eos()) {
Shinya Kitaoka 3bfa54
		std::string tagName;
Toshihiro Shimizu 890ddd
		if (is.matchTag(tagName)) {
Toshihiro Shimizu 890ddd
			if (tagName == "levels") {
Toshihiro Shimizu 890ddd
				while (!is.eos()) {
Toshihiro Shimizu 890ddd
					TPersist *p = 0;
Toshihiro Shimizu 890ddd
					is >> p;
Toshihiro Shimizu 890ddd
					TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Toshihiro Shimizu 890ddd
					if (xshLevel) {
Toshihiro Shimizu 890ddd
						insertLevel(xshLevel);
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else if (tagName == "folder") {
Shinya Kitaoka 3bfa54
				std::string name = toString(defaultRootFolder.getWideString());
Toshihiro Shimizu 890ddd
				is.getTagParam("name", name);
Toshihiro Shimizu 890ddd
				TFilePath folder(name);
Toshihiro Shimizu 890ddd
				if (folderCount == 1)
Toshihiro Shimizu 890ddd
					m_defaultFolder = m_folders[0] = folder;
Toshihiro Shimizu 890ddd
				else if (name != defaultSoundRootFolder.getName())
Toshihiro Shimizu 890ddd
					m_folders.push_back(folder);
Toshihiro Shimizu 890ddd
				folderCount++;
Toshihiro Shimizu 890ddd
				loadFolder(is, folder);
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				throw TException("expected <levels> or <folder>");</folder></levels>
Toshihiro Shimizu 890ddd
			is.closeChild();
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			throw TException("expected tag");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevelSet::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	os.openChild("levels");
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < getLevelCount(); i++) {
Toshihiro Shimizu 890ddd
		TXshLevel *level = getLevel(i);
Toshihiro Shimizu 890ddd
		if (m_saveSet.empty() || m_saveSet.count(level) > 0)
Toshihiro Shimizu 890ddd
			os << level;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.closeChild();
Toshihiro Shimizu 890ddd
	std::vector<tfilepath> folders;</tfilepath>
Toshihiro Shimizu 890ddd
	listFolders(folders, TFilePath());
Toshihiro Shimizu 890ddd
	assert(!folders.empty());
Toshihiro Shimizu 890ddd
	for (i = 0; i < (int)folders.size(); i++)
Toshihiro Shimizu 890ddd
		saveFolder(os, folders[i]);
Toshihiro Shimizu 890ddd
}