| 112 | } |
| 113 | |
| 114 | List<ObjectOrientationPtr> ObjectDatabase::parseOrientations(String const& path, Json const& configList) { |
| 115 | auto& root = Root::singleton(); |
| 116 | auto materialDatabase = root.materialDatabase(); |
| 117 | List<ObjectOrientationPtr> res; |
| 118 | JsonArray configs = configList.toArray(); |
| 119 | |
| 120 | // Preprocess the orientation list for config format backwards compatibility. |
| 121 | // If dualImage or left/right Image is set, generate two identical |
| 122 | // orientations with the appropriate image directives. |
| 123 | auto it = makeSMutableIterator(configs); |
| 124 | while (it.hasNext()) { |
| 125 | JsonObject config = it.next().toObject(); |
| 126 | if (config.contains("dualImage")) { |
| 127 | it.remove(); |
| 128 | |
| 129 | JsonObject configLeft = config; |
| 130 | configLeft["image"] = config["dualImage"]; |
| 131 | configLeft["flipImages"] = true; |
| 132 | configLeft["direction"] = "left"; |
| 133 | it.insert(configLeft); |
| 134 | |
| 135 | JsonObject configRight = config; |
| 136 | configRight["image"] = config["dualImage"]; |
| 137 | configRight["direction"] = "right"; |
| 138 | it.insert(configRight); |
| 139 | |
| 140 | } else if (config.contains("leftImage")) { |
| 141 | it.remove(); |
| 142 | |
| 143 | JsonObject configLeft = config; |
| 144 | configLeft["image"] = config["leftImage"]; |
| 145 | configLeft["direction"] = "left"; |
| 146 | it.insert(configLeft); |
| 147 | |
| 148 | JsonObject configRight = config; |
| 149 | configRight["image"] = config["rightImage"]; |
| 150 | configRight["direction"] = "right"; |
| 151 | it.insert(configRight); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | for (auto const& orientationSettings : configs) { |
| 156 | auto orientation = make_shared<ObjectOrientation>(); |
| 157 | orientation->config = orientationSettings; |
| 158 | |
| 159 | if (orientationSettings.contains("imageLayers")) { |
| 160 | for (Json layer : orientationSettings.get("imageLayers").iterateArray()) { |
| 161 | if (auto image = layer.opt("image")) |
| 162 | layer = layer.set("image", AssetPath::relativeTo(path, image->toString())); |
| 163 | Drawable drawable(layer.set("centered", layer.getBool("centered", false))); |
| 164 | drawable.scale(1.0f / TilePixels); |
| 165 | orientation->imageLayers.append(drawable); |
| 166 | } |
| 167 | } else { |
| 168 | Drawable drawable = Drawable::makeImage( |
| 169 | AssetPath::relativeTo(path, orientationSettings.getString("image")), 1.0 / TilePixels, false, {}); |
| 170 | drawable.fullbright = orientationSettings.getBool("fullbright", false); |
| 171 | orientation->imageLayers.append(drawable); |
nothing calls this directly
no test coverage detected