Skip to content

Commit

Permalink
Android Support:
Browse files Browse the repository at this point in the history
  - Uses a different dir for NONGs on Android
  - Makes the dir if it doesn't already exist
  - Update `setSong` to be Android friendly
  - Uncomment android build commands for actions
  - (OBSELETE/REDACTED) Update `.clang-format` for better code readability
  - (OBSELETE/REDACTED) Format ALL `cpp/hpp` files based on new `.clang-format`
  • Loading branch information
TheBearodactyl committed May 29, 2024
1 parent baea0aa commit 89297c1
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 163 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
# - name: macOS
# os: macos-latest

# - name: Android32
# os: ubuntu-latest
# target: Android32
- name: Android32
os: ubuntu-latest
target: Android32
#
# - name: Android64
# os: ubuntu-latest
# target: Android64
- name: Android64
os: ubuntu-latest
target: Android64

name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
Expand Down
7 changes: 5 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"geode": "2.0.0-beta.27",
"gd": "2.204",
"version": "v0.0.3",
"gd": {
"win": "2.204",
"android": "2.205"
},
"version": "v0.0.4",
"id": "flafy.autonong",
"name": "Auto Nong",
"developer": "Flafy",
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/custom_song_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct ANCustomSongWidget : geode::Modify<ANCustomSongWidget, CustomSongWidget>
CCMenu *m_nongMenu;
};

std::set<int> getSongIds() {
std::set<int> songIds;
Set<int> getSongIds() {
Set<int> songIds;
for (const auto &pair : m_songs) {
songIds.insert(pair.first);
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/level_info_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ struct ANLevelInfoLayer : geode::Modify<ANLevelInfoLayer, LevelInfoLayer> {
if (!LevelInfoLayer::init(level, p1)) {
return false;
}

AutoNongManager::get()->setCurrentLevelID(level->m_levelID);

return true;
}
};
11 changes: 11 additions & 0 deletions src/includes/geode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/string.hpp>
#include <fleym.nongd/include/jukebox.hpp>
#include <map>
#include <matjson.hpp>
#include <set>

template <typename T> using Vec = std::vector<T>;
template <typename K, typename V> using Map = std::map<K, V>;
template <typename T> using Set = std::set<T>;
template <typename T> using Opt = std::optional<T>;
template <typename T> using Shared = std::shared_ptr<T>;

using String = std::string;
using str = const std::string &;

using namespace geode::prelude;
7 changes: 3 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

$on_mod(Loaded) {
Mod::get()->addCustomSetting<MultiStringSettingValue>(
"indexes", Mod::get()
->getSettingDefinition("indexes")
->get<CustomSetting>()
->json->get<std::vector<std::string>>("default"));
"indexes",
Mod::get()->getSettingDefinition("indexes")->get<CustomSetting>()->json->get<Vec<String>>(
"default"));
Mod::get()->addCustomSetting<ANClearPPBlacklistSettingValue>("_blacklistPPClear", 0);

AutoNongManager::get()->loadIndexes();
Expand Down
30 changes: 15 additions & 15 deletions src/managers/auto_nong_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "auto_nong_manager.hpp"
#include "../includes/geode.hpp"

std::vector<std::shared_ptr<ANSong>> AutoNongManager::getNongsFromSongID(int songID) {
Vec<Shared<ANSong>> AutoNongManager::getNongsFromSongID(int songID) {
if (m_songIDToNongs.find(songID) == m_songIDToNongs.end()) {
return std::vector<std::shared_ptr<ANSong>>{};
return Vec<Shared<ANSong>>{};
}
return m_songIDToNongs[songID];
}

bool AutoNongManager::anySongExists(std::set<int> songIDs) {
bool AutoNongManager::anySongExists(Set<int> songIDs) {
for (int songID : songIDs) {
if (m_songIDToNongs.find(songID) != m_songIDToNongs.end())
return true;
Expand All @@ -19,42 +20,41 @@ bool AutoNongManager::anySongExists(std::set<int> songIDs) {
void AutoNongManager::loadIndexesSchedule(float) { loadIndexes(); }

void AutoNongManager::loadIndexes() {
std::vector<std::string> indexes =
Mod::get()->getSettingValue<MultiStringSettingStruct>("indexes").m_strings;
Vec<String> indexes = Mod::get()->getSettingValue<MultiStringSettingStruct>("indexes").m_strings;

m_songIDToNongs = {};

for (std::string index : indexes) {
for (String index : indexes) {
if (index.size() < 5)
continue;
log::info("Loading index: {}", index);
geode::utils::web::AsyncWebRequest()
.fetch(index)
.bytes()
.then([this, index](const geode::ByteVector &r) {
std::vector<uint8_t> rVec = r;
Vec<uint8_t> rVec = r;
bool isGzip = (rVec.size() > 2) && (rVec[0] == 0x1F) && (rVec[1] == 0x8B);

std::string jsonString;
String jsonString;
if (isGzip) {
jsonString = decompressGz(rVec);
} else {
jsonString = std::string(rVec.begin(), rVec.end());
jsonString = String(rVec.begin(), rVec.end());
}

matjson::Value jsonObj = matjson::parse(jsonString);

for (const auto &songData : jsonObj.as_array()) {
std::string name = songData["name"].as_string();
std::string artist = songData.contains("artist") ? songData["artist"].as_string() : "";
std::string source = songData["source"].as_string();
String name = songData["name"].as_string();
String artist = songData.contains("artist") ? songData["artist"].as_string() : "";
String source = songData["source"].as_string();

std::shared_ptr<ANSong> song;
Shared<ANSong> song;
if (source == "youtube") {
std::string yt_id = songData["yt-id"].as_string();
String yt_id = songData["yt-id"].as_string();
song = std::make_shared<ANYTSong>(name, artist, index, yt_id);
} else if (source == "host") {
std::string url = songData["url"].as_string();
String url = songData["url"].as_string();
song = std::make_shared<ANHostSong>(name, artist, index, url);
} else {
log::warn("Unsupported source: {}", source);
Expand Down
4 changes: 2 additions & 2 deletions src/managers/auto_nong_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class AutoNongManager : public CCNode {
protected:
inline static AutoNongManager *m_instance = nullptr;
int m_currentLevelID = 0;
std::map<int, std::vector<std::shared_ptr<ANSong>>> m_songIDToNongs;
Map<int, Vec<Shared<ANSong>>> m_songIDToNongs;

public:
std::vector<std::shared_ptr<ANSong>> getNongsFromSongID(int songID);
Vec<Shared<ANSong>> getNongsFromSongID(int songID);
bool anySongExists(std::set<int> songIDs);
void loadIndexes();
int getCurrentLevelID();
Expand Down
3 changes: 2 additions & 1 deletion src/types/an_song.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "an_song.hpp"
#include "../includes/geode.hpp"

std::string ANSong::getSource() {
String ANSong::getSource() {
if (typeid(*this) == typeid(ANYTSong)) {
return "youtube";
} else if (typeid(*this) == typeid(ANHostSong)) {
Expand Down
24 changes: 11 additions & 13 deletions src/types/an_song.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
#pragma once

#include "../includes/geode.hpp"

class ANYTSong;
class ANHostSong;

class ANSong {
public:
ANSong(const std::string &name, const std::string &artist, const std::string &index)
: m_name(name), m_artist(artist), m_index(index) {}
std::string m_name;
std::string m_artist;
std::string m_index;
ANSong(str name, str artist, str index) : m_name(name), m_artist(artist), m_index(index) {}
String m_name;
String m_artist;
String m_index;
virtual ~ANSong() {}
std::string getSource();
String getSource();
};

class ANYTSong : public ANSong {
public:
ANYTSong(const std::string &name, const std::string &artist, const std::string &index,
const std::string &yt_id)
ANYTSong(str name, str artist, str index, str yt_id)
: ANSong(name, artist, index), m_ytId(yt_id) {}
std::string m_ytId;
String m_ytId;
};

class ANHostSong : public ANSong {
public:
ANHostSong(const std::string &name, const std::string &artist, const std::string &index,
const std::string &url)
: ANSong(name, artist, index), m_url(url) {}
std::string m_url;
ANHostSong(str name, str artist, str index, str url) : ANSong(name, artist, index), m_url(url) {}
String m_url;
};
17 changes: 9 additions & 8 deletions src/types/serializable_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#pragma once

#include "../includes/geode.hpp"
#include <matjson.hpp>
#include <vector>

template <> struct matjson::Serialize<std::vector<int>> {
template <> struct matjson::Serialize<Vec<int>> {
static bool is_json(matjson::Value const &value) { return value.is_array(); }

static std::vector<int> from_json(matjson::Value const &value) {
std::vector<int> vec;
static Vec<int> from_json(matjson::Value const &value) {
Vec<int> vec;
auto array = value.as_array();
for (auto const &elem : array) {
vec.push_back(elem.as_int());
}
return vec;
}

static matjson::Value to_json(std::vector<int> const &vec) {
static matjson::Value to_json(Vec<int> const &vec) {
auto array = matjson::Array();
for (auto const &elem : vec) {
array.push_back(elem);
Expand All @@ -24,19 +25,19 @@ template <> struct matjson::Serialize<std::vector<int>> {
}
};

template <> struct matjson::Serialize<std::vector<std::string>> {
template <> struct matjson::Serialize<Vec<String>> {
static bool is_json(matjson::Value const &value) { return value.is_array(); }

static std::vector<std::string> from_json(matjson::Value const &value) {
std::vector<std::string> vec;
static Vec<String> from_json(matjson::Value const &value) {
Vec<String> vec;
auto array = value.as_array();
for (auto const &elem : array) {
vec.push_back(elem.as_string());
}
return vec;
}

static matjson::Value to_json(std::vector<std::string> const &vec) {
static matjson::Value to_json(Vec<String> const &vec) {
auto array = matjson::Array();
for (auto const &elem : vec) {
array.push_back(elem);
Expand Down
9 changes: 4 additions & 5 deletions src/ui/an_clear_popup_blacklist.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "an_clear_popup_blacklist.hpp"
#include "../includes/geode.hpp"
#include "../types/serializable_vector.hpp"

SettingNode *ANClearPPBlacklistSettingValue::createNode(float width) {
return ANClearPPBlacklistSettingNode::create(this, width);
}

bool ANClearPPBlacklistSettingNode::init(ANClearPPBlacklistSettingValue *value, float width) {
if (!SettingNode::init(value))
if (!SettingNode::init(value)) {
return false;
}

this->value = value;

float height = 40.f;
Expand Down Expand Up @@ -42,13 +45,9 @@ void ANClearPPBlacklistSettingNode::onReset(CCObject *target) {
}

void ANClearPPBlacklistSettingNode::commit() { this->dispatchCommitted(); }

bool ANClearPPBlacklistSettingNode::hasUncommittedChanges() { return false; }

bool ANClearPPBlacklistSettingNode::hasNonDefaultValue() { return false; }

void ANClearPPBlacklistSettingNode::resetToDefault() {}

ANClearPPBlacklistSettingNode *
ANClearPPBlacklistSettingNode::create(ANClearPPBlacklistSettingValue *value, float width) {
auto ret = new ANClearPPBlacklistSettingNode();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/an_clear_popup_blacklist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ANClearPPBlacklistSettingValue : public SettingValue {
int m_unused;

public:
ANClearPPBlacklistSettingValue(std::string const &key, std::string const &modID, int unused)
ANClearPPBlacklistSettingValue(String const &key, String const &modID, int unused)
: SettingValue(key, modID), m_unused(unused) {}

bool load(matjson::Value const &json) override {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/an_dropdown_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "an_dropdown_layer.hpp"
#include "../includes/geode.hpp"
#include "an_song_cell.hpp"

bool ANDropdownLayer::setup(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
bool ANDropdownLayer::setup(int songId, Vec<Shared<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) {
m_songID = songId;
m_songCandidates = songCandidates;
Expand Down
11 changes: 5 additions & 6 deletions src/ui/an_dropdown_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
#include "../includes/geode.hpp"
#include "../types/an_song.hpp"

class ANDropdownLayer
: public Popup<int, std::vector<std::shared_ptr<ANSong>>, CustomSongWidget *, int, int> {
class ANDropdownLayer : public Popup<int, Vec<Shared<ANSong>>, CustomSongWidget *, int, int> {
protected:
int m_songID;
std::vector<std::shared_ptr<ANSong>> m_songCandidates;
Vec<Shared<ANSong>> m_songCandidates;
int m_popupNumber;
int m_totalPopups;
ListView *m_listView = nullptr;
CCSize m_cellSize = {320.f, 60.f};

bool setup(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) override;
bool setup(int songId, Vec<Shared<ANSong>> songCandidates, CustomSongWidget *parent,
int popupNumber, int totalPopups) override;

public:
Ref<CustomSongWidget> m_parentWidget;

static ANDropdownLayer *create(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
static ANDropdownLayer *create(int songId, Vec<Shared<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) {
auto ret = new ANDropdownLayer;
if (ret && ret->initAnchored(420.f, 280.f, songId, songCandidates, parent, popupNumber,
Expand Down
Loading

0 comments on commit 89297c1

Please sign in to comment.