Skip to content

Commit a1da519

Browse files
committed
Editor: Implemented soft-limit option
It allows to set the minimum of required items for integrational config packs. Some packages might contain missing dummy graphics, and this case should not being a hard reason to invalidate the config pack. So, this option allows to load these packs but with disabling dummy item ranges that has missing graphics.
1 parent c8a99d5 commit a1da519

File tree

9 files changed

+161
-17
lines changed

9 files changed

+161
-17
lines changed

Editor/common_features/data_array.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ class PGE_DataArray
9898
m_total_elements = 0;
9999
}
100100

101+
/*!
102+
* \brief Shrink the store size to value, but don't reallocate the store itself!
103+
*/
104+
void shrinkTo(int number)
105+
{
106+
if(number == 0 || m_data == nullptr)
107+
return;
108+
109+
if(number > m_total_elements)
110+
return; // It's shrink! Not expand!
111+
112+
m_size = number + 1;
113+
m_total_elements = number;
114+
}
115+
101116
/**
102117
* @brief Allocate array of required size. Everything which was previously will be deleted
103118
* @param number Number of reuired element slots

Editor/data_configs/conf_wld_level.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
bool DataConfig::loadWorldLevel(obj_w_level &slevel, QString section, obj_w_level *merge_with, QString iniFile, IniProcessing *setup)
2727
{
28-
bool valid = true;
2928
bool internal = !setup;
3029
PGEString errStr;
30+
3131
if(internal)
3232
setup = new IniProcessing(iniFile);
3333

@@ -43,11 +43,15 @@ bool DataConfig::loadWorldLevel(obj_w_level &slevel, QString section, obj_w_leve
4343
addError(errStr);
4444
slevel.isValid = false;
4545
}
46+
4647
slevel.m_itemType = ItemTypes::WLD_Level;
48+
4749
closeSection(setup);
50+
4851
if(internal)
4952
delete setup;
50-
return valid;
53+
54+
return slevel.isValid;
5155
}
5256

5357
void DataConfig::loadWorldLevels()
@@ -56,6 +60,7 @@ void DataConfig::loadWorldLevels()
5660

5761
obj_w_level slevel;
5862
unsigned long levels_total = 0;
63+
unsigned long soft_limit = 0;
5964
bool useDirectory = false;
6065

6166
QString level_ini = getFullIniPath("wld_levels.ini");
@@ -70,13 +75,15 @@ void DataConfig::loadWorldLevels()
7075
if(!openSection(&setup, "levels-main"))
7176
return;
7277
{
73-
levels_total = setup.value("total", 0).toUInt();
74-
defaultGrid.levels = setup.value("grid", defaultGrid.levels).toUInt();
75-
marker_wlvl.path = setup.value("path", 0).toUInt();
76-
marker_wlvl.bigpath = setup.value("bigpath", 0).toUInt();
78+
setup.read("total", levels_total, 0);
79+
setup.read("soft-limit", soft_limit, 0);
80+
setup.read("grid", defaultGrid.levels, defaultGrid.levels);
81+
setup.read("path", marker_wlvl.path, 0);
82+
setup.read("bigpath", marker_wlvl.bigpath, 0);
7783
total_data += levels_total;
7884
setup.read("config-dir", folderWldLevelPoints.items, "");
7985
setup.read("extra-settings", folderWldLevelPoints.extraSettings, folderWldLevelPoints.items);
86+
8087
if(!folderWldLevelPoints.items.isEmpty())
8188
{
8289
folderWldLevelPoints.items = config_dir + folderWldLevelPoints.items;
@@ -127,6 +134,21 @@ void DataConfig::loadWorldLevels()
127134
slevel.setup.icon_n,
128135
slevel.icon);
129136
}
137+
else if(soft_limit > 0 && i > soft_limit)
138+
{
139+
// If resource after soft-limit is invalid, consider previous is the total number:
140+
--i;
141+
total_data -= levels_total;
142+
total_data += i;
143+
levels_total = i;
144+
ConfStatus::total_wlvl = signed(levels_total);
145+
main_wlevels.shrinkTo(i);
146+
// Remove last error
147+
errorsList[ERR_GLOBAL].pop_back();
148+
emit progressMax(int(i));
149+
break;
150+
}
151+
130152
/***************Load image*end***************/
131153
slevel.setup.id = i;
132154
main_wlevels.storeElement(int(i), slevel, valid);

Editor/data_configs/conf_wld_path.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
bool DataConfig::loadWorldPath(obj_w_path &spath, QString section, obj_w_path *merge_with, QString iniFile, IniProcessing *setup)
2727
{
28-
bool valid = true;
2928
bool internal = !setup;
3029
QString errStr;
3130
if(internal)
@@ -43,11 +42,13 @@ bool DataConfig::loadWorldPath(obj_w_path &spath, QString section, obj_w_path *m
4342
addError(errStr);
4443
spath.isValid = false;
4544
}
45+
4646
spath.m_itemType = ItemTypes::WLD_Path;
4747
closeSection(setup);
4848
if(internal)
4949
delete setup;
50-
return valid;
50+
51+
return spath.isValid;
5152
}
5253

5354
void DataConfig::loadWorldPaths()
@@ -56,6 +57,7 @@ void DataConfig::loadWorldPaths()
5657

5758
obj_w_path sPath;
5859
unsigned long path_total = 0;
60+
unsigned long soft_limit = 0;
5961
bool useDirectory = false;
6062

6163
QString scene_ini = getFullIniPath("wld_paths.ini");
@@ -72,6 +74,7 @@ void DataConfig::loadWorldPaths()
7274
return;
7375
{
7476
path_total = setup.value("total", 0).toUInt();
77+
setup.read("soft-limit", soft_limit, 0);
7578
defaultGrid.paths = setup.value("grid", defaultGrid.paths).toUInt();
7679
total_data += path_total;
7780
setup.read("config-dir", folderWldPaths.items, "");
@@ -107,6 +110,7 @@ void DataConfig::loadWorldPaths()
107110
valid = loadWorldPath(sPath, "path", nullptr, QString("%1/path-%2.ini").arg(folderWldPaths.items).arg(i));
108111
else
109112
valid = loadWorldPath(sPath, QString("path-%1").arg(i), 0, "", &setup);
113+
110114
/***************Load image*******************/
111115
if(valid)
112116
{
@@ -126,6 +130,21 @@ void DataConfig::loadWorldPaths()
126130
sPath.icon);
127131
}
128132
/***************Load image*end***************/
133+
else if(soft_limit > 0 && i > soft_limit)
134+
{
135+
// If resource after soft-limit is invalid, consider previous is the total number:
136+
--i;
137+
total_data -= path_total;
138+
total_data += i;
139+
path_total = i;
140+
ConfStatus::total_wpath = signed(path_total);
141+
main_wpaths.shrinkTo(i);
142+
// Remove last error
143+
errorsList[ERR_GLOBAL].pop_back();
144+
emit progressMax(int(i));
145+
break;
146+
}
147+
129148
sPath.setup.id = i;
130149
main_wpaths.storeElement(int(i), sPath, valid);
131150

Editor/data_configs/conf_wld_scene.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
bool DataConfig::loadWorldScene(obj_w_scenery &sScene, QString section, obj_w_scenery *merge_with, QString iniFile, IniProcessing *setup)
2727
{
28-
bool valid = true;
2928
bool internal = !setup;
3029
QString errStr;
3130
if(internal)
@@ -43,11 +42,13 @@ bool DataConfig::loadWorldScene(obj_w_scenery &sScene, QString section, obj_w_sc
4342
addError(errStr);
4443
sScene.isValid = false;
4544
}
45+
4646
sScene.m_itemType = ItemTypes::WLD_Scenery;
4747
closeSection(setup);
4848
if(internal)
4949
delete setup;
50-
return valid;
50+
51+
return sScene.isValid;
5152
}
5253

5354

@@ -57,6 +58,7 @@ void DataConfig::loadWorldScene()
5758

5859
obj_w_scenery sScene;
5960
unsigned long scenery_total = 0;
61+
unsigned long soft_limit = 0;
6062
bool useDirectory = false;
6163

6264
QString scene_ini = getFullIniPath("wld_scenery.ini");
@@ -72,6 +74,7 @@ void DataConfig::loadWorldScene()
7274
return;
7375
{
7476
setup.read("total", scenery_total, 0);
77+
setup.read("soft-limit", soft_limit, 0);
7578
setup.read("grid", defaultGrid.scenery, defaultGrid.scenery);
7679
total_data += scenery_total;
7780
setup.read("config-dir", folderWldScenery.items, "");
@@ -107,6 +110,7 @@ void DataConfig::loadWorldScene()
107110
valid = loadWorldScene(sScene, "scenery", nullptr, QString("%1/scenery-%2.ini").arg(folderWldScenery.items).arg(i));
108111
else
109112
valid = loadWorldScene(sScene, QString("scenery-%1").arg(i), 0, "", &setup);
113+
110114
/***************Load image*******************/
111115
if(valid)
112116
{
@@ -126,6 +130,21 @@ void DataConfig::loadWorldScene()
126130
sScene.icon);
127131
}
128132
/***************Load image*end***************/
133+
else if(soft_limit > 0 && i > soft_limit)
134+
{
135+
// If resource after soft-limit is invalid, consider previous is the total number:
136+
--i;
137+
total_data -= scenery_total;
138+
total_data += i;
139+
scenery_total = i;
140+
ConfStatus::total_wscene = signed(scenery_total);
141+
main_wscene.shrinkTo(i);
142+
// Remove last error
143+
errorsList[ERR_GLOBAL].pop_back();
144+
emit progressMax(int(i));
145+
break;
146+
}
147+
129148
sScene.setup.id = i;
130149
main_wscene.storeElement(int(i), sScene, valid);
131150

Editor/data_configs/conf_wld_tile.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
bool DataConfig::loadWorldTerrain(obj_w_tile &stile, QString section, obj_w_tile *merge_with, QString iniFile, IniProcessing *setup)
2727
{
28-
bool valid = true;
2928
bool internal = !setup;
3029
QString errStr;
3130
if(internal)
@@ -43,11 +42,13 @@ bool DataConfig::loadWorldTerrain(obj_w_tile &stile, QString section, obj_w_tile
4342
addError(errStr);
4443
stile.isValid = false;
4544
}
45+
4646
stile.m_itemType = ItemTypes::WLD_Tile;
4747
closeSection(setup);
4848
if(internal)
4949
delete setup;
50-
return valid;
50+
51+
return stile.isValid;
5152
}
5253

5354
void DataConfig::loadWorldTiles()
@@ -56,6 +57,7 @@ void DataConfig::loadWorldTiles()
5657

5758
obj_w_tile stile;
5859
unsigned long tiles_total = 0;
60+
unsigned long soft_limit = 0;
5961
bool useDirectory = false;
6062

6163
QString tile_ini = getFullIniPath("wld_tiles.ini");
@@ -71,6 +73,7 @@ void DataConfig::loadWorldTiles()
7173
return;
7274
{
7375
setup.read("total", tiles_total, 0);
76+
setup.read("soft-limit", soft_limit, 0);
7477
setup.read("grid", defaultGrid.terrain, defaultGrid.terrain);
7578
total_data += tiles_total;
7679
setup.read("config-dir", folderWldTerrain.items, "");
@@ -125,6 +128,21 @@ void DataConfig::loadWorldTiles()
125128
stile.icon);
126129
}
127130
/***************Load image*end***************/
131+
else if(soft_limit > 0 && i > soft_limit)
132+
{
133+
// If resource after soft-limit is invalid, consider previous is the total number:
134+
--i;
135+
total_data -= tiles_total;
136+
total_data += i;
137+
tiles_total = i;
138+
ConfStatus::total_wtile = signed(tiles_total);
139+
main_wtiles.shrinkTo(i);
140+
// Remove last error
141+
errorsList[ERR_GLOBAL].pop_back();
142+
emit progressMax(int(i));
143+
break;
144+
}
145+
128146
stile.setup.id = i;
129147
main_wtiles.storeElement(int(i), stile, valid);
130148

Editor/data_configs/obj_bgo.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void obj_bgo::copyTo(obj_bgo &bgo)
5151
*/
5252
bool DataConfig::loadLevelBGO(obj_bgo &sbgo, QString section, obj_bgo *merge_with, QString iniFile, IniProcessing *setup)
5353
{
54-
bool valid = true;
5554
bool internal = !setup;
5655
QString errStr;
5756
if(internal)
@@ -73,7 +72,8 @@ bool DataConfig::loadLevelBGO(obj_bgo &sbgo, QString section, obj_bgo *merge_wit
7372
closeSection(setup);
7473
if(internal)
7574
delete setup;
76-
return valid;
75+
76+
return sbgo.isValid;
7777
}
7878

7979

@@ -83,6 +83,7 @@ void DataConfig::loadLevelBGO()
8383

8484
obj_bgo sbgo;
8585
unsigned long bgo_total = 0;
86+
unsigned long soft_limit = 0;
8687
bool useDirectory = false;
8788

8889
QString bgo_ini = getFullIniPath("lvl_bgo.ini");
@@ -98,6 +99,7 @@ void DataConfig::loadLevelBGO()
9899
return;
99100
{
100101
setup.read("total", bgo_total, 0);
102+
setup.read("soft-limit", soft_limit, 0);
101103
setup.read("grid", defaultGrid.bgo, defaultGrid.bgo);
102104
total_data += bgo_total;
103105
setup.read("config-dir", folderLvlBgo.items, "");
@@ -155,6 +157,21 @@ void DataConfig::loadLevelBGO()
155157
sbgo.icon);
156158
}
157159
/***************Load image*end***************/
160+
else if(soft_limit > 0 && i > soft_limit)
161+
{
162+
// If resource after soft-limit is invalid, consider previous is the total number:
163+
--i;
164+
total_data -= bgo_total;
165+
total_data += i;
166+
bgo_total = i;
167+
ConfStatus::total_bgo = signed(bgo_total);
168+
main_bgo.shrinkTo(i);
169+
// Remove last error
170+
errorsList[ERR_GLOBAL].pop_back();
171+
emit progressMax(int(i));
172+
break;
173+
}
174+
158175
sbgo.setup.id = i;
159176
main_bgo.storeElement(static_cast<int>(i), sbgo, valid);
160177

0 commit comments

Comments
 (0)