Skip to content

Commit

Permalink
Fixed executable on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashe committed Jan 19, 2020
1 parent 6e68a07 commit 8ce97f6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ project (Project)
message("Using CMake version ${CMAKE_VERSION}")
message("Processing CMakeLists.txt")

# Where should the project build to
set (CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/Build)

# Compiler version
set (CMAKE_CXX_STANDARD 17)

Expand Down
87 changes: 47 additions & 40 deletions src/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,69 @@ Resources::load() {

// Declare that we're loading resources
const std::string dir = "Assets/";
Console::log("Loading resources recursively from directory: '%s'..",
dir.c_str());

// For every file in the directory
for (const auto& entry :
std::filesystem::recursive_directory_iterator(dir)) {
const auto fp = entry.path();
if (entry.is_regular_file()) {// && fp.extension().string() == ".lua") {
// Try to iterate through the assets directory
try {

// Prepare to load resources
bool loaded = false;
// Get the directory to load
const auto& directory = std::filesystem::recursive_directory_iterator(dir);
Console::log("Loading resources recursively from directory: '%s'..",
dir.c_str());

// Get the extension to load the resource properly
auto ext = fp.extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(),
// For every file in the directory
for (const auto& entry : directory) {
const auto fp = entry.path();
if (entry.is_regular_file()) {// && fp.extension().string() == ".lua") {

// Prepare to load resources
bool loaded = false;

// Get the extension to load the resource properly
auto ext = fp.extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(),
[](unsigned char c) { return std::tolower(c); });

// Textures
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg") {
auto tex = std::make_unique<sf::Texture>();
if (tex->loadFromFile(fp)) {
textures_.emplace(fp.stem(), std::move(tex));
Console::log("Loaded texture: %s as %s",
// Textures
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg") {
auto tex = std::make_unique<sf::Texture>();
if (tex->loadFromFile(fp.string())) {
textures_.emplace(fp.stem().string(), std::move(tex));
Console::log("Loaded texture: %s as %s",
fp.c_str(), fp.stem().c_str());
loaded = true;
loaded = true;
}
}
}

// Fonts
else if (ext == ".ttf") {
auto font = std::make_unique<sf::Font>();
if (font->loadFromFile(fp)) {
fonts_.emplace(fp.stem(), std::move(font));
Console::log("Loaded font: %s as %s",
// Fonts
else if (ext == ".ttf") {
auto font = std::make_unique<sf::Font>();
if (font->loadFromFile(fp.string())) {
fonts_.emplace(fp.stem().string(), std::move(font));
Console::log("Loaded font: %s as %s",
fp.c_str(), fp.stem().c_str());
loaded = true;
loaded = true;
}
}
}

// Strategy maps
else if (ext == ".stratmap") {
std::ifstream infile(fp);
std::stringstream ss;
ss << infile.rdbuf();
strategyMaps_.emplace(fp.stem(), ss.str());
Console::log("Loaded strategy map: %s as %s",
// Strategy maps
else if (ext == ".stratmap") {
std::ifstream infile(fp);
std::stringstream ss;
ss << infile.rdbuf();
strategyMaps_.emplace(fp.stem().string(), ss.str());
Console::log("Loaded strategy map: %s as %s",
fp.c_str(), fp.stem().c_str());
loaded = true;
}
loaded = true;
}

// If resource failed to load
if (!loaded) {
Console::log("[Error] Failed to load resource: %s", fp.c_str());
// If resource failed to load
if (!loaded) {
Console::log("[Error] Failed to load resource: %s", fp.c_str());
}
}
}
}
catch (...) {}
}

// Retrieve all map names
Expand Down
8 changes: 0 additions & 8 deletions src/Scenes/Strategy/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ namespace Strategy {
// Attack Range
typedef int Range;

// Team colours
static std::map<Team, sf::Color> teamColours = {
{0, sf::Color::Cyan},
{1, sf::Color::Red},
{2, sf::Color::Green},
{3, sf::Color::Yellow}
};

// Different methods of drawing an object
enum class RenderStyle {
NotPlaying,
Expand Down
11 changes: 6 additions & 5 deletions src/Scenes/Strategy/Strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,10 +2282,11 @@ Strategy::Game::renderResources(
// Get the colour associated with a team
sf::Color
Strategy::Game::getTeamColour(const Team& team) {
const auto& coloursIt = teamColours.find(team);
auto col = sf::Color::White;
if (coloursIt != teamColours.end()) {
col = coloursIt->second;
switch (team) {
case 0: return sf::Color::Cyan; break;
case 1: return sf::Color::Red; break;
case 2: return sf::Color::Green; break;
case 3: return sf::Color::Yellow; break;
default: return sf::Color::White;
}
return col;
}

0 comments on commit 8ce97f6

Please sign in to comment.