Пример #1
0
    bool GlobalScripts::readRecord (ESM::ESMReader& reader, int32_t type)
    {
        if (type==ESM::REC_GSCR)
        {
            ESM::GlobalScript script;
            script.load (reader);

            std::map<std::string, std::pair<bool, Locals> >::iterator iter =
                mScripts.find (script.mId);

            if (iter==mScripts.end())
            {
                if (const ESM::Script *scriptRecord = mStore.get<ESM::Script>().search (script.mId))
                {
                    std::pair<bool, Locals> data (false, Locals());

                    data.second.configure (*scriptRecord);

                    iter = mScripts.insert (std::make_pair (script.mId, data)).first;
                }
                else // script does not exist anymore
                    return true;
            }

            iter->second.first = script.mRunning!=0;
            iter->second.second.read (script.mLocals, script.mId);

            return true;
        }

        return false;
    }
Пример #2
0
    void GlobalScripts::write (ESM::ESMWriter& writer) const
    {
        for (std::map<std::string, std::pair<bool, Locals> >::const_iterator iter (mScripts.begin());
            iter!=mScripts.end(); ++iter)
        {
            ESM::GlobalScript script;

            script.mId = iter->first;

            iter->second.second.write (script.mLocals, iter->first);

            script.mRunning = iter->second.first ? 1 : 0;

            writer.startRecord (ESM::REC_GSCR);
            script.save (writer);
            writer.endRecord (ESM::REC_GSCR);
        }
    }
Пример #3
0
    bool GlobalScripts::readRecord (ESM::ESMReader& reader, uint32_t type)
    {
        if (type==ESM::REC_GSCR)
        {
            ESM::GlobalScript script;
            script.load (reader);

            std::map<std::string, GlobalScriptDesc>::iterator iter =
                mScripts.find (script.mId);

            if (iter==mScripts.end())
            {
                if (const ESM::Script *scriptRecord = mStore.get<ESM::Script>().search (script.mId))
                {
                    try
                    {
                        GlobalScriptDesc desc;
                        desc.mLocals.configure (*scriptRecord);

                        iter = mScripts.insert (std::make_pair (script.mId, desc)).first;
                    }
                    catch (const std::exception& exception)
                    {
                        std::cerr
                            << "Failed to add start script " << script.mId
                            << " because an exception has been thrown: " << exception.what()
                            << std::endl;

                        return true;
                    }
                }
                else // script does not exist anymore
                    return true;
            }

            iter->second.mRunning = script.mRunning!=0;
            iter->second.mLocals.read (script.mLocals, script.mId);
            iter->second.mId = script.mTargetId;

            return true;
        }

        return false;
    }
Пример #4
0
    void GlobalScripts::write (ESM::ESMWriter& writer, Loading::Listener& progress) const
    {
        for (std::map<std::string, GlobalScriptDesc>::const_iterator iter (mScripts.begin());
            iter!=mScripts.end(); ++iter)
        {
            ESM::GlobalScript script;

            script.mId = iter->first;

            iter->second.mLocals.write (script.mLocals, iter->first);

            script.mRunning = iter->second.mRunning ? 1 : 0;

            script.mTargetId = iter->second.mId;

            writer.startRecord (ESM::REC_GSCR);
            script.save (writer);
            writer.endRecord (ESM::REC_GSCR);
        }
    }