Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
Granatier
Commits
a4c320f3
Commit
a4c320f3
authored
Feb 07, 2022
by
Laurent Montel
😁
Browse files
modernize code
parent
1b39de13
Pipeline
#134399
passed with stage
in 1 minute and 43 seconds
Changes
23
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/arena.cpp
View file @
a4c320f3
...
...
@@ -14,8 +14,7 @@
#include <cstdlib>
Arena
::
Arena
()
{
}
=
default
;
Arena
::~
Arena
()
{
...
...
@@ -114,11 +113,11 @@ QPoint Arena::getCoords(Cell* p_cell) const
{
if
(
&
m_cells
[
i
][
j
]
==
p_cell
)
{
return
QPoint
(
j
,
i
)
;
return
{
j
,
i
}
;
}
}
}
return
QPoint
()
;
return
{}
;
}
int
Arena
::
getRowFromY
(
const
qreal
p_y
)
const
...
...
src/arenaitem.cpp
View file @
a4c320f3
...
...
@@ -19,8 +19,7 @@ ArenaItem::ArenaItem(qreal p_x, qreal p_y, KGameRenderer* renderer, const QStrin
}
ArenaItem
::~
ArenaItem
()
{
}
=
default
;
void
ArenaItem
::
updateGraphics
(
qreal
svgScaleFactor
)
{
...
...
src/block.cpp
View file @
a4c320f3
...
...
@@ -17,8 +17,7 @@ Block::Block(qreal p_x, qreal p_y, Arena* p_arena, const QString& p_imageId) : E
}
Block
::~
Block
()
{
}
=
default
;
void
Block
::
setBonus
(
Bonus
*
bonus
)
{
...
...
src/bombexplosionitem.cpp
View file @
a4c320f3
...
...
@@ -62,8 +62,7 @@ BombExplosionItem::BombExplosionItem(Bomb* p_model, Granatier::Direction::Type d
}
BombExplosionItem
::~
BombExplosionItem
()
{
}
=
default
;
QPainterPath
BombExplosionItem
::
shape
()
const
{
...
...
src/bonus.cpp
View file @
a4c320f3
...
...
@@ -19,9 +19,7 @@ Bonus::Bonus(qreal p_x, qreal p_y, Arena* p_arena, Granatier::Bonus::Type bonusT
}
Bonus
::~
Bonus
()
{
}
=
default
;
void
Bonus
::
doActionOnCollision
(
Player
*
p_player
)
{
...
...
src/cell.cpp
View file @
a4c320f3
...
...
@@ -13,8 +13,7 @@ Cell::Cell() : m_type(Granatier::Cell::WALL)
}
Cell
::~
Cell
()
{
}
=
default
;
bool
Cell
::
isWalkable
(
Element
*
p_element
)
const
{
...
...
src/character.cpp
View file @
a4c320f3
...
...
@@ -16,8 +16,7 @@ Character::Character(qreal p_x, qreal p_y, Arena* p_arena) : Element(p_x, p_y, p
}
Character
::~
Character
()
{
}
=
default
;
void
Character
::
move
()
{
...
...
src/characteritem.cpp
View file @
a4c320f3
...
...
@@ -17,8 +17,7 @@ CharacterItem::CharacterItem(Character* p_model, KGameRenderer* renderer) : Elem
}
CharacterItem
::~
CharacterItem
()
{
}
=
default
;
QPainterPath
CharacterItem
::
shape
()
const
{
...
...
src/config/arenaselector.cpp
View file @
a4c320f3
...
...
@@ -85,7 +85,7 @@ void ArenaSelector::showEvent(QShowEvent*)
ArenaSelector
::
Private
::
Private
(
ArenaSelector
*
parent
,
Options
options
)
:
q
(
parent
),
m_options
(
options
),
m_arena
(
nullptr
),
m_graphicsScene
(
nullptr
),
m_svgScaleFactor
(
1
)
{
KgTheme
*
theme
=
new
KgTheme
(
QByteArray
());
auto
*
theme
=
new
KgTheme
(
QByteArray
());
theme
->
setGraphicsPath
(
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QStringLiteral
(
"themes/granatier.svgz"
)));
m_renderer
=
new
KGameRenderer
(
theme
);
}
...
...
@@ -166,7 +166,7 @@ void ArenaSelector::Private::findArenas(const QString &initialSelection)
for
(
const
auto
&
file
:
arenasAvailable
)
{
QString
arenaPath
=
lookupDirectory
+
QLatin1Char
(
'/'
)
+
file
;
ArenaSettings
*
arenaSettings
=
new
ArenaSettings
(
groupName
);
auto
*
arenaSettings
=
new
ArenaSettings
(
groupName
);
if
(
arenaSettings
->
load
(
arenaPath
))
{
QString
arenaName
;
// Start with an empty QString here so that the first += allocates a reserve for future +=.
...
...
@@ -175,7 +175,7 @@ void ArenaSelector::Private::findArenas(const QString &initialSelection)
while
(
arenaMap
.
contains
(
arenaName
))
arenaName
+=
QLatin1Char
(
'_'
);
arenaMap
.
insert
(
arenaName
,
arenaSettings
);
QListWidgetItem
*
item
=
new
QListWidgetItem
(
arenaName
,
ui
.
arenaList
);
auto
*
item
=
new
QListWidgetItem
(
arenaName
,
ui
.
arenaList
);
if
(
ui
.
kcfg_RandomArenaMode
->
isChecked
())
{
if
(
m_tempRandomArenaModeArenaList
.
contains
(
file
))
...
...
@@ -332,7 +332,7 @@ void ArenaSelector::Private::_k_updatePreview(QListWidgetItem* currentItem)
for
(
int
j
=
0
;
j
<
m_arena
->
getNbColumns
();
++
j
)
{
// Create the ArenaItem and set the image
ArenaItem
*
arenaItem
=
new
ArenaItem
(
j
*
Granatier
::
CellSize
,
i
*
Granatier
::
CellSize
,
m_renderer
,
QLatin1String
(
""
));
auto
*
arenaItem
=
new
ArenaItem
(
j
*
Granatier
::
CellSize
,
i
*
Granatier
::
CellSize
,
m_renderer
,
QLatin1String
(
""
));
switch
(
m_arena
->
getCell
(
i
,
j
).
getType
())
{
...
...
@@ -394,7 +394,7 @@ QSize ArenaSelector::Private::calculateSvgSize()
{
if
(
m_graphicsScene
->
views
().
isEmpty
())
{
return
QSize
(
1
,
1
)
;
return
{
1
,
1
}
;
}
QPoint
topLeft
(
0
,
0
);
...
...
src/config/arenasettings.cpp
View file @
a4c320f3
...
...
@@ -116,7 +116,7 @@ QString ArenaSettings::property(const QString &key) const
if
(
!
d
->
loaded
)
{
qCDebug
(
GRANATIER_LOG
)
<<
"No arena file has been loaded. ArenaSettings::load() or ArenaSettings::loadDefault() must be called."
;
return
QString
()
;
return
{}
;
}
KConfig
arenaConfig
(
path
(),
KConfig
::
SimpleConfig
);
KConfigGroup
group
=
arenaConfig
.
group
(
d
->
arenaGroup
);
...
...
@@ -127,7 +127,7 @@ QString ArenaSettings::path() const {
if
(
!
d
->
loaded
)
{
qCDebug
(
GRANATIER_LOG
)
<<
"No arena file has been loaded. ArenaSettings::load() or ArenaSettings::loadDefault() must be called."
;
return
QString
()
;
return
{}
;
}
return
d
->
fullPath
;
}
...
...
@@ -136,7 +136,7 @@ QString ArenaSettings::fileName() const {
if
(
!
d
->
loaded
)
{
qCDebug
(
GRANATIER_LOG
)
<<
"No arena file has been loaded. ArenaSettings::load() or ArenaSettings::loadDefault() must be called."
;
return
QString
()
;
return
{}
;
}
return
d
->
fileName
;
}
...
...
@@ -145,7 +145,7 @@ QString ArenaSettings::graphics() const {
if
(
!
d
->
loaded
)
{
qCDebug
(
GRANATIER_LOG
)
<<
"No arena file has been loaded. ArenaSettings::load() or ArenaSettings::loadDefault() must be called."
;
return
QString
()
;
return
{}
;
}
return
d
->
graphics
;
}
...
...
@@ -154,7 +154,7 @@ QString ArenaSettings::arenaProperty(const QString &key) const {
if
(
!
d
->
loaded
)
{
qCDebug
(
GRANATIER_LOG
)
<<
"No arena file has been loaded. ArenaSettings::load() or ArenaSettings::loadDefault() must be called."
;
return
QString
()
;
return
{}
;
}
return
d
->
arenaProperties
[
key
];
}
src/config/playerselector.cpp
View file @
a4c320f3
...
...
@@ -58,12 +58,12 @@ PlayerSelector::PlayerSelector(PlayerSettings* playerSettings, Options options,
//load themes from provider
d
->
fillList
();
//setup appearance of the theme list (min. size = 4 items)
PlayerSelectorDelegate
*
delegate
=
new
PlayerSelectorDelegate
(
d
->
m_list
);
auto
*
delegate
=
new
PlayerSelectorDelegate
(
d
->
m_list
);
const
QSize
itemSizeHint
=
delegate
->
sizeHint
(
QStyleOptionViewItem
(),
QModelIndex
());
const
QSize
scrollBarSizeHint
=
d
->
m_list
->
verticalScrollBar
()
->
sizeHint
();
d
->
m_list
->
setMinimumSize
(
static_cast
<
int
>
(
itemSizeHint
.
width
()
+
2
*
scrollBarSizeHint
.
width
()),
static_cast
<
int
>
(
3.3
*
itemSizeHint
.
height
()));
//setup main layout
QVBoxLayo
ut
*
layout
=
new
QVBoxLayout
(
this
);
a
ut
o
*
layout
=
new
QVBoxLayout
(
this
);
layout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
layout
->
addWidget
(
d
->
m_list
);
}
...
...
@@ -89,7 +89,7 @@ void PlayerSelector::Private::fillList()
for
(
int
i
=
0
;
i
<
playerIDs
.
count
();
i
++
)
{
QListWidgetItem
*
item
=
new
QListWidgetItem
(
playerIDs
[
i
],
m_list
);
auto
*
item
=
new
QListWidgetItem
(
playerIDs
[
i
],
m_list
);
item
->
setFlags
(
item
->
flags
()
&
~
Qt
::
ItemIsSelectable
);
...
...
@@ -100,7 +100,7 @@ void PlayerSelector::Private::fillList()
playerSelectorItem
->
setPlayerPreviewPixmap
(
pixmap
);
KConfig
desktopFile
(
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QStringLiteral
(
"players/%1"
).
arg
(
playerIDs
[
i
])),
KConfig
::
SimpleConfig
);
QString
author
=
desktopFile
.
group
(
"KGameTheme"
).
readEntry
<
QString
>
(
"Author"
,
QStringLiteral
(
""
));
auto
author
=
desktopFile
.
group
(
"KGameTheme"
).
readEntry
<
QString
>
(
"Author"
,
QStringLiteral
(
""
));
QString
authorEmail
=
QStringLiteral
(
"<a href=
\"
mailto:%1
\"
>%1</a>"
).
arg
(
desktopFile
.
group
(
"KGameTheme"
).
readEntry
<
QString
>
(
"AuthorEmail"
,
QStringLiteral
(
""
)));
//TODO: QString description = desktopFile.group("KGameTheme").readEntry<QString>("Description", "");
playerSelectorItem
->
setPlayerAuthor
(
author
,
authorEmail
);
...
...
@@ -116,7 +116,7 @@ void PlayerSelector::Private::fillList()
PlayerSelectorDelegate
::
PlayerSelectorDelegate
(
QObject
*
parent
)
:
QStyledItemDelegate
(
parent
)
{
QAbstractItemView
*
view
=
qobject_cast
<
QAbstractItemView
*>
(
parent
);
auto
*
view
=
qobject_cast
<
QAbstractItemView
*>
(
parent
);
if
(
view
)
view
->
setItemDelegate
(
this
);
}
...
...
@@ -131,7 +131,7 @@ QSize PlayerSelectorDelegate::sizeHint(const QStyleOptionViewItem& option, const
{
Q_UNUSED
(
option
)
Q_UNUSED
(
index
)
//TODO: take text size into account
return
QSize
(
600
,
64
/*player preview height*/
+
2
*
6
/*padding*/
+
40
/* some space for the player name */
)
;
return
{
600
,
64
/*player preview height*/
+
2
*
6
/*padding*/
+
40
/* some space for the player name */
}
;
}
//END PlayerSelectorDelegate
...
...
src/config/playerselectoritem.cpp
View file @
a4c320f3
...
...
@@ -30,13 +30,13 @@ PlayerSelectorItem::PlayerSelectorItem(const QString& playerId, PlayerSettings*
m_playerPreviewPixmapLabel
=
new
QLabel
;
m_playerAuthor
=
new
QLabel
;
QHBoxLayo
ut
*
mainLayout
=
new
QHBoxLayout
(
this
);
a
ut
o
*
mainLayout
=
new
QHBoxLayout
(
this
);
mainLayout
->
setContentsMargins
(
6
,
6
,
6
,
6
);
QGridLayo
ut
*
gridLayoutPlayer
=
new
QGridLayout
();
a
ut
o
*
gridLayoutPlayer
=
new
QGridLayout
();
gridLayoutPlayer
->
setContentsMargins
(
0
,
0
,
0
,
0
);
QVBoxLayo
ut
*
verticalLayoutKeySequence
=
new
QVBoxLayout
();
a
ut
o
*
verticalLayoutKeySequence
=
new
QVBoxLayout
();
verticalLayoutKeySequence
->
setContentsMargins
(
0
,
0
,
0
,
0
);
mainLayout
->
addLayout
(
gridLayoutPlayer
);
...
...
@@ -49,7 +49,7 @@ PlayerSelectorItem::PlayerSelectorItem(const QString& playerId, PlayerSettings*
gridLayoutPlayer
->
addWidget
(
m_playerPreviewPixmapLabel
,
1
,
1
,
2
,
1
);
gridLayoutPlayer
->
addWidget
(
m_playerAuthor
,
2
,
2
);
//, 1, 1, Qt::AlignBottom);
QGridLayo
ut
*
gridLayoutKeySequence
=
new
QGridLayout
();
a
ut
o
*
gridLayoutKeySequence
=
new
QGridLayout
();
gridLayoutKeySequence
->
setContentsMargins
(
0
,
0
,
0
,
0
);
verticalLayoutKeySequence
->
addSpacerItem
(
new
QSpacerItem
(
0
,
0
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Expanding
));
...
...
src/config/playersettings.cpp
View file @
a4c320f3
...
...
@@ -113,8 +113,7 @@ PlayerSettings::PlayerSettings()
}
PlayerSettings
::~
PlayerSettings
()
{
}
=
default
;
const
QStringList
PlayerSettings
::
playerIDs
()
const
{
...
...
src/element.cpp
View file @
a4c320f3
...
...
@@ -13,8 +13,7 @@ Element::Element(qreal p_x, qreal p_y, Arena* p_arena) : m_xInit(p_x), m_yInit(p
}
Element
::~
Element
()
{
}
=
default
;
void
Element
::
doActionOnCollision
(
Player
*
)
{
...
...
src/elementitem.cpp
View file @
a4c320f3
...
...
@@ -26,8 +26,7 @@ ElementItem::ElementItem(Element* p_model, KGameRenderer* renderer) : KGameRende
}
ElementItem
::~
ElementItem
()
{
}
=
default
;
Element
*
ElementItem
::
getModel
()
const
{
...
...
src/game.cpp
View file @
a4c320f3
...
...
@@ -52,7 +52,7 @@ Game::Game(PlayerSettings* playerSettings)
{
if
(
m_playerSettings
->
enabled
(
strPlayerIDs
[
i
]))
{
Player
*
player
=
new
Player
(
qreal
(
Granatier
::
CellSize
*
(
-
0.5
)),
qreal
(
Granatier
::
CellSize
*
0.5
),
strPlayerIDs
[
i
],
playerSettings
,
m_arena
);
auto
*
player
=
new
Player
(
qreal
(
Granatier
::
CellSize
*
(
-
0.5
)),
qreal
(
Granatier
::
CellSize
*
0.5
),
strPlayerIDs
[
i
],
playerSettings
,
m_arena
);
m_players
.
append
(
player
);
connect
(
player
,
&
Player
::
dying
,
this
,
&
Game
::
playerDeath
);
connect
(
player
,
&
Player
::
falling
,
this
,
&
Game
::
playerFalling
);
...
...
@@ -149,7 +149,7 @@ void Game::init()
{
if
(
m_arena
->
getCell
(
i
,
j
).
getType
()
==
Granatier
::
Cell
::
BLOCK
)
{
Block
*
block
=
new
Block
((
j
+
0.5
)
*
Granatier
::
CellSize
,
(
i
+
0.5
)
*
Granatier
::
CellSize
,
m_arena
,
QStringLiteral
(
"arena_block"
));
auto
*
block
=
new
Block
((
j
+
0.5
)
*
Granatier
::
CellSize
,
(
i
+
0.5
)
*
Granatier
::
CellSize
,
m_arena
,
QStringLiteral
(
"arena_block"
));
m_blocks
.
append
(
block
);
m_arena
->
setCellElement
(
i
,
j
,
block
);
}
...
...
src/gamescene.cpp
View file @
a4c320f3
...
...
@@ -58,7 +58,7 @@ GameScene::GameScene(Game* p_game, KgThemeProvider* p_themeProvider) : m_game(p_
for
(
auto
&
player
:
players
)
{
const
QString
desktopPath
=
player
->
getDesktopFilePath
();
KgTheme
*
theme
=
new
KgTheme
(
desktopPath
.
toUtf8
());
auto
*
theme
=
new
KgTheme
(
desktopPath
.
toUtf8
());
theme
->
readFromDesktopFile
(
desktopPath
);
auto
playerRenderer
=
new
KGameRenderer
(
theme
);
m_mapRendererPlayerItems
.
insert
(
player
,
playerRenderer
);
...
...
@@ -109,7 +109,7 @@ void GameScene::setupThemeRenderer()
selectedThemeIsDefault
=
false
;
if
(
m_rendererDefaultTheme
==
nullptr
)
{
KgTheme
*
theme
=
new
KgTheme
(
m_themeProvider
->
defaultTheme
()
->
identifier
());
auto
*
theme
=
new
KgTheme
(
m_themeProvider
->
defaultTheme
()
->
identifier
());
theme
->
setGraphicsPath
(
m_themeProvider
->
defaultTheme
()
->
graphicsPath
());
m_rendererDefaultTheme
=
new
KGameRenderer
(
theme
);
}
...
...
@@ -269,7 +269,7 @@ void GameScene::initItemsWithGraphicsFromTheme()
for
(
int
j
=
0
;
j
<
m_game
->
getArena
()
->
getNbColumns
();
++
j
)
{
// Create the ArenaItem and set the image
ArenaItem
*
arenaItem
=
new
ArenaItem
(
j
*
Granatier
::
CellSize
,
i
*
Granatier
::
CellSize
,
m_rendererArenaItems
,
QStringLiteral
(
""
));
auto
*
arenaItem
=
new
ArenaItem
(
j
*
Granatier
::
CellSize
,
i
*
Granatier
::
CellSize
,
m_rendererArenaItems
,
QStringLiteral
(
""
));
connect
(
this
,
&
GameScene
::
resizeGraphics
,
arenaItem
,
&
ArenaItem
::
updateGraphics
);
//TODO: use this function call
...
...
@@ -334,8 +334,8 @@ void GameScene::initItemsWithGraphicsFromTheme()
// Create the element item and set the image
for
(
const
auto
&
element
:
std
::
as_const
(
blockElements
))
{
Block
*
block
=
dynamic_cast
<
Block
*>
(
element
);
BlockItem
*
blockItem
=
new
BlockItem
(
block
,
m_rendererArenaItems
);
auto
*
block
=
dynamic_cast
<
Block
*>
(
element
);
auto
*
blockItem
=
new
BlockItem
(
block
,
m_rendererArenaItems
);
connect
(
this
,
&
GameScene
::
resizeGraphics
,
blockItem
,
&
BlockItem
::
updateGraphics
);
blockItem
->
setSpriteKey
(
block
->
getImageId
());
blockItem
->
update
(
block
->
getX
(),
block
->
getY
());
...
...
@@ -351,7 +351,7 @@ void GameScene::initItemsWithGraphicsFromTheme()
Bonus
*
bonus
=
block
->
getBonus
();
if
(
bonus
)
{
BonusItem
*
bonusItem
=
new
BonusItem
(
bonus
,
m_rendererBonusItems
);
auto
*
bonusItem
=
new
BonusItem
(
bonus
,
m_rendererBonusItems
);
switch
(
bonus
->
getBonusType
())
{
case
Granatier
::
Bonus
::
SPEED
:
...
...
@@ -818,7 +818,7 @@ void GameScene::updateInfo(const Granatier::Info::Type p_info)
void
GameScene
::
createBombItem
(
Bomb
*
bomb
)
{
// Create the Bombs
BombItem
*
bombItem
=
new
BombItem
(
bomb
,
m_rendererBombItems
);
auto
*
bombItem
=
new
BombItem
(
bomb
,
m_rendererBombItems
);
// Corrects the position of the BombItem
bombItem
->
update
(
bomb
->
getX
(),
bomb
->
getY
());
addItem
(
bombItem
);
...
...
src/gameview.cpp
View file @
a4c320f3
...
...
@@ -25,9 +25,7 @@ GameView::GameView(GameScene* p_scene, Game * p_game) : QGraphicsView(p_scene)
}
GameView
::~
GameView
()
{
}
=
default
;
void
GameView
::
resizeEvent
(
QResizeEvent
*
)
{
...
...
src/infooverlay.cpp
View file @
a4c320f3
...
...
@@ -33,14 +33,14 @@ InfoOverlay::InfoOverlay (Game* p_game, GameScene* p_scene) : QObject()
for
(
const
auto
&
player
:
playerList
)
{
QList
<
KGameRenderedItem
*>
svgItemList
;
QGraphicsTextItem
*
playerName
=
new
QGraphicsTextItem
(
player
->
getPlayerName
());
auto
*
playerName
=
new
QGraphicsTextItem
(
player
->
getPlayerName
());
playerName
->
setFont
(
QFont
(
QStringLiteral
(
"Helvetica"
),
static_cast
<
int
>
(
Granatier
::
CellSize
*
0.35
),
QFont
::
Bold
,
false
));
playerName
->
setDefaultTextColor
(
QColor
(
"#FFFF00"
));
playerName
->
setZValue
(
2001
);
for
(
int
j
=
0
;
j
<
nWinPoints
;
j
++
)
{
KGameRenderedItem
*
score
=
new
KGameRenderedItem
(
renderer
,
QStringLiteral
(
"score_star_disabled"
));
auto
*
score
=
new
KGameRenderedItem
(
renderer
,
QStringLiteral
(
"score_star_disabled"
));
score
->
setZValue
(
2001
);
svgItemList
.
append
(
score
);
}
...
...
src/main.cpp
View file @
a4c320f3
...
...
@@ -96,7 +96,7 @@ int main(int argc, char** argv)
KDBusService
service
;
// Create the application
// Create the main window
MainWindow
*
window
=
new
MainWindow
();
auto
*
window
=
new
MainWindow
();
// Show the main window
window
->
show
();
// Execute the application
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment