mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-04 00:26:45 +00:00 
			
		
		
		
	Merge DialInfo objects by subrecord instead of overwriting the object
Fixes #1360
This commit is contained in:
		
							parent
							
								
									d26f756c53
								
							
						
					
					
						commit
						16ac6e7aac
					
				
					 3 changed files with 45 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -68,13 +68,12 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
 | 
			
		|||
 | 
			
		||||
        if (it == mStores.end()) {
 | 
			
		||||
            if (n.val == ESM::REC_INFO) {
 | 
			
		||||
                std::string id = esm.getHNOString("INAM");
 | 
			
		||||
                if (dialogue) {
 | 
			
		||||
                    ESM::DialInfo info;
 | 
			
		||||
                    info.mId = id;
 | 
			
		||||
                    info.load(esm);
 | 
			
		||||
                    dialogue->addInfo(info, esm.getIndex() != 0);
 | 
			
		||||
                } else {
 | 
			
		||||
                if (dialogue)
 | 
			
		||||
                {
 | 
			
		||||
                    dialogue->readInfo(esm, esm.getIndex() != 0);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    std::cerr << "error: info record without dialog" << std::endl;
 | 
			
		||||
                    esm.skipRecord();
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,21 +40,21 @@ void Dialogue::save(ESMWriter &esm) const
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    void Dialogue::blank()
 | 
			
		||||
    {
 | 
			
		||||
        mInfo.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
 | 
			
		||||
void Dialogue::blank()
 | 
			
		||||
{
 | 
			
		||||
    if (!merge || mInfo.empty() || info.mNext.empty())
 | 
			
		||||
    mInfo.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Dialogue::readInfo(ESMReader &esm, bool merge)
 | 
			
		||||
{
 | 
			
		||||
    const std::string& id = esm.getHNOString("INAM");
 | 
			
		||||
 | 
			
		||||
    if (!merge || mInfo.empty())
 | 
			
		||||
    {
 | 
			
		||||
        mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (info.mPrev.empty())
 | 
			
		||||
    {
 | 
			
		||||
        mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
 | 
			
		||||
        ESM::DialInfo info;
 | 
			
		||||
        info.mId = id;
 | 
			
		||||
        info.load(esm);
 | 
			
		||||
        mLookup[id] = mInfo.insert(mInfo.end(), info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -62,11 +62,30 @@ void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
 | 
			
		|||
 | 
			
		||||
    std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
 | 
			
		||||
 | 
			
		||||
    lookup = mLookup.find(info.mId);
 | 
			
		||||
    lookup = mLookup.find(id);
 | 
			
		||||
    if (lookup != mLookup.end())
 | 
			
		||||
    {
 | 
			
		||||
        it = lookup->second;
 | 
			
		||||
        *it = info;
 | 
			
		||||
 | 
			
		||||
        // Merge with existing record. Only the subrecords that are present in
 | 
			
		||||
        // the new record will be overwritten.
 | 
			
		||||
        it->load(esm);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // New record
 | 
			
		||||
    ESM::DialInfo info;
 | 
			
		||||
    info.mId = id;
 | 
			
		||||
    info.load(esm);
 | 
			
		||||
 | 
			
		||||
    if (info.mNext.empty())
 | 
			
		||||
    {
 | 
			
		||||
        mLookup[id] = mInfo.insert(mInfo.end(), info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (info.mPrev.empty())
 | 
			
		||||
    {
 | 
			
		||||
        mLookup[id] = mInfo.insert(mInfo.begin(), info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +94,7 @@ void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
 | 
			
		|||
    {
 | 
			
		||||
        it = lookup->second;
 | 
			
		||||
 | 
			
		||||
        mLookup[info.mId] = mInfo.insert(++it, info);
 | 
			
		||||
        mLookup[id] = mInfo.insert(++it, info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -84,11 +103,11 @@ void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
 | 
			
		|||
    {
 | 
			
		||||
        it = lookup->second;
 | 
			
		||||
 | 
			
		||||
        mLookup[info.mId] = mInfo.insert(it, info);
 | 
			
		||||
        mLookup[id] = mInfo.insert(it, info);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::cerr << "Failed to insert info " << info.mId << std::endl;
 | 
			
		||||
    std::cerr << "Failed to insert info " << id << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,8 +47,9 @@ struct Dialogue
 | 
			
		|||
    void load(ESMReader &esm);
 | 
			
		||||
    void save(ESMWriter &esm) const;
 | 
			
		||||
 | 
			
		||||
    /// Read the next info record
 | 
			
		||||
    /// @param merge Merge with existing list, or just push each record to the end of the list?
 | 
			
		||||
    void addInfo (const ESM::DialInfo& info, bool merge);
 | 
			
		||||
    void readInfo (ESM::ESMReader& esm, bool merge);
 | 
			
		||||
 | 
			
		||||
    void blank();
 | 
			
		||||
    ///< Set record to default state (does not touch the ID and does not change the type).
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue