mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
use string_view for sprite expansion
This commit is contained in:
parent
84e47a596f
commit
22cc33b8a9
6 changed files with 16 additions and 13 deletions
|
@ -444,7 +444,7 @@ namespace geode {
|
|||
*/
|
||||
bool hasUnresolvedIncompatibilities() const;
|
||||
|
||||
char const* expandSpriteName(char const* name);
|
||||
std::string_view expandSpriteName(std::string_view name);
|
||||
|
||||
/**
|
||||
* Get info about the mod as JSON
|
||||
|
@ -466,6 +466,6 @@ namespace geode {
|
|||
};
|
||||
}
|
||||
|
||||
GEODE_HIDDEN inline char const* operator"" _spr(char const* str, size_t) {
|
||||
return geode::Mod::get()->expandSpriteName(str);
|
||||
GEODE_HIDDEN inline char const* operator"" _spr(char const* str, size_t len) {
|
||||
return geode::Mod::get()->expandSpriteName({ str, len }).data();
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ GEODE_HIDDEN inline cocos2d::ccColor3B operator"" _cc3b_gd(const char* str, size
|
|||
return geode::ColorProvider::get()->color3b(str);
|
||||
}
|
||||
GEODE_HIDDEN inline cocos2d::ccColor4B operator"" _cc4b(const char* str, size_t) {
|
||||
return geode::ColorProvider::get()->color(geode::Mod::get()->expandSpriteName(str));
|
||||
return geode::ColorProvider::get()->color(std::string(geode::Mod::get()->expandSpriteName(str)));
|
||||
}
|
||||
GEODE_HIDDEN inline cocos2d::ccColor3B operator"" _cc3b(const char* str, size_t) {
|
||||
return geode::ColorProvider::get()->color3b(geode::Mod::get()->expandSpriteName(str));
|
||||
return geode::ColorProvider::get()->color3b(std::string(geode::Mod::get()->expandSpriteName(str)));
|
||||
}
|
||||
|
|
|
@ -225,7 +225,7 @@ bool Mod::hasUnresolvedIncompatibilities() const {
|
|||
return m_impl->hasUnresolvedIncompatibilities();
|
||||
}
|
||||
|
||||
char const* Mod::expandSpriteName(char const* name) {
|
||||
std::string_view Mod::expandSpriteName(std::string_view name) {
|
||||
return m_impl->expandSpriteName(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
|
@ -743,14 +744,15 @@ std::filesystem::path Mod::Impl::getConfigDir(bool create) const {
|
|||
return dir;
|
||||
}
|
||||
|
||||
char const* Mod::Impl::expandSpriteName(char const* name) {
|
||||
if (m_expandedSprites.count(name)) return m_expandedSprites[name];
|
||||
std::string_view Mod::Impl::expandSpriteName(std::string_view name) {
|
||||
std::string nameKey(name);
|
||||
if (m_expandedSprites.contains(nameKey)) return m_expandedSprites[nameKey];
|
||||
|
||||
auto exp = new char[strlen(name) + 2 + m_metadata.getID().size()];
|
||||
auto exps = m_metadata.getID() + "/" + name;
|
||||
auto exp = new char[name.size() + 2 + m_metadata.getID().size()];
|
||||
auto exps = (m_metadata.getID() + "/") + name.data();
|
||||
memcpy(exp, exps.c_str(), exps.size() + 1);
|
||||
|
||||
m_expandedSprites[name] = exp;
|
||||
m_expandedSprites[nameKey] = exp;
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <matjson.hpp>
|
||||
#include "ModPatch.hpp"
|
||||
#include <Geode/loader/Loader.hpp>
|
||||
#include <string_view>
|
||||
|
||||
namespace geode {
|
||||
class Mod::Impl {
|
||||
|
@ -148,7 +149,7 @@ namespace geode {
|
|||
|
||||
Result<> loadBinary();
|
||||
|
||||
char const* expandSpriteName(char const* name);
|
||||
std::string_view expandSpriteName(std::string_view name);
|
||||
ModJson getRuntimeInfo() const;
|
||||
|
||||
bool isLoggingEnabled() const;
|
||||
|
|
|
@ -182,7 +182,7 @@ static std::string baseEnumsToString(BaseType type, int size, int color) {
|
|||
|
||||
bool BasedButtonSprite::init(CCNode* ontop, BaseType type, int size, int color) {
|
||||
if (!CCSprite::initWithSpriteFrameName(
|
||||
Mod::get()->expandSpriteName(baseEnumsToString(type, size, color).c_str())
|
||||
Mod::get()->expandSpriteName(baseEnumsToString(type, size, color)).data()
|
||||
)) return false;
|
||||
|
||||
m_type = type;
|
||||
|
|
Loading…
Reference in a new issue