diff --git a/loader/src/loader/ModMetadataImpl.cpp b/loader/src/loader/ModMetadataImpl.cpp index f16c82e7..54162a44 100644 --- a/loader/src/loader/ModMetadataImpl.cpp +++ b/loader/src/loader/ModMetadataImpl.cpp @@ -477,12 +477,6 @@ std::string ModMetadata::getName() const { return m_impl->m_name; } -std::string ModMetadata::getDeveloper() const { - // m_developers should be guaranteed to never be empty, but this is - // just in case it is anyway somehow - return m_impl->m_developers.empty() ? "" : m_impl->m_developers.front(); -} - std::string ModMetadata::formatDeveloperDisplayString(std::vector const& developers) { switch (developers.size()) { case 0: return "Unknown"; break; @@ -510,9 +504,6 @@ std::optional ModMetadata::getChangelog() const { std::optional ModMetadata::getSupportInfo() const { return m_impl->m_supportInfo; } -std::optional ModMetadata::getRepository() const { - return m_impl->m_links.getSourceURL(); -} ModMetadataLinks ModMetadata::getLinks() const { return m_impl->m_links; } @@ -629,10 +620,6 @@ void ModMetadata::setIncompatibilities(std::vector const& value void ModMetadata::setSpritesheets(std::vector const& value) { m_impl->m_spritesheets = value; } -void ModMetadata::setSettings(std::vector> const& value) { - // intentionally no-op because no one is supposed to be using this - // without subscribing to "internals are not stable" mentality -} void ModMetadata::setSettings(std::vector> const& value) { m_impl->m_settings = value; } diff --git a/loader/src/loader/SettingNodeV3.cpp b/loader/src/loader/SettingNodeV3.cpp index 19573417..a925485a 100644 --- a/loader/src/loader/SettingNodeV3.cpp +++ b/loader/src/loader/SettingNodeV3.cpp @@ -682,51 +682,3 @@ UnresolvedCustomSettingNodeV3* UnresolvedCustomSettingNodeV3::create(std::string CC_SAFE_DELETE(ret); return nullptr; } - -// LegacyCustomSettingToV3Node - -bool LegacyCustomSettingToV3Node::init(std::shared_ptr original, float width) { - if (!SettingNodeV3::init(original, width)) - return false; - - this->getNameMenu()->setVisible(false); - this->getButtonMenu()->setVisible(false); - - m_original = original->getValue()->createNode(width); - m_original->setDelegate(this); - this->setContentSize({ width, m_original->getContentHeight() }); - this->addChildAtPosition(m_original, Anchor::BottomLeft, ccp(0, 0), ccp(0, 0)); - - return true; -} - -void LegacyCustomSettingToV3Node::settingValueChanged(SettingNode*) { - SettingNodeValueChangeEventV3(this, false).post(); -} -void LegacyCustomSettingToV3Node::settingValueCommitted(SettingNode*) { - SettingNodeValueChangeEventV3(this, true).post(); -} - -void LegacyCustomSettingToV3Node::onCommit() { - m_original->commit(); -} - -bool LegacyCustomSettingToV3Node::hasUncommittedChanges() const { - return m_original->hasUncommittedChanges(); -} -bool LegacyCustomSettingToV3Node::hasNonDefaultValue() const { - return m_original->hasNonDefaultValue(); -} -void LegacyCustomSettingToV3Node::onResetToDefault() { - m_original->resetToDefault(); -} - -LegacyCustomSettingToV3Node* LegacyCustomSettingToV3Node::create(std::shared_ptr original, float width) { - auto ret = new LegacyCustomSettingToV3Node(); - if (ret && ret->init(original, width)) { - ret->autorelease(); - return ret; - } - CC_SAFE_DELETE(ret); - return nullptr; -} diff --git a/loader/src/loader/SettingV3.cpp b/loader/src/loader/SettingV3.cpp index 6ee54927..32511f0e 100644 --- a/loader/src/loader/SettingV3.cpp +++ b/loader/src/loader/SettingV3.cpp @@ -610,54 +610,6 @@ bool TitleSettingV3::isDefaultValue() const { } void TitleSettingV3::reset() {} -class LegacyCustomSettingV3::Impl final { -public: - matjson::Value json; - std::shared_ptr legacyValue = nullptr; -}; - -LegacyCustomSettingV3::LegacyCustomSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} - -Result> LegacyCustomSettingV3::parse(std::string const& key, std::string const& modID, matjson::Value const& json) { - auto ret = std::make_shared(PrivateMarker()); - ret->init(key, modID); - ret->m_impl->json = json; - return Ok(ret); -} - -std::shared_ptr LegacyCustomSettingV3::getValue() const { - return m_impl->legacyValue; -} -void LegacyCustomSettingV3::setValue(std::shared_ptr value) { - m_impl->legacyValue = value; -} - -bool LegacyCustomSettingV3::load(matjson::Value const& json) { - if (m_impl->legacyValue) { - return m_impl->legacyValue->load(json); - } - return true; -} -bool LegacyCustomSettingV3::save(matjson::Value& json) const { - if (m_impl->legacyValue) { - return m_impl->legacyValue->save(json); - } - return true; -} -SettingNodeV3* LegacyCustomSettingV3::createNode(float width) { - if (m_impl->legacyValue) { - return LegacyCustomSettingToV3Node::create( - std::static_pointer_cast(shared_from_this()), width - ); - } - return UnresolvedCustomSettingNodeV3::create(this->getKey(), this->getMod(), width); -} - -bool LegacyCustomSettingV3::isDefaultValue() const { - return true; -} -void LegacyCustomSettingV3::reset() {} - class BoolSettingV3::Impl final { public: }; diff --git a/loader/src/loader/updater.cpp b/loader/src/loader/updater.cpp index e5868a11..9fda6f27 100644 --- a/loader/src/loader/updater.cpp +++ b/loader/src/loader/updater.cpp @@ -105,8 +105,7 @@ void updater::downloadLatestLoaderResources() { auto root = checkJson(raw, "[]"); // find release asset - for (auto asset : root.needs("assets").iterate()) { - auto obj = asset.obj(); + for (auto& obj : root.needs("assets").items()) { if (obj.needs("name").get() == "resources.zip") { updater::tryDownloadLoaderResources( obj.needs("browser_download_url").get(), @@ -207,8 +206,7 @@ void updater::downloadLoaderResources(bool useLatestRelease) { auto root = checkJson(ok.unwrap(), "[]"); // find release asset - for (auto asset : root.needs("assets").iterate()) { - auto obj = asset.obj(); + for (auto& obj : root.needs("assets").items()) { if (obj.needs("name").get() == "resources.zip") { updater::tryDownloadLoaderResources( obj.needs("browser_download_url").get(), @@ -382,8 +380,7 @@ void updater::checkForLoaderUpdates() { } // find release asset - for (auto asset : root.needs("assets").iterate()) { - auto obj = asset.obj(); + for (auto& obj : root.needs("assets").items()) { if (string::endsWith( obj.needs("name").get(), fmt::format("{}.zip", PlatformID::toShortString(GEODE_PLATFORM_TARGET, true)) diff --git a/loader/src/server/Server.cpp b/loader/src/server/Server.cpp index 9437e807..43a9e08a 100644 --- a/loader/src/server/Server.cpp +++ b/loader/src/server/Server.cpp @@ -265,7 +265,7 @@ Result ServerModVersion::parse(matjson::Value const& raw) { res.metadata.setGeodeVersion(root.needs("geode").get()); // Verify target GD version - auto gd_obj = root.needs("gd").obj(); + auto gd_obj = root.needs("gd"); std::string gd = "0.000"; if (gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER)) { gd = gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER). get(); @@ -288,13 +288,11 @@ Result ServerModVersion::parse(matjson::Value const& raw) { res.metadata.setIsAPI(root.needs("api").get()); std::vector dependencies {}; - for (auto dep : root.has("dependencies").iterate()) { + for (auto& obj : root.has("dependencies").items()) { // todo: this should probably be generalized to use the same function as mod.json - auto obj = dep.obj(); - bool onThisPlatform = !obj.has("platforms"); - for (auto& plat : obj.has("platforms").iterate()) { + for (auto& plat : obj.has("platforms").items()) { if (PlatformID::coveredBy(plat.get(), GEODE_PLATFORM_TARGET)) { onThisPlatform = true; } @@ -304,7 +302,7 @@ Result ServerModVersion::parse(matjson::Value const& raw) { } ModMetadata::Dependency dependency; - obj.needs("mod_id").validate(MiniFunction(&ModMetadata::validateID)).into(dependency.id); + obj.needs("mod_id").mustBe("a valid id", &ModMetadata::validateID).into(dependency.id); obj.needs("version").into(dependency.version); obj.has("importance").into(dependency.importance); @@ -319,9 +317,7 @@ Result ServerModVersion::parse(matjson::Value const& raw) { res.metadata.setDependencies(dependencies); std::vector incompatibilities {}; - for (auto& incompat : root.has("incompatibilities").iterate()) { - auto obj = incompat.obj(); - + for (auto& obj : root.has("incompatibilities").items()) { ModMetadata::Incompatibility incompatibility; obj.has("importance").into(incompatibility.importance); @@ -331,7 +327,7 @@ Result ServerModVersion::parse(matjson::Value const& raw) { if (incompatibility.importance == ModMetadata::Incompatibility::Importance::Superseded) { modIdValue.into(incompatibility.id); } else { - modIdValue.validate(MiniFunction(&ModMetadata::validateID)).into(incompatibility.id); + modIdValue.mustBe("a valid id", &ModMetadata::validateID).into(incompatibility.id); } obj.needs("version").into(incompatibility.version); @@ -346,11 +342,7 @@ Result ServerModVersion::parse(matjson::Value const& raw) { } res.metadata.setIncompatibilities(incompatibilities); - // Check for errors and return result - if (root.isError()) { - return Err(root.getError()); - } - return Ok(res); + return root.ok(res); } Result ServerModReplacement::parse(matjson::Value const& raw) { @@ -360,10 +352,7 @@ Result ServerModReplacement::parse(matjson::Value const& r root.needs("id").into(res.id); root.needs("version").into(res.version); - if (root.isError()) { - return Err(root.getError()); - } - return Ok(res); + return root.ok(res); } Result ServerModUpdate::parse(matjson::Value const& raw) { @@ -377,18 +366,14 @@ Result ServerModUpdate::parse(matjson::Value const& raw) { GEODE_UNWRAP_INTO(res.replacement, ServerModReplacement::parse(root.has("replacement").json())); } - // Check for errors and return result - if (root.isError()) { - return Err(root.getError()); - } - return Ok(res); + return root.ok(res); } Result> ServerModUpdate::parseList(matjson::Value const& raw) { auto payload = checkJson(raw, "ServerModUpdatesList"); std::vector list {}; - for (auto item : payload.iterate()) { + for (auto& item : payload.items()) { auto mod = ServerModUpdate::parse(item.json()); if (mod) { list.push_back(mod.unwrap()); @@ -398,11 +383,7 @@ Result> ServerModUpdate::parseList(matjson::Value c } } - // Check for errors and return result - if (payload.isError()) { - return Err(payload.getError()); - } - return Ok(list); + return payload.ok(list); } bool ServerModUpdate::hasUpdateForInstalledMod() const { @@ -430,8 +411,7 @@ Result ServerModMetadata::parse(matjson::Value const& raw) { } std::vector developerNames; - for (auto item : root.needs("developers").iterate()) { - auto obj = item.obj(); + for (auto& obj : root.needs("developers").items()) { auto dev = ServerDeveloper(); obj.needs("username").into(dev.username); obj.needs("display_name").into(dev.displayName); @@ -439,7 +419,7 @@ Result ServerModMetadata::parse(matjson::Value const& raw) { res.developers.push_back(dev); developerNames.push_back(dev.displayName); } - for (auto item : root.needs("versions").iterate()) { + for (auto& item : root.needs("versions").items()) { auto versionRes = ServerModVersion::parse(item.json()); if (versionRes) { auto version = versionRes.unwrap(); @@ -459,17 +439,13 @@ Result ServerModMetadata::parse(matjson::Value const& raw) { return Err("Mod '{}' has no (valid) versions", res.id); } - for (auto item : root.has("tags").iterate()) { + for (auto& item : root.has("tags").items()) { res.tags.insert(item.get()); } root.needs("download_count").into(res.downloadCount); - // Check for errors and return result - if (root.isError()) { - return Err(root.getError()); - } - return Ok(res); + return root.ok(res); } std::string ServerModMetadata::formatDevelopersToString() const { @@ -494,7 +470,7 @@ Result ServerModsList::parse(matjson::Value const& raw) { auto payload = checkJson(raw, "ServerModsList"); auto list = ServerModsList(); - for (auto item : payload.needs("data").iterate()) { + for (auto& item : payload.needs("data").items()) { auto mod = ServerModMetadata::parse(item.json()); if (mod) { list.mods.push_back(mod.unwrap()); @@ -505,11 +481,7 @@ Result ServerModsList::parse(matjson::Value const& raw) { } payload.needs("count").into(list.totalModCount); - // Check for errors and return result - if (payload.isError()) { - return Err(payload.getError()); - } - return Ok(list); + return payload.ok(list); } ModMetadata ServerModMetadata::latestVersion() const { diff --git a/loader/src/ui/GeodeUI.cpp b/loader/src/ui/GeodeUI.cpp index 9c1dce65..dff7dff6 100644 --- a/loader/src/ui/GeodeUI.cpp +++ b/loader/src/ui/GeodeUI.cpp @@ -147,10 +147,6 @@ Task geode::openInfoPopup(std::string const& modID) { return task; } } -void geode::openIndexPopup(Mod* mod) { - // deprecated func - openInfoPopup(mod); -} void geode::openChangelogPopup(Mod* mod) { auto popup = ModPopup::create(mod); diff --git a/loader/src/utils/JsonValidation.cpp b/loader/src/utils/JsonValidation.cpp index 71a5c908..1f1df324 100644 --- a/loader/src/utils/JsonValidation.cpp +++ b/loader/src/utils/JsonValidation.cpp @@ -3,165 +3,6 @@ using namespace geode::prelude; -matjson::Value& JsonMaybeSomething::json() { - return m_json; -} - -JsonMaybeSomething::JsonMaybeSomething( - JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue -) : - m_checker(checker), - m_json(json), m_hierarchy(hierarchy), m_hasValue(hasValue) {} - -bool JsonMaybeSomething::isError() const { - return m_checker.isError() || !m_hasValue; -} - -std::string JsonMaybeSomething::getError() const { - return m_checker.getError(); -} - -JsonMaybeSomething::operator bool() const { - return !isError(); -} - -void JsonMaybeSomething::setError(std::string const& error) { - m_checker.m_result = error; -} - -JsonMaybeValue::JsonMaybeValue( - JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue -) : JsonMaybeSomething(checker, json, hierarchy, hasValue) {} - -JsonMaybeSomething& JsonMaybeValue::self() { - return *static_cast(this); -} - -JsonMaybeValue& JsonMaybeValue::array() { - this->as(); - return *this; -} - -JsonMaybeObject JsonMaybeValue::obj() { - this->as(); - return JsonMaybeObject(self().m_checker, self().m_json, self().m_hierarchy, self().m_hasValue); -} - -JsonMaybeValue JsonMaybeValue::at(size_t i) { - this->as(); - if (this->isError()) return *this; - - auto& json = self().m_json.as_array(); - if (json.size() <= i) { - this->setError( - self().m_hierarchy + ": has " + std::to_string(json.size()) + - "items " - ", expected to have at least " + - std::to_string(i + 1) - ); - return *this; - } - return JsonMaybeValue( - self().m_checker, json.at(i), self().m_hierarchy + "." + std::to_string(i), self().m_hasValue - ); -} - -typename JsonMaybeValue::template Iterator JsonMaybeValue::iterate() { - this->as(); - Iterator iter; - if (this->isError()) return iter; - - auto& json = self().m_json.as_array(); - size_t i = 0; - for (auto& obj : json) { - iter.m_values.emplace_back( - self().m_checker, obj, self().m_hierarchy + "." + std::to_string(i++), self().m_hasValue - ); - } - return iter; -} - -typename JsonMaybeValue::template Iterator> JsonMaybeValue::items() { - this->as(); - Iterator> iter; - if (this->isError()) return iter; - - for (auto& [k, v] : self().m_json.as_object()) { - iter.m_values.emplace_back( - k, - JsonMaybeValue(self().m_checker, v, self().m_hierarchy + "." + k, self().m_hasValue) - ); - } - - return iter; -} - -JsonMaybeObject::JsonMaybeObject( - JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue -) : JsonMaybeSomething(checker, json, hierarchy, hasValue) {} - -JsonMaybeSomething& JsonMaybeObject::self() { - return *static_cast(this); -} - -void JsonMaybeObject::addKnownKey(std::string const& key) { - m_knownKeys.insert(key); -} - -matjson::Value& JsonMaybeObject::json() { - return self().m_json; -} - -JsonMaybeValue JsonMaybeObject::emptyValue() { - return JsonMaybeValue(self().m_checker, self().m_json, "", false); -} - -JsonMaybeValue JsonMaybeObject::has(std::string const& key) { - this->addKnownKey(key); - if (this->isError()) return emptyValue(); - if (!self().m_json.contains(key) || self().m_json[key].is_null()) { - return emptyValue(); - } - return JsonMaybeValue(self().m_checker, self().m_json[key], key, true); -} - -JsonMaybeValue JsonMaybeObject::needs(std::string const& key) { - this->addKnownKey(key); - if (this->isError()) return emptyValue(); - if (!self().m_json.contains(key)) { - this->setError(self().m_hierarchy + " is missing required key \"" + key + "\""); - return emptyValue(); - } - return JsonMaybeValue(self().m_checker, self().m_json[key], key, true); -} - -// TODO: gross hack :3 (ctrl+f this comment to find the other part) -extern bool s_jsonCheckerShouldCheckUnknownKeys; -bool s_jsonCheckerShouldCheckUnknownKeys = true; -void JsonMaybeObject::checkUnknownKeys() { - if (!s_jsonCheckerShouldCheckUnknownKeys) - return; - for (auto& [key, _] : self().m_json.as_object()) { - if (!m_knownKeys.count(key)) { - log::warn("{} contains unknown key \"{}\"", self().m_hierarchy, key); - } - } -} - -JsonChecker::JsonChecker(matjson::Value& json) : m_json(json), m_result(std::monostate()) {} - -bool JsonChecker::isError() const { - return std::holds_alternative(m_result); -} - -std::string JsonChecker::getError() const { - return std::get(m_result); -} - -JsonMaybeValue JsonChecker::root(std::string const& hierarchy) { - return JsonMaybeValue(*this, m_json, hierarchy, true); -} - // This is used for null JsonExpectedValues (for example when doing // `json.has("key")` where "key" doesn't exist) static matjson::Value NULL_SCOPED_VALUE = nullptr; diff --git a/loader/src/utils/VersionInfo.cpp b/loader/src/utils/VersionInfo.cpp index a2271344..069f674b 100644 --- a/loader/src/utils/VersionInfo.cpp +++ b/loader/src/utils/VersionInfo.cpp @@ -113,9 +113,6 @@ Result VersionInfo::parse(std::string const& string) { return Ok(VersionInfo(major, minor, patch, tag)); } -std::string VersionInfo::toString(bool includeTag) const { - return this->toVString(); -} std::string VersionInfo::toVString(bool includeTag) const { return fmt::format("v{}", this->toNonVString(includeTag)); }