瀏覽代碼

Added support for using zcompat shaders, should fix audio bars shaders for the most part

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 3 年之前
父節點
當前提交
4e0f02f64d
共有 2 個文件被更改,包括 43 次插入 和 2 次删除
  1. 34 2
      src/WallpaperEngine/Assets/CContainer.cpp
  2. 9 0
      src/WallpaperEngine/Assets/CContainer.h

+ 34 - 2
src/WallpaperEngine/Assets/CContainer.cpp

@@ -1,8 +1,11 @@
 #include "CContainer.h"
 #include "CTexture.h"
+#include "WallpaperEngine/Logging/CLog.h"
+#include "CAssetLoadException.h"
 
 #include <cstring>
 #include <utility>
+#include <filesystem>
 
 using namespace WallpaperEngine::Assets;
 
@@ -21,15 +24,44 @@ const ITexture* CContainer::readTexture (std::string filename) const
 
     return result;
 }
+std::string CContainer::readShader (const std::string& filename) const
+{
+	std::filesystem::path shader = filename;
+	auto it = shader.begin ();
+
+	// detect workshop shaders and check if there's a
+	if (*it++ == "workshop")
+	{
+		std::filesystem::path workshopId = *it++;
+		std::filesystem::path shaderfile = *++it;
+
+		try
+		{
+			shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
+			// replace the old path with the new one
+			std::string contents = this->readFileAsString (shader);
+
+			sLog.out ("Replaced ", filename, " with compat ", shader);
+
+			return contents;
+		}
+		catch (CAssetLoadException&)
+		{
+
+		}
+	}
+
+	return this->readFileAsString ("shaders/" + filename);
+}
 
 std::string CContainer::readVertexShader (const std::string& filename) const
 {
-    return this->readFileAsString ("shaders/" + filename + ".vert");
+    return this->readShader (filename + ".vert");
 }
 
 std::string CContainer::readFragmentShader (const std::string& filename) const
 {
-    return this->readFileAsString ("shaders/" + filename + ".frag");
+    return this->readShader (filename + ".frag");
 }
 
 std::string CContainer::readIncludeShader (const std::string& filename) const

+ 9 - 0
src/WallpaperEngine/Assets/CContainer.h

@@ -28,6 +28,15 @@ namespace WallpaperEngine::Assets
          */
         const ITexture* readTexture (std::string filename) const;
 
+		/**
+		 * Wrapper for readFile, checks for compat versions of the given shader file
+		 *
+		 * @param filename
+		 *
+		 * @return The shader code as an string to be used
+		 */
+		std::string readShader (const std::string& filename) const;
+
         /**
          * Wrapper for readFile, appends the .vert extension at the end and opens the given shader file
          *