Skip to content

Setup assets directory, demo JSON load #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/test_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"hello world"
17 changes: 16 additions & 1 deletion src/app.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <imgui.h>
#include <app.hpp>
#include <djson/json.hpp>
#include <log.hpp>

namespace miracle {
namespace {
Expand All @@ -8,7 +10,13 @@ constexpr auto context_ci = le::Context::CreateInfo{
};
} // namespace

App::App() : m_context(context_ci) {}
App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")) {
bind_services();

// test code, remove later.
auto json = dj::Json{};
if (m_services.get<le::IDataLoader>().load_json(json, "test_file.json")) { log.info("loaded JSON: {}", json); }
}

void App::run() {
while (m_context.is_running()) {
Expand All @@ -19,4 +27,11 @@ void App::run() {
m_context.present();
}
}

void App::bind_services() {
m_services.bind(&m_context);
// m_data_loader is bound to both the interface and the concrete class for use through either type.
m_services.bind<le::IDataLoader>(&m_data_loader);
m_services.bind<le::FileDataLoader>(&m_data_loader);
}
} // namespace miracle
7 changes: 7 additions & 0 deletions src/app.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include <le2d/context.hpp>
#include <le2d/file_data_loader.hpp>
#include <le2d/service_locator.hpp>

namespace miracle {
class App {
Expand All @@ -9,6 +11,11 @@ class App {
void run();

private:
void bind_services();

le::Context m_context;
le::FileDataLoader m_data_loader{};

le::ServiceLocator m_services{};
};
} // namespace miracle