Skip to content

Commit

Permalink
ProjectLoader: Clear sprites before loading project
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Sep 25, 2024
1 parent 8bef51b commit 594b90d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/projectloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ void ProjectLoader::callLoad(ProjectLoader *loader)
void ProjectLoader::load()
{
m_unpositionedMonitors.clear();
m_sprites.clear();
m_clones.clear();
emit spritesChanged();
emit clonesChanged();

m_loadStatus = m_project.load();
m_engineMutex.lock();
m_engine = m_project.engine().get();
Expand All @@ -262,6 +267,7 @@ void ProjectLoader::load()
emit loadingFinished();
emit engineChanged();
emit spritesChanged();
emit clonesChanged();
return;
}

Expand Down Expand Up @@ -308,6 +314,7 @@ void ProjectLoader::load()
emit loadingFinished();
emit engineChanged();
emit spritesChanged();
emit clonesChanged();
return;
}

Expand All @@ -327,6 +334,7 @@ void ProjectLoader::load()
emit engineChanged();
emit stageChanged();
emit spritesChanged();
emit clonesChanged();
}

void ProjectLoader::initTimer()
Expand Down
10 changes: 5 additions & 5 deletions test/projectloader/projectloader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class ProjectLoaderTest : public testing::Test
ASSERT_EQ(loadingFinishedSpy.count(), 1);
ASSERT_EQ(engineSpy.count(), 2);
ASSERT_EQ(stageSpy.count(), 1);
ASSERT_EQ(spritesSpy.count(), 2);
ASSERT_EQ(clonesSpy.count(), 1);
ASSERT_EQ(spritesSpy.count(), 3);
ASSERT_EQ(clonesSpy.count(), 3);
ASSERT_EQ(monitorsSpy.count(), loader->monitorList().size() + 1);
ASSERT_EQ(monitorAddedSpy.count(), loader->monitorList().size());
ASSERT_EQ(unsupportedBlocksSpy.count(), 1);
Expand Down Expand Up @@ -137,13 +137,13 @@ TEST_F(ProjectLoaderTest, Clones)
load(&loader, "clones.sb3");
ASSERT_TRUE(cloneCreatedSpy.empty());
ASSERT_TRUE(cloneDeletedSpy.empty());
ASSERT_EQ(clonesChangedSpy.count(), 1);
ASSERT_EQ(clonesChangedSpy.count(), 3);

auto engine = loader.engine();
engine->run();
ASSERT_EQ(cloneCreatedSpy.count(), 3);
ASSERT_EQ(cloneDeletedSpy.count(), 0);
ASSERT_EQ(clonesChangedSpy.count(), 4);
ASSERT_EQ(clonesChangedSpy.count(), 6);

const auto &sprites = loader.spriteList();
const auto &clones = loader.cloneList();
Expand All @@ -162,7 +162,7 @@ TEST_F(ProjectLoaderTest, Clones)
clones[1]->sprite()->deleteClone();
ASSERT_EQ(cloneCreatedSpy.count(), 3);
ASSERT_EQ(cloneDeletedSpy.count(), 1);
ASSERT_EQ(clonesChangedSpy.count(), 5);
ASSERT_EQ(clonesChangedSpy.count(), 7);
ASSERT_EQ(clones.size(), 2);
}

Expand Down

0 comments on commit 594b90d

Please sign in to comment.