134 lines
3.8 KiB
C++
134 lines
3.8 KiB
C++
#ifndef BUILDINGS_DATA_H
|
|
#define BUILFINGS_DATA_H
|
|
#include <vector>
|
|
#include <core/reference.h>
|
|
class PackedScene;
|
|
class ResourceInteractiveLoader;
|
|
class BuildingsData {
|
|
public:
|
|
/* Per-building information */
|
|
struct building {
|
|
String id;
|
|
int pattern_id;
|
|
Vector<int> residents, workers, guests;
|
|
String key;
|
|
uint64_t key_hash;
|
|
Transform xform;
|
|
int worktime[2];
|
|
bool generated;
|
|
static void from_dict(struct building *b,
|
|
const Dictionary &dict);
|
|
Dictionary to_dict() const;
|
|
String line_name;
|
|
};
|
|
/* Scene objects data */
|
|
//private:
|
|
// HashMap<String, struct scene_data> scenes;
|
|
|
|
public:
|
|
void get_scene_keys_list(List<String> *keys) const;
|
|
bool has_scene(const String &key) const;
|
|
void remove_scene_item(const String &key, const String &bkey);
|
|
void add_scene_item(const String &key, const String &bkey);
|
|
void create_scene_data(const String &key, const String &bkey);
|
|
Ref<PackedScene> scene_get_packed_scene(const String &key) const;
|
|
int scene_get_item_count(const String &key) const;
|
|
// String scene_get_item(const String &key, int index) const;
|
|
List<String> scene_get_items(const String &key) const;
|
|
void set_scene_item_node(const String &key, const String &bkey,
|
|
Node *node);
|
|
bool has_scene_item(const String &key, const String &bkey) const;
|
|
Node *get_scene_item_node(const String &key, const String &bkey) const;
|
|
|
|
public:
|
|
Node *item_nodes_get_node(const String &key) const;
|
|
|
|
private:
|
|
Error scene_loader_poll(const String &key);
|
|
|
|
public:
|
|
void scene_update();
|
|
/* Path for each building type */
|
|
HashMap<String, String> building_data;
|
|
HashMap<String, Vector<Transform> > building_doors;
|
|
HashMap<String, AABB> building_aabbs;
|
|
|
|
public:
|
|
struct building &get_building(const String &building_key);
|
|
const struct building &get_building(const String &building_key) const;
|
|
struct callme {
|
|
class H {};
|
|
H *obj;
|
|
void (H::*method)(const String &key, void *data);
|
|
void *data;
|
|
callme(H *obj, void (H::*method)(const String &key, void *data),
|
|
void *data)
|
|
: obj(obj)
|
|
, method(method)
|
|
, data(data)
|
|
{
|
|
}
|
|
void operator()(const String &key)
|
|
{
|
|
(obj->*method)(key, data);
|
|
}
|
|
};
|
|
template <class T>
|
|
void set_foreach_method(T *obj,
|
|
void (T::*method)(const String &key,
|
|
void *data),
|
|
struct callme &c)
|
|
{
|
|
c.obj = reinterpret_cast<callme::H *>(obj);
|
|
c.method = reinterpret_cast<void (callme::H::*)(const String &,
|
|
void *)>(obj);
|
|
}
|
|
|
|
void for_each_building(struct callme &c);
|
|
template <typename Func> void for_each_building(Func &&func, void *data)
|
|
{
|
|
List<String> keys;
|
|
get_building_keys_list(&keys);
|
|
List<String>::Element *e = keys.front();
|
|
while (e) {
|
|
func(e->get(), data);
|
|
e = e->next();
|
|
}
|
|
}
|
|
void for_each_building(void (*func)(const String &key, void *data),
|
|
void *data);
|
|
void get_building_keys_list(List<String> *keys);
|
|
|
|
int get_building_count() const;
|
|
String create_building(const Dictionary &dict);
|
|
String create_building(const struct building &building);
|
|
String create_building(const struct building *building);
|
|
bool destroy_building(const String &key);
|
|
struct checkpoint_data {
|
|
HashMap<String, String> building_data;
|
|
std::vector<struct building> buildings;
|
|
};
|
|
std::vector<struct checkpoint_data> undo_log;
|
|
int undo_log_size;
|
|
BuildingsData();
|
|
virtual ~BuildingsData();
|
|
static BuildingsData *singleton;
|
|
|
|
public:
|
|
void read_buildings_json(const String &buildings_path);
|
|
void save_buildings_json(const String &buildings_path);
|
|
void filter_generated_stuff();
|
|
void remove_generated_stuff();
|
|
void load_data();
|
|
void checkpoint();
|
|
void undo();
|
|
void fill_door_locations();
|
|
void build_building_aabbs();
|
|
void update_building_transform(const String &key,
|
|
const Transform &xform);
|
|
bool has_building(const String &key);
|
|
String get_closest_building(const Transform &xform);
|
|
static BuildingsData *get_singleton();
|
|
static void cleanup();
|
|
};
|
|
#endif |