Basic assets lists constructor
General datas/lists structure should be reviewed
This commit is contained in:
parent
e07d861535
commit
5764d27ef4
@ -58,6 +58,7 @@ namespace RDI {
|
||||
* @return Handler of RogueData file, should be used with other function of this lib.
|
||||
*/
|
||||
RDI_EXTERN void CreateRDatHandler( std::string roguePath );
|
||||
RDI_EXTERN void CreateLegacyHandler( void );
|
||||
|
||||
RDI_EXTERN unsigned char getSectionCount( void );
|
||||
RDI_EXTERN std::string getSectionName( unsigned char id );
|
||||
@ -67,10 +68,16 @@ namespace RDI {
|
||||
RDI_EXTERN std::vector<std::string> getDirectoryElements( std::string path );
|
||||
RDI_EXTERN bool isElementDirectory( std::string path );
|
||||
|
||||
|
||||
RDI_EXTERN std::vector<std::string> getLevelsName( void );
|
||||
RDI_EXTERN std::vector<std::string> getModelsName( void );
|
||||
RDI_EXTERN std::vector<std::string> getMusicsName( void );
|
||||
|
||||
/**
|
||||
* @brief Clean up global resources.
|
||||
*/
|
||||
RDI_EXTERN void DestroyRDatHandler( void );
|
||||
RDI_EXTERN void DestroyLegacyHandler( void );
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,19 +13,86 @@
|
||||
#include <RSPModel.h>
|
||||
#include <RSPTerrain.h>
|
||||
#include <RSPTexture.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "RDat.h"
|
||||
#include "LegacyExplorer.h"
|
||||
|
||||
|
||||
namespace RDI {
|
||||
|
||||
LegacyExplorer::LegacyExplorer( RDat& pRDat ) {
|
||||
// TODO Auto-generated constructor stub
|
||||
LegacyExplorer::LegacyExplorer( RDat* pRDat ) {
|
||||
BuildLevelList(pRDat);
|
||||
BuildModelList(pRDat);
|
||||
BuildTextureList(pRDat);
|
||||
BuildMusicList(pRDat);
|
||||
BuildSampleList(pRDat);
|
||||
}
|
||||
|
||||
LegacyExplorer::~LegacyExplorer() {}
|
||||
|
||||
|
||||
void LegacyExplorer::BuildLevelList( RDat* pRDat ) {
|
||||
const static std::string legacyLvlPath = "data/level";
|
||||
DirectoryEntry* levelDir = nullptr;
|
||||
|
||||
listLevel.clear();
|
||||
levelDir = dynamic_cast<DirectoryEntry*>(pRDat->getElement(boost::filesystem::path(legacyLvlPath)));
|
||||
if (levelDir != nullptr) {
|
||||
for ( DatEntry* fl : levelDir->getFiles() ) {
|
||||
if (fl->isDirectory()) {
|
||||
if (pRDat->getElement(boost::filesystem::path(legacyLvlPath).append(fl->getName()).append("dat")) != nullptr) {
|
||||
listLevel.push_back(legacyLvlPath + "/" + fl->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: LvlClass builder
|
||||
}
|
||||
|
||||
void LegacyExplorer::BuildModelList( RDat* pRDat ) {
|
||||
const static std::vector<std::string> legacyModelPath = {
|
||||
"data/pl_crafts", "data/reb_stuff", "data/imp_stuff",
|
||||
"data/gnrc_stuff", "data2"
|
||||
};
|
||||
DirectoryEntry* curModelDir = nullptr;
|
||||
|
||||
listModel.clear();
|
||||
for ( std::string path_it : legacyModelPath ) {
|
||||
curModelDir = dynamic_cast<DirectoryEntry*>(pRDat->getElement(boost::filesystem::path(path_it)));
|
||||
if (curModelDir != nullptr) {
|
||||
for ( DatEntry* fl : curModelDir->getFiles() ) {
|
||||
if (fl->getName().find("_HOB") != std::string::npos) {
|
||||
listModel.push_back(path_it + "/" + fl->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LegacyExplorer::BuildTextureList( RDat* pRDat ) {
|
||||
|
||||
}
|
||||
|
||||
LegacyExplorer::~LegacyExplorer() {
|
||||
// TODO Auto-generated destructor stub
|
||||
void LegacyExplorer::BuildMusicList( RDat* pRDat ) {
|
||||
const static std::string legacyMusicPath = "data/sound";
|
||||
DirectoryEntry* musicDir = nullptr;
|
||||
|
||||
listMusic.clear();
|
||||
musicDir = dynamic_cast<DirectoryEntry*>(pRDat->getElement(boost::filesystem::path(legacyMusicPath)));
|
||||
if (musicDir != nullptr) {
|
||||
for ( DatEntry* fl : musicDir->getFiles() ) {
|
||||
//TODO: MusyX-Class builder
|
||||
|
||||
if (fl->getName().find("_SNG") != std::string::npos) {
|
||||
listMusic.push_back(legacyMusicPath + "/" + fl->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LegacyExplorer::BuildSampleList( RDat* pRDat ) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "RDat.h"
|
||||
#include "datfiles/GenericFile.h"
|
||||
#include "datfiles/HMT.h"
|
||||
|
||||
|
||||
#ifndef LEGACYEXPLORER_H_
|
||||
#define LEGACYEXPLORER_H_
|
||||
|
||||
@ -17,8 +25,56 @@ namespace RDI {
|
||||
|
||||
class LegacyExplorer final {
|
||||
public:
|
||||
LegacyExplorer( RDat& pRDat );
|
||||
LegacyExplorer( RDat* pRDat );
|
||||
~LegacyExplorer();
|
||||
|
||||
/**
|
||||
* Retrieve know list of legacy game files type.
|
||||
* @return Array of filtered elements.
|
||||
*/
|
||||
///@{
|
||||
std::vector<std::string> getLevelsList() { return listLevel; }
|
||||
std::vector<std::string> getModelsList() { return listModel; }
|
||||
std::vector<std::string> getTexturesList() { return listTexture; }
|
||||
std::vector<std::string> getMusicsList() { return listMusic; }
|
||||
std::vector<std::string> getSamplesList() { return listSample; }
|
||||
///@}
|
||||
|
||||
/**
|
||||
* Obtain the class interface for datas in specified file type.
|
||||
* @param name Name of the file, should be in list.
|
||||
* @return File type class handler.
|
||||
*/
|
||||
///@{
|
||||
void* getLevel( std::string name );
|
||||
void* getModel( std::string name );
|
||||
HMT *getTexture( std::string name );
|
||||
void* getMusic( std::string name );
|
||||
void* getSample( std::string name );
|
||||
///@}
|
||||
|
||||
/**
|
||||
* @brief Retrieve default file instance.
|
||||
* @details Unknown file type can be wrapped in dummy class to access raw
|
||||
* content without parsing or other type of processing.
|
||||
*
|
||||
* @param[in] vPath Virtual path to the file.
|
||||
* @return Generic file type class handler.
|
||||
*/
|
||||
GenericFile *getFile( boost::filesystem::path vPath );
|
||||
|
||||
private:
|
||||
std::vector<std::string> listLevel;
|
||||
std::vector<std::string> listModel;
|
||||
std::vector<std::string> listTexture;
|
||||
std::vector<std::string> listMusic;
|
||||
std::vector<std::string> listSample;
|
||||
|
||||
void BuildLevelList( RDat* pRDat );
|
||||
void BuildModelList( RDat* pRDat );
|
||||
void BuildTextureList( RDat* pRDat );
|
||||
void BuildMusicList( RDat* pRDat );
|
||||
void BuildSampleList( RDat* pRDat );
|
||||
};
|
||||
|
||||
}
|
||||
|
24
src/RDI.cpp
24
src/RDI.cpp
@ -18,6 +18,7 @@
|
||||
#include "config.h"
|
||||
#include "RDat.h"
|
||||
#include "DatEntry.h"
|
||||
#include "LegacyExplorer.h"
|
||||
#include "RDI.h"
|
||||
|
||||
|
||||
@ -25,6 +26,7 @@
|
||||
* Internal variable
|
||||
*/
|
||||
static RDI::RDat *hRDat = nullptr;
|
||||
static RDI::LegacyExplorer *hLegacyExp = nullptr;
|
||||
|
||||
/*
|
||||
* Libs interface
|
||||
@ -38,6 +40,12 @@ void RDI::CreateRDatHandler( std::string roguePath ){
|
||||
//return hRDat;
|
||||
}
|
||||
|
||||
void RDI::CreateLegacyHandler( void ){
|
||||
if (hRDat != nullptr) hLegacyExp = new RDI::LegacyExplorer(hRDat);
|
||||
|
||||
//return hLegacyExp;
|
||||
}
|
||||
|
||||
|
||||
unsigned char RDI::getSectionCount() {
|
||||
if (hRDat == nullptr) return 0;
|
||||
@ -95,6 +103,22 @@ bool RDI::isElementDirectory( std::string path ) {
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> RDI::getLevelsName( void ) {
|
||||
return hLegacyExp->getLevelsList();
|
||||
}
|
||||
|
||||
std::vector<std::string> RDI::getModelsName( void ) {
|
||||
return hLegacyExp->getModelsList();
|
||||
}
|
||||
|
||||
std::vector<std::string> RDI::getMusicsName( void ) {
|
||||
return hLegacyExp->getMusicsList();
|
||||
}
|
||||
|
||||
void RDI::DestroyRDatHandler(){
|
||||
if (hRDat) delete hRDat;
|
||||
}
|
||||
|
||||
void RDI::DestroyLegacyHandler(){
|
||||
if (hLegacyExp) delete hLegacyExp;
|
||||
}
|
||||
|
25
src/datfiles/GenericFile.cpp
Normal file
25
src/datfiles/GenericFile.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file GenericFile.cpp
|
||||
* @date 23/09/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief Generic file object class.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "../DatEntry.h"
|
||||
#include "GenericFile.h"
|
||||
|
||||
namespace RDI {
|
||||
|
||||
GenericFile::GenericFile( FileEntry& hDat ) {
|
||||
this->size = hDat.getSize();
|
||||
this->fileName = hDat.getName();
|
||||
this->fileExtension = "";
|
||||
this->pMemLoc = hDat.getDatas();
|
||||
}
|
||||
|
||||
GenericFile::~GenericFile() {}
|
||||
|
||||
}
|
34
src/datfiles/GenericFile.h
Normal file
34
src/datfiles/GenericFile.h
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @file GenericFile.h
|
||||
* @date 23/09/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief Generic file object class.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "../DatEntry.h"
|
||||
|
||||
|
||||
#ifndef GENERICFILE_H_
|
||||
#define GENERICFILE_H_
|
||||
|
||||
namespace RDI {
|
||||
|
||||
class GenericFile {
|
||||
public:
|
||||
GenericFile( FileEntry& hDat );
|
||||
virtual ~GenericFile();
|
||||
|
||||
MEMFILE get() { return pMemLoc; }
|
||||
|
||||
protected:
|
||||
unsigned long size;
|
||||
std::string fileName, fileExtension;
|
||||
MEMFILE pMemLoc = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* GENERICFILE_H_ */
|
@ -7,17 +7,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "GenericFile.h"
|
||||
#include "HMT.h"
|
||||
|
||||
|
||||
namespace RDI {
|
||||
|
||||
HMT::HMT() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
HMT::HMT( FileEntry& hDat ): GenericFile( hDat ) {
|
||||
this->fileExtension = "hmt";
|
||||
}
|
||||
|
||||
HMT::~HMT() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
HMT::~HMT() {}
|
||||
|
||||
} /* namespace RDI */
|
||||
}
|
||||
|
@ -7,17 +7,20 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRC_DATFILES_HMT_H_
|
||||
#define SRC_DATFILES_HMT_H_
|
||||
#include "GenericFile.h"
|
||||
|
||||
|
||||
#ifndef HMT_H_
|
||||
#define HMT_H_
|
||||
|
||||
namespace RDI {
|
||||
|
||||
class HMT {
|
||||
class HMT : public GenericFile {
|
||||
public:
|
||||
HMT();
|
||||
HMT( FileEntry& hDat );
|
||||
virtual ~HMT();
|
||||
};
|
||||
|
||||
} /* namespace RDI */
|
||||
}
|
||||
|
||||
#endif /* SRC_DATFILES_HMT_H_ */
|
||||
#endif /* HMT_H_ */
|
||||
|
@ -46,6 +46,17 @@ int main( int argc, char *argv[] ) {
|
||||
PrintVirtualDirectoryContents(pathBuilder, prefix);
|
||||
}
|
||||
|
||||
RDI::CreateLegacyHandler();
|
||||
for ( std::string lname : RDI::getLevelsName() ) {
|
||||
printf("Level found: %s\n", lname.c_str());
|
||||
}
|
||||
for ( std::string mdname : RDI::getModelsName() ) {
|
||||
printf("Model found: %s\n", mdname.c_str());
|
||||
}
|
||||
for ( std::string mname : RDI::getMusicsName() ) {
|
||||
printf("Music found: %s\n", mname.c_str());
|
||||
}
|
||||
|
||||
RDI::DestroyRDatHandler();
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user