Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- name: macOS
os: macos-latest

- name: iOS
os: macos-latest
target: iOS

- name: Android32
os: ubuntu-latest
target: Android32
Expand Down Expand Up @@ -62,7 +66,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: hiimjustin000/release-geode-mod@main
- uses: hiimjasmine00/release-geode-mod@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR IOS)
set(CMAKE_OSX_ARCHITECTURES "arm64")
else()
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(PositionSwitch VERSION 1.0.0)
Expand Down
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"geode": "4.5.0",
"gd": {
"win": "2.2074",
"android": "2.2074",
"mac": "2.2074",
"ios": "2.2074"
"ios": "2.2074",
"android": "2.2074"
},
"id": "techstudent10.positionswitch",
"name": "PositionSwitch",
Expand Down
45 changes: 36 additions & 9 deletions src/LevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@ LevelManager::LevelManager() {
m_listener.bind([this] (web::WebTask::Event* e) {
if (web::WebResponse* res = e->getValue()) {
auto _res = res->string().unwrapOr("Uh oh!");
if (_res == "Uh oh!") return log::info("The request could not be stringified... So sad :(");

auto index = _res.find("{");
if (index == std::string::npos) return;
if (index == std::string::npos) return log::info("The request could not be stringified... So sad :(");

auto _result = _res.substr(index);
auto result = matjson::parse(_result.substr(0, _result.length() - 2)).unwrapOr(matjson::makeObject({ {"table", { {"rows", [] } }} }));
auto rows = result["table"].unwrap()["rows"].as_array().unwrap();
for (auto& row : rows) {
auto contents = row["c"].as_array().unwrap();
auto result = matjson::parse(_result.substr(0, _result.length() - 2));
if (result.isErr()) return log::info("The results could not be parsed into JSON... So sad :(");

auto unwrappedResult = result.unwrap();
if (!unwrappedResult.contains("table")) return log::info("The results did not have a 'table' key... So sad :(");
if (!unwrappedResult["table"].contains("rows")) return log::info("The results had a 'table' key, but not a 'rows' key... So sad :(");
// auto rows = result["table"].unwrap()["rows"].as_array().unwrap();

auto rows = unwrappedResult["table"]["rows"].asArray();
if (rows.isErr()) return log::info("The 'rows' key could not become a matjson array... So sad :(");

for (auto& row : rows.unwrap()) {
if (!row.contains("c")) {
log::info("this row does not have a 'c' key... So sad :(");
continue;
}
auto stillWrappedContents = row["c"].asArray();
if (stillWrappedContents.isErr()) {
log::info("this row's contents were not formed into an array... So sad :(");
continue;
}

auto contents = stillWrappedContents.unwrap();
if (contents.size() < 2 || !contents[0].contains("v") || !contents[1].contains("f")) {
log::info("this row's has fewer than two elements OR has no level name OR no level ID... So sad :(");
continue;
}

auto levelName = geode::utils::string::toLower(contents[0]["v"].as_string().unwrap());
auto levelID = contents[1]["f"].as_string().unwrap();
levels[levelName] = levelID;
auto levelName = contents[0]["v"].asString();
if (levelName.isErr()) return log::info("levelName could not be parded into a string... So sad :(");
auto levelID = contents[1]["f"].asString();
if (levelID.isErr()) return log::info("levelID could not be parded into a string... So sad :(");
levels[geode::utils::string::toLower(levelName.unwrap())] = levelID.unwrap();
}
// log::info("levels inserted! length: {}", levels.size());

} else if (web::WebProgress* p = e->getProgress()) {
// TODO: make this log toggleable
Expand Down
3 changes: 1 addition & 2 deletions src/LevelManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ class LevelManager {
static LevelManager instance;
return instance;
}
};

};
24 changes: 10 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@

using namespace geode::prelude;

class $modify(MyMenuLayer, MenuLayer) {
bool init() {
if (!MenuLayer::init()) {
return false;
}

LevelManager::get(); // inititalizes the list on startup

return true;
}
};
$on_mod(Loaded) {
LevelManager::get(); // inititalizes the list on startup
}

class $modify(MyInfoLayer, LevelInfoLayer) {
bool init(GJGameLevel* level, bool challenge) {
if (!LevelInfoLayer::init(level, challenge)) return false;

auto hasLevel = LevelManager::get().levels.contains(
geode::utils::string::toLower(level->m_levelName)
);
auto startPosLevels = LevelManager::get().levels;
auto levelName = geode::utils::string::toLower(level->m_levelName);
auto hasStartPosCounterpart = startPosLevels.contains(levelName);
if (!hasStartPosCounterpart) return true;
auto parsedStartPosLevelID = geode::utils::numFromString<int>(startPosLevels.find(levelName)->second).unwrapOr(-1);
auto isNotStartPosLevel = parsedStartPosLevelID != level->m_levelID.value();
auto hasLevel = hasStartPosCounterpart && isNotStartPosLevel;
if (hasLevel) {
auto startPosSprite = CCSprite::create("startpos-btn.png"_spr);
startPosSprite->setScale(0.625);
Expand Down