Explorar el Código

Try to convert/install field back ground files, fails due to #70

Paul hace 11 años
padre
commit
ff1ff436ed

+ 1 - 1
QGearsMain/include/common/QGearsResource.h

@@ -49,7 +49,7 @@ namespace QGears
         virtual ~Resource() = default;
 
     protected:
-        Ogre::DataStreamPtr openResource()
+        virtual Ogre::DataStreamPtr openResource()
         {
             return Ogre::ResourceGroupManager::getSingleton().openResource(mName, mGroup, true, this);
         }

+ 1 - 1
QGearsMain/include/data/QGearsLZSFLevelFile.h

@@ -44,7 +44,7 @@ namespace QGears
 
     protected:
         virtual const String& getResourceType( void ) const;
-        virtual Ogre::DataStreamPtr openResource( void );
+        virtual Ogre::DataStreamPtr openResource( void ) override;
 
     private:
     };

+ 1 - 1
QGearsMain/include/data/QGearsPaletteFile.h

@@ -51,7 +51,7 @@ namespace QGears
 
         virtual PageList&  getPages( void ) { return m_pages; }
 
-        virtual const Page& getPage( size_t index ) const { return m_pages[index]; }
+        virtual const Page& getPage( size_t index ) const { return m_pages.at(index); }
 
     protected:
         virtual void loadImpl();

+ 1 - 1
QGearsMain/src/data/QGearsBackgroundFile.cpp

@@ -175,7 +175,7 @@ namespace QGears
                         Ogre::LogManager::getSingleton().stream()
                             << "Error: data page Index out of Bounds " << data_index;
                     }
-                    uint8 index( data_page.data[ data_index ] );
+                    uint8 index( data_page.data.at(data_index) );
                     if( index >= palette_page.size() )
                     {
                         Ogre::LogManager::getSingleton().stream()

+ 6 - 0
QGearsMain/src/data/QGearsFLevelFile.cpp

@@ -37,6 +37,7 @@ THE SOFTWARE.
 #include "data/QGearsHRCFileManager.h"
 #include "map/QGearsBackground2DFileManager.h"
 #include "FF7Common.h"
+#include "core/Logger.h"
 
 namespace QGears
 {
@@ -87,6 +88,11 @@ namespace QGears
     {
         FLevelFileSerializer serializer;
         Ogre::DataStreamPtr stream( openResource() );
+        if (stream.isNull())
+        {
+            LOG_ERROR("Failed to open resource");
+        }
+
         serializer.importFLevelFile( stream, this );
 
         String background_texture_name( getBackgroundTextureName() );

+ 25 - 4
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -50,17 +50,18 @@ void FF7DataInstaller::Convert(std::string inputDir, std::string outputDir, cons
         // TODO: Comparison will be incorrect on some platforms
         if (file == "field\\char.lgp")
         {
+            /*
             auto fullPath = inputDir + file;
             mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
             ConvertFieldModels(fullPath, outputDir);
-            mApp.getRoot()->removeResourceLocation(fullPath, "FFVII");
+            mApp.getRoot()->removeResourceLocation(fullPath, "FFVII");*/
         }
         else if (file == "field\\flevel.lgp")
         {
             auto fullPath = inputDir + file;
-            mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
+            mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVIIFields");
             ConvertFields(fullPath, outputDir);
-            mApp.getRoot()->removeResourceLocation(fullPath, "FFVII");
+            mApp.getRoot()->removeResourceLocation(fullPath, "FFVIIFields");
         }
     }
 }
@@ -134,9 +135,29 @@ void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDi
 void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
 {
     // Everything in here is a field
-    Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVII", "*.hrc");
+    Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVIIFields", "*");
     for (auto& resourceName : *resources)
     {
+        if (!QGears::StringUtil::endsWith(resourceName, ".tex"))
+        {
+            try
+            {
+                QGears::FLevelFilePtr field = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
 
+                const QGears::BackgroundFilePtr& bg = field->getBackground();
+                const QGears::PaletteFilePtr& pal = field->getPalette();
+                Ogre::Image* bgImage = bg->createImage(pal);
+                bgImage->save(outDir + "/" + field->getName() + ".png");
+                delete bgImage;
+            }
+            catch (const Ogre::Exception& ex)
+            {
+                std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
+            }
+            catch (const std::exception& ex)
+            {
+                std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
+            }
+        }
     }
 }