#include <njin.h>
#include <string>
#include <vector>
namespace {
struct progress {
std::vector<std::string> items;
};
progress p;
std::string file(njin::context &ctx) {
return njin::save_path(ctx,
"save.json"); }
void save(njin::context &ctx) {
for (const std::string &it : p.items)
doc.
set(
"version", 1).
set(
"level", p.level).
set(
"volume", p.volume).
set(
"items", std::move(items));
}
void load(njin::context &ctx) {
return;
p.level = doc[
"level"].
int_or(1);
p.volume = doc[
"volume"].
f32_or(0.8f);
p.items.clear();
p.items.push_back(it.string_or(""));
}
void setup(njin::context &ctx) {
}
}
njin::mod_desc save_module() {
return {.name =
"save", .setup = setup}; }
std::string save_path(const context &ctx, const char *file_name)
Đường dẫn đầy đủ của một file lưu game, trong thư mục riêng của người dùng.
bool json_save(const char *path, const json_value &value, bool pretty=true)
Ghi một giá trị ra file JSON, tạo thư mục cha nếu cần.
bool json_load(const char *path, json_value &out)
Đọc và phân tích một file JSON.
void ecs_register(context &ctx, sys_phase phase, sys_fnc fnc, const char *name=nullptr)
Thêm một system vào lịch chạy của một phase.
@ phase_shutdown
Một lần, sau khi cửa sổ đóng.
Definition _mod.h:40
@ phase_startup
Một lần, trước frame đầu tiên.
Definition _mod.h:32
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
Một giá trị JSON: null, bool, số, chuỗi, mảng hoặc object.
Definition njin_json.h:33
i32 int_or(i32 fallback) const
Số nguyên (làm tròn về 0), hoặc fallback.
Definition njin_json.h:124
json_value & push(json_value value)
Thêm phần tử vào cuối mảng.
f32 f32_or(f32 fallback) const
Số thực 32 bit, hoặc fallback.
Definition njin_json.h:122
static json_value make_array()
Một mảng rỗng.
Definition njin_json.h:75
static json_value make_object()
Một object rỗng.
Definition njin_json.h:69
json_value & set(std::string_view key, json_value value)
Đặt thành viên key (thay nếu đã có, thêm vào cuối nếu chưa).
Mô tả một module: một nhóm system có tên.
Definition _mod.h:67