Merge branch 'main' of https://github.com/MihailRis/VoxelEngine-Cpp
This commit is contained in:
+22
-7
@@ -44,15 +44,27 @@ int64_t List::integer(size_t index) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map* List::map(size_t index) const {
|
Map* List::map(size_t index) const {
|
||||||
|
if (values[index]->type != valtype::map) {
|
||||||
|
throw std::runtime_error("type error");
|
||||||
|
}
|
||||||
return values[index]->value.map;
|
return values[index]->value.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
List* List::list(size_t index) const {
|
List* List::list(size_t index) const {
|
||||||
|
if (values[index]->type != valtype::list) {
|
||||||
|
throw std::runtime_error("type error");
|
||||||
|
}
|
||||||
return values[index]->value.list;
|
return values[index]->value.list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool List::flag(size_t index) const {
|
bool List::flag(size_t index) const {
|
||||||
return values[index]->value.boolean;
|
const auto& val = values[index];
|
||||||
|
switch (val->type) {
|
||||||
|
case valtype::integer: return val->value.integer;
|
||||||
|
case valtype::boolean: return val->value.boolean;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("type error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List& List::put(std::string value) {
|
List& List::put(std::string value) {
|
||||||
@@ -180,9 +192,14 @@ int64_t Map::getInt(std::string key, int64_t def) const {
|
|||||||
|
|
||||||
bool Map::getBool(std::string key, bool def) const {
|
bool Map::getBool(std::string key, bool def) const {
|
||||||
auto found = values.find(key);
|
auto found = values.find(key);
|
||||||
if (found != values.end())
|
if (found == values.end())
|
||||||
return found->second->value.boolean;
|
return def;
|
||||||
return def;
|
auto& val = found->second;
|
||||||
|
switch (val->type) {
|
||||||
|
case valtype::integer: return val->value.integer;
|
||||||
|
case valtype::boolean: return val->value.boolean;
|
||||||
|
default: throw std::runtime_error("type error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::num(std::string key, double& dst) const {
|
void Map::num(std::string key, double& dst) const {
|
||||||
@@ -232,9 +249,7 @@ List* Map::list(std::string key) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Map::flag(std::string key, bool& dst) const {
|
void Map::flag(std::string key, bool& dst) const {
|
||||||
auto found = values.find(key);
|
dst = getBool(key, dst);
|
||||||
if (found != values.end())
|
|
||||||
dst = found->second->value.boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map& Map::put(std::string key, uint value) {
|
Map& Map::put(std::string key, uint value) {
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ namespace dynamic {
|
|||||||
std::string* str;
|
std::string* str;
|
||||||
double decimal;
|
double decimal;
|
||||||
int64_t integer;
|
int64_t integer;
|
||||||
bool boolean;
|
uint64_t boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Value {
|
class Value {
|
||||||
|
|||||||
+2
-1
@@ -138,6 +138,7 @@ void Engine::loadContent() {
|
|||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
ContentBuilder contentBuilder;
|
ContentBuilder contentBuilder;
|
||||||
setup_definitions(&contentBuilder);
|
setup_definitions(&contentBuilder);
|
||||||
|
paths->setContentPacks(&contentPacks);
|
||||||
|
|
||||||
std::vector<fs::path> resRoots;
|
std::vector<fs::path> resRoots;
|
||||||
for (auto& pack : contentPacks) {
|
for (auto& pack : contentPacks) {
|
||||||
@@ -163,7 +164,7 @@ void Engine::loadContent() {
|
|||||||
}
|
}
|
||||||
assets->extend(*new_assets.get());
|
assets->extend(*new_assets.get());
|
||||||
|
|
||||||
paths->setContentPacks(&contentPacks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadWorldContent(const fs::path& folder) {
|
void Engine::loadWorldContent(const fs::path& folder) {
|
||||||
|
|||||||
@@ -250,9 +250,11 @@ void create_main_menu_panel(Engine* engine, PagesControl* menu) {
|
|||||||
|
|
||||||
typedef std::function<void(const ContentPack& pack)> packconsumer;
|
typedef std::function<void(const ContentPack& pack)> packconsumer;
|
||||||
|
|
||||||
|
const int PACKS_PANEL_WIDTH = 550;
|
||||||
|
|
||||||
std::shared_ptr<Panel> create_packs_panel(const std::vector<ContentPack>& packs, Engine* engine, bool backbutton, packconsumer callback) {
|
std::shared_ptr<Panel> create_packs_panel(const std::vector<ContentPack>& packs, Engine* engine, bool backbutton, packconsumer callback) {
|
||||||
auto assets = engine->getAssets();
|
auto assets = engine->getAssets();
|
||||||
auto panel = std::make_shared<Panel>(vec2(400, 200), vec4(5.0f));
|
auto panel = std::make_shared<Panel>(vec2(PACKS_PANEL_WIDTH, 200), vec4(5.0f));
|
||||||
panel->color(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
panel->color(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
||||||
panel->maxLength(400);
|
panel->maxLength(400);
|
||||||
panel->scrollable(true);
|
panel->scrollable(true);
|
||||||
@@ -266,7 +268,7 @@ std::shared_ptr<Panel> create_packs_panel(const std::vector<ContentPack>& packs,
|
|||||||
}
|
}
|
||||||
auto idlabel = std::make_shared<Label>("["+pack.id+"]");
|
auto idlabel = std::make_shared<Label>("["+pack.id+"]");
|
||||||
idlabel->color(vec4(1, 1, 1, 0.5f));
|
idlabel->color(vec4(1, 1, 1, 0.5f));
|
||||||
packpanel->add(idlabel, vec2(360-idlabel->size().x, 2));
|
packpanel->add(idlabel, vec2(PACKS_PANEL_WIDTH-40-idlabel->size().x, 2));
|
||||||
|
|
||||||
auto titlelabel = std::make_shared<Label>(pack.title);
|
auto titlelabel = std::make_shared<Label>(pack.title);
|
||||||
packpanel->add(titlelabel, vec2(78, 6));
|
packpanel->add(titlelabel, vec2(78, 6));
|
||||||
@@ -284,7 +286,7 @@ std::shared_ptr<Panel> create_packs_panel(const std::vector<ContentPack>& packs,
|
|||||||
if (!pack.creator.empty()) {
|
if (!pack.creator.empty()) {
|
||||||
auto creatorlabel = std::make_shared<Label>("@"+pack.creator);
|
auto creatorlabel = std::make_shared<Label>("@"+pack.creator);
|
||||||
creatorlabel->color(vec4(0.8f, 1.0f, 0.9f, 0.7f));
|
creatorlabel->color(vec4(0.8f, 1.0f, 0.9f, 0.7f));
|
||||||
packpanel->add(creatorlabel, vec2(360-creatorlabel->size().x, 60));
|
packpanel->add(creatorlabel, vec2(PACKS_PANEL_WIDTH-40-creatorlabel->size().x, 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto descriptionlabel = std::make_shared<Label>(pack.description);
|
auto descriptionlabel = std::make_shared<Label>(pack.description);
|
||||||
@@ -304,7 +306,7 @@ std::shared_ptr<Panel> create_packs_panel(const std::vector<ContentPack>& packs,
|
|||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
void create_content_panel(Engine* engine, PagesControl* menu) {
|
void create_content_panel(Engine* engine, PagesControl* menu) {
|
||||||
auto paths = engine->getPaths();
|
auto paths = engine->getPaths();
|
||||||
auto mainPanel = create_page(engine, "content", 400, 0.0f, 5);
|
auto mainPanel = create_page(engine, "content", PACKS_PANEL_WIDTH, 0.0f, 5);
|
||||||
|
|
||||||
std::vector<ContentPack> scanned;
|
std::vector<ContentPack> scanned;
|
||||||
ContentPack::scan(engine->getPaths(), scanned);
|
ContentPack::scan(engine->getPaths(), scanned);
|
||||||
|
|||||||
Reference in New Issue
Block a user