Skip to content

Commit a583cd9

Browse files
committed
added usings to reduce the typing.
1 parent 5edd8bc commit a583cd9

File tree

5 files changed

+67
-59
lines changed

5 files changed

+67
-59
lines changed

src/assetsManager.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#include "assetsManager.h"
22

3-
std::vector<Kana> loadAssets()
3+
using std::vector;
4+
using std::string;
5+
6+
vector<Kana> loadAssets()
47
{
5-
std::vector<Kana> kanas;
8+
vector<Kana> kanas;
69
kanas.reserve(142);
710

8-
std::string audioPath = "assets/sounds/";
9-
std::string hiraganaImgsPath = "assets/img/hiraganas/";
10-
std::string audioExtension = ".mp3";
11-
std::string imageExtension = ".png";
12-
std::string hiraganaGifPath = "assets/gifs/hiraganas/";
13-
std::string gifExtension = ".gif";
11+
string audioPath = "assets/sounds/";
12+
string hiraganaImgsPath = "assets/img/hiraganas/";
13+
string audioExtension = ".mp3";
14+
string imageExtension = ".png";
15+
string hiraganaGifPath = "assets/gifs/hiraganas/";
16+
string gifExtension = ".gif";
1417

15-
std::string kanaNames[] = {
18+
string kanaNames[] = {
1619
"a", "e", "i", "o", "u",
1720
"ka", "ga", "ki", "gi", "ku",
1821
"gu", "ke", "ge", "ko", "go",
@@ -30,17 +33,17 @@ std::vector<Kana> loadAssets()
3033
"wa", "wo", "n"
3134
};
3235

33-
for (std::string &kanaName : kanaNames)
36+
for (string &kanaName : kanaNames)
3437
{
35-
std::string actualAudioPath = audioPath + kanaName + audioExtension;
38+
string actualAudioPath = audioPath + kanaName + audioExtension;
3639
Sound actualSound = LoadSound(actualAudioPath.c_str());
3740
SetSoundVolume(actualSound, 0.8);
3841

39-
std::string actualImagePath = hiraganaImgsPath + kanaName + imageExtension;
42+
string actualImagePath = hiraganaImgsPath + kanaName + imageExtension;
4043
Texture2D actualTexture = LoadTexture(actualImagePath.c_str());
4144
Rectangle kanaBounds = {40, 40, (float)actualTexture.width, (float)actualTexture.height};
4245

43-
std::string actualGifPath = hiraganaGifPath + kanaName + gifExtension;
46+
string actualGifPath = hiraganaGifPath + kanaName + gifExtension;
4447

4548
int animationFrames = 0;
4649
// Since I'm loading images, the ram consumption will go up.
@@ -58,20 +61,20 @@ std::vector<Kana> loadAssets()
5861
kanas.push_back({kanaName, kanaBounds, actualTexture, actualSound, drawKanaTexture, kanaAnimation, animationFrames});
5962
}
6063

61-
std::string katakanaImgsPath = "assets/img/katakanas/";
62-
std::string katakanaGifPath = "assets/gifs/katakanas/";
64+
string katakanaImgsPath = "assets/img/katakanas/";
65+
string katakanaGifPath = "assets/gifs/katakanas/";
6366

6467
int actualMaxSize = kanas.size();
6568

6669
for (int i = 0; i < actualMaxSize; i++)
6770
{
6871
auto actualKana = kanas[i];
6972

70-
std::string actualImagePath = katakanaImgsPath + actualKana.name + imageExtension;
73+
string actualImagePath = katakanaImgsPath + actualKana.name + imageExtension;
7174
Texture2D actualTexture = LoadTexture(actualImagePath.c_str());
7275
Rectangle kanaBounds = {40, 40, (float)actualTexture.width, (float)actualTexture.height};
7376

74-
std::string actualGifPath = katakanaGifPath + actualKana.name + gifExtension;
77+
string actualGifPath = katakanaGifPath + actualKana.name + gifExtension;
7578

7679
int animationFrames = 0;
7780
Image kanaAnimation = LoadImageAnim(actualGifPath.c_str(), &animationFrames);
@@ -84,9 +87,9 @@ std::vector<Kana> loadAssets()
8487
return kanas;
8588
}
8689

87-
std::string handleMissingGifName(std::string kanaName)
90+
string handleMissingGifName(string kanaName)
8891
{
89-
std::string actualName = kanaName;
92+
string actualName = kanaName;
9093

9194
if (actualName.compare("ji") == 0)
9295
{

src/assetsManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <raylib.h>
44
#include <vector>
5-
#include <iostream>
5+
#include <string>
66

77
typedef struct
88
{

src/fileManager.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#include "fileManager.h"
2+
#include <fstream>
23

3-
std::vector<std::string> saveInitialHighScores()
4+
vector<string> saveInitialHighScores()
45
{
5-
std::vector<std::string> highScores;
6+
vector<string> highScores;
67
highScores.reserve(9);
78

89
std::ofstream highScoresFile("assets/high-scores.txt");
910

10-
std::string name = "aaa";
11+
string name = "aaa";
1112

1213
for (int i = 8; i > 0; i--)
1314
{
14-
std::string scoreString = std::to_string(i * 100);
15-
std::string fullScoreString = name + " " + scoreString;
15+
string scoreString = std::to_string(i * 100);
16+
string fullScoreString = name + " " + scoreString;
1617

1718
if (i == 1)
1819
{
@@ -31,7 +32,7 @@ std::vector<std::string> saveInitialHighScores()
3132
return highScores;
3233
}
3334

34-
std::string extractLastNChars(std::string const &str, size_t n)
35+
string extractLastNChars(string const &str, size_t n)
3536
{
3637
if (str.size() < n)
3738
{
@@ -41,19 +42,19 @@ std::string extractLastNChars(std::string const &str, size_t n)
4142
return str.substr(str.size() - n);
4243
}
4344

44-
std::vector<HighScore> getFullScoreData(std::vector<std::string> highScores)
45+
vector<HighScore> getFullScoreData(vector<string> highScores)
4546
{
46-
std::vector<HighScore> scores;
47+
vector<HighScore> scores;
4748
scores.reserve(9);
4849

4950
int rank = 1;
5051

5152
for (auto &highScore: highScores)
5253
{
53-
std::string scoreString = extractLastNChars(highScore, 3);
54+
string scoreString = extractLastNChars(highScore, 3);
5455
int score = stoi(scoreString);
5556

56-
std::string nameString = highScore.substr(0, 3);
57+
string nameString = highScore.substr(0, 3);
5758

5859
scores.push_back({rank, nameString, score});
5960
rank++;
@@ -62,24 +63,24 @@ std::vector<HighScore> getFullScoreData(std::vector<std::string> highScores)
6263
return scores;
6364
}
6465

65-
std::vector<std::string> saveActualHighScores(std::vector<std::string> highScores, int actualScore, std::string playerName)
66+
vector<string> saveActualHighScores(vector<string> highScores, int actualScore, string playerName)
6667
{
67-
std::vector<std::string> actualScores;
68+
vector<string> actualScores;
6869
actualScores.reserve(9);
6970

7071
bool actualScoreWasAdded = false;
7172

7273
for (size_t i = 0; i < highScores.size(); i++)
7374
{
74-
std::string highScore = highScores[i];
75+
string highScore = highScores[i];
7576

76-
std::string scoreString = extractLastNChars(highScore, 3);
77+
string scoreString = extractLastNChars(highScore, 3);
7778

7879
int score = stoi(scoreString);
7980

8081
if (!actualScoreWasAdded && actualScore > score)
8182
{
82-
std::string fullScore = playerName + " " + std::to_string(actualScore);
83+
string fullScore = playerName + " " + std::to_string(actualScore);
8384
actualScores.push_back(fullScore);
8485
actualScoreWasAdded = true;
8586
}
@@ -98,7 +99,7 @@ std::vector<std::string> saveActualHighScores(std::vector<std::string> highScore
9899
//I can create a infinite loop and it will create a really big file and create a high ram consumption.
99100
for (size_t i = 0; i < actualScores.size(); i++)
100101
{
101-
std::string fullScoreString = actualScores[i];
102+
string fullScoreString = actualScores[i];
102103

103104
if (i == actualScores.size() - 1)
104105
{
@@ -118,9 +119,9 @@ std::vector<std::string> saveActualHighScores(std::vector<std::string> highScore
118119
return highScores;
119120
}
120121

121-
std::vector<std::string> loadHighScores()
122+
vector<string> loadHighScores()
122123
{
123-
std::vector<std::string> scores;
124+
vector<string> scores;
124125
scores.reserve(9);
125126

126127
std::ifstream highScoresFile("assets/high-scores.txt");
@@ -130,7 +131,7 @@ std::vector<std::string> loadHighScores()
130131
return saveInitialHighScores();
131132
}
132133

133-
for (std::string line; getline(highScoresFile, line);)
134+
for (string line; getline(highScoresFile, line);)
134135
{
135136
scores.push_back(line);
136137
}
@@ -149,7 +150,7 @@ void saveScore(int score)
149150
highScoreFile.close();
150151
}
151152

152-
void savePlayerName(std::string playerName)
153+
void savePlayerName(string playerName)
153154
{
154155
std::ofstream playerNameFile("assets/player.txt");
155156

@@ -158,9 +159,9 @@ void savePlayerName(std::string playerName)
158159
playerNameFile.close();
159160
}
160161

161-
std::string loadPlayerName()
162+
string loadPlayerName()
162163
{
163-
std::string playerName;
164+
string playerName;
164165

165166
std::ifstream playerNameFile("assets/player.txt");
166167

@@ -179,7 +180,7 @@ std::string loadPlayerName()
179180

180181
int loadHighScore()
181182
{
182-
std::string highScoreText;
183+
string highScoreText;
183184

184185
std::ifstream highScoreFile("assets/high-score.txt");
185186

src/fileManager.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
#pragma once
22

33
#include <vector>
4-
#include <fstream>
4+
#include <string>
5+
6+
//with usings I can remove the need to the of the extra typing string, vector, etc..
7+
using std::vector;
8+
using std::string;
59

610
typedef struct
711
{
812
int rank;
9-
std::string name;
13+
string name;
1014
int score;
1115
} HighScore;
1216

13-
std::vector<std::string> saveInitialHighScores();
17+
vector<string> saveInitialHighScores();
1418

15-
std::string extractLastNChars(std::string const &str, size_t n);
19+
string extractLastNChars(string const &str, size_t n);
1620

17-
std::vector<HighScore> getFullScoreData(std::vector<std::string> highScores);
21+
vector<HighScore> getFullScoreData(vector<string> highScores);
1822

19-
std::vector<std::string> saveActualHighScores(std::vector<std::string> highScores, int actualScore, std::string playerName);
23+
vector<string> saveActualHighScores(vector<string> highScores, int actualScore, string playerName);
2024

21-
std::vector<std::string> loadHighScores();
25+
vector<string> loadHighScores();
2226

2327
void saveScore(int score);
2428

25-
void savePlayerName(std::string playerName);
29+
void savePlayerName(string playerName);
2630

27-
std::string loadPlayerName();
31+
string loadPlayerName();
2832

2933
int loadHighScore();

src/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void updateHighScore(int &score, int &highScore)
1717
}
1818
}
1919

20-
void toLowerCase(std::string &string)
20+
void toLowerCase(string &string)
2121
{
2222
// Manual converting each character to lowercase using ASCII values
2323
for (char &character : string)
@@ -57,7 +57,7 @@ int main()
5757

5858
int highScore = loadHighScore();
5959

60-
std::string playerName = loadPlayerName();
60+
string playerName = loadPlayerName();
6161

6262
bool isHighScoreScreen = false;
6363

@@ -66,9 +66,9 @@ int main()
6666
isHighScoreScreen = true;
6767
}
6868

69-
std::vector<std::string> highScores = loadHighScores();
69+
vector<string> highScores = loadHighScores();
7070

71-
std::vector<HighScore> fullScores = getFullScoreData(highScores);
71+
vector<HighScore> fullScores = getFullScoreData(highScores);
7272

7373
int attempts = 0;
7474

@@ -78,7 +78,7 @@ int main()
7878

7979
InitAudioDevice();
8080

81-
std::vector<Kana> kanas = loadAssets();
81+
vector<Kana> kanas = loadAssets();
8282

8383
// there are 71 hiragana + 71 katakanas = 142.
8484
int totalKanas = kanas.size() - 1;
@@ -219,7 +219,7 @@ int main()
219219
mouseBounds.x = mousePosition.x;
220220
mouseBounds.y = mousePosition.y;
221221

222-
std::string actualKanaName = answer;
222+
string actualKanaName = answer;
223223

224224
if (!isLearningMode && !isHighScoreScreen)
225225
{
@@ -422,7 +422,7 @@ int main()
422422

423423
if (IsKeyPressed(KEY_SPACE))
424424
{
425-
std::string name = answer;
425+
string name = answer;
426426
name.pop_back();
427427
toLowerCase(name);
428428

0 commit comments

Comments
 (0)