| 104 | } |
| 105 | |
| 106 | Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects) |
| 107 | { |
| 108 | ObjectId id = read32(is); |
| 109 | std::string name = read_string(is); |
| 110 | uint32_t flags = read32(is); // Flags |
| 111 | uint16_t layer_type = read16(is); // Type |
| 112 | std::unique_ptr<Layer> layer; |
| 113 | |
| 114 | switch (static_cast<ObjectType>(layer_type)) { |
| 115 | |
| 116 | case ObjectType::LayerImage: { |
| 117 | LayerImage* imgLayer = new LayerImage(subObjects->sprite()); |
| 118 | |
| 119 | // Create layer |
| 120 | layer.reset(imgLayer); |
| 121 | |
| 122 | // Blend mode & opacity |
| 123 | imgLayer->setBlendMode((BlendMode)read16(is)); |
| 124 | imgLayer->setOpacity(read8(is)); |
| 125 | |
| 126 | // Read images |
| 127 | int images = read16(is); // Number of images |
| 128 | for (int c=0; c<images; ++c) { |
| 129 | ImageRef image(read_image(is)); |
| 130 | subObjects->addImageRef(image); |
| 131 | } |
| 132 | |
| 133 | // Read celdatas |
| 134 | int celdatas = read16(is); |
| 135 | for (int c=0; c<celdatas; ++c) { |
| 136 | CelDataRef celdata(read_celdata(is, subObjects)); |
| 137 | subObjects->addCelDataRef(celdata); |
| 138 | } |
| 139 | |
| 140 | // Read cels |
| 141 | int cels = read16(is); // Number of cels |
| 142 | for (int c=0; c<cels; ++c) { |
| 143 | // Read the cel |
| 144 | auto cel = std::shared_ptr<Cel>(read_cel(is, subObjects)); |
| 145 | |
| 146 | // Add the cel in the layer |
| 147 | imgLayer->addCel(cel); |
| 148 | } |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | case ObjectType::LayerFolder: { |
| 153 | // Create the layer set |
| 154 | layer.reset(new LayerFolder(subObjects->sprite())); |
| 155 | |
| 156 | // Number of sub-layers |
| 157 | int layers = read16(is); |
| 158 | for (int c=0; c<layers; c++) { |
| 159 | Layer* child = read_layer(is, subObjects); |
| 160 | if (child) |
| 161 | static_cast<LayerFolder*>(layer.get())->addLayer(child); |
| 162 | else |
| 163 | break; |
no test coverage detected