Commit 3b9ad3b3 authored by Gerhard Stein's avatar Gerhard Stein

Some filenames can now be read from main python script

parent a183bf7c
Subproject commit d6fd2b5407e9abcc5a8e4ed1d9c754d9b2d4338d
Subproject commit b1fe274f4ffea6f1319f23aa04c880a7ba6db364
......@@ -40,10 +40,8 @@ bool loadActionFile(const std::string &actFilePath)
return true;
}
void ActionFormatType::setActionFormat( const size_t sprite_offset )
byte *getActionBasePtr()
{
byte *ptr = nullptr;
auto &exeFile = gKeenFiles.exeFile;
if(exeFile.isPythonScript())
......@@ -62,19 +60,23 @@ void ActionFormatType::setActionFormat( const size_t sprite_offset )
if(actFullFilePath == "")
{
gLogging << "Error Loading Action file " << actFullFilePath;
return;
return nullptr;
}
loadActionFile(actFullFilePath);
}
ptr = actionFormatData.data();
return actionFormatData.data();
}
else
{
ptr = exeFile.getDSegPtr();
return exeFile.getDSegPtr();
}
}
void ActionFormatType::setActionFormat( const size_t sprite_offset )
{
byte *ptr = getActionBasePtr();
ptr += sprite_offset;
memcpy( this, ptr, 15*sizeof(int16_t) );
}
......@@ -92,7 +94,7 @@ void ActionFormatType::setNextActionFormat()
bool ActionFormatType::getActionFormat( const size_t sprite_offset )
{
byte *ptr = gKeenFiles.exeFile.getDSegPtr();
byte *ptr = getActionBasePtr();
ptr += sprite_offset;
return (memcmp( this, ptr, 15*sizeof(int16_t) ) == 0);
}
......@@ -101,8 +103,7 @@ bool ActionFormatType::getActionFormat( const size_t sprite_offset )
bool dumpActionFormatToFile(const std::string &fileName,
const size_t numChunks)
{
auto &exeFile = gKeenFiles.exeFile;
byte *ptr = exeFile.getDSegPtr();
byte *ptr = getActionBasePtr();
//std::vector<byte> actionData(numChunks*30, 0);
std::vector<byte> actionData;
......
......@@ -59,6 +59,11 @@ bool KeenEngine::start()
gKeenFiles.setupFilenames(mEp);
if(!loadGamefileNames())
{
return false;
}
gBehaviorEngine.setEpisode(mEp);
// Load the Resources
......
......@@ -127,7 +127,8 @@ bool CMapLoaderGalaxy::unpackPlaneData( std::ifstream &mapFile,
for(size_t i=0 ; i<length ; i++)
{
Carmack_Plane.push_back( mapFile.get() );
const byte value = mapFile.get();
Carmack_Plane.push_back( value );
}
size_t decarmacksize = (Carmack_Plane.at(1)<<8)+Carmack_Plane.at(0);
......@@ -246,7 +247,8 @@ bool CMapLoaderGalaxy::loadMap(CMap &Map, Uint8 level)
std::string gamemapfile = gKeenFiles.gamemapsFilename;
std::ifstream MapFile;
if(OpenGameFileR(MapFile, getResourceFilename(gamemapfile,path,true,false), std::ios::binary))
if(OpenGameFileR(MapFile,
getResourceFilename(gamemapfile,path,true,false), std::ios::binary))
{
if(level_offset == 0 && mapHeadContainer.empty())
{
......
......@@ -55,6 +55,7 @@ bool CTileLoader::readOffsetMapfromFile(const std::string &tliFname,
tliFile.seekg(0, tliFile.end);
const auto fileSize = tliFile.tellg();
tliFile.seekg(0, tliFile.beg);
tileData.resize(size_t(fileSize));
tliFile.read(reinterpret_cast<char*>(tileData.data()), fileSize);
......
......@@ -12,7 +12,7 @@
#include <base/utils/FindFile.h>
#include <base/GsLogging.h>
#include <base/GsPython.h>
/**
* \brief retrieves Ressource ID from a file
......@@ -28,3 +28,33 @@ int getRessourceID(const std::string& filename, const std::string& namefilter)
return value;
}
bool loadGamefileNames()
{
// Only for python scripts
if(!gKeenFiles.exeFile.isPythonScript())
return true;
#if USE_PYTHON3
auto pModule = gPython.loadModule( "keen5", gKeenFiles.gameDir );
if (pModule != nullptr)
{
bool ok = true;
std::string stdmapheadFilename;
ok &= loadStrFunction(pModule, "getMapheadFile", stdmapheadFilename);
std::string stdGamemapsFilename;
ok &= loadStrFunction(pModule, "getGamemapsFile", stdGamemapsFilename);
gKeenFiles.mapheadFilename = stdmapheadFilename;
gKeenFiles.gamemapsFilename = stdGamemapsFilename;
return ok;
}
return false;
#endif
}
......@@ -74,4 +74,6 @@ struct FileListAdder
int getRessourceID(const std::string& filename, const std::string& namefilter);
bool loadGamefileNames();
#endif /* __KEENFILES_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment