Working on initial stages of procedural generator
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -68,7 +68,8 @@
|
|||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"variant": "cpp",
|
"variant": "cpp",
|
||||||
"format": "cpp",
|
"format": "cpp",
|
||||||
"future": "cpp"
|
"future": "cpp",
|
||||||
|
"cassert": "cpp"
|
||||||
},
|
},
|
||||||
"cmake.ignoreCMakeListsMissing": true
|
"cmake.ignoreCMakeListsMissing": true
|
||||||
}
|
}
|
||||||
@@ -2,112 +2,132 @@
|
|||||||
|
|
||||||
entries=[ {
|
entries=[ {
|
||||||
"children": [ 1, 2, 3 ],
|
"children": [ 1, 2, 3 ],
|
||||||
|
"floor_index": 0,
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"name": "v1",
|
"name": "v1",
|
||||||
"type": "layout"
|
"type": "layout"
|
||||||
}, {
|
}, {
|
||||||
"children": [ 4, 5 ],
|
"children": [ 4, 5, 6 ],
|
||||||
"index": 1,
|
"index": 1,
|
||||||
|
"name": "zone_0",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 0
|
||||||
|
}, {
|
||||||
|
"children": [ 7, 8, 9, 10 ],
|
||||||
|
"index": 2,
|
||||||
|
"name": "zone_1",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 1
|
||||||
|
}, {
|
||||||
|
"children": [ 11, 12 ],
|
||||||
|
"index": 3,
|
||||||
"name": "unit_0",
|
"name": "unit_0",
|
||||||
"type": "unit"
|
"type": "unit"
|
||||||
}, {
|
}, {
|
||||||
"children": [ 6, 7, 8 ],
|
|
||||||
"index": 2,
|
|
||||||
"name": "zone_0",
|
|
||||||
"type": "zone",
|
|
||||||
"zone_type": 0
|
|
||||||
}, {
|
|
||||||
"children": [ 9, 10, 11 ],
|
|
||||||
"index": 3,
|
|
||||||
"name": "zone_1",
|
|
||||||
"type": "zone",
|
|
||||||
"zone_type": 1
|
|
||||||
}, {
|
|
||||||
"children": [ 12, 13, 14 ],
|
|
||||||
"index": 4,
|
|
||||||
"name": "zone_0",
|
|
||||||
"type": "zone",
|
|
||||||
"zone_type": 0
|
|
||||||
}, {
|
|
||||||
"children": [ 15, 16 ],
|
|
||||||
"index": 5,
|
|
||||||
"name": "zone_1",
|
|
||||||
"type": "zone",
|
|
||||||
"zone_type": 1
|
|
||||||
}, {
|
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 6,
|
"index": 4,
|
||||||
"name": "wc_0",
|
"name": "wc_0",
|
||||||
|
"room_area": 4.0,
|
||||||
"room_type": 200,
|
"room_type": 200,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 7,
|
"index": 5,
|
||||||
"name": "bathroom_0",
|
"name": "bathroom_0",
|
||||||
|
"room_area": 16.0,
|
||||||
"room_type": 201,
|
"room_type": 201,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 8,
|
"index": 6,
|
||||||
"name": "bedroom_0",
|
"name": "bedroom_0",
|
||||||
|
"room_area": 36.0,
|
||||||
"room_type": 202,
|
"room_type": 202,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
|
"index": 7,
|
||||||
|
"name": "living_room_0",
|
||||||
|
"room_area": 36.0,
|
||||||
|
"room_type": 300,
|
||||||
|
"type": "room",
|
||||||
|
"window": true
|
||||||
|
}, {
|
||||||
|
"children": [ ],
|
||||||
|
"index": 8,
|
||||||
|
"name": "kitchen_0",
|
||||||
|
"room_area": 16.0,
|
||||||
|
"room_type": 302,
|
||||||
|
"type": "room",
|
||||||
|
"window": true
|
||||||
|
}, {
|
||||||
|
"children": [ ],
|
||||||
"index": 9,
|
"index": 9,
|
||||||
"name": "living_room_0",
|
|
||||||
"room_type": 300,
|
|
||||||
"type": "room",
|
|
||||||
"window": true
|
|
||||||
}, {
|
|
||||||
"children": [ ],
|
|
||||||
"index": 10,
|
|
||||||
"name": "kitchen_0",
|
|
||||||
"room_type": 302,
|
|
||||||
"type": "room",
|
|
||||||
"window": true
|
|
||||||
}, {
|
|
||||||
"children": [ ],
|
|
||||||
"index": 11,
|
|
||||||
"name": "storage_room_0",
|
"name": "storage_room_0",
|
||||||
|
"room_area": 16.0,
|
||||||
"room_type": 307,
|
"room_type": 307,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
|
"index": 10,
|
||||||
|
"name": "enterance_0",
|
||||||
|
"room_area": 16.0,
|
||||||
|
"room_type": 304,
|
||||||
|
"type": "room",
|
||||||
|
"window": true
|
||||||
|
}, {
|
||||||
|
"children": [ 13, 14, 15 ],
|
||||||
|
"index": 11,
|
||||||
|
"name": "zone_0",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 0
|
||||||
|
}, {
|
||||||
|
"children": [ 16, 17 ],
|
||||||
"index": 12,
|
"index": 12,
|
||||||
|
"name": "zone_1",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 1
|
||||||
|
}, {
|
||||||
|
"children": [ ],
|
||||||
|
"index": 13,
|
||||||
"name": "bedroom_0",
|
"name": "bedroom_0",
|
||||||
|
"room_area": 36.0,
|
||||||
"room_type": 202,
|
"room_type": 202,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 13,
|
"index": 14,
|
||||||
"name": "bathroom_0",
|
"name": "bathroom_0",
|
||||||
|
"room_area": 16.0,
|
||||||
"room_type": 201,
|
"room_type": 201,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 14,
|
"index": 15,
|
||||||
"name": "wc_0",
|
"name": "wc_0",
|
||||||
|
"room_area": 4.0,
|
||||||
"room_type": 200,
|
"room_type": 200,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 15,
|
"index": 16,
|
||||||
"name": "living_room_0",
|
"name": "living_room_0",
|
||||||
|
"room_area": 36.0,
|
||||||
"room_type": 300,
|
"room_type": 300,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 16,
|
"index": 17,
|
||||||
"name": "kitchen_0",
|
"name": "kitchen_0",
|
||||||
|
"room_area": 16.0,
|
||||||
"room_type": 302,
|
"room_type": 302,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
|
|||||||
@@ -1,12 +1,69 @@
|
|||||||
|
#undef NDEBUG
|
||||||
|
#include <cassert>
|
||||||
#include <core/os/memory.h>
|
#include <core/os/memory.h>
|
||||||
|
#include <core/object.h>
|
||||||
|
#include <scene/main/scene_tree.h>
|
||||||
#include "base_data.h"
|
#include "base_data.h"
|
||||||
|
|
||||||
static BaseData *base_data = nullptr;
|
static BaseData *base_data = nullptr;
|
||||||
|
|
||||||
|
class Updater : public Object {
|
||||||
|
GDCLASS(Updater, Object)
|
||||||
|
BaseData *base;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Updater(BaseData *base)
|
||||||
|
: Object()
|
||||||
|
, base(base)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~Updater()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
float delta =
|
||||||
|
SceneTree::get_singleton()->get_physics_process_time();
|
||||||
|
base->update(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods()
|
||||||
|
{
|
||||||
|
ClassDB::bind_method(D_METHOD("update"), &Updater::update);
|
||||||
|
ClassDB::bind_method(D_METHOD("setup"), &Updater::setup);
|
||||||
|
}
|
||||||
|
void _notification(int what)
|
||||||
|
{
|
||||||
|
switch (what) {
|
||||||
|
case NOTIFICATION_POSTINITIALIZE:
|
||||||
|
call_deferred("setup");
|
||||||
|
break;
|
||||||
|
case NOTIFICATION_PREDELETE:
|
||||||
|
SceneTree::get_singleton()->disconnect("physics_frame",
|
||||||
|
this, "update");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
assert(SceneTree::get_singleton());
|
||||||
|
SceneTree::get_singleton()->connect("physics_frame", this,
|
||||||
|
"update");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static Updater *updater = nullptr;
|
||||||
|
|
||||||
BaseData::BaseData()
|
BaseData::BaseData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseData::update(float delta)
|
||||||
|
{
|
||||||
|
BaseData::get_singleton()->get().progress(delta);
|
||||||
|
}
|
||||||
|
|
||||||
flecs::world &BaseData::get()
|
flecs::world &BaseData::get()
|
||||||
{
|
{
|
||||||
return ecs;
|
return ecs;
|
||||||
@@ -14,6 +71,8 @@ flecs::world &BaseData::get()
|
|||||||
|
|
||||||
BaseData::~BaseData()
|
BaseData::~BaseData()
|
||||||
{
|
{
|
||||||
|
if (updater)
|
||||||
|
memdelete(updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseData *BaseData::get_singleton()
|
BaseData *BaseData::get_singleton()
|
||||||
@@ -30,3 +89,9 @@ void BaseData::cleanup()
|
|||||||
base_data = nullptr;
|
base_data = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseData::setup()
|
||||||
|
{
|
||||||
|
if (!updater)
|
||||||
|
updater = memnew(Updater(this));
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,5 +12,7 @@ public:
|
|||||||
virtual ~BaseData();
|
virtual ~BaseData();
|
||||||
static BaseData *get_singleton();
|
static BaseData *get_singleton();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
void setup();
|
||||||
|
void update(float delta);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -84,45 +84,12 @@ struct module {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Updater : public Object {
|
|
||||||
GDCLASS(Updater, Object)
|
|
||||||
NPC *base;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Updater(NPC *base)
|
|
||||||
: Object()
|
|
||||||
, base(base)
|
|
||||||
{
|
|
||||||
SceneTree::get_singleton()->connect("physics_frame", this,
|
|
||||||
"update");
|
|
||||||
}
|
|
||||||
virtual ~Updater()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void update()
|
|
||||||
{
|
|
||||||
float delta =
|
|
||||||
SceneTree::get_singleton()->get_physics_process_time();
|
|
||||||
base->update(delta);
|
|
||||||
print_line("Update running");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods()
|
|
||||||
{
|
|
||||||
ClassDB::bind_method(D_METHOD("update"), &Updater::update);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static Updater *updater = nullptr;
|
|
||||||
|
|
||||||
NPC::NPC()
|
NPC::NPC()
|
||||||
{
|
{
|
||||||
flecs::world ecs = BaseData::get_singleton()->get();
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
ecs.import <NPCModule::module>();
|
ecs.import <NPCModule::module>();
|
||||||
flecs::entity npcs_e = ecs.entity("npc");
|
flecs::entity npcs_e = ecs.entity("npc");
|
||||||
if (!updater)
|
|
||||||
updater = memnew(Updater(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NPC *NPC::get_singleton()
|
NPC *NPC::get_singleton()
|
||||||
@@ -143,5 +110,4 @@ NPC::~NPC()
|
|||||||
|
|
||||||
void NPC::update(float delta)
|
void NPC::update(float delta)
|
||||||
{
|
{
|
||||||
BaseData::get_singleton()->get().progress(delta);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "line_metadata_editor.h"
|
#include "line_metadata_editor.h"
|
||||||
#include "buildings/building_layout_editor.h"
|
#include "buildings/building_layout_editor.h"
|
||||||
#include "ui/main_tabs.h"
|
#include "ui/main_tabs.h"
|
||||||
|
#include "base_data.h"
|
||||||
|
|
||||||
void register_stream_types()
|
void register_stream_types()
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,7 @@ void register_stream_types()
|
|||||||
ClassDB::register_class<LineMetadataEditor>();
|
ClassDB::register_class<LineMetadataEditor>();
|
||||||
ClassDB::register_class<BuildingLayoutEditor>();
|
ClassDB::register_class<BuildingLayoutEditor>();
|
||||||
ClassDB::register_class<MainTabs>();
|
ClassDB::register_class<MainTabs>();
|
||||||
|
BaseData::get_singleton()->setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_stream_types()
|
void unregister_stream_types()
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "base_data.h"
|
#include "base_data.h"
|
||||||
#include "world_editor.h"
|
#include "world_editor.h"
|
||||||
|
#include "editor_event.h"
|
||||||
#include "building_layout_graph.h"
|
#include "building_layout_graph.h"
|
||||||
|
|
||||||
BuildingLayoutGraph *BuildingLayoutGraph::singleton = nullptr;
|
BuildingLayoutGraph *BuildingLayoutGraph::singleton = nullptr;
|
||||||
|
|
||||||
BuildingLayoutGraph::BuildingLayoutGraph()
|
BuildingLayoutGraph::BuildingLayoutGraph()
|
||||||
{
|
{
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.import <BuildingLayoutGraph::graph_module>();
|
||||||
Error err = config.load("res://astream/building_layout.conf");
|
Error err = config.load("res://astream/building_layout.conf");
|
||||||
assert(err == OK);
|
assert(err == OK);
|
||||||
public_rooms = config.get_value("rooms", "public", Array());
|
public_rooms = config.get_value("rooms", "public", Array());
|
||||||
@@ -80,7 +84,7 @@ void BuildingLayoutGraph::create_unit(const String &base_path)
|
|||||||
|
|
||||||
void BuildingLayoutGraph::create_floor(const String &base_path)
|
void BuildingLayoutGraph::create_floor(const String &base_path)
|
||||||
{
|
{
|
||||||
flecs::entity new_e = create_graph_entity(base_path, "unit");
|
flecs::entity new_e = create_graph_entity(base_path, "floor");
|
||||||
new_e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
new_e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +100,7 @@ void BuildingLayoutGraph::create_room(const String &base_path, int id)
|
|||||||
flecs::entity new_e = create_graph_entity(base_path, type_name);
|
flecs::entity new_e = create_graph_entity(base_path, type_name);
|
||||||
new_e.set<WorldEditor::components::buildings_layout_room>(
|
new_e.set<WorldEditor::components::buildings_layout_room>(
|
||||||
{ id, window });
|
{ id, window });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_area>({ 0.0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildingLayoutGraph::destroy_graph_entity(const String &path)
|
void BuildingLayoutGraph::destroy_graph_entity(const String &path)
|
||||||
@@ -125,6 +130,25 @@ flecs::entity BuildingLayoutGraph::get_layout_base() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flecs::entity BuildingLayoutGraph::get_layout_grid_base() const
|
||||||
|
{
|
||||||
|
const String &layout_grid_name = "buildings_layout_grid_v2";
|
||||||
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
|
flecs::entity layout_base_e =
|
||||||
|
ecs.lookup(layout_grid_name.ascii().ptr());
|
||||||
|
if (layout_base_e.is_valid()) {
|
||||||
|
assert(layout_base_e.has<
|
||||||
|
WorldEditor::components::buildings_layout_grid_base>());
|
||||||
|
return layout_base_e;
|
||||||
|
} else {
|
||||||
|
layout_base_e = ecs.entity(layout_grid_name.ascii().ptr());
|
||||||
|
assert(layout_base_e.is_valid());
|
||||||
|
layout_base_e.add<
|
||||||
|
WorldEditor::components::buildings_layout_grid_base>();
|
||||||
|
return layout_base_e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BuildingLayoutGraph::get_layout_list(List<String> *keys) const
|
void BuildingLayoutGraph::get_layout_list(List<String> *keys) const
|
||||||
{
|
{
|
||||||
flecs::entity base = get_layout_base();
|
flecs::entity base = get_layout_base();
|
||||||
@@ -145,6 +169,7 @@ void BuildingLayoutGraph::create_new_layout(const String &layout_name)
|
|||||||
if (e.is_valid()) {
|
if (e.is_valid()) {
|
||||||
e.add<WorldEditor::components::buildings_layout_graph>();
|
e.add<WorldEditor::components::buildings_layout_graph>();
|
||||||
e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
||||||
|
e.set<WorldEditor::components::buildings_layout_area>({ 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,10 +403,23 @@ void BuildingLayoutGraph::save_layouts()
|
|||||||
if (e.has<WorldEditor::components::buildings_layout_graph>()) {
|
if (e.has<WorldEditor::components::buildings_layout_graph>()) {
|
||||||
entry["type"] = "layout";
|
entry["type"] = "layout";
|
||||||
/* remember it has floor component too */
|
/* remember it has floor component too */
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()) {
|
||||||
|
int floor_index =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index;
|
||||||
|
entry["floor_index"] = floor_index;
|
||||||
|
}
|
||||||
} else if (e.has<WorldEditor::components::
|
} else if (e.has<WorldEditor::components::
|
||||||
buildings_layout_floor>()) {
|
buildings_layout_floor_index>()) {
|
||||||
/* non-root floor */
|
/* non-root floor */
|
||||||
entry["type"] = "floor";
|
entry["type"] = "floor";
|
||||||
|
int floor_index =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index;
|
||||||
|
entry["floor_index"] = floor_index;
|
||||||
} else if (e.has<WorldEditor::components::
|
} else if (e.has<WorldEditor::components::
|
||||||
buildings_layout_zone>()) {
|
buildings_layout_zone>()) {
|
||||||
entry["type"] = "zone";
|
entry["type"] = "zone";
|
||||||
@@ -403,6 +441,15 @@ void BuildingLayoutGraph::save_layouts()
|
|||||||
buildings_layout_room>()
|
buildings_layout_room>()
|
||||||
->window;
|
->window;
|
||||||
entry["window"] = window;
|
entry["window"] = window;
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
float room_area =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
entry["room_area"] = room_area;
|
||||||
|
} else
|
||||||
|
entry["room_area"] = 0.0f;
|
||||||
}
|
}
|
||||||
entries[index] = entry;
|
entries[index] = entry;
|
||||||
}
|
}
|
||||||
@@ -416,6 +463,7 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
List<int> queue;
|
List<int> queue;
|
||||||
flecs::world ecs = BaseData::get_singleton()->get();
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
flecs::entity base = get_layout_base();
|
flecs::entity base = get_layout_base();
|
||||||
|
assert(base.is_valid());
|
||||||
ConfigFile config_layouts;
|
ConfigFile config_layouts;
|
||||||
config_layouts.load("res://astream/building_layout_data.conf");
|
config_layouts.load("res://astream/building_layout_data.conf");
|
||||||
Array entities =
|
Array entities =
|
||||||
@@ -447,27 +495,61 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
flecs::entity parent_e = base;
|
flecs::entity parent_e = base;
|
||||||
if (parent >= 0)
|
if (parent >= 0)
|
||||||
parent_e = entity_index[parent];
|
parent_e = entity_index[parent];
|
||||||
|
assert(parent_e.is_valid());
|
||||||
flecs::entity e =
|
flecs::entity e =
|
||||||
ecs.entity(name.ascii().ptr()).child_of(parent_e);
|
ecs.entity(name.ascii().ptr()).child_of(parent_e);
|
||||||
|
assert(e.is_valid());
|
||||||
|
print_line(String(e.path()));
|
||||||
if (type == "layout") {
|
if (type == "layout") {
|
||||||
e.add<WorldEditor::components::buildings_layout_graph>();
|
e.add<WorldEditor::components::buildings_layout_graph>();
|
||||||
e.set<WorldEditor::components::buildings_layout_floor>(
|
if (entry.has("floor_index")) {
|
||||||
{ 0 });
|
int floor_index = entry["floor_index"];
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor>({ 0 });
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ floor_index });
|
||||||
|
} else
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor>({ 0 });
|
||||||
} else if (type == "floor") {
|
} else if (type == "floor") {
|
||||||
e.set<WorldEditor::components::buildings_layout_floor>(
|
if (entry.has("floor_index")) {
|
||||||
{ 0 });
|
int floor_index = entry["floor_index"];
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor>({ 0 });
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ floor_index });
|
||||||
|
} else {
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor>({ 0 });
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ 0 });
|
||||||
|
}
|
||||||
} else if (type == "zone") {
|
} else if (type == "zone") {
|
||||||
int zone_type = entry["zone_type"];
|
int zone_type = entry["zone_type"];
|
||||||
e.set<WorldEditor::components::buildings_layout_zone>(
|
e.set<WorldEditor::components::buildings_layout_zone>(
|
||||||
{ zone_type });
|
{ zone_type });
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
} else if (type == "unit") {
|
} else if (type == "unit") {
|
||||||
e.set<WorldEditor::components::buildings_layout_unit>(
|
e.set<WorldEditor::components::buildings_layout_unit>(
|
||||||
{ 0 });
|
{ 0 });
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
} else if (type == "room") {
|
} else if (type == "room") {
|
||||||
int room_type = entry["room_type"];
|
int room_type = entry["room_type"];
|
||||||
bool window = entry["window"];
|
bool window = entry["window"];
|
||||||
e.set<WorldEditor::components::buildings_layout_room>(
|
e.set<WorldEditor::components::buildings_layout_room>(
|
||||||
{ room_type, window });
|
{ room_type, window });
|
||||||
|
if (entry.has("room_area")) {
|
||||||
|
float room_area = entry["room_area"];
|
||||||
|
assert(e.is_valid());
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_area>(
|
||||||
|
{ room_area });
|
||||||
|
} else
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_area>({ 0.0f });
|
||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
entity_index[index] = e;
|
entity_index[index] = e;
|
||||||
@@ -477,10 +559,676 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BuildingLayoutGraph::create_interior_tilemap(const String &layout_name)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
flecs::entity base_e = get_layout_base();
|
||||||
|
queue.push_back(base_e);
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity e = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
if (e.has<WorldEditor::components::buildings_layout_room_size>()) {
|
||||||
|
if (e.parent()
|
||||||
|
.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone>()) {
|
||||||
|
if (e.parent()
|
||||||
|
.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.children([&queue](flecs::entity ce) { queue.push_back(ce); });
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int BuildingLayoutGraph::get_layout_count() const
|
int BuildingLayoutGraph::get_layout_count() const
|
||||||
{
|
{
|
||||||
flecs::entity e = get_layout_base();
|
flecs::entity base_e = get_layout_base();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
e.children([&count](flecs::entity e) { count++; });
|
base_e.children([&count](flecs::entity e) { count++; });
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
||||||
|
{
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_graph>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_base>();
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_floor &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_unit>("UnitArea")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_unit &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_zone>("ZoneArea")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_zone &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_area,
|
||||||
|
const WorldEditor::components::buildings_layout_zone,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"MakeZoneAreas")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
const WorldEditor::components::buildings_layout_zone &f,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx) {
|
||||||
|
flecs::entity zone_e = it.entity(count);
|
||||||
|
int index = idx.index;
|
||||||
|
float parea = 0.0f;
|
||||||
|
zone_e.children([index, &parea](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_room>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
if (ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index == index)
|
||||||
|
parea +=
|
||||||
|
ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
area.area = parea;
|
||||||
|
print_line(String(zone_e.path()) +
|
||||||
|
" area: " + String::num(area.area));
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_area,
|
||||||
|
const WorldEditor::components::buildings_layout_unit,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"MakeUnitAreas")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
const WorldEditor::components::buildings_layout_unit &f,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx) {
|
||||||
|
flecs::entity zone_e = it.entity(count);
|
||||||
|
int index = idx.index;
|
||||||
|
float parea = 0.0f;
|
||||||
|
zone_e.children([index, &parea](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
if (ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index == index)
|
||||||
|
parea +=
|
||||||
|
ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
area.area = parea;
|
||||||
|
print_line(String(zone_e.path()) +
|
||||||
|
" area: " + String::num(area.area));
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"MakeFloorAreas")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&f,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
int index = idx.index;
|
||||||
|
float parea = 0.0f;
|
||||||
|
floor_e.children([index, &parea](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
if (ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index == index)
|
||||||
|
parea +=
|
||||||
|
ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
}
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_unit>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>() &&
|
||||||
|
ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
if (ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index == index)
|
||||||
|
parea +=
|
||||||
|
ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
area.area = parea;
|
||||||
|
print_line(String(floor_e.path()) +
|
||||||
|
" area: " + String::num(area.area));
|
||||||
|
});
|
||||||
|
#if 0
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"MakeAreas")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
// .read<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&f,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
flecs::world ecs_ = floor_e.world();
|
||||||
|
ecs_.system(ecs_.lookup("MakeZoneAreas")).run();
|
||||||
|
ecs_.system(ecs_.lookup("MakeUnitAreas")).run();
|
||||||
|
ecs_.system(ecs_.lookup("MakeFloorAreas")).run();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"MakeGridEntities")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
// .read<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&f,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx) {
|
||||||
|
#if 0
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
assert(false);
|
||||||
|
floor_e.children([&queue](flecs::entity ec) {
|
||||||
|
if (!ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>())
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity e = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
#if 0
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_zone>(
|
||||||
|
"CreateZoneData")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_zone_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_zone_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_zone
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
e.set<WorldEditor::components::buildings_layout_zone_data>(
|
||||||
|
{ 0.0f, false });
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
String path(it.entity(count).path());
|
||||||
|
print_line("Create zone data: entity: " + path);
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_unit>(
|
||||||
|
"CreateUnitData")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_unit_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_unit_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_unit
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
e.set<WorldEditor::components::buildings_layout_unit_data>(
|
||||||
|
{ 0.0f });
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
String path(it.entity(count).path());
|
||||||
|
print_line("Create unit data: entity: " + path);
|
||||||
|
});
|
||||||
|
#if 0
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor>("CreateFloorIndex")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.without<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
e.set<WorldEditor::components::buildings_layout_unit_data>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_unit>(
|
||||||
|
"UpdateUnitData")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_unit_data>()
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_unit_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_unit
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
float area = 0.0f;
|
||||||
|
e.children([&area](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>())
|
||||||
|
area += ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>()
|
||||||
|
->area;
|
||||||
|
});
|
||||||
|
WorldEditor::components::buildings_layout_unit_data
|
||||||
|
*udata = e.get_mut<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_unit_data>();
|
||||||
|
udata->area = area;
|
||||||
|
String path(it.entity(count).path());
|
||||||
|
print_line("Update unit data: entity: " + path +
|
||||||
|
" area: " + String::num(area));
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_base()
|
||||||
|
.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_zone>(
|
||||||
|
"UpdateZoneData")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_zone_data>()
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_zone_data>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_zone
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
float area = 0.0f;
|
||||||
|
bool window = false;
|
||||||
|
e.children([&area, &window](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_room_size>())
|
||||||
|
area += ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_room_size>()
|
||||||
|
->area;
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_room>()) {
|
||||||
|
bool w =
|
||||||
|
ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_room>()
|
||||||
|
->window;
|
||||||
|
if (w)
|
||||||
|
window = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
WorldEditor::components::buildings_layout_zone_data
|
||||||
|
*zdata = e.get_mut<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>();
|
||||||
|
zdata->area = area;
|
||||||
|
zdata->align_wall = window;
|
||||||
|
String path(it.entity(count).path());
|
||||||
|
print_line("Update zone data: entity: " + path +
|
||||||
|
" area: " + String::num(area));
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
flecs::entity parent_e = e.parent();
|
||||||
|
if (parent_e.has<WorldEditor::components::
|
||||||
|
buildings_layout_unit>())
|
||||||
|
parent_e.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_base()
|
||||||
|
.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor>(
|
||||||
|
"PropogateFloorIndex")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_floor_data>()
|
||||||
|
.immediate()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&r) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
print_line("propogate: " + String(e.path()) + " " +
|
||||||
|
itos(r.index));
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
float area = 0.0f;
|
||||||
|
/* e is a floor so skip it and add children instead*/
|
||||||
|
e.children([&area](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_unit_data>())
|
||||||
|
area += ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_unit_data>()
|
||||||
|
->area;
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>())
|
||||||
|
area += ec.get<WorldEditor::components::
|
||||||
|
buildings_layout_zone_data>()
|
||||||
|
->area;
|
||||||
|
});
|
||||||
|
float size = Math::ceil(Math::sqrt(area) * 2.0f);
|
||||||
|
int grid_size = (int)Math::ceil(size / 2.0f);
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_data>(
|
||||||
|
{ area, grid_size });
|
||||||
|
e.children([&queue](flecs::entity ec) {
|
||||||
|
/* do not add children floors to the queue */
|
||||||
|
if (!ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>())
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity qe = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
if (!qe.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
/* do not add children under another floor either */
|
||||||
|
qe.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ r.index });
|
||||||
|
qe.children([&queue](flecs::entity ec) {
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_base()
|
||||||
|
.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
#if 0
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_graph>(
|
||||||
|
"CollectFloors")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_graph
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
queue.push_back(e);
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity em = queue.front()->get();
|
||||||
|
if (em.has<WorldEditor::components::buildings_layout_floor_data)
|
||||||
|
queue.pop_front();
|
||||||
|
em.children([&queue](flecs::entity ec) {
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_base>(
|
||||||
|
"DestroyGrid")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.immediate()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_base
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
flecs::entity grid_base_e =
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_grid_base();
|
||||||
|
grid_base_e.children([](flecs::entity ce) {
|
||||||
|
print_line("delete: " + String(ce.path()));
|
||||||
|
ce.destruct();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_base>("CreateGrid")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.immediate()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_base
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
flecs::entity grid_base_e =
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_grid_base();
|
||||||
|
e.children([&grid_base_e](flecs::entity ec) {
|
||||||
|
if (ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_graph>()) {
|
||||||
|
print_line(String(grid_base_e.path()));
|
||||||
|
flecs::entity gc =
|
||||||
|
ec.world()
|
||||||
|
.entity(ec.name())
|
||||||
|
.child_of(grid_base_e);
|
||||||
|
gc.add<WorldEditor::components::
|
||||||
|
buildings_layout_grid>();
|
||||||
|
gc.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
print_line("create: " +
|
||||||
|
String(gc.path()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_grid>(
|
||||||
|
"PopulateGrid")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.immediate()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_grid
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
flecs::entity grid_layout_e =
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_base();
|
||||||
|
flecs::entity layout_e
|
||||||
|
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_base>(
|
||||||
|
"UpdateGraph")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_base
|
||||||
|
&p) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
EditorEvent::get_singleton()->event.emit(
|
||||||
|
"update_layout_view", varray());
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
ecs.observer<WorldEditor::components::buildings_layout_room>()
|
||||||
|
.event(flecs::OnSet)
|
||||||
|
.each([](flecs::entity e,
|
||||||
|
WorldEditor::components::buildings_layout_room &r) {
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
print_line("room set " + String(e.path()));
|
||||||
|
});
|
||||||
|
ecs.observer<WorldEditor::components::buildings_layout_zone>()
|
||||||
|
.event(flecs::OnSet)
|
||||||
|
.each([](flecs::entity e,
|
||||||
|
WorldEditor::components::buildings_layout_zone &r) {
|
||||||
|
e.add<WorldEditor::components::buildings_layout_zone>();
|
||||||
|
print_line("zone set " + String(e.path()));
|
||||||
|
});
|
||||||
|
ecs.observer<WorldEditor::components::buildings_layout_unit>()
|
||||||
|
.event(flecs::OnSet)
|
||||||
|
.each([](flecs::entity e,
|
||||||
|
WorldEditor::components::buildings_layout_unit &r) {
|
||||||
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
print_line("unit set " + String(e.path()));
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
ecs.system<const WorldEditor::components::buildings_layout_floor,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index,
|
||||||
|
const WorldEditor::components::buildings_layout_area>(
|
||||||
|
"FinishGraphUpdate")
|
||||||
|
.kind(flecs::OnUpdate)
|
||||||
|
.with<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&p,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx,
|
||||||
|
const WorldEditor::components::buildings_layout_area
|
||||||
|
&area) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
EditorEvent::get_singleton()->event.emit(
|
||||||
|
"update_layout_view", varray());
|
||||||
|
e.remove<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
});
|
||||||
|
|
||||||
|
ecs.observer<const WorldEditor::components::buildings_layout_area>()
|
||||||
|
.event(flecs::OnSet)
|
||||||
|
.with<WorldEditor::components::buildings_layout_room>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
|
.each([](flecs::entity e,
|
||||||
|
const WorldEditor::components::buildings_layout_area
|
||||||
|
&r) {
|
||||||
|
/* if set for room make zone dirty */
|
||||||
|
flecs::entity parent_e = e.parent();
|
||||||
|
while (parent_e.is_valid()) {
|
||||||
|
print_line(String(parent_e.path()));
|
||||||
|
if (parent_e.has<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
parent_e.add<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent_e = parent_e.parent();
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
if (parent_e.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone>())
|
||||||
|
parent_e.add<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
parent_e.set<WorldEditor::components::
|
||||||
|
buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
flecs::world ecs_ = e.world();
|
||||||
|
ecs_.system(ecs_.lookup("MakeZoneAreas")).run();
|
||||||
|
ecs_.system(ecs_.lookup("MakeUnitAreas")).run();
|
||||||
|
ecs_.system(ecs_.lookup("MakeFloorAreas")).run();
|
||||||
|
#endif
|
||||||
|
print_line(String(e.path()) + ": set area");
|
||||||
|
});
|
||||||
|
/* Propagate floor index to children which are not floor */
|
||||||
|
ecs.observer<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
.event(flecs::OnSet)
|
||||||
|
.with<WorldEditor::components::buildings_layout_floor>()
|
||||||
|
.each([](flecs::entity e,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &r) {
|
||||||
|
// e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
e.children([&queue](flecs::entity ec) {
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity qe = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
if (!qe.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
qe.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ r.index });
|
||||||
|
print_line(String(qe.path()) +
|
||||||
|
" index set");
|
||||||
|
qe.children(
|
||||||
|
[&queue](flecs::entity
|
||||||
|
ec) {
|
||||||
|
queue.push_back(
|
||||||
|
ec);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EditorEvent::get_singleton()->event.emit(
|
||||||
|
"update_layout_view", varray());
|
||||||
|
print_line("floor set");
|
||||||
|
#if 0
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
queue.push_back(e);
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity qe = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
if (!qe.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
qe.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ r.index });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->get_layout_base()
|
||||||
|
.add<WorldEditor::components::
|
||||||
|
buildings_layout_dirty>();
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
void create_room(const String &base_path, int id);
|
void create_room(const String &base_path, int id);
|
||||||
void destroy_graph_entity(const String &path);
|
void destroy_graph_entity(const String &path);
|
||||||
flecs::entity get_layout_base() const;
|
flecs::entity get_layout_base() const;
|
||||||
|
flecs::entity get_layout_grid_base() const;
|
||||||
void get_layout_list(List<String> *keys) const;
|
void get_layout_list(List<String> *keys) const;
|
||||||
void create_new_layout(const String &layout_name);
|
void create_new_layout(const String &layout_name);
|
||||||
flecs::entity get_layout(const String &layout_name) const;
|
flecs::entity get_layout(const String &layout_name) const;
|
||||||
@@ -45,5 +46,9 @@ public:
|
|||||||
List<Pair<int, String> > *list) const;
|
List<Pair<int, String> > *list) const;
|
||||||
void save_layouts();
|
void save_layouts();
|
||||||
void load_layouts();
|
void load_layouts();
|
||||||
|
void create_interior_tilemap(const String &layout_name);
|
||||||
int get_layout_count() const;
|
int get_layout_count() const;
|
||||||
|
struct graph_module {
|
||||||
|
graph_module(flecs::world ecs);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
@@ -138,9 +138,15 @@ public:
|
|||||||
"select_layout");
|
"select_layout");
|
||||||
} else if (event == "button:building_layouts_save")
|
} else if (event == "button:building_layouts_save")
|
||||||
BuildingLayoutGraph::get_singleton()->save_layouts();
|
BuildingLayoutGraph::get_singleton()->save_layouts();
|
||||||
|
else if (event == "button:building_layouts_create_grid")
|
||||||
|
BuildingLayoutGraph::get_singleton()
|
||||||
|
->create_interior_tilemap(current_layout);
|
||||||
else if (event == "building_layouts_layout_selected") {
|
else if (event == "building_layouts_layout_selected") {
|
||||||
update_graph();
|
update_graph();
|
||||||
dlg->update();
|
dlg->update();
|
||||||
|
} else if (event == "update_layout_view") {
|
||||||
|
update_graph();
|
||||||
|
dlg->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void tree_entered()
|
void tree_entered()
|
||||||
@@ -176,6 +182,27 @@ public:
|
|||||||
void room_size_entered(float value, Control *item, const String &path)
|
void room_size_entered(float value, Control *item, const String &path)
|
||||||
{
|
{
|
||||||
print_line(String::num(value));
|
print_line(String::num(value));
|
||||||
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
|
flecs::entity e = ecs.lookup(path.ascii().ptr());
|
||||||
|
float value_r = Math::ceil(Math::sqrt(Math::abs(value)));
|
||||||
|
float value_div = Math::ceil(value_r / 2);
|
||||||
|
float area_final = (value_div * 2) * (value_div * 2);
|
||||||
|
assert(e.is_valid());
|
||||||
|
e.set<WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ area_final });
|
||||||
|
print_line("data set room_size");
|
||||||
|
}
|
||||||
|
void floor_index_entered(float value, Control *item, const String &path)
|
||||||
|
{
|
||||||
|
print_line(String::num(value));
|
||||||
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
|
flecs::entity e = ecs.lookup(path.ascii().ptr());
|
||||||
|
assert(e.is_valid());
|
||||||
|
e.get_mut<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
->index = (int)value;
|
||||||
|
e.modified<
|
||||||
|
WorldEditor::components::buildings_layout_floor_index>();
|
||||||
|
print_line("data set floor");
|
||||||
}
|
}
|
||||||
Vector<Vector2> buttons;
|
Vector<Vector2> buttons;
|
||||||
#define DEPTH_MUL 160
|
#define DEPTH_MUL 160
|
||||||
@@ -248,12 +275,48 @@ public:
|
|||||||
button->set_text(button->get_text() +
|
button->set_text(button->get_text() +
|
||||||
"Floor\n" +
|
"Floor\n" +
|
||||||
String(e.name()));
|
String(e.name()));
|
||||||
|
std::vector<Variant> args = {
|
||||||
|
"Floor: ", "floor_index"
|
||||||
|
};
|
||||||
|
HashMap<String, Object *> save_data;
|
||||||
|
int floor_index =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index;
|
||||||
|
ui_field::ui_field_builder(canvas, box,
|
||||||
|
"p{h{lx#$}}",
|
||||||
|
args.data(),
|
||||||
|
args.size(),
|
||||||
|
&save_data);
|
||||||
|
assert(save_data.has("floor_index"));
|
||||||
|
Object::cast_to<SpinBox>(
|
||||||
|
save_data["floor_index"])
|
||||||
|
->set_value(floor_index);
|
||||||
|
save_data["floor_index"]->connect(
|
||||||
|
"value_changed", this,
|
||||||
|
"floor_index_entered",
|
||||||
|
varray(save_data["floor_index"],
|
||||||
|
String(e.path())));
|
||||||
}
|
}
|
||||||
if (e.has<WorldEditor::components::
|
if (e.has<WorldEditor::components::
|
||||||
buildings_layout_unit>()) {
|
buildings_layout_unit>()) {
|
||||||
button->set_text(button->get_text() +
|
button->set_text(button->get_text() +
|
||||||
"Unit\n" +
|
"Unit\n" +
|
||||||
String(e.name()));
|
String(e.name()));
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
float area =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
std::vector<Variant> args = {
|
||||||
|
"Area: " + itos(area)
|
||||||
|
};
|
||||||
|
ui_field::ui_field_builder(
|
||||||
|
canvas, box, "l",
|
||||||
|
args.data(),
|
||||||
|
args.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (e.has<WorldEditor::components::
|
if (e.has<WorldEditor::components::
|
||||||
buildings_layout_zone>()) {
|
buildings_layout_zone>()) {
|
||||||
@@ -274,6 +337,21 @@ public:
|
|||||||
}
|
}
|
||||||
button->set_text(button->get_text() +
|
button->set_text(button->get_text() +
|
||||||
String(e.name()));
|
String(e.name()));
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
float area =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
std::vector<Variant> args = {
|
||||||
|
"Area: " +
|
||||||
|
String::num(area)
|
||||||
|
};
|
||||||
|
ui_field::ui_field_builder(
|
||||||
|
canvas, box, "l",
|
||||||
|
args.data(),
|
||||||
|
args.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (e.has<WorldEditor::components::
|
if (e.has<WorldEditor::components::
|
||||||
buildings_layout_room>()) {
|
buildings_layout_room>()) {
|
||||||
@@ -285,21 +363,67 @@ public:
|
|||||||
button->get_text() + "Room\n" +
|
button->get_text() + "Room\n" +
|
||||||
String(e.name() + " " +
|
String(e.name() + " " +
|
||||||
itos(room_type)));
|
itos(room_type)));
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_area>()) {
|
||||||
|
std::vector<Variant> args = {
|
||||||
|
"Area: ", "area_value"
|
||||||
|
};
|
||||||
|
HashMap<String, Object *>
|
||||||
|
save_data;
|
||||||
|
float area =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
->area;
|
||||||
|
ui_field::ui_field_builder(
|
||||||
|
canvas, box,
|
||||||
|
"p{h{lx#$}}",
|
||||||
|
args.data(),
|
||||||
|
args.size(),
|
||||||
|
&save_data);
|
||||||
|
assert(save_data.has(
|
||||||
|
"area_value"));
|
||||||
|
Object::cast_to<SpinBox>(
|
||||||
|
save_data["area_value"])
|
||||||
|
->set_value(area);
|
||||||
|
save_data["area_value"]->connect(
|
||||||
|
"value_changed", this,
|
||||||
|
"room_size_entered",
|
||||||
|
varray(save_data["area_value"],
|
||||||
|
String(e.path())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()) {
|
||||||
|
int index =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
->index;
|
||||||
std::vector<Variant> args = {
|
std::vector<Variant> args = {
|
||||||
"Area: ", "area_value"
|
"Floor index: " + itos(index)
|
||||||
};
|
};
|
||||||
HashMap<String, Object *> save_data;
|
|
||||||
ui_field::ui_field_builder(canvas, box,
|
ui_field::ui_field_builder(canvas, box,
|
||||||
"p{h{lx#$}}",
|
"l",
|
||||||
args.data(),
|
args.data(),
|
||||||
args.size(),
|
args.size());
|
||||||
&save_data);
|
}
|
||||||
assert(save_data.has("area_value"));
|
if (e.has<WorldEditor::components::
|
||||||
save_data["area_value"]->connect(
|
buildings_layout_floor_data>()) {
|
||||||
"value_changed", this,
|
float area =
|
||||||
"room_size_entered",
|
e.get<WorldEditor::components::
|
||||||
varray(save_data["area_value"],
|
buildings_layout_area>()
|
||||||
String(e.path())));
|
->area;
|
||||||
|
int grid_size =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_data>()
|
||||||
|
->grid_size;
|
||||||
|
std::vector<Variant> args = {
|
||||||
|
"Area: " + String::num(area),
|
||||||
|
"Grid size: " + itos(grid_size)
|
||||||
|
};
|
||||||
|
ui_field::ui_field_builder(canvas, box,
|
||||||
|
"ll",
|
||||||
|
args.data(),
|
||||||
|
args.size());
|
||||||
}
|
}
|
||||||
button->get_popup()->connect(
|
button->get_popup()->connect(
|
||||||
"id_pressed", this, "menu_pressed",
|
"id_pressed", this, "menu_pressed",
|
||||||
@@ -382,8 +506,7 @@ public:
|
|||||||
Rect2(p1x - Vector2(0, r),
|
Rect2(p1x - Vector2(0, r),
|
||||||
(p2x - p1x) +
|
(p2x - p1x) +
|
||||||
Vector2(0, r * 2.0)),
|
Vector2(0, r * 2.0)),
|
||||||
Color(0.4, 0.4, 0.55, 1.0), true, 4.0f,
|
Color(0.4, 0.4, 0.55, 1.0), true);
|
||||||
true);
|
|
||||||
canvas_item->draw_circle(
|
canvas_item->draw_circle(
|
||||||
p1x, r, Color(0.4, 0.4, 0.55, 1.0));
|
p1x, r, Color(0.4, 0.4, 0.55, 1.0));
|
||||||
canvas_item->draw_circle(
|
canvas_item->draw_circle(
|
||||||
@@ -428,10 +551,12 @@ public:
|
|||||||
"building_layouts_create_new", varray(),
|
"building_layouts_create_new", varray(),
|
||||||
"Save", "building_layouts_save_button",
|
"Save", "building_layouts_save_button",
|
||||||
"building_layouts_save", varray(),
|
"building_layouts_save", varray(),
|
||||||
|
"Build", "building_layouts_create_grid",
|
||||||
|
"building_layouts_create_grid", varray(),
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
};
|
};
|
||||||
ui_field::ui_field_builder(gui, tab,
|
ui_field::ui_field_builder(gui, tab,
|
||||||
"l_p{v{li.#!lh{e#+!b#!Q}b#!Q}}",
|
"l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Q}}",
|
||||||
args_data.data(), args_data.size());
|
args_data.data(), args_data.size());
|
||||||
}
|
}
|
||||||
static void _bind_methods()
|
static void _bind_methods()
|
||||||
@@ -449,6 +574,11 @@ public:
|
|||||||
"item"
|
"item"
|
||||||
"path"),
|
"path"),
|
||||||
&BuildingLayoutGraphUI::room_size_entered);
|
&BuildingLayoutGraphUI::room_size_entered);
|
||||||
|
ClassDB::bind_method(
|
||||||
|
D_METHOD("floor_index_entered", "value",
|
||||||
|
"item"
|
||||||
|
"path"),
|
||||||
|
&BuildingLayoutGraphUI::floor_index_entered);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
|
|||||||
} break;
|
} break;
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'L':
|
case 'L':
|
||||||
assert(i < fmt_size - 1);
|
assert(i < fmt_size);
|
||||||
assert(argp < args_size);
|
assert(argp < args_size);
|
||||||
{
|
{
|
||||||
Label *l = memnew(Label);
|
Label *l = memnew(Label);
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ WorldEditor::WorldEditor()
|
|||||||
ecs.component<WorldEditor::components::buildings_editor_node>();
|
ecs.component<WorldEditor::components::buildings_editor_node>();
|
||||||
ecs.component<WorldEditor::components::road_lines_editor_node>();
|
ecs.component<WorldEditor::components::road_lines_editor_node>();
|
||||||
ecs.component<WorldEditor::components::buildings_editor_mode>();
|
ecs.component<WorldEditor::components::buildings_editor_mode>();
|
||||||
ecs.component<WorldEditor::components::buildings_layout_graph>();
|
|
||||||
e = ecs.lookup("world_editor");
|
e = ecs.lookup("world_editor");
|
||||||
assert(!e.is_valid());
|
assert(!e.is_valid());
|
||||||
if (!InputMap::get_singleton()->has_action("left"))
|
if (!InputMap::get_singleton()->has_action("left"))
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ public:
|
|||||||
String current_type;
|
String current_type;
|
||||||
};
|
};
|
||||||
struct buildings_layout_base {};
|
struct buildings_layout_base {};
|
||||||
|
struct buildings_layout_grid_base {};
|
||||||
|
struct buildings_layout_grid {};
|
||||||
struct buildings_layout_graph {};
|
struct buildings_layout_graph {};
|
||||||
struct buildings_layout_graph_node {
|
struct buildings_layout_graph_node {
|
||||||
int depth;
|
int depth;
|
||||||
@@ -79,14 +81,26 @@ public:
|
|||||||
};
|
};
|
||||||
struct buildings_layout_zone {
|
struct buildings_layout_zone {
|
||||||
int type;
|
int type;
|
||||||
|
bool align_wall;
|
||||||
};
|
};
|
||||||
struct buildings_layout_floor {
|
struct buildings_layout_floor {
|
||||||
int flags;
|
int flags;
|
||||||
};
|
};
|
||||||
|
struct buildings_layout_floor_data {
|
||||||
|
int grid_size;
|
||||||
|
};
|
||||||
struct buildings_layout_room {
|
struct buildings_layout_room {
|
||||||
int room_type;
|
int room_type;
|
||||||
bool window;
|
bool window;
|
||||||
};
|
};
|
||||||
|
struct buildings_layout_area {
|
||||||
|
float area;
|
||||||
|
};
|
||||||
|
struct buildings_layout_dirty {};
|
||||||
|
/* for all things except floor */
|
||||||
|
struct buildings_layout_floor_index {
|
||||||
|
int index;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user