KeenFiles.cpp 1.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * ResourceMgmt.cpp
 *
 *  Created on: 16.05.2010
 *      Author: gerstrong
 *
 *  This small but effective code guarantees that the file the game is looking for are really loaded.
 *  It looks into global and local as needed.
 */

#include "KeenFiles.h"
#include <base/utils/FindFile.h>
#include <base/GsLogging.h>

15
#include <base/GsPython.h>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

/**
 * \brief retrieves Ressource ID from a file
 */
int getRessourceID(const std::string& filename, const std::string& namefilter)
{
	int value;
	std::string text = filename.substr(namefilter.size());

	text.erase(text.find("."));

	value = atoi(text.c_str());
	return value;
}

31 32 33 34 35 36 37 38
bool loadGamefileNames()
{
    // Only for python scripts
    if(!gKeenFiles.exeFile.isPythonScript())
        return true;

#if USE_PYTHON3

39
    auto pModule = gPython.loadModule( "keen5", gKeenFiles.gameDir );
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

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

}