Skip to content

Commit eb34111

Browse files
committed
fallbacks for chipsets and panoramas
1 parent f14b673 commit eb34111

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lmu2png/src/main.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ std::string GetFileDirectory (const std::string& file) {
5151
}
5252

5353
bool Exists(const std::string& filename) {
54-
std::ifstream infile(filename.c_str());
54+
std::ifstream infile(filename.c_str());
5555
return infile.good();
5656
}
57-
5857
std::string path;
5958

6059
std::string FindResource(const std::string& folder, const std::string& base_name) {
@@ -154,19 +153,31 @@ void DrawEvents(SDL_Surface* output_img, stChipset * gen, std::unique_ptr<lcf::r
154153
}
155154

156155
void RenderCore(SDL_Surface* output_img, std::string chipset, uint8_t * csflag, std::unique_ptr<lcf::rpg::Map> & map, int show_background, int show_lowertiles, int show_uppertiles, int show_events) {
157-
SDL_Surface* chipset_img = LoadImage(chipset.c_str(), true);
156+
SDL_Surface* chipset_img;
157+
if (!chipset.empty()) {
158+
chipset_img = LoadImage(chipset.c_str(), true);
159+
} else {
160+
chipset_img = SDL_CreateRGBSurfaceWithFormat(0, 32 * 16, 45 * 16, 32, SDL_PIXELFORMAT_RGBA32);
161+
}
158162

159163
stChipset gen;
160164
gen.GenerateFromSurface(chipset_img);
161165

162166
// Draw parallax background
163-
if (show_background && !map->parallax_name.empty()) {
167+
if (show_background) {
168+
164169
std::string pname = lcf::ToString(map->parallax_name);
165170
std::string background(FindResource("Panorama", pname));
166-
if (background.empty()) {
171+
if (background.empty() && !map->parallax_name.empty()) {
167172
std::cout << "Can't find parallax background " << map->parallax_name << std::endl;
168173
} else {
169-
SDL_Surface* background_img(LoadImage(background.c_str()));
174+
SDL_Surface* background_img;
175+
if (map->parallax_name.empty()) {
176+
background_img = SDL_CreateRGBSurface(0, 1, 1, 24, 0, 0, 0, 0);
177+
SDL_FillRect(background_img, 0, 0);
178+
} else {
179+
background_img = (LoadImage(background.c_str()));
180+
}
170181
SDL_Rect dst_rect = background_img->clip_rect;
171182
// Fill screen with copies of the background
172183
for (dst_rect.x = 0; dst_rect.x < output_img->w; dst_rect.x += background_img->w) {
@@ -284,7 +295,7 @@ int main(int argc, char** argv) {
284295
std::string chipset_base(cs.chipset_name);
285296

286297
chipset = FindResource("ChipSet", chipset_base);
287-
if (chipset.empty()) {
298+
if (chipset.empty() && !chipset_base.empty()) {
288299
std::cout << "Chipset " << chipset_base << " can't be found." << std::endl;
289300
exit(EXIT_FAILURE);
290301
}

0 commit comments

Comments
 (0)