| 17 | } |
| 18 | |
| 19 | void BackgroundImage::loadFromConfig(const filesystem::path &filepath) { |
| 20 | |
| 21 | configFilepath = filepath; // save filepath for latter use with writeToConfig |
| 22 | |
| 23 | if (!filesystem::exists(filepath)) { // Config file doesn't exist, do not attempt to read or write it and load images |
| 24 | SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Board configuration file %s does not exist", filepath.generic_string().c_str()); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading background image settings from board configuration file: %s", filepath.generic_string().c_str()); |
| 29 | |
| 30 | auto configDir = filesystem::weakly_canonical(filepath).parent_path(); |
| 31 | |
| 32 | Confparse confparse{}; |
| 33 | confparse.Load(filepath); |
| 34 | |
| 35 | std::string topImageFilename{confparse.ParseStr("TopImageFile", "")}; |
| 36 | topImage = Image{topImageFilename.empty() ? filesystem::path{} : configDir/filesystem::u8path(topImageFilename)}; |
| 37 | topImage.offsetX = confparse.ParseInt("TopImageOffsetX", 0); |
| 38 | topImage.offsetY = confparse.ParseInt("TopImageOffsetY", 0); |
| 39 | topImage.scalingX = confparse.ParseDouble("TopImageScalingX", 1.0); |
| 40 | topImage.scalingY = confparse.ParseDouble("TopImageScalingY", 1.0); |
| 41 | topImage.mirrorX = confparse.ParseBool("TopImageMirrorX", false); |
| 42 | topImage.mirrorY = confparse.ParseBool("TopImageMirrorY", false); |
| 43 | topImage.transparency = confparse.ParseDouble("TopImageTransparency", 0.0); |
| 44 | |
| 45 | std::string bottomImageFilename{confparse.ParseStr("BottomImageFile", "")}; |
| 46 | bottomImage = Image{bottomImageFilename.empty() ? filesystem::path{} : configDir/filesystem::u8path(bottomImageFilename)}; |
| 47 | bottomImage.offsetX = confparse.ParseInt("BottomImageOffsetX", 0); |
| 48 | bottomImage.offsetY = confparse.ParseInt("BottomImageOffsetY", 0); |
| 49 | bottomImage.scalingX = confparse.ParseDouble("BottomImageScalingX", 1.0); |
| 50 | bottomImage.scalingY = confparse.ParseDouble("BottomImageScalingY", 1.0); |
| 51 | bottomImage.mirrorX = confparse.ParseBool("BottomImageMirrorX", false); |
| 52 | bottomImage.mirrorY = confparse.ParseBool("BottomImageMirrorY", false); |
| 53 | bottomImage.transparency = confparse.ParseDouble("BottomImageTransparency", 0.0); |
| 54 | |
| 55 | writeToConfig(filepath); |
| 56 | reload(); |
| 57 | } |
| 58 | |
| 59 | void BackgroundImage::writeToConfig(const filesystem::path &filepath) { |
| 60 | if (filepath.empty()) // No destination file to save to |
nothing calls this directly
no test coverage detected