Skip to content

Commit

Permalink
Fixed|Definitions|Deh Reader: Conflicting MAPINFO and DeHackEd music
Browse files Browse the repository at this point in the history
If there is both a DEH that overrides music lump names and a custom MAPINFO that sets map music, prefer to use only the latter.

IssueID #2303
  • Loading branch information
skyjake committed Dec 6, 2019
1 parent ecd7f0b commit 549c090
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/defs/definition.h
Expand Up @@ -47,6 +47,8 @@ class LIBDOOMSDAY_PUBLIC Definition : public de::RecordAccessor
*/
operator bool() const;

de::String id() const;

/**
* Returns the ordinal of the definition. Ordinals are automatically set by
* DEDRegister as definitions are created.
Expand Down
6 changes: 6 additions & 0 deletions doomsday/apps/libdoomsday/src/defs/definition.cpp
Expand Up @@ -40,6 +40,12 @@ Record const &Definition::def() const
return accessedRecord();
}

String Definition::id() const
{
if (!accessedRecordPtr()) return {};
return gets(VAR_ID);
}

int Definition::order() const
{
if (!accessedRecordPtr()) return -1;
Expand Down
15 changes: 11 additions & 4 deletions doomsday/apps/plugins/importdeh/src/dehreader.cpp
Expand Up @@ -1836,14 +1836,21 @@ class DehReader
int numPatched = 0;
for(int i = 0; i < ded->musics.size(); ++i)
{
Record &music = ded->musics[i];
if(music.gets("lumpName").compareWithoutCase(origNamePref)) continue;
defn::Definition music{ded->musics[i]};
if (music.id().endsWith("_dd_xlt"))
{
// This is a Music definition generated by MapInfoTranslator based on
// a custom MAPINFO lump. We'll skip it because the music lump set in the
// MAPINFO should be used instead.
continue;
}
if (music.gets("lumpName").compareWithoutCase(origNamePref)) continue;

music.set("lumpName", newNamePref);
music.def().set("lumpName", newNamePref);
numPatched++;

LOG_DEBUG("Music #%i \"%s\" lumpName => \"%s\"")
<< i << music.gets("id") << music.gets("lumpName");
<< i << music.id() << music.gets("lumpName");
}
return (numPatched > 0);
}
Expand Down
7 changes: 4 additions & 3 deletions doomsday/apps/plugins/importidtech1/src/mapinfotranslator.cpp
Expand Up @@ -655,9 +655,9 @@ namespace internal {
*/
void parseMap(MapInfo *info = 0)
{
de::Uri mapUri;
if(!info)
{
de::Uri mapUri;
String const mapRef = String(Str_Text(lexer.readString()));

bool isNumber;
Expand Down Expand Up @@ -1469,6 +1469,7 @@ DENG2_PIMPL_NOREF(MapInfoTranslator)
if (mapUri.path().isEmpty()) continue;

const String mapId = toMapId(mapUri);
const String musicId = mapId + "_dd_xlt"; // doomsday translated
const String musicLumpName = info.gets("music");
bool addedMusicDef = false;

Expand All @@ -1478,7 +1479,7 @@ DENG2_PIMPL_NOREF(MapInfoTranslator)

// Add a music def for this custom music.
os << "\n\nMusic {"
<< "\n ID = \"" + mapId + "\";"; // music ID == map ID
<< "\n ID = \"" + musicId + "\";";
if (!musicLumpName.isEmpty())
{
os << "\n Lump = \"" + musicLumpName + "\";";
Expand All @@ -1499,7 +1500,7 @@ DENG2_PIMPL_NOREF(MapInfoTranslator)
os << "\n Fade Table = \"" + info.gets("fadeTable") + "\";";
if (addedMusicDef)
{
os << "\n Music = \"" + mapId + "\";";
os << "\n Music = \"" + musicId + "\";";
}
de::Uri titleImageUri(info.gets("titleImage"), RC_NULL);
if(!titleImageUri.path().isEmpty())
Expand Down

0 comments on commit 549c090

Please sign in to comment.