Skip to content

Commit

Permalink
libgui|ImageBank: Loading image definitions from an Info file
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 14, 2013
1 parent 34d8bf3 commit 6e2a4f2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
5 changes: 5 additions & 0 deletions doomsday/libgui/include/de/gui/imagebank.h
Expand Up @@ -26,6 +26,8 @@

namespace de {

class File;

/**
* Bank containing Image instances loaded from files.
*
Expand All @@ -47,6 +49,9 @@ class LIBGUI_PUBLIC ImageBank : public Bank

void add(Path const &path, String const &imageFilePath);

void addFromInfo(String const &source, String const &relativeToPath = "");
void addFromInfo(File const &file);

Image &image(Path const &path) const;

protected:
Expand Down
15 changes: 3 additions & 12 deletions doomsday/libgui/src/colorbank.cpp
Expand Up @@ -29,13 +29,8 @@ DENG2_PIMPL(ColorBank)
Instance *d;
String id;

ColorSource(Instance *inst, String const &colorId) : d(inst), id(colorId)
{}

Time modifiedAt() const
{
return d->modTime;
}
ColorSource(Instance *inst, String const &colorId) : d(inst), id(colorId) {}
Time modifiedAt() const { return d->modTime; }

Vector4d load() const
{
Expand All @@ -60,11 +55,7 @@ DENG2_PIMPL(ColorBank)
Vector4d color;

ColorData(Vector4d const &c = Vector4d()) : color(c) {}

duint sizeInMemory() const
{
return 0; // we don't count
}
duint sizeInMemory() const { return 0; /* we don't count */ }
};

Time modTime;
Expand Down
14 changes: 3 additions & 11 deletions doomsday/libgui/src/fontbank.cpp
Expand Up @@ -31,13 +31,8 @@ DENG2_PIMPL(FontBank)
Instance *d;
String id;

FontSource(Instance *inst, String const &fontId) : d(inst), id(fontId)
{}

Time modifiedAt() const
{
return d->modTime;
}
FontSource(Instance *inst, String const &fontId) : d(inst), id(fontId) {}
Time modifiedAt() const { return d->modTime; }

Font *load() const
{
Expand Down Expand Up @@ -78,10 +73,7 @@ DENG2_PIMPL(FontBank)
FontData(Font *f = 0) : font(f) {}
~FontData() { delete font; }

duint sizeInMemory() const
{
return 0; // we don't count
}
duint sizeInMemory() const { return 0; /* we don't count */ }
};

Time modTime;
Expand Down
32 changes: 30 additions & 2 deletions doomsday/libgui/src/imagebank.cpp
Expand Up @@ -19,6 +19,8 @@
#include "de/ImageBank"
#include "de/App"

#include <de/ScriptedInfo>

namespace de {

DENG2_PIMPL_NOREF(ImageBank)
Expand All @@ -27,8 +29,7 @@ DENG2_PIMPL_NOREF(ImageBank)
{
String filePath;

ImageSource(String const &path) : filePath(path)
{}
ImageSource(String const &path) : filePath(path) {}

Time modifiedAt() const
{
Expand Down Expand Up @@ -60,6 +61,8 @@ DENG2_PIMPL_NOREF(ImageBank)
return image.byteCount();
}
};

ScriptedInfo info;
};

ImageBank::ImageBank(Flags const &flags)
Expand All @@ -71,6 +74,31 @@ void ImageBank::add(Path const &path, String const &imageFilePath)
Bank::add(path, new Instance::ImageSource(imageFilePath));
}

void ImageBank::addFromInfo(String const &source, String const &relativeToPath)
{
LOG_AS("ImageBank");
try
{
d->info.parse(source);

foreach(String id, d->info.allBlocksOfType("image"))
{
Record const &def = d->info[id];
add(id, relativeToPath / def["path"]);
}
}
catch(Error const &er)
{
LOG_WARNING("Failed to read Info source:\n") << er.asText();
}
}

void ImageBank::addFromInfo(File const &file)
{
// Relative paths in the defs are assumed relative to this file.
addFromInfo(String::fromUtf8(Block(file)), file.path().fileNamePath());
}

Image &ImageBank::image(Path const &path) const
{
return static_cast<Instance::ImageData &>(data(path)).image;
Expand Down

0 comments on commit 6e2a4f2

Please sign in to comment.