-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49950 from Ramza13/talker_item
Create talker item, paving way for greater item json interactions.
- Loading branch information
Showing
10 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <memory> | ||
|
||
#include "character_id.h" | ||
#include "item.h" | ||
#include "magic.h" | ||
#include "npc.h" | ||
#include "pimpl.h" | ||
#include "player.h" | ||
#include "point.h" | ||
#include "talker_item.h" | ||
#include "vehicle.h" | ||
|
||
std::string talker_item::disp_name() const | ||
{ | ||
return me_it->get_item()->display_name(); | ||
} | ||
|
||
int talker_item::posx() const | ||
{ | ||
return me_it->position().x; | ||
} | ||
|
||
int talker_item::posy() const | ||
{ | ||
return me_it->position().y; | ||
} | ||
|
||
int talker_item::posz() const | ||
{ | ||
return me_it->position().z; | ||
} | ||
|
||
tripoint talker_item::pos() const | ||
{ | ||
return me_it->position(); | ||
} | ||
|
||
tripoint_abs_omt talker_item::global_omt_location() const | ||
{ | ||
return get_player_character().global_omt_location(); | ||
} | ||
|
||
std::string talker_item::get_value( const std::string &var_name ) const | ||
{ | ||
return me_it->get_item()->get_var( var_name ); | ||
} | ||
|
||
void talker_item::set_value( const std::string &var_name, const std::string &value ) | ||
{ | ||
me_it->get_item()->set_var( var_name, value ); | ||
} | ||
|
||
void talker_item::remove_value( const std::string &var_name ) | ||
{ | ||
me_it->get_item()->erase_var( var_name ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_TALKER_ITEM_H | ||
#define CATA_SRC_TALKER_ITEM_H | ||
|
||
#include <functional> | ||
#include <iosfwd> | ||
#include <list> | ||
#include <vector> | ||
|
||
#include "coordinates.h" | ||
#include "npc.h" | ||
#include "talker.h" | ||
#include "type_id.h" | ||
|
||
class item; | ||
|
||
struct tripoint; | ||
|
||
/* | ||
* Talker wrapper class for Character. well, ideally, but since Character is such a mess, | ||
* it's the wrapper class for player | ||
* Should never be invoked directly. Only talker_avatar and talker_npc are really valid. | ||
*/ | ||
class talker_item: public talker | ||
{ | ||
public: | ||
explicit talker_item( item_location *new_me ): me_it( new_me ) { | ||
} | ||
~talker_item() override = default; | ||
|
||
// underlying element accessor functions | ||
item_location *get_item() override { | ||
return me_it; | ||
} | ||
item_location *get_item() const override { | ||
return me_it; | ||
} | ||
// identity and location | ||
std::string disp_name() const override; | ||
int posx() const override; | ||
int posy() const override; | ||
int posz() const override; | ||
tripoint pos() const override; | ||
tripoint_abs_omt global_omt_location() const override; | ||
|
||
std::string get_value( const std::string &var_name ) const override; | ||
void set_value( const std::string &var_name, const std::string &value ) override; | ||
void remove_value( const std::string & ) override; | ||
|
||
protected: | ||
talker_item() = default; | ||
item_location *me_it; | ||
}; | ||
#endif // CATA_SRC_TALKER_ITEM_H |