Skip to content
Snippets Groups Projects
Commit 1f2498e5 authored by Amorilia's avatar Amorilia
Browse files

Extract action names for 2.0.0.0b KFM files.

MergeActions: read NIF file and all KF files (TODO: merge them as well).
parent 2cad2154
No related branches found
No related tags found
No related merge requests found
...@@ -1088,6 +1088,20 @@ unsigned int Kfm::Read( istream & in ) { ...@@ -1088,6 +1088,20 @@ unsigned int Kfm::Read( istream & in ) {
unk_int3 = ReadUInt(in); unk_int3 = ReadUInt(in);
for ( vector<KfmAction>::iterator it = actions.begin(); it != actions.end(); it++ ) it->Read(in, version); for ( vector<KfmAction>::iterator it = actions.begin(); it != actions.end(); it++ ) it->Read(in, version);
}; };
// Retrieve action names
if ( version >= VER_KFM_2_0_0_0b ) {
string model_name = nif_filename.substr(0, nif_filename.length()-4); // strip .nif extension
for ( vector<KfmAction>::iterator it = actions.begin(); it != actions.end(); it++ ) {
string action_name = it->action_filename.substr(0, it->action_filename.length()-3); // strip .kf extension
if (action_name.find( model_name + "_" ) == 0)
action_name = action_name.substr(model_name.length() + 1, string::npos);
if (action_name.find( master + "_" ) == 0)
action_name = action_name.substr(master.length() + 1, string::npos);
it->action_name = action_name;
};
};
return version; return version;
}; };
...@@ -1105,4 +1119,28 @@ void Kfm::Write( ostream & out, uint version ) { ...@@ -1105,4 +1119,28 @@ void Kfm::Write( ostream & out, uint version ) {
else throw runtime_error("Cannot write KFM file of this version."); else throw runtime_error("Cannot write KFM file of this version.");
}; };
}; };
*/ */
\ No newline at end of file
blk_ref Kfm::MergeActions( string const & path ) {
// Read NIF file
cout << path + '\\' + nif_filename << endl;
blk_ref nif = ReadNifTree( path + '\\' + nif_filename);
// Read Kf files
vector<blk_ref> kf;
for ( vector<KfmAction>::iterator it = actions.begin(); it != actions.end(); it++ ) {
string action_filename = path + '\\' + it->action_filename;
// Check if the file exists.
// Probably we should check some other field in the Kfm file to determine this...
bool exists = false;
fstream fin;
fin.open(action_filename.c_str(), ios::in);
if( fin.is_open() ) exists = true;
fin.close();
// Import it, if it exists.
if (exists) kf.push_back( ReadNifTree(action_filename) );
};
// TODO: merge everything into the nif file
return nif;
}
...@@ -3409,7 +3409,7 @@ struct Kfm { ...@@ -3409,7 +3409,7 @@ struct Kfm {
* unsigned int ver = kfm.Read( "test_in.kfm" ); * unsigned int ver = kfm.Read( "test_in.kfm" );
* if ( ver == VER_UNSUPPORTED ) cout << "unsupported" << endl; * if ( ver == VER_UNSUPPORTED ) cout << "unsupported" << endl;
* else if ( ver == VER_INVALID ) cout << "invalid" << endl; * else if ( ver == VER_INVALID ) cout << "invalid" << endl;
* else cout << "Describes keyframes for NIF file " << kfm.nif_file_name << "." << endl; * else cout << "Describes keyframes for NIF file " << kfm.nif_filename << "." << endl;
* *
* \endcode * \endcode
* *
...@@ -3422,11 +3422,43 @@ struct Kfm { ...@@ -3422,11 +3422,43 @@ struct Kfm {
* elif ( ver == VER_INVALID ): * elif ( ver == VER_INVALID ):
* print "invalid" * print "invalid"
* else: * else:
* print "Describes keyframes for NIF file %s."%kfm.nif_file_name * print "Describes keyframes for NIF file %s."%kfm.nif_filename
* \endcode * \endcode
*/ */
unsigned int Read( string const & file_name ); // returns Kfm version unsigned int Read( string const & file_name ); // returns Kfm version
unsigned int Read( istream & in ); // returns Kfm version unsigned int Read( istream & in ); // returns Kfm version
/*!
* Reads the NIF file and all KF files referred to in this KFM, and returns the root block of the resulting NIF tree.
* \param path The file path; usually, this should be the directory where the KFM file was read from.
* \return The root block of the NIF tree.
*
* <b>Example:</b>
* \code
* Kfm kfm;
* unsigned int ver = kfm.Read( "test_in.kfm" );
* if ( ver == VER_UNSUPPORTED ) cout << "unsupported" << endl;
* else if ( ver == VER_INVALID ) cout << "invalid" << endl;
* else {
* blk_ref root = kfm.MergeActions(".");
* cout << root << endl;
* };
*
* \endcode
*
* <b>In Python:</b>
* \code
* kfm = Kfm()
* ver = kfm.Read( "test_in.kfm" )
* if ( ver == VER_UNSUPPORTED ):
* print "unsupported"
* elif ( ver == VER_INVALID ):
* print "invalid"
* else:
* print kfm.MergeActions(".")
* \endcode
*/
blk_ref Kfm::MergeActions( string const & path );
//void Write( string const & file_name, unsigned int version ); //void Write( string const & file_name, unsigned int version );
//void Write( ostream & out, unsigned int version ); //void Write( ostream & out, unsigned int version );
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment