images are now human readable

This commit is contained in:
cornernote 2012-08-17 19:13:52 +09:30
parent addc27c289
commit 62694fc82c
3 changed files with 29 additions and 27 deletions

View File

@ -20,12 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "itemdef.h"
#include "base64.h" // WIKI IMAGE EXTRACT
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <tchar.h>
#include "gamedef.h"
#include "nodedef.h"
#include "tool.h"
@ -40,6 +34,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>
#include <set>
// BEGIN WIKI IMAGE EXTRACT
#include <string>
#include <iostream>
#include <algorithm>
// END WIKI IMAGE EXTRACT
/*
ItemDefinition
*/
@ -471,15 +471,11 @@ public:
);
def->inventory_texture->unlock();
if(wiki_image != NULL) {
//std::string se = def->name;
//for (int i = 0; i < se.length(); ++i) if (se[i] == ':') se[i] = '_';
std::string se = base64_encode(reinterpret_cast<const unsigned char*>(def->name.c_str()), def->name.length());
irr::c8 filename[200];
snprintf(filename, 200, "itemcubes/%s.png", se);
std::string se(def->name);
std::replace(se.begin(), se.end(), ':', '-');
irr::c8 filename[250];
snprintf(filename, 200, "itemcubes/%s.png", se.c_str());
driver->writeImageToFile(wiki_image, filename);
wiki_image->drop();
}
}
@ -565,8 +561,3 @@ IWritableItemDefManager* createItemDefManager()
return new CItemDefManager();
}
void SignalHandler(int signal)
{
printf("Signal %d",signal);
throw "!Access Violation!";
}

View File

@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tile.h"
#include "debug.h"
#include "base64.h" // WIKI IMAGE EXTRACT
#include "main.h" // for g_settings
#include "filesys.h"
#include "settings.h"
@ -34,6 +33,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/thread.h"
#include "util/numeric.h"
// BEGIN WIKI IMAGE EXTRACT
#include <string>
#include <iostream>
#include <algorithm>
std::string myreplace(std::string &s, std::string toReplace, std::string replaceWith)
{
return(s.replace(s.find(toReplace), toReplace.length(), replaceWith));
}
// END WIKI IMAGE EXTRACT
/*
A cache from texture name to texture path
*/
@ -1615,12 +1624,15 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
// BEGIN WIKI IMAGE EXTRACT
infostream<<"part_of_name = "<<part_of_name<<std::endl;
irr::c8 filename[1024];
std::string se = base64_encode(reinterpret_cast<const unsigned char*>(part_of_name.c_str()), part_of_name.length());
snprintf(filename, 1024, "itemcubes/%s.png", se);
std::string se(part_of_name);
myreplace(se,":","-");
myreplace(se,"[inventorycube","");
myreplace(se,".png","");
irr::c8 filename[250];
snprintf(filename, 250, "itemcubes/%s.png", se.c_str());
driver->writeImageToFile(baseimg, filename);
// END WIKI IMAGE EXTRACT
}
}
/*
@ -1708,7 +1720,6 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
errorstream<<"generate_image(): Invalid "
" modification: \""<<part_of_name<<"\""<<std::endl;
}
}
return true;

View File

@ -75,13 +75,13 @@ function item_image($item, $options = array())
{
$file = false;
if (!$file && !empty($item['name'])) {
$file = 'itemcubes/' . str_replace('=', '', base64_encode($item['name'])) . '.png';
$file = 'itemcubes/' . str_replace(':', '-', $item['name']) . '.png';
if (!file_exists($file))
$file = false;
}
if (!$file && !empty($item['image'])) {
if (substr($item['image'], 0, 14) == '[inventorycube') {
$file = 'itemcubes/' . str_replace('=', '', base64_encode($item['image'])) . '.png';
$file = 'itemcubes/' . str_replace(array('[inventorycube','.png'), '', base64_encode($item['image'])) . '.png';
if (!file_exists($file))
return '';
}