|
29 | 29 | #include <SDL2/SDL_net.h> |
30 | 30 | #endif |
31 | 31 |
|
| 32 | +#include "ship/resource/type/Json.h" |
32 | 33 | #include <fast/resource/ResourceType.h> |
33 | 34 | #include <ship/window/gui/Fonts.h> |
34 | 35 | #include <fast/resource/factory/DisplayListFactory.h> |
|
37 | 38 | #include <fast/resource/factory/VertexFactory.h> |
38 | 39 | #include <fast/resource/factory/LightFactory.h> |
39 | 40 | #include <ship/resource/factory/BlobFactory.h> |
| 41 | +#include <ship/resource/factory/JsonFactory.h> |
40 | 42 | #include <ship/utils/StringHelper.h> |
41 | 43 | #include <ship/resource/ResourceType.h> |
42 | 44 | #include <ship/window/gui/resource/Font.h> |
43 | 45 |
|
44 | 46 | #include "importer/AssetArrayFactory.h" |
45 | 47 | #include "importer/RawTextureFactory.h" |
| 48 | +#include "importer/TextFactory.h" |
| 49 | +#include "port/ui/Notification.h" |
46 | 50 | #include "port/importer/GenericArrayFactory.h" |
47 | 51 | #include "controller/controldeck/ControlDeck.h" |
48 | 52 | #include "port/mods/utils/GfxPrint.h" |
| 53 | +#include "scripting/scripting.h" |
49 | 54 |
|
50 | 55 | #ifdef __SWITCH__ |
51 | 56 | #include <ship/port/switch/SwitchImpl.h> |
@@ -346,6 +351,7 @@ void GameEngine::FinishInit() { |
346 | 351 | DevConsole_Init(); |
347 | 352 | PortEnhancements_Init(); |
348 | 353 | ShipInit::InitAll(); |
| 354 | + LoadManifest(); |
349 | 355 | } |
350 | 356 |
|
351 | 357 | void GameEngine::RunExtract(int argc, char* argv[]) { |
@@ -799,6 +805,68 @@ void GameEngine::ScaleImGui() { |
799 | 805 | previousImGuiScaleIndex = imGuiScaleIndex; |
800 | 806 | } |
801 | 807 |
|
| 808 | +void GameEngine::LoadManifest() { |
| 809 | + auto archive = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager(); |
| 810 | + auto loader = Ship::Context::GetInstance()->GetResourceManager()->GetResourceLoader(); |
| 811 | + auto list = archive->GetArchives(); |
| 812 | + auto init = std::make_shared<Ship::ResourceInitData>(); |
| 813 | + init->Type = (uint32_t)Ship::ResourceType::Json; |
| 814 | + init->ByteOrder = Ship::Endianness::Native; |
| 815 | + init->Format = RESOURCE_FORMAT_BINARY; |
| 816 | + |
| 817 | + for (auto& entry : *list) { |
| 818 | + const auto path = "manifest.json"; |
| 819 | + if (!entry->HasFile(path)) { |
| 820 | + continue; |
| 821 | + } |
| 822 | + |
| 823 | + auto file = entry->LoadFile(path); |
| 824 | + |
| 825 | + if (file == nullptr) { |
| 826 | + continue; |
| 827 | + } |
| 828 | + |
| 829 | + auto raw = loader->LoadResource(path, file, init); |
| 830 | + auto res = std::static_pointer_cast<Ship::Json>(raw); |
| 831 | + if (res == nullptr) { |
| 832 | + continue; |
| 833 | + } |
| 834 | + |
| 835 | + auto json = res->Data; |
| 836 | + |
| 837 | + try { |
| 838 | + auto name = json["name"].get<std::string>(); |
| 839 | + auto main = json["main"].get<std::string>(); |
| 840 | + auto version = json.value("version", "1.0"); |
| 841 | + auto website = json.value("website", "https://github.com/HarbourMasters/Ghostship"); |
| 842 | + auto description = json.value("description", ""); |
| 843 | + auto author = json.value("author", "unknown"); |
| 844 | + auto license = json.value("license", "MIT"); |
| 845 | + auto dependencies = json.value("dependencies", std::vector<std::string>()); |
| 846 | + |
| 847 | + SPDLOG_INFO("Name: {}", name); |
| 848 | + SPDLOG_INFO("Version: {}", version); |
| 849 | + SPDLOG_INFO("License: {}", license); |
| 850 | + SPDLOG_INFO("Author: {}", author); |
| 851 | + |
| 852 | + ScriptingLayer::Instance->Load(main, entry); |
| 853 | + Notification::Emit({ .message = "Loaded " + name, .remainingTime = 7.0f }); |
| 854 | + } catch (nlohmann::json::exception& e) { |
| 855 | + SPDLOG_ERROR("Invalid manifest.json, skipping {}", entry->GetPath()); |
| 856 | + Notification::Emit({ .message = "Failed to load mod, check log for details", |
| 857 | + .messageColor = ImVec4(1.0f, 0.5f, 0.5f, 1.0f), |
| 858 | + .remainingTime = 7.0f }); |
| 859 | + continue; |
| 860 | + } catch (std::exception& e) { |
| 861 | + SPDLOG_ERROR("Failed to load manifest.json, skipping {}: {}", entry->GetPath(), e.what()); |
| 862 | + Notification::Emit({ .message = "Failed to load mod, check log for details", |
| 863 | + .messageColor = ImVec4(1.0f, 0.5f, 0.5f, 1.0f), |
| 864 | + .remainingTime = 7.0f }); |
| 865 | + continue; |
| 866 | + } |
| 867 | + } |
| 868 | +} |
| 869 | + |
802 | 870 | void GameEngine::Create(int argc, char* argv[]) { |
803 | 871 | const auto instance = Instance = new GameEngine(); |
804 | 872 | instance->RunExtract(argc, argv); |
|
0 commit comments