removing deprecated things part 2 (compiles)

This commit is contained in:
altalk23 2024-11-04 20:28:38 +03:00
parent 50ab4ebed7
commit 985b3aedb5
8 changed files with 20 additions and 326 deletions

View file

@ -477,12 +477,6 @@ std::string ModMetadata::getName() const {
return m_impl->m_name; 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<std::string> const& developers) { std::string ModMetadata::formatDeveloperDisplayString(std::vector<std::string> const& developers) {
switch (developers.size()) { switch (developers.size()) {
case 0: return "Unknown"; break; case 0: return "Unknown"; break;
@ -510,9 +504,6 @@ std::optional<std::string> ModMetadata::getChangelog() const {
std::optional<std::string> ModMetadata::getSupportInfo() const { std::optional<std::string> ModMetadata::getSupportInfo() const {
return m_impl->m_supportInfo; return m_impl->m_supportInfo;
} }
std::optional<std::string> ModMetadata::getRepository() const {
return m_impl->m_links.getSourceURL();
}
ModMetadataLinks ModMetadata::getLinks() const { ModMetadataLinks ModMetadata::getLinks() const {
return m_impl->m_links; return m_impl->m_links;
} }
@ -629,10 +620,6 @@ void ModMetadata::setIncompatibilities(std::vector<Incompatibility> const& value
void ModMetadata::setSpritesheets(std::vector<std::string> const& value) { void ModMetadata::setSpritesheets(std::vector<std::string> const& value) {
m_impl->m_spritesheets = value; m_impl->m_spritesheets = value;
} }
void ModMetadata::setSettings(std::vector<std::pair<std::string, Setting>> 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<std::pair<std::string, matjson::Value>> const& value) { void ModMetadata::setSettings(std::vector<std::pair<std::string, matjson::Value>> const& value) {
m_impl->m_settings = value; m_impl->m_settings = value;
} }

View file

@ -682,51 +682,3 @@ UnresolvedCustomSettingNodeV3* UnresolvedCustomSettingNodeV3::create(std::string
CC_SAFE_DELETE(ret); CC_SAFE_DELETE(ret);
return nullptr; return nullptr;
} }
// LegacyCustomSettingToV3Node
bool LegacyCustomSettingToV3Node::init(std::shared_ptr<LegacyCustomSettingV3> 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<LegacyCustomSettingV3> original, float width) {
auto ret = new LegacyCustomSettingToV3Node();
if (ret && ret->init(original, width)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}

View file

@ -610,54 +610,6 @@ bool TitleSettingV3::isDefaultValue() const {
} }
void TitleSettingV3::reset() {} void TitleSettingV3::reset() {}
class LegacyCustomSettingV3::Impl final {
public:
matjson::Value json;
std::shared_ptr<SettingValue> legacyValue = nullptr;
};
LegacyCustomSettingV3::LegacyCustomSettingV3(PrivateMarker) : m_impl(std::make_shared<Impl>()) {}
Result<std::shared_ptr<LegacyCustomSettingV3>> LegacyCustomSettingV3::parse(std::string const& key, std::string const& modID, matjson::Value const& json) {
auto ret = std::make_shared<LegacyCustomSettingV3>(PrivateMarker());
ret->init(key, modID);
ret->m_impl->json = json;
return Ok(ret);
}
std::shared_ptr<SettingValue> LegacyCustomSettingV3::getValue() const {
return m_impl->legacyValue;
}
void LegacyCustomSettingV3::setValue(std::shared_ptr<SettingValue> 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<LegacyCustomSettingV3>(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 { class BoolSettingV3::Impl final {
public: public:
}; };

View file

@ -105,8 +105,7 @@ void updater::downloadLatestLoaderResources() {
auto root = checkJson(raw, "[]"); auto root = checkJson(raw, "[]");
// find release asset // find release asset
for (auto asset : root.needs("assets").iterate()) { for (auto& obj : root.needs("assets").items()) {
auto obj = asset.obj();
if (obj.needs("name").get<std::string>() == "resources.zip") { if (obj.needs("name").get<std::string>() == "resources.zip") {
updater::tryDownloadLoaderResources( updater::tryDownloadLoaderResources(
obj.needs("browser_download_url").get<std::string>(), obj.needs("browser_download_url").get<std::string>(),
@ -207,8 +206,7 @@ void updater::downloadLoaderResources(bool useLatestRelease) {
auto root = checkJson(ok.unwrap(), "[]"); auto root = checkJson(ok.unwrap(), "[]");
// find release asset // find release asset
for (auto asset : root.needs("assets").iterate()) { for (auto& obj : root.needs("assets").items()) {
auto obj = asset.obj();
if (obj.needs("name").get<std::string>() == "resources.zip") { if (obj.needs("name").get<std::string>() == "resources.zip") {
updater::tryDownloadLoaderResources( updater::tryDownloadLoaderResources(
obj.needs("browser_download_url").get<std::string>(), obj.needs("browser_download_url").get<std::string>(),
@ -382,8 +380,7 @@ void updater::checkForLoaderUpdates() {
} }
// find release asset // find release asset
for (auto asset : root.needs("assets").iterate()) { for (auto& obj : root.needs("assets").items()) {
auto obj = asset.obj();
if (string::endsWith( if (string::endsWith(
obj.needs("name").get<std::string>(), obj.needs("name").get<std::string>(),
fmt::format("{}.zip", PlatformID::toShortString(GEODE_PLATFORM_TARGET, true)) fmt::format("{}.zip", PlatformID::toShortString(GEODE_PLATFORM_TARGET, true))

View file

@ -265,7 +265,7 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
res.metadata.setGeodeVersion(root.needs("geode").get<VersionInfo>()); res.metadata.setGeodeVersion(root.needs("geode").get<VersionInfo>());
// Verify target GD version // Verify target GD version
auto gd_obj = root.needs("gd").obj(); auto gd_obj = root.needs("gd");
std::string gd = "0.000"; std::string gd = "0.000";
if (gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER)) { if (gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER)) {
gd = gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER). get<std::string>(); gd = gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER). get<std::string>();
@ -288,13 +288,11 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
res.metadata.setIsAPI(root.needs("api").get<bool>()); res.metadata.setIsAPI(root.needs("api").get<bool>());
std::vector<ModMetadata::Dependency> dependencies {}; std::vector<ModMetadata::Dependency> 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 // todo: this should probably be generalized to use the same function as mod.json
auto obj = dep.obj();
bool onThisPlatform = !obj.has("platforms"); bool onThisPlatform = !obj.has("platforms");
for (auto& plat : obj.has("platforms").iterate()) { for (auto& plat : obj.has("platforms").items()) {
if (PlatformID::coveredBy(plat.get<std::string>(), GEODE_PLATFORM_TARGET)) { if (PlatformID::coveredBy(plat.get<std::string>(), GEODE_PLATFORM_TARGET)) {
onThisPlatform = true; onThisPlatform = true;
} }
@ -304,7 +302,7 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
} }
ModMetadata::Dependency dependency; ModMetadata::Dependency dependency;
obj.needs("mod_id").validate(MiniFunction<bool(std::string const&)>(&ModMetadata::validateID)).into(dependency.id); obj.needs("mod_id").mustBe<std::string>("a valid id", &ModMetadata::validateID).into(dependency.id);
obj.needs("version").into(dependency.version); obj.needs("version").into(dependency.version);
obj.has("importance").into(dependency.importance); obj.has("importance").into(dependency.importance);
@ -319,9 +317,7 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
res.metadata.setDependencies(dependencies); res.metadata.setDependencies(dependencies);
std::vector<ModMetadata::Incompatibility> incompatibilities {}; std::vector<ModMetadata::Incompatibility> incompatibilities {};
for (auto& incompat : root.has("incompatibilities").iterate()) { for (auto& obj : root.has("incompatibilities").items()) {
auto obj = incompat.obj();
ModMetadata::Incompatibility incompatibility; ModMetadata::Incompatibility incompatibility;
obj.has("importance").into(incompatibility.importance); obj.has("importance").into(incompatibility.importance);
@ -331,7 +327,7 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
if (incompatibility.importance == ModMetadata::Incompatibility::Importance::Superseded) { if (incompatibility.importance == ModMetadata::Incompatibility::Importance::Superseded) {
modIdValue.into(incompatibility.id); modIdValue.into(incompatibility.id);
} else { } else {
modIdValue.validate(MiniFunction<bool(std::string const&)>(&ModMetadata::validateID)).into(incompatibility.id); modIdValue.mustBe<std::string>("a valid id", &ModMetadata::validateID).into(incompatibility.id);
} }
obj.needs("version").into(incompatibility.version); obj.needs("version").into(incompatibility.version);
@ -346,11 +342,7 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
} }
res.metadata.setIncompatibilities(incompatibilities); res.metadata.setIncompatibilities(incompatibilities);
// Check for errors and return result return root.ok(res);
if (root.isError()) {
return Err(root.getError());
}
return Ok(res);
} }
Result<ServerModReplacement> ServerModReplacement::parse(matjson::Value const& raw) { Result<ServerModReplacement> ServerModReplacement::parse(matjson::Value const& raw) {
@ -360,10 +352,7 @@ Result<ServerModReplacement> ServerModReplacement::parse(matjson::Value const& r
root.needs("id").into(res.id); root.needs("id").into(res.id);
root.needs("version").into(res.version); root.needs("version").into(res.version);
if (root.isError()) { return root.ok(res);
return Err(root.getError());
}
return Ok(res);
} }
Result<ServerModUpdate> ServerModUpdate::parse(matjson::Value const& raw) { Result<ServerModUpdate> ServerModUpdate::parse(matjson::Value const& raw) {
@ -377,18 +366,14 @@ Result<ServerModUpdate> ServerModUpdate::parse(matjson::Value const& raw) {
GEODE_UNWRAP_INTO(res.replacement, ServerModReplacement::parse(root.has("replacement").json())); GEODE_UNWRAP_INTO(res.replacement, ServerModReplacement::parse(root.has("replacement").json()));
} }
// Check for errors and return result return root.ok(res);
if (root.isError()) {
return Err(root.getError());
}
return Ok(res);
} }
Result<std::vector<ServerModUpdate>> ServerModUpdate::parseList(matjson::Value const& raw) { Result<std::vector<ServerModUpdate>> ServerModUpdate::parseList(matjson::Value const& raw) {
auto payload = checkJson(raw, "ServerModUpdatesList"); auto payload = checkJson(raw, "ServerModUpdatesList");
std::vector<ServerModUpdate> list {}; std::vector<ServerModUpdate> list {};
for (auto item : payload.iterate()) { for (auto& item : payload.items()) {
auto mod = ServerModUpdate::parse(item.json()); auto mod = ServerModUpdate::parse(item.json());
if (mod) { if (mod) {
list.push_back(mod.unwrap()); list.push_back(mod.unwrap());
@ -398,11 +383,7 @@ Result<std::vector<ServerModUpdate>> ServerModUpdate::parseList(matjson::Value c
} }
} }
// Check for errors and return result return payload.ok(list);
if (payload.isError()) {
return Err(payload.getError());
}
return Ok(list);
} }
bool ServerModUpdate::hasUpdateForInstalledMod() const { bool ServerModUpdate::hasUpdateForInstalledMod() const {
@ -430,8 +411,7 @@ Result<ServerModMetadata> ServerModMetadata::parse(matjson::Value const& raw) {
} }
std::vector<std::string> developerNames; std::vector<std::string> developerNames;
for (auto item : root.needs("developers").iterate()) { for (auto& obj : root.needs("developers").items()) {
auto obj = item.obj();
auto dev = ServerDeveloper(); auto dev = ServerDeveloper();
obj.needs("username").into(dev.username); obj.needs("username").into(dev.username);
obj.needs("display_name").into(dev.displayName); obj.needs("display_name").into(dev.displayName);
@ -439,7 +419,7 @@ Result<ServerModMetadata> ServerModMetadata::parse(matjson::Value const& raw) {
res.developers.push_back(dev); res.developers.push_back(dev);
developerNames.push_back(dev.displayName); 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()); auto versionRes = ServerModVersion::parse(item.json());
if (versionRes) { if (versionRes) {
auto version = versionRes.unwrap(); auto version = versionRes.unwrap();
@ -459,17 +439,13 @@ Result<ServerModMetadata> ServerModMetadata::parse(matjson::Value const& raw) {
return Err("Mod '{}' has no (valid) versions", res.id); 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<std::string>()); res.tags.insert(item.get<std::string>());
} }
root.needs("download_count").into(res.downloadCount); root.needs("download_count").into(res.downloadCount);
// Check for errors and return result return root.ok(res);
if (root.isError()) {
return Err(root.getError());
}
return Ok(res);
} }
std::string ServerModMetadata::formatDevelopersToString() const { std::string ServerModMetadata::formatDevelopersToString() const {
@ -494,7 +470,7 @@ Result<ServerModsList> ServerModsList::parse(matjson::Value const& raw) {
auto payload = checkJson(raw, "ServerModsList"); auto payload = checkJson(raw, "ServerModsList");
auto list = ServerModsList(); auto list = ServerModsList();
for (auto item : payload.needs("data").iterate()) { for (auto& item : payload.needs("data").items()) {
auto mod = ServerModMetadata::parse(item.json()); auto mod = ServerModMetadata::parse(item.json());
if (mod) { if (mod) {
list.mods.push_back(mod.unwrap()); list.mods.push_back(mod.unwrap());
@ -505,11 +481,7 @@ Result<ServerModsList> ServerModsList::parse(matjson::Value const& raw) {
} }
payload.needs("count").into(list.totalModCount); payload.needs("count").into(list.totalModCount);
// Check for errors and return result return payload.ok(list);
if (payload.isError()) {
return Err(payload.getError());
}
return Ok(list);
} }
ModMetadata ServerModMetadata::latestVersion() const { ModMetadata ServerModMetadata::latestVersion() const {

View file

@ -147,10 +147,6 @@ Task<bool> geode::openInfoPopup(std::string const& modID) {
return task; return task;
} }
} }
void geode::openIndexPopup(Mod* mod) {
// deprecated func
openInfoPopup(mod);
}
void geode::openChangelogPopup(Mod* mod) { void geode::openChangelogPopup(Mod* mod) {
auto popup = ModPopup::create(mod); auto popup = ModPopup::create(mod);

View file

@ -3,165 +3,6 @@
using namespace geode::prelude; 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<JsonMaybeSomething*>(this);
}
JsonMaybeValue& JsonMaybeValue::array() {
this->as<value_t::Array>();
return *this;
}
JsonMaybeObject JsonMaybeValue::obj() {
this->as<value_t::Object>();
return JsonMaybeObject(self().m_checker, self().m_json, self().m_hierarchy, self().m_hasValue);
}
JsonMaybeValue JsonMaybeValue::at(size_t i) {
this->as<value_t::Array>();
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> JsonMaybeValue::iterate() {
this->as<value_t::Array>();
Iterator<JsonMaybeValue> 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<std::pair<std::string, JsonMaybeValue>> JsonMaybeValue::items() {
this->as<value_t::Object>();
Iterator<std::pair<std::string, JsonMaybeValue>> 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<JsonMaybeSomething*>(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<std::string>(m_result);
}
std::string JsonChecker::getError() const {
return std::get<std::string>(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 // This is used for null JsonExpectedValues (for example when doing
// `json.has("key")` where "key" doesn't exist) // `json.has("key")` where "key" doesn't exist)
static matjson::Value NULL_SCOPED_VALUE = nullptr; static matjson::Value NULL_SCOPED_VALUE = nullptr;

View file

@ -113,9 +113,6 @@ Result<VersionInfo> VersionInfo::parse(std::string const& string) {
return Ok(VersionInfo(major, minor, patch, tag)); return Ok(VersionInfo(major, minor, patch, tag));
} }
std::string VersionInfo::toString(bool includeTag) const {
return this->toVString();
}
std::string VersionInfo::toVString(bool includeTag) const { std::string VersionInfo::toVString(bool includeTag) const {
return fmt::format("v{}", this->toNonVString(includeTag)); return fmt::format("v{}", this->toNonVString(includeTag));
} }