Theme keys are now sorted when loading so they appear in the right order down the line.

pull/28/head
sigonasr2 1 year ago
parent 2224065304
commit 9246852c25
  1. 9
      Crawler/Crawler.cpp
  2. 6
      Crawler/TestSubMenu.cpp
  3. 1
      Crawler/Theme.h
  4. 2
      Crawler/Version.h
  5. 2
      Crawler/assets/config/gfx/themes.txt
  6. 18
      Crawler/safemap.h

@ -1690,7 +1690,14 @@ void Crawler::InitializeGraphics(){
} }
//Specifically split up the 9 patch image into multiple pieces for each theme. //Specifically split up the 9 patch image into multiple pieces for each theme.
for(auto&key:DATA["Themes"].GetKeys()){ const auto&unordered_map=DATA["Themes"].GetKeys();
std::vector<std::pair<std::string,size_t>>mappedKeys;
mappedKeys.reserve(unordered_map.size());
for(auto&key:unordered_map){
mappedKeys.push_back(key);
}
std::sort(mappedKeys.begin(),mappedKeys.end(),[](std::pair<std::string,size_t>&key1,std::pair<std::string,size_t>&key2){return key1.second<key2.second;});
for(auto&key:mappedKeys){
std::string themeName=key.first; std::string themeName=key.first;
std::string imgPath=DATA["Themes"][themeName]["Name"].GetString(); std::string imgPath=DATA["Themes"][themeName]["Name"].GetString();
Renderable&img=GFX["theme_img_directory"_S+imgPath+".png"]; Renderable&img=GFX["theme_img_directory"_S+imgPath+".png"];

@ -20,7 +20,7 @@ const Menu Menu::InitializeTestSubMenu(){
int index=0; int index=0;
for(auto&theme:Menu::themes){ for(auto&theme:Menu::themes){
if(theme.first==Menu::themeSelection){ if(theme.displayName==Menu::themeSelection){
testSubMenu.I(A::INDEXED_THEME)=index; testSubMenu.I(A::INDEXED_THEME)=index;
break; break;
} }
@ -36,7 +36,7 @@ const Menu Menu::InitializeTestSubMenu(){
int index=0; int index=0;
for(auto&theme:Menu::themes){ for(auto&theme:Menu::themes){
if(index==menu.I(A::INDEXED_THEME)){ if(index==menu.I(A::INDEXED_THEME)){
Menu::themeSelection=theme.first; Menu::themeSelection=theme.displayName;
((MenuLabel*)(menu.components["THEME_DISPLAY"]))->SetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName()); ((MenuLabel*)(menu.components["THEME_DISPLAY"]))->SetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName());
break; break;
} }
@ -53,7 +53,7 @@ const Menu Menu::InitializeTestSubMenu(){
int index=0; int index=0;
for(auto&theme:Menu::themes){ for(auto&theme:Menu::themes){
if(index==menu.I(A::INDEXED_THEME)){ if(index==menu.I(A::INDEXED_THEME)){
Menu::themeSelection=theme.first; Menu::themeSelection=theme.displayName;
((MenuLabel*)(menu.components["THEME_DISPLAY"]))->SetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName()); ((MenuLabel*)(menu.components["THEME_DISPLAY"]))->SetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName());
break; break;
} }

@ -2,6 +2,7 @@
#include "olcPixelGameEngine.h" #include "olcPixelGameEngine.h"
class Theme{ class Theme{
friend class Menu;
std::string displayName; std::string displayName;
std::string imgPath; std::string imgPath;

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 1706 #define VERSION_BUILD 1719
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -1,7 +1,7 @@
ThemeGlobal ThemeGlobal
{ {
# How long it takes for the fade-in/fade-out effect to occur. # How long it takes for the fade-in/fade-out effect to occur.
HighlightTime = 0.6 HighlightTime = 0.2
} }
Themes Themes

@ -50,9 +50,11 @@ public:
}; };
//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection. //A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.
//This unordered map should return items inserted in order. Therefore internally, it's hosted as a vector. As such, if an item is added to this map it's possible the refernce becomes stale when another item is added due to a vector expanding. BEWARE!
template<typename T,typename O> template<typename T,typename O>
class safeunorderedmap{ class safeunorderedmap{
std::unordered_map<T,O>map; std::unordered_map<T,int>map;
std::vector<O>items;
bool initialized=false; bool initialized=false;
public: public:
O&operator[](T key){ O&operator[](T key){
@ -62,18 +64,19 @@ public:
} }
if(!initialized){ if(!initialized){
size_t originalSize=map.size(); size_t originalSize=map.size();
O&val=map[key]; map[key]=items.size();
if(originalSize==map.size()){ if(originalSize==map.size()){
std::cout<<"WARNING! A previously set value has been overwritten! Key: "<<key<<std::endl; std::cout<<"WARNING! A previously set value has been overwritten! Key: "<<key<<std::endl;
throw; throw;
} }
return val; items.push_back({});
return items[map[key]];
}else{ }else{
return map[key]; return items[map[key]];
} }
} }
O&at(T key){ O&at(T key){
return map.at(key); return items[map.at(key)];
} }
size_t count(T key){ size_t count(T key){
return map.count(key); return map.count(key);
@ -88,11 +91,12 @@ public:
void Reset(){ void Reset(){
initialized=false; initialized=false;
map.clear(); map.clear();
items.clear();
} }
auto begin()const{ auto begin()const{
return map.begin(); return items.begin();
} }
auto end()const{ auto end()const{
return map.end(); return items.end();
} }
}; };
Loading…
Cancel
Save