Skip to content

Commit

Permalink
More fatal log messages for maps. Fixed fatal logs for scenes.
Browse files Browse the repository at this point in the history
  • Loading branch information
TricksterGuy committed Feb 16, 2015
1 parent 853c5f9 commit 397b5a3
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ set(SRC_NIN10KITGUI
gui/nin10kitviewer.cpp
gui/imageutil.cpp
gui/exporter.cpp
gui/wxlogger.cpp
)

find_package(wxWidgets REQUIRED core base)
Expand Down
20 changes: 14 additions & 6 deletions gui/exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,20 @@ void DoExport(int mode, const std::string& filename, std::vector<std::string>& f
}
}

if (params.device == "GBA")
DoGBAExport(params.images, params.tileset_images);
else if (params.device == "DS")
DoDSExport(params.images, params.tileset_images);
else if (params.device == "3DS")
Do3DSExport(params.images, params.tileset_images);
try
{
if (params.device == "GBA")
DoGBAExport(params.images, params.tileset_images);
else if (params.device == "DS")
DoDSExport(params.images, params.tileset_images);
else if (params.device == "3DS")
Do3DSExport(params.images, params.tileset_images);
}
catch (const char* e)
{
WarnLog("Export failed");
return;
}

InfoLog("Export complete now writing files");
// Write the files
Expand Down
8 changes: 7 additions & 1 deletion gui/nin10kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ void Nin10KitFrame::OnView(wxCommandEvent& event)
viewer = new Nin10KitViewerFrame();

viewer->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Nin10KitFrame::OnCloseView), NULL, this);
viewer->Set(mode->GetSelection(), images);
if (!viewer->Set(mode->GetSelection(), images))
{
viewer->Close(true);
delete viewer;
viewer = NULL;
return;
}
viewer->Show(true);
}

Expand Down
3 changes: 2 additions & 1 deletion gui/nin10kitapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include "cmd-line-parser-helper.hpp"
#include "cpercep.hpp"
#include "logger.hpp"
#include "wxlogger.hpp"

IMPLEMENT_APP_NO_MAIN(Nin10KitApp);

int main(int argc, char** argv)
{
logger.reset(new LoggerWx());
Magick::InitializeMagick(*argv);
cpercep_init();

Expand Down
27 changes: 18 additions & 9 deletions gui/nin10kitviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,32 @@ Nin10KitViewerFrame::~Nin10KitViewerFrame()
{
}

void Nin10KitViewerFrame::Set(int prog_mode, std::map<std::string, ImageInfo>& images)
bool Nin10KitViewerFrame::Set(int prog_mode, std::map<std::string, ImageInfo>& images)
{
std::string mode, device;
int bpp;

GetModeInfo(prog_mode, mode, device, bpp);
VerboseLog("Viewing in mode %s", mode.c_str());

if (mode == "3")
UpdateMode3(images);
else if (mode == "4")
UpdateMode4(images);
else if (mode == "0")
UpdateMode0(images, bpp);
else if (mode == "SPRITES")
UpdateSprites(images, bpp);
try
{
if (mode == "3")
UpdateMode3(images);
else if (mode == "4")
UpdateMode4(images);
else if (mode == "0")
UpdateMode0(images, bpp);
else if (mode == "SPRITES")
UpdateSprites(images, bpp);
}
catch (const char* e)
{
WarnLog("Conversion failed");
return false;
}
UpdateGraphicsWindow();
return true;
}

void Nin10KitViewerFrame::UpdateMode3(std::map<std::string, ImageInfo>& images)
Expand Down
2 changes: 1 addition & 1 deletion gui/nin10kitviewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Nin10KitViewerFrame : public Nin10KitViewerGUI
public:
Nin10KitViewerFrame();
~Nin10KitViewerFrame();
void Set(int mode, std::map<std::string, ImageInfo>& images);
bool Set(int mode, std::map<std::string, ImageInfo>& images);
void OnPrev(wxCommandEvent& event);
void OnNext(wxCommandEvent& event);
private:
Expand Down
9 changes: 7 additions & 2 deletions shared/image8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ Magick::Image Image8Bpp::ToMagick() const

Image8BppScene::Image8BppScene(const std::vector<Image16Bpp>& images16, const std::string& name) : Scene(name), palette(new Palette(name))
{
for (const auto& image : images16)
{
if (image.width & 1)
FatalLog("Image: %s width is not a multiple of 2. Please fix", name.c_str());
}
GetPalette(images16, params.palette, params.transparent_color, params.offset, *palette);

images.reserve(images16.size());
for (unsigned int i = 0; i < images16.size(); i++)
images.emplace_back(new Image8Bpp(images16[i], palette));
for (const auto& image : images16)
images.emplace_back(new Image8Bpp(image, palette));
}

const Image8Bpp& Image8BppScene::GetImage(int index) const
Expand Down
3 changes: 1 addition & 2 deletions shared/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ class AbstractLogger
public:
AbstractLogger(std::ostream* target = &std::cerr) : out(target), log_level(LogLevel::INFO), log_time(true) {}
virtual ~AbstractLogger() {}
void Log(LogLevel level, const char* format, va_list ap);
virtual void Log(LogLevel level, const char* format, va_list ap);
virtual void DoLog(LogLevel level, const char* format, va_list ap) {}
void SetLogTarget(std::ostream* stream) {out = stream;}
void SetLogLevel(LogLevel level) {log_level = level;}
void SetLogTime(bool logging_time) {log_time = logging_time;}
protected:
std::ostream* out;
private:
LogLevel log_level;
bool log_time;
};
Expand Down
11 changes: 11 additions & 0 deletions shared/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Map::Map(const Image16Bpp& image, int bpp) : Image(image.width / 8, image.height / 8, image.name, image.filename, image.frame, image.animated),
data(width * height), tileset(NULL), export_shared_info(true)
{
if ((image.width != 256 && image.width != 512) || (image.height != 256 && image.height != 512))
FatalLog("Invalid map size for image %s, (%d %d) Please fix", image.name.c_str(), image.width, image.height);
// Create tileset according to bpp
tileset.reset(new Tileset(image, bpp));

Expand All @@ -26,6 +28,9 @@ Map::Map(const Image16Bpp& image, int bpp) : Image(image.width / 8, image.height
Map::Map(const Image16Bpp& image, std::shared_ptr<Tileset>& global_tileset) : Image(image.width / 8, image.height / 8, image.name, image.filename, image.frame, image.animated),
data(width * height), tileset(global_tileset), export_shared_info(false)
{
if ((image.width != 256 && image.width != 512) || (image.height != 256 && image.height != 512))
FatalLog("Invalid map size for image %s, (%d %d) Please fix", image.name.c_str(), image.width, image.height);

switch(tileset->bpp)
{
case 4:
Expand Down Expand Up @@ -144,6 +149,12 @@ void Map::WriteExport(std::ostream& file) const

MapScene::MapScene(const std::vector<Image16Bpp>& images16, const std::string& _name, int bpp) : Scene(_name), tileset(NULL)
{
for (const auto& image : images16)
{
if ((image.width != 256 && image.width != 512) || (image.height != 256 && image.height != 512))
FatalLog("Invalid map size for image %s, (%d %d) Please fix", image.name.c_str(), image.width, image.height);
}

tileset.reset(new Tileset(images16, name, bpp));

for (const auto& image : images16)
Expand Down
4 changes: 2 additions & 2 deletions shared/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Sprite::Sprite(const Image16Bpp& image, std::shared_ptr<Palette>& global_palette
shape = sprite_shapes[key];
size = sprite_sizes[key];
if (size == -1 || image.width & 7 || image.height & 7)
FatalLog("Invalid sprite size, (%d %d) Please fix", image.width, image.height);
FatalLog("Invalid sprite size for image %s, (%d %d) Please fix", image.name.c_str(), image.width, image.height);

// Is actually an 8 or 4bpp image
Image8Bpp image8(image, palette);
Expand All @@ -49,7 +49,7 @@ Sprite::Sprite(const Image16Bpp& image, int _bpp) : Image(image.width / 8, image
shape = sprite_shapes[key];
size = sprite_sizes[key];
if (size == -1 || image.width & 7 || image.height & 7)
FatalLog("Invalid sprite size, (%d %d) Please fix", image.width, image.height);
FatalLog("Invalid sprite size for image %s, (%d %d) Please fix", image.name.c_str(), image.width, image.height);

GetPalette(image.pixels, 1 << bpp, params.transparent_color, 0, *palette);
// Is actually an 8 or 4bpp image
Expand Down

0 comments on commit 397b5a3

Please sign in to comment.