1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/*
Copyright (C) 2012 by Aaron Perez <aaronps@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <cstdlib>
#include "SDL.h"
#include "Util/FileSystem.hpp"
#include "2D/PackedSurface.hpp"
#include "2D/Surface.hpp"
#include "2D/Palette.hpp"
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
/*******************************************************************/
// BEGIN hacks to avoid compiling everything just for this converter
typedef const struct s_ScriptVarBindRecord ScriptVarBindRecord;
struct lua_State;
struct luaL_Reg;
class ScriptManager
{
public:
static void runFileInTable(const NPString& filename, const NPString& table);
static void registerLib(const NPString& libname, const luaL_Reg * functions);
static void bindStaticVariables(const NPString& objectName,
const NPString& metaName,
ScriptVarBindRecord * getters,
ScriptVarBindRecord * setters);
};
void ScriptManager::runFileInTable(const NPString &filename, const NPString &table)
{
return;
}
void ScriptManager::registerLib(const NPString &libname, const luaL_Reg *functions)
{
return;
}
void ScriptManager::bindStaticVariables(const NPString &objectName, const NPString &metaName, ScriptVarBindRecord *getters, ScriptVarBindRecord *setters)
{
return;
}
class ScriptHelper
{
public:
static int get_byte (lua_State *L, void *v);
static int set_byte (lua_State *L, void *v);
};
int ScriptHelper::get_byte(lua_State *L, void *v)
{
return 0;
}
int ScriptHelper::set_byte(lua_State *L, void *v)
{
return 0;
}
// END hacks
/*******************************************************************/
int main ( int argc, char** argv )
{
printf("bmp2pak for NetPanzer V 1.0\n");
if (argc < 3 )
{
printf("use: %s <filename.def> <outfile.pak>\n", argv[0]);
printf("note: even on windows the path must be separated by '/'\n");
printf("note2: the .bmp files has to be in same folder as .def file\n");
return 1;
}
string filename = argv[1];
string filename_noext = filename.substr(0,filename.size()-4);
string outfile = argv[2];
if ( ! PHYSFS_init(argv[0]) )
{
printf("Error initializing filesystem: %s", PHYSFS_getLastError());
return 1;
}
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
PHYSFS_setWriteDir(PHYSFS_getBaseDir());
FILE *f = fopen(filesystem::getRealWriteName(filename.c_str()).c_str(), "r");
if ( !f )
{
printf("Error: cannot open def file %s\n", filename.c_str());
PHYSFS_deinit();
return 1;
}
int width = -1, height = -1;
int frames = -1;
float fps = -1;
int offset_x = -1, offset_y = -1;
bool isError = false;
isError = fscanf(f,"size=%d,%d\n", &width, &height) != 2;
isError |= fscanf(f,"frames=%d\n", &frames) != 1;
isError |= fscanf(f,"fps=%f\n", &fps) != 1;
isError |= fscanf(f,"offset=%d,%d\n", &offset_x, &offset_y) != 2;
fclose(f);
if ( isError )
{
printf("Error loading def file, check it\n");
PHYSFS_deinit();
return 1;
}
printf("size=%d,%d\n", width, height);
printf("frames=%d\n", frames);
printf("fps=%f\n", fps);
printf("offset=%d,%d\n", offset_x, offset_y);
Surface unpacked(width, height, frames);
unpacked.setFPS(fps);
unpacked.setOffsetX(offset_x);
unpacked.setOffsetY(offset_y);
Surface bmp;
for ( int n = 0; n < frames; n++ )
{
std::stringstream bfile;
bfile << filename_noext << "_" << n << ".bmp";
bmp.loadBMP(bfile.str().c_str());
printf("Loaded: %s\n", bfile.str().c_str());
unpacked.setFrame(n);
unpacked.fill(0);
bmp.blt(unpacked, 0, 0);
}
PackedSurface pak;
pak.pack(unpacked);
pak.setFPS(fps);
pak.save(outfile);
printf("Wrote to: %s\n", filesystem::getRealWriteName(outfile.c_str()).c_str());
PHYSFS_deinit();
printf("Exited cleanly\n");
return 0;
}
|