Skip to content

Commit

Permalink
feat(sfml): continuing lua sfml wrapper #58
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 1, 2019
1 parent 4c79393 commit 1c09453
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 0 additions & 1 deletion examples/sfml/flappy-bird-scripted/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ flappy_world::flappy_world() noexcept
auto &graphic_system = this->system_manager_.create_system<antara::gaming::sfml::graphic_system>();
this->system_manager_.create_system<antara::gaming::sfml::input_system>(graphic_system.get_window());
auto &scene_manager = this->system_manager_.create_system<antara::gaming::scenes::manager>();
//lua_scripting_system.load_scripted_system("scenes_system.lua");
scene_manager.change_scene(std::make_unique<antara::gaming::sfml::intro_scene>(entity_registry_, dispatcher_, [&lua_scripting_system, this]() {
lua_scripting_system.load_scripted_system("scenes_system.lua");
this->system_manager_.mark_system<antara::gaming::scenes::manager>();
Expand Down
1 change: 1 addition & 0 deletions modules/lua/antara/gaming/lua/antara.lua.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
******************************************************************************/

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

#include <doctest/doctest.h>
12 changes: 12 additions & 0 deletions modules/sfml/antara/gaming/sfml/lua.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
******************************************************************************/

#include "antara/gaming/sfml/lua.system.hpp"
#include "antara/gaming/sfml/component.drawable.hpp"

namespace antara::gaming::sfml
{
Expand All @@ -27,5 +28,16 @@ namespace antara::gaming::sfml
std::shared_ptr<sol::state> state) noexcept : system(registry, dispatcher), state_(state)
{
this->disable();
auto text_functor = [this](const char* text, const char *font_id, unsigned int size = 30) {
auto entity = this->entity_registry_.create();
auto handle = this->resource_mgr_.load_font(font_id);
this->entity_registry_.assign<sfml::text>(entity, sf::Text(text, handle.get(), size));
return entity;
};

auto overload_set = sol::overload(text_functor, [&text_functor](const char* text, const char *font_id) {
return text_functor(text, font_id);
});
(*this->state_)["antara"]["create_text_entity"] = overload_set;
}
}
2 changes: 2 additions & 0 deletions modules/sfml/antara/gaming/sfml/lua.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sol/state.hpp>
#include "antara/gaming/core/safe.refl.hpp"
#include "antara/gaming/ecs/system.hpp"
#include "antara/gaming/sfml/resources.manager.hpp"

namespace antara::gaming::sfml
{
Expand All @@ -30,6 +31,7 @@ namespace antara::gaming::sfml
void update() noexcept final;
private:
std::shared_ptr<sol::state> state_;
antara::gaming::sfml::resources_manager resource_mgr_;
};
}

Expand Down
20 changes: 19 additions & 1 deletion modules/sfml/antara/gaming/sfml/resources.manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,32 @@ namespace antara::gaming::sfml
static auto load(TCache &cache, const char *id, TArgs &&...args)
{
const auto identifier = entt::hashed_string::to_value(id);
if (contains<TCache>(cache, id)) {
return get<TCache>(cache, id);
}
return cache.template load<TLoader>(identifier, std::forward<TArgs>(args)...);
}

template<typename TCache>
static auto get(TCache &cache, const char *id)
{
const auto identifier = entt::hashed_string::to_value(id);
return cache.handle(identifier);
}

template<typename TCache>
static auto contains(TCache &cache, const char *id) noexcept
{
const auto identifier = entt::hashed_string::to_value(id);
return cache.contains(identifier);
}

texture_handle load_texture(const char *resource_id);

font_handle load_font(const char *resource_id);

sound_handle load_sound(const char* resource_id);
sound_handle load_sound(const char *resource_id);


private:
const std::filesystem::path assets_path_{antara::gaming::core::assets_real_path()};
Expand Down

0 comments on commit 1c09453

Please sign in to comment.