Skip to content

Commit

Permalink
DeHackEd: Apply sprite name patches
Browse files Browse the repository at this point in the history
Sprite names are changed in the Sprite and State definitions.

IssueID #1666
  • Loading branch information
skyjake committed Dec 18, 2019
1 parent a70f3b8 commit 3fb2117
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
1 change: 0 additions & 1 deletion doomsday/apps/plugins/importdeh/include/importdeh.h
Expand Up @@ -27,7 +27,6 @@

struct font_s;

//#define DENG_INTERNAL_DATA_ACCESS
#include <doomsday.h>

#include <de/libcore.h>
Expand Down
44 changes: 34 additions & 10 deletions doomsday/apps/plugins/importdeh/src/dehreader.cpp
Expand Up @@ -35,6 +35,7 @@
#include <doomsday/filesys/lumpindex.h>
#include <doomsday/defs/thing.h>
#include <doomsday/defs/state.h>
#include <doomsday/defs/ded.h>
#include <doomsday/game.h>
#include <de/App>
#include <de/ArrayValue>
Expand Down Expand Up @@ -1786,18 +1787,41 @@ class DehReader

bool patchSpriteNames(String const &origName, String const &newName)
{
// Is this a sprite name?
if(origName.length() != 4) return false;
// Is this potentially a sprite name?
if (origName.length() != 4 || newName.length() != 4)
{
return false;
}

// Only sprites names in the original name map can be patched.
/// @todo Why the restriction?
int spriteIdx = findSpriteNameInMap(origName);
if(spriteIdx < 0) return false;
// Look for the corresponding sprite definition and change the sprite name.
auto *defs = DED_Definitions();
for (int i = 0; i < defs->sprites.size(); ++i)
{
if (String(defs->sprites[i].id).compareWithoutCase(origName) == 0)
{
strcpy(defs->sprites[i].id, newName.toLatin1());
LOG_DEBUG("Sprite #%d \"%s\" => \"%s\"")
<< i << origName << newName;

/// @todo Presently disabled because the engine can't handle remapping.
DENG2_UNUSED(newName);
LOG_WARNING("DeHackEd sprite name table remapping is not supported");
return true; // Pretend success.
// Update all states that refer to this sprite.
for (int s = 0; s < defs->states.size(); ++s)
{
auto &state = defs->states[s];
if (state.gets("sprite") == origName)
{
state.set("sprite", newName);
}
}
return true;
}
}

// /// @todo Presently disabled because the engine can't handle remapping.
// DENG2_UNUSED(newName);
// LOG_WARNING("DeHackEd sprite name table remapping is not supported");
// // Pretend success.

return false;

#if 0
if(spriteIdx >= ded->count.sprites.num)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/importdeh/src/info.cpp
Expand Up @@ -227,6 +227,7 @@ int findMusicLumpNameInMap(QString const &name)
return -1; // Not found.
}

#if 0
static QString const SpriteMap[] = {
"TROO",
"SHTG",
Expand Down Expand Up @@ -380,6 +381,7 @@ int findSpriteNameInMap(QString const &name)
}
return -1; // Not found.
}
#endif

static QString const SoundMap[] = {
"None",
Expand Down

0 comments on commit 3fb2117

Please sign in to comment.