Commit eef8abad authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Merge remote-tracking branch 'origin/release/21.04'

parents 05069aab e5cfcbdb
Pipeline #69488 passed with stage
in 2 minutes and 4 seconds
......@@ -22,11 +22,117 @@ class testKBlocksItemGroup : public QObject
{
Q_OBJECT
private slots:
void refreshPositionShouldSetCorrectPositions();
void refreshPositionShouldClearCache();
void updateGameShouldProcessGameActionsOnGameOver();
void updateGameShouldRefreshItemsOnGameOver();
void stopGameShouldProcessRemainingGameActions();
};
void testKBlocksItemGroup::refreshPositionShouldSetCorrectPositions()
{
/**
* When refreshPosition is called, the positions of the SVG items
* in the prepare area and the playing field are updated. The new
* positions are determined from the (possibly updated) layout.
*/
MockSingleGame singleGame;
MockGraphics graphics;
graphics.m_PreviewArea_CenterPoint_X = 1;
graphics.m_PreviewArea_CenterPoint_Y = 1;
graphics.m_Block_Size = 1;
graphics.m_PlayArea_NumberOfBlocks_X = 2;
graphics.m_PlayArea_NumberOfBlocks_Y = 2;
graphics.m_PlayArea_OffsetPoint_X = 1;
graphics.m_PlayArea_OffsetPoint_Y = 1;
MockSound sound;
TestingKBlocksItemGroup itemGroup(0, &singleGame, &graphics, &sound);
graphics.m_PreviewArea_CenterPoint_X = 30;
graphics.m_PreviewArea_CenterPoint_Y = 50;
graphics.m_Block_Size = 12;
graphics.m_PlayArea_OffsetPoint_X = 10;
graphics.m_PlayArea_OffsetPoint_Y = 15;
itemGroup.refreshPosition();
std::vector<QPointF> expectedPreparePositions{
{ 0, 20},
{12, 20},
{24, 20},
{36, 20},
{48, 20},
{ 0, 32},
{12, 32},
{24, 32},
{36, 32}
};
for (size_t i = 0; i < expectedPreparePositions.size(); ++i) {
auto *prepareCell = itemGroup.getPrepareCell(i);
QVERIFY(prepareCell != nullptr);
QCOMPARE(prepareCell->pos(), expectedPreparePositions.at(i));
}
std::vector<QPointF> expectedFreezePositions{
{10, 15},
{22, 15},
{10, 27},
{22, 27}
};
for (size_t i = 0; i < expectedFreezePositions.size(); ++i) {
auto *freezeCell = itemGroup.getFreezeCell(i);
QVERIFY(freezeCell != nullptr);
QCOMPARE(freezeCell->pos(), expectedFreezePositions.at(i));
}
}
void testKBlocksItemGroup::refreshPositionShouldClearCache()
{
/**
* The positions are refreshed when the layout changes. Then, also
* the cache should be cleared to ensure that the graphics for each
* item is updated.
*
* See bug 380474
*/
MockSingleGame singleGame;
MockGraphics graphics;
MockSound sound;
TestingKBlocksItemGroup itemGroup(0, &singleGame, &graphics, &sound);
itemGroup.replacePrepareCell(0, new MockSvgItem());
itemGroup.replaceFreezeCell(0, new MockSvgItem());
auto *prepareCellBefore = dynamic_cast<MockSvgItem*>(
itemGroup.getPrepareCell(0)
);
QVERIFY(prepareCellBefore != nullptr);
QCOMPARE(prepareCellBefore->clearCacheCalled, false);
auto *freezeCellBefore = dynamic_cast<MockSvgItem*>(
itemGroup.getFreezeCell(0)
);
QVERIFY(freezeCellBefore != nullptr);
QCOMPARE(freezeCellBefore->clearCacheCalled, false);
itemGroup.refreshPosition();
auto *prepareCellAfter = dynamic_cast<MockSvgItem*>(
itemGroup.getPrepareCell(0)
);
QVERIFY(prepareCellAfter != nullptr);
QCOMPARE(prepareCellAfter->clearCacheCalled, true);
auto *freezeCellAfter = dynamic_cast<MockSvgItem*>(
itemGroup.getFreezeCell(0)
);
QVERIFY(freezeCellAfter != nullptr);
QCOMPARE(freezeCellAfter->clearCacheCalled, true);
}
void testKBlocksItemGroup::updateGameShouldProcessGameActionsOnGameOver()
{
/**
......@@ -65,7 +171,7 @@ void testKBlocksItemGroup::updateGameShouldRefreshItemsOnGameOver()
TestingKBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
MockSvgItem *svgItem = new MockSvgItem();
itemGroup.replaceFreezeCells(svgItem);
itemGroup.replaceFreezeCell(0, svgItem);
itemGroup.callUpdateGame();
......
---
name: kblocks
version: 20.08.0
confinement: strict
grade: stable
base: core18
adopt-info: kblocks
apps:
kblocks:
common-id: org.kde.kblocks.desktop
command: kf5-launch kblocks
plugs:
- kde-frameworks-5-plug
- home
- x11
- opengl
- desktop
- network
- network-bind
- unity7
- pulseaudio
- desktop-legacy
- removable-media
slots:
session-dbus-interface:
interface: dbus
name: org.kde.kblocks
bus: session
plugs:
kde-frameworks-5-plug:
content: kde-frameworks-5-qt-5-14-core18-all
interface: content
default-provider: kde-frameworks-5-qt-5-14-core18
target: kf5
parts:
kdegames:
plugin: cmake
source: https://download.kde.org/stable/release-service/20.08.0/src/libkdegames-20.08.0.tar.xz
build-packages:
- build-essential
- libopenal-dev
- libsndfile1-dev
configflags:
- "-DKDE_INSTALL_USE_QT_SYS_PATHS=ON"
- "-DCMAKE_INSTALL_PREFIX=/usr"
- "-DCMAKE_BUILD_TYPE=Release"
- "-DENABLE_TESTING=OFF"
- "-DBUILD_TESTING=OFF"
- "-DKDE_SKIP_TEST_SETTINGS=ON"
- "-DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-14-core18-sdk/current"
#kdoctools5:
# plugin: dump
# source: https://archive.neon.kde.org/user/pool/main/k/kdoctools/kdoctools5_5.73.0-0xneon+20.04+focal+build4_amd64.deb
#libkf5doctools-dev:
# plugin: dump
# source: https://archive.neon.kde.org/user/pool/main/k/kdoctools/libkf5doctools-dev_5.73.0-0xneon+20.04+focal+build4_amd64.deb
kblocks:
parse-info:
- usr/share/metainfo/org.kde.kblocks.appdata.xml
build-snaps:
- kde-frameworks-5-qt-5-14-core18-sdk
after:
- kdegames
#- kdoctools5
#- libkf5doctools-dev
- kde-frameworks-5-env
override-build: |
echo 'deb http://archive.neon.kde.org/user bionic main' >> /etc/apt/sources.list
wget 'https://archive.neon.kde.org/public.key' -O ppa-key
apt-key add ppa-key
rm -f /etc/apt/apt.conf.d/proxy
apt update
apt-get -y install libkf5doctools-dev
snapcraftctl build
plugin: cmake
source: http://download.kde.org/stable/release-service/20.08.0/src/kblocks-20.08.0.tar.xz
configflags:
- "-DKDE_INSTALL_USE_QT_SYS_PATHS=ON"
- "-DCMAKE_INSTALL_PREFIX=/usr"
- "-DCMAKE_BUILD_TYPE=Release"
- "-DENABLE_TESTING=OFF"
- "-DBUILD_TESTING=OFF"
- "-DKDE_SKIP_TEST_SETTINGS=ON"
- "-DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-14-core18-sdk/current"
kde-frameworks-5-env:
plugin: dump
source: https://anongit.kde.org/snap-kf5-launcher.git
......@@ -33,7 +33,7 @@ KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, Graphics
addToGroup(mpBackground);
mMaxPrepareCellNum = PREPARE_AREA_WIDTH * PREPARE_AREA_WIDTH;
maPrepareCells = new KBlocksSvgItem*[mMaxPrepareCellNum];
maPrepareCells = new SvgItemInterface*[mMaxPrepareCellNum];
for (int i = 0; i < mMaxPrepareCellNum; i++) {
maPrepareCells[i] = new KBlocksSvgItem(mpGameLayout, KBlocksSvgItem_PrepareArea,
i % PREPARE_AREA_WIDTH, i / PREPARE_AREA_WIDTH);
......@@ -121,11 +121,13 @@ void KBlocksItemGroup::refreshPosition()
for (int i = 0; i < mMaxPrepareCellNum; i++) {
maPrepareCells[i]->setPos(mPrepareLeft + mItemSize * (i % PREPARE_AREA_WIDTH),
mPrepareTop + mItemSize * (i / PREPARE_AREA_WIDTH));
maPrepareCells[i]->clearCache();
}
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i]->setPos(mFieldLeft + mItemSize * (i % mFieldWidth),
mFieldTop + mItemSize * (i / mFieldWidth));
maFreezeCells[i]->clearCache();
}
}
......
......@@ -74,14 +74,14 @@ protected:
int mMaxFreezeCellNum;
SvgItemInterface **maFreezeCells;
int mMaxPrepareCellNum;
SvgItemInterface **maPrepareCells;
private:
int mGroupID;
KBlocksSvgItem *mpBackground;
int mMaxPrepareCellNum;
KBlocksSvgItem **maPrepareCells;
SingleGameInterface *mpSingleGame;
KBlocksLayout *mpGameLayout = nullptr;
GraphicsInterface *mpGrafx = nullptr;
......
......@@ -59,6 +59,13 @@ bool KBlocksSvgItem::updateSelf()
return true;
}
void KBlocksSvgItem::clearCache()
{
setCacheMode(NoCache);
setCacheMode(DeviceCoordinateCache);
}
void KBlocksSvgItem::startOpAnim()
{
setElementId(QStringLiteral("BLOCK_OUT_%1").arg(mColor));
......
......@@ -35,6 +35,7 @@ public:
void setLayoutPos(int posX, int posY);
bool updateSelf() override;
void clearCache() override;
void startOpAnim() override;
void stopOpAnim() override;
......
......@@ -21,6 +21,7 @@ public:
public:
virtual bool updateSelf() = 0;
virtual void clearCache() = 0;
virtual void startOpAnim() = 0;
virtual void stopOpAnim() = 0;
......
......@@ -15,19 +15,21 @@
class MockSvgItem : public SvgItemInterface
{
public:
MockSvgItem() : updateSelfCalled(false) {}
MockSvgItem() = default;
virtual ~MockSvgItem() = default;
public:
bool updateSelf() override { updateSelfCalled = true; return true; }
void clearCache() override { clearCacheCalled = true; }
void startOpAnim() override {}
void stopOpAnim() override {}
void startPosAnim(QPointF) override {}
void execPosAnim(qreal) override {}
void stopPosAnim() override {}
bool updateSelfCalled;
bool updateSelfCalled = false;
bool clearCacheCalled = false;
};
#endif //MOCKSVGITEM_H
......@@ -27,17 +27,49 @@ public:
KBlocksItemGroup::updateGame();
}
void replaceFreezeCells(SvgItemInterface* newItem)
SvgItemInterface *getFreezeCell(int cellNum)
{
for (int i = 0; i < mMaxFreezeCellNum; i++) {
removeFromGroup(maFreezeCells[i]);
delete maFreezeCells[i];
if (cellNum < mMaxFreezeCellNum) {
return maFreezeCells[cellNum];
}
return nullptr;
}
int getMaxPrepareCellNum() const
{
return mMaxPrepareCellNum;
}
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i] = newItem;
addToGroup(maFreezeCells[i]);
SvgItemInterface *getPrepareCell(int cellNum)
{
if (cellNum < mMaxPrepareCellNum) {
return maPrepareCells[cellNum];
}
return nullptr;
}
void replacePrepareCell(int cellNum, SvgItemInterface* newItem)
{
if (cellNum >= mMaxPrepareCellNum) {
return;
}
removeFromGroup(maPrepareCells[cellNum]);
delete maPrepareCells[cellNum];
maPrepareCells[cellNum] = newItem;
addToGroup(maPrepareCells[cellNum]);
}
void replaceFreezeCell(int cellNum, SvgItemInterface* newItem)
{
if (cellNum >= mMaxFreezeCellNum) {
return;
}
removeFromGroup(maFreezeCells[cellNum]);
delete maFreezeCells[cellNum];
maFreezeCells[cellNum] = newItem;
addToGroup(maFreezeCells[cellNum]);
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment