skip reading some things for file picker previews

This commit is contained in:
2025-03-14 14:13:15 -05:00
committed by Celtic Minstrel
parent 2053381ea9
commit ea8dbbc06c

View File

@@ -363,6 +363,18 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ, bool preview){
}
}
if(partyIn.hasFile("save/export.png")) {
std::istream& fin = partyIn.getFile("save/export.png");
sf::Image party_sheet;
StdInputStream stream(fin);
if(party_sheet.loadFromStream(stream)) {
sf::Texture sheet;
sheet.create(party_sheet.getSize().x, party_sheet.getSize().y);
sheet.update(party_sheet);
spec_scen_g.party_sheet.reset(new sf::Texture(sheet));
} else if(!preview) showWarning("There was an error loading the party custom graphics.");
}
if(!univ.party.scen_name.empty()) {
fs::path path = locate_scenario(univ.party.scen_name);
if(path.empty()) {
@@ -389,10 +401,19 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ, bool preview){
univ.scenario.readFrom(file);
}
// We have all we need for the file picker preview.
if(preview){
univ.file = file_to_load;
real_univ = std::move(univ);
return true;
}
// Below here, if(!preview) does not need to be checked before showing errors and warnings.
{ // Then the "setup" array
std::istream& fin = partyIn.getFile("save/setup.dat");
if(!fin) {
if(!preview) showError("Loading Blades of Exile save file failed.");
showError("Loading Blades of Exile save file failed.");
return false;
}
file.readFrom(fin);
@@ -401,12 +422,12 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ, bool preview){
page[std::to_string(i)].extract(univ.party.setup[i]);
}
}
if(partyIn.hasFile("save/town.txt")) {
// Load town data
std::istream& fin = partyIn.getFile("save/town.txt");
if(!fin) {
if(!preview) showError("Loading Blades of Exile save file failed.");
showError("Loading Blades of Exile save file failed.");
return false;
}
file.readFrom(fin);
@@ -425,11 +446,11 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ, bool preview){
// Load outdoors data
std::istream& fin = partyIn.getFile("save/out.txt");
if(!fin) {
if(!preview) showError("Loading Blades of Exile save file failed.");
showError("Loading Blades of Exile save file failed.");
return false;
}
univ.out.readFrom(fin);
// Read outdoor maps
std::istream& fin2 = partyIn.getFile("save/outmaps.dat");
for(int i = 0; i < univ.scenario.outdoors.height(); i++) {
@@ -439,18 +460,6 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ, bool preview){
}
}
}
} else univ.party.scen_name = "";
if(partyIn.hasFile("save/export.png")) {
std::istream& fin = partyIn.getFile("save/export.png");
sf::Image party_sheet;
StdInputStream stream(fin);
if(party_sheet.loadFromStream(stream)) {
sf::Texture sheet;
sheet.create(party_sheet.getSize().x, party_sheet.getSize().y);
sheet.update(party_sheet);
spec_scen_g.party_sheet.reset(new sf::Texture(sheet));
} else showWarning("There was an error loading the party custom graphics.");
}
univ.file = file_to_load;