diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/entity.cc | 10 | ||||
-rw-r--r-- | src/core/entity.h | 6 | ||||
-rw-r--r-- | src/core/info.cc | 12 | ||||
-rw-r--r-- | src/core/info.h | 25 | ||||
-rw-r--r-- | src/core/parser.cc | 9 |
5 files changed, 42 insertions, 20 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 35164dc..013e66d 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -266,13 +266,9 @@ void Entity::clear_updates() } } -void Entity::set_info(Info *info) +void Entity::set_info(const Info *info) { entity_info = info; - if (entity_info) { - entity_info->set_model(model()); - entity_info->set_name(name()); - } } void Entity::set_inventory(Inventory *inventory) @@ -318,10 +314,6 @@ void Entity::set_model(model::Model *model) if (entity_model) { entity_modelname.assign(entity_model->name()); } - - if (entity_info) { - entity_info->set_model(entity_model); - } } void Entity::set_modelname(const std::string &modelname) diff --git a/src/core/entity.h b/src/core/entity.h index 1996e10..5c34f97 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -194,7 +194,7 @@ public: } /// entity info - inline Info *info() const { + inline const Info *info() const { return entity_info; } @@ -328,7 +328,7 @@ public: */ void set_inventory(Inventory *inventory); - void set_info(Info *info); + void set_info(const Info *info); /// set the timestamp when the entity was last alive void set_keepalive(unsigned long timestamp) { @@ -492,7 +492,7 @@ private: Menus entity_menus; Inventory* entity_inventory; - Info* entity_info; + const Info* entity_info; Extension* entity_extension[4]; diff --git a/src/core/info.cc b/src/core/info.cc index cc1720e..2ff6669 100644 --- a/src/core/info.cc +++ b/src/core/info.cc @@ -243,6 +243,18 @@ void Info::print() const Info::Registry Info::info_registry; +Info *Info::find(const Info *info) +{ + if (!info) + return 0; + + for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) { + if (info == (*it)); + return *it; + } + return 0; +} + Info *Info::find(unsigned int id) { if (!id) diff --git a/src/core/info.h b/src/core/info.h index b8154d7..d32ccab 100644 --- a/src/core/info.h +++ b/src/core/info.h @@ -191,23 +191,38 @@ private: /* ---- static info registry --------------------------------------- */ public: - /// info registry type definition + /** + * @brief info registry type definition + */ typedef std::vector<Info*> Registry; - /// the info registry + /** + * @brief the info registry + */ static inline Registry & registry() { return info_registry; } - /// search the info registry for a record with the specified id + /** + * @brief search the info registry for a record with the specified id + */ static Info *find(const unsigned int id); - /// search the info registry for a labeled item + /** + * @brief search the info registry for a labeled item + */ static Info *find(const char * label); - /// search the info registry for a label + /** + * @brief search the info registry for a label + */ static Info *find(const std::string & label); + /** + * @brief search the info register for a pointer + */ + static Info *find(const Info *info); + /// search the info registry for a record with a matching label or name static Info *search(const std::string & searchstr); diff --git a/src/core/parser.cc b/src/core/parser.cc index 953cd50..22b2fc3 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -47,10 +47,13 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) } } else if (inifile.got_key_string("info", strval)) { - if (!entity->info()) { - entity->set_info(new Info(Entity::infotype(), entity->label().c_str())); + + Info *info = Info::find(entity->info()); + if (!info) { + info = new Info(Entity::infotype(), entity->label().c_str()); + entity->set_info(info); } - entity->info()->add_text(strval); + info->add_text(strval); return true; } else if (inifile.got_key_label("label", strval)) { |