1// Aseprite Document Library
2// Copyright (c) 2001-2015 David Capello
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "doc/subobjects_io.h"
12
13#include "doc/cel.h"
14#include "doc/cel_io.h"
15#include "doc/image.h"
16#include "doc/image_io.h"
17#include "doc/layer.h"
18#include "doc/layer_io.h"
19#include "doc/sprite.h"
20
21namespace doc {
22
23using namespace doc;
24
25SubObjectsFromSprite::SubObjectsFromSprite(Sprite* sprite)
26 : m_sprite(sprite)
27{
28}
29
30void SubObjectsFromSprite::addImageRef(const ImageRef& image)
31{
32 ASSERT(image);
33 ASSERT(!getImageRef(image->id()));
34 m_images.insert(std::make_pair(image->id(), image));
35}
36
37ImageRef SubObjectsFromSprite::getImageRef(ObjectId imageId)
38{
39 auto it = m_images.find(imageId);
40 if (it != m_images.end()) {
41 ImageRef image = it->second;
42 ASSERT(image->id() == imageId);
43 ASSERT(!m_sprite->getImageRef(imageId));
44 return image;
45 }
46 else
47 return m_sprite->getImageRef(imageId);
48}
49
50void SubObjectsFromSprite::addCelDataRef(const CelDataRef& celdata)
51{
52 ASSERT(celdata);
53 ASSERT(!getCelDataRef(celdata->id()));
54 m_celdatas.insert(std::make_pair(celdata->id(), celdata));
55}
56
57CelDataRef SubObjectsFromSprite::getCelDataRef(ObjectId celdataId)
58{
59 auto it = m_celdatas.find(celdataId);
60 if (it != m_celdatas.end()) {
61 CelDataRef celdata = it->second;
62 ASSERT(celdata->id() == celdataId);
63 ASSERT(!m_sprite->getCelDataRef(celdataId));
64 return celdata;
65 }
66 else
67 return m_sprite->getCelDataRef(celdataId);
68}
69
70} // namespace doc
71