Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial parsing of assets.lst
Currently the parsing is done only by a local class AssetsList, and the parsed
information is not exposed or used anywhere else.
  • Loading branch information
Matthew Mott committed Feb 5, 2019
1 parent 51a15c9 commit 37016de
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions radiant/vfs/Doom3FileSystem.cpp
Expand Up @@ -147,6 +147,71 @@ class FileVisitor: public Archive::Visitor
}
};

enum class Visibility
{
/// Standard visibility, shown in all relevant areas
NORMAL,

/// Hidden from selectors, but rendered as normal in the map itself
HIDDEN
};

// Representation of an assets.lst file, containing visibility information for
// assets within a particular folder.
class AssetsList
{
std::map<std::string, Visibility> _visibilities;

// Convert visibility string to enum value
static Visibility toVisibility(const std::string& input)
{
if (string::starts_with(input, "hid" /* 'hidden' or 'hide'*/))
{
return Visibility::HIDDEN;
}
else if (input == "normal")
{
return Visibility::NORMAL;
}
else
{
rWarning() << "AssetsList: failed to parse visibility '" << input
<< "'" << std::endl;
return Visibility::NORMAL;
}
}

public:

static constexpr const char* FILENAME = "assets.lst";

// Construct with possible ArchiveTextFile pointer containing an assets.lst
// file to parse.
AssetsList(ArchiveTextFilePtr inputFile)
{
if (inputFile)
{
// Read lines from the file
std::istream stream(&inputFile->getInputStream());
while (stream.good())
{
std::string line;
std::getline(stream, line);

// Attempt to parse the line as "asset=visibility"
std::vector<std::string> tokens;
string::split(tokens, line, "=");

// Parsing was a success if we have two tokens
if (tokens.size() == 2)
{
_visibilities[tokens[0]] = toVisibility(tokens[1]);
}
}
}
}
};

}

void Doom3FileSystem::initDirectory(const std::string& inputPath)
Expand Down Expand Up @@ -349,6 +414,11 @@ void Doom3FileSystem::forEachFile(const std::string& basedir,
const VisitorFunc& visitorFunc,
std::size_t depth)
{
// Look for an assets.lst in the base dir
std::string assetsLstName = basedir + AssetsList::FILENAME;
ArchiveTextFilePtr assetsLstFile = openTextFile(assetsLstName);
AssetsList assetsList(assetsLstFile);

// Construct our FileVisitor filtering out the right elements
FileVisitor fileVisitor(visitorFunc, basedir, extension, depth);

Expand Down

0 comments on commit 37016de

Please sign in to comment.