-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SFML as bundled module, added label to button entity constructor
- Loading branch information
Arroganz
committed
Jul 29, 2018
1 parent
22f1da2
commit 1163e38
Showing
104 changed files
with
6,752 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// Created by clara on 1/12/18. | ||
// | ||
|
||
#ifdef _WIN32 | ||
# include <filesystem> | ||
#endif | ||
#include <experimental/filesystem> | ||
#include <regex> | ||
#include <string> | ||
#include "AssetLoader.hpp" | ||
|
||
namespace fender::systems::SFMLSystems | ||
{ | ||
void AssetLoader::init() { | ||
__init(); | ||
addReaction<RequestAssets>([this](futils::IMediatorPacket &){ | ||
AssetsLoaded assets; | ||
assets.fonts = &_fonts; | ||
assets.textures = &_textures; | ||
events->send<AssetsLoaded>(assets); | ||
}); | ||
|
||
std::regex patternTexture { ".*.[png|jpg|jpeg]" }; | ||
std::regex patternFont { ".*.ttf" }; | ||
// TODO: Make it easier to set the resources folder | ||
std::string assetDir = "ressources/"; | ||
|
||
try { | ||
std::experimental::filesystem::path path{assetDir.c_str()}; | ||
if (std::experimental::filesystem::exists(path)) { | ||
std::string pathFile; | ||
for (auto &p : std::experimental::filesystem::recursive_directory_iterator(path)) { | ||
|
||
pathFile = p.path().string(); | ||
|
||
std::string file = p.path().string(); | ||
file.erase(0, assetDir.size()); | ||
|
||
if (std::regex_match(file, patternTexture)) { | ||
sf::Texture texture; | ||
if (!texture.loadFromFile(pathFile)) { | ||
//events->send<std::string>("Texture " + file->d_name + " not found."); | ||
continue; | ||
} | ||
events->send<std::string>("Texture " + file + " loaded."); | ||
_textures[file] = texture; | ||
} else if (std::regex_match(file, patternFont)) { | ||
sf::Font font; | ||
if (!font.loadFromFile(pathFile)) { | ||
//events->send<std::string>("\e[31m ☒ \e[00m Font \"" + file->d_name + "\" not found."); | ||
continue; | ||
} | ||
events->send<std::string>("Font " + file + " loaded."); | ||
_fonts[file] = font; | ||
} | ||
} | ||
} else { | ||
events->send<std::string>("[Warning] Could not load assets from unexisting directory " + assetDir); | ||
} | ||
} | ||
catch (...) { | ||
std::cerr << "Something went wrong in SFMLAssetLoader" << std::endl; | ||
return ; | ||
} | ||
phase = Run; | ||
} | ||
|
||
void AssetLoader::run(float) { | ||
switch (phase) | ||
{ | ||
case Init: return init(); | ||
case Run: return ; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Created by clara on 1/12/18. | ||
// | ||
|
||
#pragma once | ||
|
||
# include <SFML/Graphics.hpp> | ||
# include "System.hpp" | ||
|
||
namespace fender::systems::SFMLSystems | ||
{ | ||
struct RequestAssets { | ||
|
||
}; | ||
|
||
//TODO: Maybe 1 pkg for font and an other one for textures? | ||
|
||
struct AssetsLoaded { | ||
std::unordered_map<std::string, sf::Texture> *textures; | ||
std::unordered_map<std::string, sf::Font> *fonts; | ||
}; | ||
|
||
class AssetLoader : public System { | ||
enum States | ||
{ | ||
Init = 0, | ||
Run | ||
}; | ||
|
||
std::unordered_map<std::string, sf::Texture> _textures; | ||
std::unordered_map<std::string, sf::Font> _fonts; | ||
void init(); | ||
|
||
public: | ||
AssetLoader(): System("AssetLoader") {} | ||
void run(float) override; | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Created by arroganz on 1/7/18. | ||
// | ||
|
||
#include "inputKeys.hpp" | ||
#include "Border.hpp" | ||
#include "Camera.hpp" | ||
|
||
namespace fender::systems::SFMLSystems | ||
{ | ||
void Border::renderBorder(components::Border const &border, sf::RenderWindow &window) | ||
{ | ||
auto &absolute = border.getEntity().get<components::AbsoluteTransform>(); | ||
sf::RectangleShape shape; | ||
sf::Color color; | ||
color << border.color; | ||
if (border.up && border.down && border.left && border.right) { | ||
shape.setFillColor(sf::Color::Transparent); | ||
shape.setOutlineThickness(border.thickness); | ||
shape.setOutlineColor(color); | ||
shape.setSize(sf::Vector2f(absolute.size.w, absolute.size.h)); | ||
shape.setPosition(absolute.position.x, absolute.position.y); | ||
window.draw(shape); | ||
} else { | ||
sf::RectangleShape line; | ||
line.setFillColor(color); | ||
if (border.up) { | ||
line.setPosition(absolute.position.x, absolute.position.y - border.thickness); | ||
line.setSize(sf::Vector2f(absolute.size.w, border.thickness)); | ||
window.draw(line); | ||
} | ||
if (border.down) { | ||
line.setPosition(absolute.position.x, absolute.position.y + absolute.size.h); | ||
line.setSize(sf::Vector2f(absolute.size.w, border.thickness)); | ||
window.draw(line); | ||
} | ||
if (border.left) { | ||
line.setPosition(absolute.position.x - border.thickness, absolute.position.y); | ||
line.setSize(sf::Vector2f(border.thickness, absolute.size.h)); | ||
window.draw(line); | ||
} | ||
if (border.right) { | ||
line.setPosition(absolute.position.x + absolute.size.w, absolute.position.y); | ||
line.setSize(sf::Vector2f(border.thickness, absolute.size.h)); | ||
window.draw(line); | ||
} | ||
} | ||
} | ||
|
||
void Border::init() { | ||
__init(); | ||
addReaction<RenderLayer>([this](futils::IMediatorPacket &pkg){ | ||
auto &packet = futils::Mediator::rebuild<RenderLayer>(pkg); | ||
for (auto &obj: packet.objects) | ||
{ | ||
if (!obj->has<components::Border>()) | ||
continue ; | ||
auto &border = obj->get<components::Border>(); | ||
if (border.visible) { | ||
renderBorder(border, *packet.window); | ||
} | ||
} | ||
}); | ||
phase = Run; | ||
} | ||
|
||
void Border::run(float) { | ||
switch (phase) | ||
{ | ||
case Init: return init(); | ||
case Run: return ; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Created by arroganz on 1/7/18. | ||
// | ||
|
||
|
||
#pragma once | ||
|
||
# include <SFML/Graphics.hpp> | ||
# include "System.hpp" | ||
# include "Components/Border.hpp" | ||
|
||
namespace fender::systems::SFMLSystems | ||
{ | ||
class Border : public System { | ||
enum States | ||
{ | ||
Init = 0, | ||
Run | ||
}; | ||
void renderBorder(components::Border const &, sf::RenderWindow &); | ||
void init(); | ||
bool shouldPrint; // debug only | ||
public: | ||
Border(): System("Border") {} | ||
void run(float) override; | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
project(SFML VERSION 1.0 DESCRIPTION "SFML system for fender") | ||
set(CMAKE_CXX_STANDARD 17) | ||
FILE (GLOB SOURCES ./*.cpp ./*.hpp) | ||
add_library(SFML SHARED ${SOURCES} include/events.hpp) | ||
target_include_directories(SFML PUBLIC include utils) | ||
target_link_libraries(SFML -lstdc++fs) | ||
set_target_properties(SFML PROPERTIES VERSION ${PROJECT_VERSION}) | ||
set_target_properties(SFML PROPERTIES PUBLIC_HEADER SFML.hpp) |
Oops, something went wrong.