mirror of
https://github.com/Motschen/Adventura.git
synced 2025-12-16 03:45:10 +01:00
docs: add more comments
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -16,21 +14,6 @@ using std::endl;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
string readInput(string feedback);
|
||||
|
||||
/**
|
||||
* Reads a string from the user. The string is expected to be the first
|
||||
* argument before a comma.
|
||||
*
|
||||
* @return The string read from the user.
|
||||
*/
|
||||
string readInput(string feedback) {
|
||||
string name;
|
||||
cout << feedback << endl;
|
||||
getline(std::cin, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all files in the specified directory, sorted alphabetically.
|
||||
*
|
||||
@@ -38,11 +21,11 @@ string readInput(string feedback) {
|
||||
*
|
||||
* @param dir The directory to get the file names from
|
||||
* @param extension The file extension to filter by
|
||||
* @return A list of all file names in the specified directory, sorted alphabetically.
|
||||
* @return A list of all filtered file names in the specified directory, sorted alphabetically.
|
||||
*/
|
||||
vector<string> getOrderedFileNames(string dir, string extension) {
|
||||
vector<string> worlds;
|
||||
// This used to be so elegant and iterate over all files in the worlds directory,
|
||||
// This used to be elegant and iterate over all files in the worlds directory,
|
||||
// but because of the weird restriction with no folders being allowed, we just filter the files based on their extension.
|
||||
for (auto & entry : std::filesystem::directory_iterator(dir)) {
|
||||
if (static_cast<string>(entry.path()).ends_with(extension)) worlds.push_back(entry.path());
|
||||
@@ -62,22 +45,10 @@ vector<string> getOrderedFileNames(string dir, string extension) {
|
||||
* @return The content of the file as a vector of strings.
|
||||
*/
|
||||
vector<string> readFileAsVector(const string& fileLocation) {
|
||||
|
||||
vector<string> lines;
|
||||
// string currentLine = "";
|
||||
// for (char c : readFile(fileLocation)) {
|
||||
// if (c == '\n' || c == '\r') {
|
||||
// file.push_back(currentLine);
|
||||
// currentLine = "";
|
||||
// }
|
||||
// else {
|
||||
// currentLine += c;
|
||||
// }
|
||||
// }
|
||||
// file.push_back(currentLine);
|
||||
vector<string> lines;
|
||||
|
||||
std::ifstream file(fileLocation);
|
||||
// Read the file line by line into a string
|
||||
// Read the file line by line
|
||||
string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines.push_back(line);
|
||||
@@ -87,7 +58,8 @@ vector<string> readFileAsVector(const string& fileLocation) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the content of a file line by line into the console (in the specified color).
|
||||
* Prints the content of a file into the console line by line.
|
||||
*
|
||||
* We use this to print our death and victory screens.
|
||||
*
|
||||
* @param fileLocation Path to the file to be printed.
|
||||
|
||||
Reference in New Issue
Block a user