Skip to content

Commit 1942048

Browse files
authored
Setup assets directory, demo JSON load (#2)
* Add `FileDataLoader` * Add `ServiceLocator` member
1 parent 24c9873 commit 1942048

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

assets/test_file.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"hello world"

src/app.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <imgui.h>
22
#include <app.hpp>
3+
#include <djson/json.hpp>
4+
#include <log.hpp>
35

46
namespace miracle {
57
namespace {
@@ -8,7 +10,13 @@ constexpr auto context_ci = le::Context::CreateInfo{
810
};
911
} // namespace
1012

11-
App::App() : m_context(context_ci) {}
13+
App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")) {
14+
bind_services();
15+
16+
// test code, remove later.
17+
auto json = dj::Json{};
18+
if (m_services.get<le::IDataLoader>().load_json(json, "test_file.json")) { log.info("loaded JSON: {}", json); }
19+
}
1220

1321
void App::run() {
1422
while (m_context.is_running()) {
@@ -19,4 +27,11 @@ void App::run() {
1927
m_context.present();
2028
}
2129
}
30+
31+
void App::bind_services() {
32+
m_services.bind(&m_context);
33+
// m_data_loader is bound to both the interface and the concrete class for use through either type.
34+
m_services.bind<le::IDataLoader>(&m_data_loader);
35+
m_services.bind<le::FileDataLoader>(&m_data_loader);
36+
}
2237
} // namespace miracle

src/app.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22
#include <le2d/context.hpp>
3+
#include <le2d/file_data_loader.hpp>
4+
#include <le2d/service_locator.hpp>
35

46
namespace miracle {
57
class App {
@@ -9,6 +11,11 @@ class App {
911
void run();
1012

1113
private:
14+
void bind_services();
15+
1216
le::Context m_context;
17+
le::FileDataLoader m_data_loader{};
18+
19+
le::ServiceLocator m_services{};
1320
};
1421
} // namespace miracle

0 commit comments

Comments
 (0)