Exemplo n.º 1
0
void GlobalScripts::addScript (const std::string& name)
{
    if (mScripts.find (name)==mScripts.end())
        if (const ESM::Script *script = mStore.scripts.find (name))
        {
            Locals locals;

            locals.configure (*script);

            mScripts.insert (std::make_pair (name, std::make_pair (true, locals)));
        }
}
Exemplo n.º 2
0
    void GlobalScripts::addScript (const std::string& name)
    {
        std::map<std::string, std::pair<bool, Locals> >::iterator iter =
            mScripts.find (::Misc::StringUtils::lowerCase (name));

        if (iter==mScripts.end())
        {
            if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
            {
                Locals locals;

                locals.configure (*script);

                mScripts.insert (std::make_pair (name, std::make_pair (true, locals)));
            }
        }
        else
            iter->second.first = true;
    }
Exemplo n.º 3
0
    Locals& GlobalScripts::getLocals (const std::string& name)
    {
        std::string name2 = ::Misc::StringUtils::lowerCase (name);
        std::map<std::string, std::pair<bool, Locals> >::iterator iter =
            mScripts.find (name2);

        if (iter==mScripts.end())
        {
            if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
            {
                Locals locals;

                locals.configure (*script);

                iter = mScripts.insert (std::make_pair (name, std::make_pair (false, locals))).first;
            }
        }

        return iter->second.second;
    }
Exemplo n.º 4
0
bool IoCmd::exportLevel(const TFilePath &path, TXshSimpleLevel *sl,
						ExportLevelOptions opts,
						OverwriteCallbacks *overwriteCB, ProgressCallbacks *progressCB)
{
	struct Locals {
		const TFilePath &m_path;
		TXshSimpleLevel *m_sl;
		const ExportLevelOptions &m_opts;

		OverwriteCallbacks *m_overwriteCB;
		ProgressCallbacks *m_progressCB;

		bool exportToMultifile()
		{
			ImageExporter exporter(*m_sl, m_opts);

			TXshLevelType outputLevelType = (m_path.getType() == "tlv") ? TZP_TYPE : OVL_TYPE;

			bool firstTime = true;
			for (int i = 0; i < m_sl->getFrameCount(); ++i) {
				if (m_progressCB->canceled())
					return false;

				// Prepare frame export path
				TFilePath fpout;

				if (m_opts.m_forRetas) {
					QString pathOut = QString::fromStdWString(m_path.getParentDir().getWideString()) +
									  "\\" + QString::fromStdString(m_path.getName()) +
									  QString::fromStdString(m_sl->index2fid(i).expand()) +
									  "." + QString::fromStdString(m_path.getType());
					fpout = TFilePath(pathOut.toStdString());
				} else
					fpout = TFilePath(m_path.withFrame(m_sl->index2fid(i)));

				// Ask for overwrite permission in case a level with the built path already exists
				if (firstTime) {
					firstTime = false;

					if (TSystem::doesExistFileOrLevel(fpout)) {
						QApplication::restoreOverrideCursor();
						bool overwrite = m_overwriteCB->overwriteRequest(fpout);
						QApplication::setOverrideCursor(Qt::WaitCursor);

						if (!overwrite)
							return false;
					}
				}

				// Retrieve the image to export at current frame
				TImageP img = exporter.exportedImage(m_sl->index2fid(i), outputLevelType);
				assert(img);

				// Save the prepared fullcolor image to file
				TImageWriter iw(fpout);
				iw.setProperties(m_opts.m_props);
				iw.save(img);

				m_progressCB->setValue(i + 1);
			}

			return true;
		}

		bool exportToTlv()
		{
			TFilePath fp(m_path.withNoFrame());

			// Remove any existing level
			if (TSystem::doesExistFileOrLevel(fp)) {
				bool overwrite = m_overwriteCB->overwriteRequest(fp);
				if (!overwrite)
					return false;

				TSystem::deleteFile(fp);
			}

			TSystem::removeFileOrLevel(fp.withType("tpl"));

			// Export level
			TLevelWriterP lw(fp);

			ImageExporter exporter(*m_sl, m_opts);

			for (int i = 0; i < m_sl->getFrameCount(); ++i) {
				if (m_progressCB->canceled())
					return false;

				const TFrameId &fid = m_sl->index2fid(i);

				TImageP img = exporter.exportedImage(fid, TZP_TYPE);
				assert(img);

				lw->getFrameWriter(fid)->save(img);

				m_progressCB->setValue(i + 1);
			}

			return true;
		}
	}; // Locals

	// Use default values in case some were not specified by input

	// Level
	if (!sl) {
		sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();

		if (!sl) {
			DVGui::error(QObject::tr("No level selected!"));
			return false;
		}
	}

	if (sl->isEmpty())
		return false;

	// Output properties
	if (!opts.m_props) {
		ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
		opts.m_props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(path.getType());
	}

	// Camera (todo)
	assert(opts.m_camera.getRes().lx > 0 &&
		   opts.m_camera.getRes().ly > 0);

	// Callbacks
	std::auto_ptr<OverwriteCallbacks> overwriteDefault(
		overwriteCB ? 0 : (overwriteCB = new ExportOverwriteCB()));
	std::auto_ptr<ProgressCallbacks> progressDefault(
		progressCB ? 0 : (progressCB = new ExportProgressCB()));

	// Initialize variables
	Locals locals = {path, sl, opts, overwriteCB, progressCB};

	progressCB->setProcessedName(QString::fromStdWString(path.getWideString()));
	progressCB->setRange(0, sl->getFrameCount());

	// Export level
	BusyCursorOverride cursorOverride;
	QCoreApplication::processEvents(); // Refresh screen.   ...But WHY is this
									   //                      necessary?
	try {
		return (path.getType() == "tlv") ? assert(sl->getType() == PLI_XSHLEVEL),
			   locals.exportToTlv() : locals.exportToMultifile();
	} catch (...) {
		return false;
	}
}