Commit 2b17d389 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Extract interface of KBlocksSound

Similar to KBlocksGraphics, I want to abstract out the interface of
KBlocksSound, so that I can create a MockSound class to use in unit
testing.
parent 849aa2f1
......@@ -9,10 +9,11 @@
* (at your option) any later version. *
***************************************************************************/
#include "GraphicsInterface.h"
#include "SoundInterface.h"
#include "KBlocksItemGroup.h"
KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, KBlocksSound *pS, bool snapshotMode)
KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode)
{
mGroupID = groupID;
mpSingleGame = p;
......
......@@ -16,7 +16,6 @@
#include <QTimer>
#include <QList>
#include "KBlocksSound.h"
#include "KBlocksSvgItem.h"
#include "KBlocksAnimator.h"
......@@ -25,13 +24,14 @@
#include "KBlocksDefine.h"
class GraphicsInterface;
class SoundInterface;
class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
{
Q_OBJECT
public:
KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, KBlocksSound *pS, bool snapshotMode = false);
KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode = false);
~KBlocksItemGroup();
public:
......@@ -78,7 +78,7 @@ private:
SingleGameInterface *mpSingleGame;
KBlocksLayout *mpGameLayout = nullptr;
GraphicsInterface *mpGrafx = nullptr;
KBlocksSound *mpSnd = nullptr;
SoundInterface *mpSnd = nullptr;
QTimer mUpdateTimer;
int mUpdateInterval;
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
/*******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009-2021 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
******************************************************************************/
//Uses routines from Kapman sound manager (game.cpp)
#include "KBlocksSound.h"
......@@ -20,6 +21,7 @@
#include "settings.h"
KBlocksSound::KBlocksSound(const QString &themeFile)
: SoundInterface()
{
loadTheme(themeFile);
}
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
/*******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009-2021 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
******************************************************************************/
#ifndef KBLOCKSSOUND_H
#define KBLOCKSSOUND_H
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgametheme.h>
class KgSound;
#include "SoundInterface.h"
enum class Sound {
BlockFall,
BlockMove,
BlockRemove
};
class KgSound;
class KBlocksSound
class KBlocksSound : public SoundInterface
{
public:
explicit KBlocksSound(const QString &themeFile);
~KBlocksSound();
virtual ~KBlocksSound();
public:
bool loadTheme(const QString &themeFile);
void setSoundsEnabled(bool p_enabled);
void playSound(Sound soundType);
bool loadTheme(const QString &themeFile) override;
void setSoundsEnabled(bool p_enabled) override;
void playSound(Sound soundType) override;
private:
KgSound *m_blockFallSound = nullptr;
......
/*******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009-2021 Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
******************************************************************************/
#ifndef SOUNDINTERFACE_H
#define SOUNDINTERFACE_H
enum class Sound {
BlockFall,
BlockMove,
BlockRemove
};
class SoundInterface
{
public:
SoundInterface() = default;
virtual ~SoundInterface() = default;
public:
virtual bool loadTheme(const QString &) = 0;
virtual void setSoundsEnabled(bool) = 0;
virtual void playSound(Sound) = 0;
};
#endif // SOUNDINTERFACE_H
Markdown is supported
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