diff --git a/ext/src.zip b/ext/src.zip index 9119d18..3ebecc5 100644 Binary files a/ext/src.zip and b/ext/src.zip differ diff --git a/src/app.cpp b/src/app.cpp index a583071..a525495 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -14,7 +14,9 @@ constexpr auto context_ci = le::Context::CreateInfo{ }; } // namespace -App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")) { bind_services(); } +App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")), m_asset_loader(m_context.create_asset_loader(&m_data_loader)) { + bind_services(); +} void App::run() { auto game = Game{&m_services}; @@ -40,5 +42,7 @@ void App::bind_services() { // m_data_loader is bound to both the interface and the concrete class for use through either type. m_services.bind(&m_data_loader); m_services.bind(&m_data_loader); + + m_services.bind(&m_asset_loader); } } // namespace miracle diff --git a/src/app.hpp b/src/app.hpp index de44f45..1d63270 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -15,6 +15,7 @@ class App { le::Context m_context; le::FileDataLoader m_data_loader{}; + le::AssetLoader m_asset_loader{}; le::ServiceLocator m_services{}; }; diff --git a/src/enemy.hpp b/src/enemy.hpp index 20f6773..81d6c2a 100644 --- a/src/enemy.hpp +++ b/src/enemy.hpp @@ -7,9 +7,8 @@ #include #include #include -#include -#include "glm/vec2.hpp" -#include "le2d/texture.hpp" +#include +#include "le2d/resource/texture.hpp" namespace miracle { class Enemy { @@ -35,7 +34,7 @@ class Enemy { private: gsl::not_null m_services; - std::optional m_texture; + std::unique_ptr m_texture; le::drawable::Circle m_sprite{}; glm::vec2 m_target_pos{}; float m_move_speed{}; diff --git a/src/game.cpp b/src/game.cpp index 547aac5..3221fdb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -9,8 +8,6 @@ #include #include "enemy.hpp" #include "kvf/time.hpp" -#include "le2d/asset_loader.hpp" -#include "le2d/data_loader.hpp" #include "le2d/drawable/text.hpp" #include "lighthouse.hpp" #include "util/random.hpp" @@ -18,10 +15,9 @@ namespace miracle { Game::Game(gsl::not_null services) : m_services(services), m_lighthouse(services), m_light(services) { spawn_wave(); - auto const& data_loader = services->get(); - auto const& context = services->get(); - auto const asset_loader = le::AssetLoader{&data_loader, &context}; - m_font = asset_loader.load_font("fonts/specialElite.ttf"); + auto const& asset_loader = services->get(); + m_font = asset_loader.load("fonts/specialElite.ttf"); + if (!m_font) { throw std::runtime_error{"Failed to load font"}; } } void Game::on_cursor_pos(le::event::CursorPos const& cursor_pos) { @@ -79,7 +75,7 @@ void Game::update_score(int points) { m_score += points; m_score_str.clear(); std::format_to(std::back_inserter(m_score_str), "Score: {}", m_score); - m_score_text.set_string(m_font, m_score_str); + m_score_text.set_string(*m_font, m_score_str); } void Game::update_health_text() { @@ -95,7 +91,7 @@ void Game::update_health_text() { std::format_to(std::back_inserter(m_health_str), "Health: {:.1f}", m_lighthouse.get_health()); } - m_health_text.set_string(m_font, m_health_str); + m_health_text.set_string(*m_font, m_health_str); } } // namespace miracle diff --git a/src/game.hpp b/src/game.hpp index 2b52532..2b599db 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -4,10 +4,10 @@ #include #include #include -#include +#include #include "enemy.hpp" #include "le2d/drawable/text.hpp" -#include "le2d/font.hpp" +#include "le2d/resource/font.hpp" #include "light.hpp" #include "lighthouse.hpp" @@ -29,7 +29,7 @@ class Game { Lighthouse m_lighthouse; Light m_light; - le::Font m_font{}; + std::unique_ptr m_font{}; le::drawable::Text m_score_text{}; le::drawable::Text m_health_text{}; int m_score{}; diff --git a/src/light.hpp b/src/light.hpp index 5b0a1f4..79333bb 100644 --- a/src/light.hpp +++ b/src/light.hpp @@ -1,12 +1,11 @@ #pragma once #include "enemy.hpp" -#include "glm/vec2.hpp" #include "gsl/pointers" #include "le2d/drawable/shape.hpp" #include "le2d/renderer.hpp" +#include "le2d/resource/texture.hpp" #include "le2d/service_locator.hpp" -#include "le2d/texture.hpp" namespace miracle { class Light { @@ -19,7 +18,7 @@ class Light { private: gsl::not_null m_services; - std::optional m_texture; + std::unique_ptr m_texture; le::drawable::Circle m_sprite{}; float m_diameter{}; }; diff --git a/src/lighthouse.cpp b/src/lighthouse.cpp index 0be75fd..7b3bc8c 100644 --- a/src/lighthouse.cpp +++ b/src/lighthouse.cpp @@ -1,17 +1,13 @@ #include #include #include "glm/gtx/norm.hpp" -#include "le2d/asset_loader.hpp" -#include "le2d/data_loader.hpp" namespace miracle { Lighthouse::Lighthouse(gsl::not_null services) : m_services(services) { m_sprite.create(m_hitbox_diameter); - auto const& data_loader = services->get(); - auto const& context = services->get(); - auto const asset_loader = le::AssetLoader{&data_loader, &context}; - m_texture = asset_loader.load_texture("images/lighthouse.png"); - m_sprite.texture = &m_texture.value(); + auto const& asset_loader = services->get(); + m_texture = asset_loader.load("images/lighthouse.png"); + m_sprite.texture = m_texture.get(); } void Lighthouse::rotate_towards_cursor(glm::vec2 cursor_pos) { diff --git a/src/lighthouse.hpp b/src/lighthouse.hpp index 9170f64..7a035b2 100644 --- a/src/lighthouse.hpp +++ b/src/lighthouse.hpp @@ -6,10 +6,9 @@ #include #include #include -#include -#include +#include #include "enemy.hpp" -#include "le2d/texture.hpp" +#include "le2d/resource/texture.hpp" namespace miracle { class Lighthouse { @@ -27,7 +26,7 @@ class Lighthouse { gsl::not_null m_services; float m_hitbox_diameter{150.0f}; float m_visibility_diameter{250.0f}; - std::optional m_texture; + std::unique_ptr m_texture; le::drawable::Circle m_sprite{}; float m_health{100}; };