@@ -193,35 +193,25 @@ void Target::setCurrentCostume(int newCostume)
193193}
194194
195195/* ! Returns the list of costumes. */
196- const std::vector<Costume> &Target::costumes () const
196+ const std::vector<std::shared_ptr< Costume> > &Target::costumes () const
197197{
198198 return impl->costumes ;
199199}
200200
201201/* ! Adds a costume and returns its index. */
202- int Target::addCostume (const Costume & costume)
202+ int Target::addCostume (std::shared_ptr< Costume> costume)
203203{
204- // TODO: Use shared_ptr for assets
205- /* auto it = std::find(impl->costumes.begin(), impl->costumes.end(), costume);
204+ auto it = std::find (impl->costumes .begin (), impl->costumes .end (), costume);
206205
207- if (it != impl->blocks.end())
208- return it - impl->blocks.begin();*/
209-
210- int i = 0 ;
211-
212- for (const auto &c : impl->costumes ) {
213- if (c.name () == costume.name ())
214- return i;
215-
216- i++;
217- }
206+ if (it != impl->costumes .end ())
207+ return it - impl->costumes .begin ();
218208
219209 impl->costumes .push_back (costume);
220210 return impl->costumes .size () - 1 ;
221211}
222212
223213/* ! Returns the costume at index. */
224- const libscratchcpp:: Costume & Target::costumeAt (int index) const
214+ std::shared_ptr< Costume> Target::costumeAt (int index) const
225215{
226216 // TODO: Add range check
227217 return impl->costumes [index];
@@ -232,42 +222,33 @@ int Target::findCostume(const std::string &costumeName) const
232222{
233223 int i = 0 ;
234224 for (auto costume : impl->costumes ) {
235- if (costume. name () == costumeName)
225+ if (costume-> name () == costumeName)
236226 return i;
237227 i++;
238228 }
239229 return -1 ;
240230}
241231
242232/* ! Returns the list of sounds. */
243- const std::vector<Sound> &Target::sounds () const
233+ const std::vector<std::shared_ptr< Sound> > &Target::sounds () const
244234{
245235 return impl->sounds ;
246236}
247237
248238/* ! Adds a sound and returns its index. */
249- int Target::addSound (const Sound & sound)
239+ int Target::addSound (std::shared_ptr< Sound> sound)
250240{
251- // TODO: Use shared_ptr for assets
252- /* auto it = std::find(impl->sounds.begin(), impl->sounds.end(), sound);
241+ auto it = std::find (impl->sounds .begin (), impl->sounds .end (), sound);
253242
254243 if (it != impl->sounds .end ())
255- return it - impl->sounds.begin();*/
256-
257- int i = 0 ;
244+ return it - impl->sounds .begin ();
258245
259- for (const auto &s : impl->sounds ) {
260- if (s.name () == sound.name ())
261- return i;
262-
263- i++;
264- }
265246 impl->sounds .push_back (sound);
266247 return impl->sounds .size () - 1 ;
267248}
268249
269250/* ! Returns the sound at index. */
270- const libscratchcpp:: Sound & Target::soundAt (int index) const
251+ std::shared_ptr< Sound> Target::soundAt (int index) const
271252{
272253 // TODO: Add range check
273254 return impl->sounds [index];
@@ -278,7 +259,7 @@ int Target::findSound(const std::string &soundName) const
278259{
279260 int i = 0 ;
280261 for (auto sound : impl->sounds ) {
281- if (sound. name () == soundName)
262+ if (sound-> name () == soundName)
282263 return i;
283264 i++;
284265 }
0 commit comments