From dfa62f083e36d3e165506e1274ec5fdba1b9616b Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sun, 20 Nov 2022 13:50:27 +0000
Subject: [PATCH] expose lua scripts to asset system

---
 integrations/lua/include/fggl/script/lua/module.hpp | 11 +++++++++--
 integrations/lua/src/module.cpp                     | 11 +++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/integrations/lua/include/fggl/script/lua/module.hpp b/integrations/lua/include/fggl/script/lua/module.hpp
index 5f9bd96..e904f51 100644
--- a/integrations/lua/include/fggl/script/lua/module.hpp
+++ b/integrations/lua/include/fggl/script/lua/module.hpp
@@ -23,15 +23,22 @@
 #include "fggl/entity/module.hpp"
 #include "fggl/script/engine.hpp"
 #include "fggl/data/module.hpp"
+#include "fggl/assets/packed/adapter.hpp"
+
 
 namespace fggl::script::lua {
+
+	constexpr auto MIME_LUA = assets::from_mime("text/lua");
+	constexpr auto SCRIPT_LUA = assets::make_asset_type("script/lua");
+
 	struct Lua {
 		constexpr static const char* name = "fggl::script::lua";
 		constexpr static const std::array<modules::ModuleService, 1> provides = {
 			script::ScriptProvider::service
 		};
-		constexpr static const std::array<modules::ModuleService, 1> depends = {
-			data::SERVICE_STORAGE
+		constexpr static const std::array<modules::ModuleService, 2> depends = {
+			data::SERVICE_STORAGE,
+			assets::CheckinAdapted::service
 		};
 		static bool factory(modules::ModuleService name, modules::Services& serviceManager);
 	};
diff --git a/integrations/lua/src/module.cpp b/integrations/lua/src/module.cpp
index af4b1e3..5356a4b 100644
--- a/integrations/lua/src/module.cpp
+++ b/integrations/lua/src/module.cpp
@@ -21,11 +21,22 @@
 
 namespace fggl::script::lua {
 
+	static assets::AssetTypeID is_lua(std::filesystem::path path) {
+		if ( path.extension() == ".lua" ) {
+			return SCRIPT_LUA;
+		}
+		return assets::INVALID_ASSET_TYPE;
+	}
+
 	bool Lua::factory(modules::ModuleService service, modules::Services &serviceManager) {
 
 		if ( service == ScriptProvider::service ) {
 			auto storageService = serviceManager.get<data::Storage>();
 			serviceManager.bind<ScriptProvider,LuaScriptProvider>(storageService);
+
+			auto *assetPacker = serviceManager.get<assets::CheckinAdapted>();
+			assetPacker->setLoader(MIME_LUA, assets::NEEDS_CHECKIN, is_lua);
+
 			return true;
 		}
 
-- 
GitLab