Use structured bindings for map k,v pairs. Place counters for for range iterator loops locally inside their scopes.

pull/28/head
sigonasr2 1 year ago
parent 6d4f024d3c
commit 30287c91d2
  1. 3
      Crawler/CharacterMenuWindow.cpp
  2. 36
      Crawler/Crawler.cpp
  3. 59
      Crawler/Item.cpp
  4. 76
      Crawler/Menu.cpp
  5. 3
      Crawler/TMXParser.h
  6. 12
      Crawler/Test.cpp
  7. 2
      Crawler/Version.h

@ -123,8 +123,7 @@ void Menu::InitializeCharacterMenuWindow(){
ScrollableWindowComponent*equipList=Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List");
equipList->RemoveAllComponents();
int counter=0;
for(Item&it:availableEquipment){
for(int counter=0;Item&it:availableEquipment){
float xOffset=(counter%3)*26;
Item&itemInvRef=Inventory::GetItem(it.Name());
MenuItemItemButton*equip=NEW MenuItemItemButton(CHARACTER_MENU,{{2+xOffset,2},{24,24}},itemInvRef,MenuType::ENUM_END,[](MenuFuncData data){

@ -126,8 +126,8 @@ Crawler::Crawler()
std::string ITEM_SET_CONFIG = CONFIG_PATH + "item_set_config"_S;
utils::datafile::Read(DATA,ITEM_SET_CONFIG);
for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key.first].GetString();
for(auto&[key,value]:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key].GetString();
utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config);
}
@ -1436,8 +1436,8 @@ void Crawler::LoadLevel(MapName map){
Inventory::Clear("Stage Loot");
#pragma region Monster Spawn Data Setup
for(auto&key:MAP_DATA[map].SpawnerData){
SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key.first];
for(auto&[key,value]:MAP_DATA[map].SpawnerData){
SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key];
std::vector<std::pair<int,vf2d>>monster_list;
vf2d spawnerRadius=vf2d{spawnData.ObjectData.GetFloat("width"),spawnData.ObjectData.GetFloat("height")}/2;
@ -1565,9 +1565,8 @@ void Crawler::LoadLevel(MapName map){
#pragma endregion
#pragma region Bridge Layer Setup
int counter=0;
bridgeLayerIndex=-1;
for(LayerTag&layer:MAP_DATA[map].LayerData){
for(int counter=0;LayerTag&layer:MAP_DATA[map].LayerData){
if(IsBridgeLayer(layer)){
bridgeLayerIndex=counter;
}
@ -1644,9 +1643,8 @@ geom2d::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel)
return NO_COLLISION;
}
}
int counter=0;
geom2d::rect<int>foundRect=NO_COLLISION;
for(LayerTag&layer:MAP_DATA[map].LayerData){
for(int counter=0;LayerTag&layer:MAP_DATA[map].LayerData){
//auto HasNoClass=[&](){return layer.tag.data.find("class")==layer.tag.data.end();};
if(counter!=bridgeLayerIndex){
int tileID=layer.tiles[int(pos.y)/game->GetCurrentMap().tilewidth][int(pos.x)/game->GetCurrentMap().tilewidth]-1;
@ -1868,21 +1866,21 @@ bool Crawler::IsReflectiveTile(TilesheetData tileSheet,int tileID){
bool Crawler::OnUserDestroy(){
GFX.Reset();
for(auto&data:MAP_DATA){
if(MAP_DATA[data.first].optimizedTile!=nullptr){
delete MAP_DATA[data.first].optimizedTile;
for(auto&[key,value]:MAP_DATA){
if(MAP_DATA[key].optimizedTile!=nullptr){
delete MAP_DATA[key].optimizedTile;
}
}
for(auto&key:MAP_TILESETS){
delete key.second.tileset;
for(auto&[key,value]:MAP_TILESETS){
delete value.tileset;
}
for(auto&data:GameState::states){
delete data.second;
for(auto&[key,value]:GameState::states){
delete value;
}
delete[]pathfinder.nodes;
Menu::CleanupAllMenus();
for(auto&key:MonsterData::imgs){
delete key.second;
for(auto&[key,value]:MonsterData::imgs){
delete value;
}
return true;
}
@ -2049,8 +2047,8 @@ void Crawler::InitializeGraphics(){
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;
for(auto&[key,value]:mappedKeys){
std::string themeName=key;
std::string imgPath=DATA["Themes"][themeName]["filename"].GetString();
Renderable&img=GFX["theme_img_directory"_S+imgPath+".png"];
img.Load("GFX_Prefix"_S+"theme_img_directory"_S+imgPath+".png");

@ -82,16 +82,16 @@ void ItemInfo::InitializeItems(){
InitializeSets();
for(auto&key:DATA["ItemCategory"].GetKeys()){
ITEM_CATEGORIES[key.first];
Inventory::sortedInv[key.first];
Menu::inventoryListeners[key.first];
for(auto&[key,value]:DATA["ItemCategory"].GetKeys()){
ITEM_CATEGORIES[key];
Inventory::sortedInv[key];
Menu::inventoryListeners[key];
}
auto ReadItems=[&](datafile&data){
for(auto&key:data.GetKeys()){
std::string imgPath="assets/"+"item_img_directory"_S+key.first+".png";
Renderable&img=GFX["item_img_directory"_S+key.first+".png"];
for(auto&[key,value]:data.GetKeys()){
std::string imgPath="assets/"+"item_img_directory"_S+key+".png";
Renderable&img=GFX["item_img_directory"_S+key+".png"];
img.Load(imgPath);
std::string scriptName="",description="",category="";
@ -100,45 +100,45 @@ void ItemInfo::InitializeItems(){
std::vector<std::string> slot;
float cooldownTime="Item.Item Cooldown Time"_F;
std::vector<ItemAttribute>statValueList;
for(auto&itemKey:data[key.first].GetKeys()){
std::string keyName=itemKey.first;
for(auto&[itemKey,itemValue]:data[key].GetKeys()){
std::string keyName=itemKey;
if(keyName=="Description"){
description=data[key.first][keyName].GetString();
description=data[key][keyName].GetString();
}else
if(keyName=="ItemCategory"){
category=data[key.first][keyName].GetString();
category=data[key][keyName].GetString();
}else
if(keyName=="ItemScript"){
scriptName=data[key.first][keyName].GetString();
scriptName=data[key][keyName].GetString();
}else
if(keyName=="Cast Time"){
castTime=float(data[key.first][keyName].GetReal());
castTime=float(data[key][keyName].GetReal());
}else
if(keyName=="Cooldown Time"){
castTime=float(data[key.first][keyName].GetReal());
castTime=float(data[key][keyName].GetReal());
}else
if(keyName=="Slot"){
for(auto&val:data[key.first][keyName].GetValues()){
for(auto&val:data[key][keyName].GetValues()){
slot.push_back(val);
}
}else
if(keyName=="StatValues"){
for(int i=0;i<data[key.first]["StatValues"].GetValueCount();i++){
statValueList.push_back(ItemAttributable::GetAttributeFromString(data[key.first]["StatValues"].GetString(i)));
for(int i=0;i<data[key]["StatValues"].GetValueCount();i++){
statValueList.push_back(ItemAttributable::GetAttributeFromString(data[key]["StatValues"].GetString(i)));
}
}else
if(keyName=="PartofSet"){
setName=data[key.first][keyName].GetString();
setName=data[key][keyName].GetString();
}else{ //THis is a custom override modifier for a script. NO-OP
}
}
ItemInfo&it=ITEM_DATA[key.first];
ItemInfo&it=ITEM_DATA[key];
if(statValueList.size()>0){
EnhancementInfo enhancementStats;
for(int enhancementLevel=0;enhancementLevel<=10;enhancementLevel++){
datafile&dat=data[key.first]["StatValues["+std::to_string(enhancementLevel)+"]"];
datafile&dat=data[key]["StatValues["+std::to_string(enhancementLevel)+"]"];
int attrIndex=0;
for(ItemAttribute&attr:statValueList){
enhancementStats.SetAttribute(enhancementLevel,attr,dat.GetInt(attrIndex));
@ -149,11 +149,11 @@ void ItemInfo::InitializeItems(){
}
if(scriptName!=""){
if(!ITEM_SCRIPTS.count(scriptName)){
ERR("Could not load script "<<scriptName<<" for Item "<<key.first<<"!")
ERR("Could not load script "<<scriptName<<" for Item "<<key<<"!")
}
}
it.name=key.first;
it.name=key;
it.description=description;
it.category=category;
it.castTime=castTime;
@ -174,7 +174,7 @@ void ItemInfo::InitializeItems(){
ItemProps&props=it.customProps;
if(scriptName!=""){
props.scriptProps=&DATA["ItemScript"][scriptName];
props.customProps=&data[key.first];
props.customProps=&data[key];
}
it.useFunc=scriptName;
}
@ -432,9 +432,8 @@ void ItemOverlay::Update(){
}
void ItemOverlay::Draw(){
int counter=0;
float itemScale="ItemDrop.Item Drop Scale"_F;
for(ItemOverlay&item:items){
for(int counter=0;ItemOverlay&item:items){
vf2d pos={item.xOffset,96.f+counter*10};
Pixel darkCol=Menu::GetCurrentTheme().GetButtonCol();
Pixel lightCol=Menu::GetCurrentTheme().GetButtonCol()*1.2f;
@ -530,17 +529,17 @@ void EnhancementInfo::SetAttribute(int enhanceLevel,ItemAttribute attribute,int
}
void ItemInfo::InitializeSets(){
for(auto&key:DATA["ItemSet"].GetKeys()){
std::string setName=key.first;
for(auto&[key,value]:DATA["ItemSet"].GetKeys()){
std::string setName=key;
datafile&setInfo=DATA["ItemSet"][setName];
for(int pieceCount=1;pieceCount<=8;pieceCount++){
if(setInfo.HasProperty(std::to_string(pieceCount))){
datafile&statInfo=setInfo[std::to_string(pieceCount)];
Stats bonuses;
for(auto&key:statInfo.GetKeys()){
ItemAttribute attr=bonuses.GetAttributeFromString(key.first);
bonuses.A(attr)=statInfo[key.first].GetInt(0);
for(auto&[key,value]:statInfo.GetKeys()){
ItemAttribute attr=bonuses.GetAttributeFromString(key);
bonuses.A(attr)=statInfo[key].GetInt(0);
}
ItemSet::AddSetBonus(setName,pieceCount,bonuses);
}

@ -79,8 +79,8 @@ Menu::Menu(vf2d pos,vf2d size)
}
Menu::~Menu(){
for(auto&key:components){
delete key.second;
for(auto&[key,value]:components){
delete value;
}
}
@ -105,8 +105,8 @@ void Menu::InitializeMenus(){
//Lock up everything once it's done.
menus[type]->buttons.SetInitialized();
menus[type]->keyboardButtons.SetInitialized();
for(auto&key:menus[type]->components){
MenuComponent*component=key.second;
for(auto&[key,value]:menus[type]->components){
MenuComponent*component=value;
component->AfterCreate();
}
}
@ -218,8 +218,8 @@ void Menu::Update(Crawler*game){
SetMouseNavigation(true);
}
for(auto&key:buttons){
for(auto&button:key.second){
for(auto&[key,value]:buttons){
for(auto&button:value){
if(!button->disabled){
button->hovered=false;
}
@ -235,14 +235,14 @@ void Menu::Update(Crawler*game){
}
}else{
selection={-1,-1};
for(auto&key:buttons){
for(auto&[key,value]:buttons){
int index=0;
for(auto&button:key.second){
for(auto&button:value){
if(!button->disabled){
if(button->GetHoverState(game)){
button->hovered=true;
itemHovered=true;
selection.y=key.first;
selection.y=key;
selection.x=index;
}
}
@ -291,8 +291,8 @@ void Menu::Update(Crawler*game){
}
KeyboardButtonNavigation(game,pos);
for(auto&key:buttons){
for(auto&button:key.second){
for(auto&[key,value]:buttons){
for(auto&button:value){
if(button->renderInMain){
button->_Update(game);
}
@ -321,8 +321,8 @@ void Menu::Draw(Crawler*game){
component->_Draw(game);
}
}
for(auto&key:buttons){
for(auto&button:key.second){
for(auto&[key,value]:buttons){
for(auto&button:value){
if(button->renderInMain){
button->_Draw(game);
}
@ -337,8 +337,8 @@ void Menu::Draw(Crawler*game){
component->_DrawDecal(game,this==Menu::stack.back());
}
}
for(auto&key:buttons){
for(auto&button:key.second){
for(auto&[key,value]:buttons){
for(auto&button:value){
if(button->renderInMain){
button->_DrawDecal(game,this==Menu::stack.back());
}
@ -409,17 +409,17 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
bool selectedItem=false;
if(selection==vi2d{-1,-1}){
//Highlight first item.
for(auto&key:keyboardButtons){
selection.y=key.first;
for(auto&[key,value]:keyboardButtons){
selection.y=key;
break;
}
}else{
for(auto&key:keyboardButtons){
for(auto&[key,value]:keyboardButtons){
if(found){ //Once we discover the previous element, the next element becomes our next selection.
int previousButtonX=int(keyboardButtons[selection.y][selection.x]->rect.pos.x);
selection.y=key.first;
selection.y=key;
int index=0;
for(auto&button:key.second){ //Try to match a button in the same column as this button first.
for(auto&button:value){ //Try to match a button in the same column as this button first.
if(previousButtonX==button->rect.pos.x){
selection.x=index;
break;
@ -429,15 +429,15 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
selectedItem=true;
break;
}
if(key.first==selection.y
if(key==selection.y
//It's entirely possible this button was selected from the button selection list and may be out-of-bounds here.
&&selection.x>=0&&selection.x<keyboardButtons[selection.y].size()){
found=true;
}
}
if(!selectedItem){ //This means we need to loop around instead and pick the first one.
for(auto&key:keyboardButtons){
selection.y=key.first;
for(auto&[key,value]:keyboardButtons){
selection.y=key;
break;
}
}
@ -447,18 +447,18 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
SetMouseNavigation(false);
if(selection==vi2d{-1,-1}){
//Highlight last item.
for(auto&key:keyboardButtons){
selection.y=key.first;
for(auto&[key,value]:keyboardButtons){
selection.y=key;
}
}else{
int prevInd=-1;
for(auto&key:keyboardButtons){
if(key.first==selection.y&&
for(auto&[key,value]:keyboardButtons){
if(key==selection.y&&
//It's entirely possible this button was selected from the button selection list and may be out-of-bounds here.
selection.x>=0&&selection.x<keyboardButtons[selection.y].size()){
break;
}
prevInd=key.first;
prevInd=key;
}
if(prevInd!=-1){
int previousButtonX=int(keyboardButtons[selection.y][selection.x]->rect.pos.x);
@ -473,8 +473,8 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
}
}else{ //Since we didn't find it, it means we're at the top of the list or the list is empty. Go to the last element and use that one.
int lastInd=-1;
for(auto&key:keyboardButtons){
lastInd=key.first;
for(auto&[key,value]:keyboardButtons){
lastInd=key;
}
selection.y=lastInd;
}
@ -495,9 +495,9 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
if(selection==vi2d{-1,-1}&&buttons.size()>0){
//Find the first possible button entry in the map...
int firstInd=-1;
for(auto&key:buttons){
if(buttons[key.first].size()>0){
firstInd=key.first;
for(auto&[key,value]:buttons){
if(buttons[key].size()>0){
firstInd=key;
break;
}
}
@ -507,12 +507,12 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
}
}else{//Mouse click.
selection={-1,-1};
for(auto&key:buttons){
for(auto&[key,value]:buttons){
int index=0;
for(auto&button:key.second){
for(auto&button:value){
if(!button->disabled){
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){
selection={index,key.first};
selection={index,key};
break;
}
}
@ -692,8 +692,8 @@ bool Menu::IsMenuOpen(){
}
void Menu::CleanupAllMenus(){
for(auto&key:Menu::menus){
Menu*menu=key.second;
for(auto&[key,value]:Menu::menus){
Menu*menu=value;
for(auto&componentKey:menu->components){
MenuComponent*component=componentKey.second;
component->Cleanup();

@ -470,8 +470,7 @@ class TMXParser{
}
}
}
int counter=0;
for(ConnectionPoint&connection:State_OverworldMap::connections){
for(int counter=0;ConnectionPoint&connection:State_OverworldMap::connections){
for(int val:connection.neighbors){
if(val!=-1){
ConnectionPoint&neighbor=State_OverworldMap::connections.at(val);

@ -56,12 +56,12 @@ void Test::RunMapTests(){
is("There are two LowerBridgeCollision zones in Campaign I-I",
game->MAP_DATA.at(CAMPAIGN_1_1).ZoneData.count("LowerBridgeCollision")
&&game->MAP_DATA.at(CAMPAIGN_1_1).ZoneData.at("LowerBridgeCollision").size()>=2);
for(auto&key:game->MAP_DATA){
is("A Map type has been selected for map "+std::to_string(key.first),
key.second.mapType!=""&&key.second.mapType!="Unspecified");
if(key.second.mapType=="Dungeon"){
is("There is an EndZone in Dungeon "+std::to_string(key.first),
key.second.ZoneData.count("EndZone"));
for(auto&[key,value]:game->MAP_DATA){
is("A Map type has been selected for map "+std::to_string(key),
value.mapType!=""&&value.mapType!="Unspecified");
if(value.mapType=="Dungeon"){
is("There is an EndZone in Dungeon "+std::to_string(key),
value.ZoneData.count("EndZone"));
}
}
}

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3470
#define VERSION_BUILD 3471
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save