From ddc9325f31455ee68e972e39d3798b95cca60605 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Mon, 27 May 2024 20:39:19 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#4165=20ItemEntity::get=5Fsymbol()?= =?utf8?q?=20=E3=81=AE=E6=88=BB=E3=82=8A=E5=80=A4=E3=82=92DisplaySymbol=20?= =?utf8?q?=E3=81=AB=E5=A4=89=E3=81=88=E3=80=81=E8=89=B2=E3=81=A8=E6=96=87?= =?utf8?q?=E5=AD=97=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=83=A1?= =?utf8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=81=AFprivate=20=E3=81=AB=E5=A4=89?= =?utf8?q?=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit シンボル変更コマンドでシンボルが変わってしまってもいいように、get_symbol() はベースアイテム情報から都度再取得する --- src/combat/shoot.cpp | 5 +-- src/object-use/throw-execution.cpp | 10 ++--- src/system/item-entity.cpp | 82 ++++++++++++++++++++--------------- src/system/item-entity.h | 6 ++- src/view/display-inventory.cpp | 8 +--- src/view/display-map.cpp | 2 +- src/view/display-player.cpp | 9 ++-- src/view/display-store.cpp | 5 +-- src/window/display-sub-windows.cpp | 11 ++--- src/window/main-window-equipments.cpp | 4 +- 10 files changed, 69 insertions(+), 73 deletions(-) diff --git a/src/combat/shoot.cpp b/src/combat/shoot.cpp index 871cb43a4..2f0d23010 100644 --- a/src/combat/shoot.cpp +++ b/src/combat/shoot.cpp @@ -670,12 +670,11 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SP /* The player can see the (on screen) missile */ if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) { - const auto a = q_ptr->get_color(); - const auto c = q_ptr->get_symbol(); + const auto symbol = q_ptr->get_symbol(); /* Draw, Hilite, Fresh, Pause, Erase */ if (delay_factor > 0) { - print_rel(player_ptr, c, a, ny, nx); + print_rel(player_ptr, symbol.character, symbol.color, ny, nx); move_cursor_relative(ny, nx); term_fresh(); term_xtra(TERM_XTRA_DELAY, delay_factor); diff --git a/src/object-use/throw-execution.cpp b/src/object-use/throw-execution.cpp index 56fe3b66d..d6ad5edb2 100644 --- a/src/object-use/throw-execution.cpp +++ b/src/object-use/throw-execution.cpp @@ -412,9 +412,8 @@ void ObjectThrowEntity::check_racial_target_seen() return; } - const auto c = this->q_ptr->get_symbol(); - const auto a = this->q_ptr->get_color(); - print_rel(this->player_ptr, c, a, this->ny[this->cur_dis], this->nx[this->cur_dis]); + const auto symbol = this->q_ptr->get_symbol(); + print_rel(this->player_ptr, symbol.character, symbol.color, this->ny[this->cur_dis], this->nx[this->cur_dis]); move_cursor_relative(this->ny[this->cur_dis], this->nx[this->cur_dis]); term_fresh(); term_xtra(TERM_XTRA_DELAY, this->msec); @@ -531,13 +530,12 @@ void ObjectThrowEntity::process_boomerang_throw() continue; } - const auto c = this->q_ptr->get_symbol(); - const auto a = this->q_ptr->get_color(); if (this->msec <= 0) { continue; } - print_rel(this->player_ptr, c, a, this->ny[i], this->nx[i]); + const auto symbol = this->q_ptr->get_symbol(); + print_rel(this->player_ptr, symbol.character, symbol.color, this->ny[i], this->nx[i]); move_cursor_relative(this->ny[i], this->nx[i]); term_fresh(); term_xtra(TERM_XTRA_DELAY, this->msec); diff --git a/src/system/item-entity.cpp b/src/system/item-entity.cpp index c42b00d55..25110a250 100644 --- a/src/system/item-entity.cpp +++ b/src/system/item-entity.cpp @@ -594,44 +594,14 @@ bool ItemEntity::can_pile(const ItemEntity *j_ptr) const return true; } -/* - * @brief アイテムの色を取得する - * @details 未鑑定名のあるアイテム (薬等)は、未鑑定名の割り当てられた色を返す - * 未鑑定名のないアイテム (魔法書等)はベースアイテム定義そのままを返す - * その中でモンスターの死体以外は、ベースアイテムの色を返す - * モンスターの死体は、元モンスターの色を返す - * 異常アイテム (「何か」)の場合、ベースアイテム定義に基づき黒を返す - */ -TERM_COLOR ItemEntity::get_color() const -{ - const auto &baseitem = this->get_baseitem(); - const auto flavor = baseitem.flavor; - if (flavor != 0) { - return BaseitemList::get_instance().get_baseitem(flavor).symbol_config.color; - } - - const auto &symbol_config = baseitem.symbol_config; - auto has_attr = this->is_valid(); - has_attr &= this->is_corpse(); - has_attr &= symbol_config.color == TERM_DARK; - if (!has_attr) { - return symbol_config.color; - } - - return monraces_info[i2enum(this->pval)].symbol_config.color; -} - -/* - * @brief アイテムシンボルを取得する - * @details 未鑑定名のないアイテム (魔法書等)はベースアイテム定義そのまま - * 未鑑定名のあるアイテム (薬等)は、未鑑定名の割り当てられたシンボル - * 以上について、設定で変更しているシンボルならばそれを、していないならば定義シンボルを返す +/*! + * @brief アイテムのシンボルを取得する + * @return シンボル + * @details シンボル変更コマンドの影響を受けたくないので毎回ベースアイテムからシンボルを引っ張って返す. */ -char ItemEntity::get_symbol() const +DisplaySymbol ItemEntity::get_symbol() const { - const auto &baseitem = this->get_baseitem(); - const auto flavor = baseitem.flavor; - return flavor ? BaseitemList::get_instance().get_baseitem(flavor).symbol_config.character : baseitem.symbol_config.character; + return { this->get_color(), this->get_character() }; } /*! @@ -1123,3 +1093,43 @@ std::string ItemEntity::build_activation_description_dragon_breath() const const auto flags = this->get_flags(); return DragonBreaths::build_description(flags); } + +/* + * @brief アイテムの色を取得する + * @details 未鑑定名のあるアイテム (薬等)は、未鑑定名の割り当てられた色を返す + * 未鑑定名のないアイテム (魔法書等)はベースアイテム定義そのままを返す + * その中でモンスターの死体以外は、ベースアイテムの色を返す + * モンスターの死体は、元モンスターの色を返す + * 異常アイテム (「何か」)の場合、ベースアイテム定義に基づき黒を返す + */ +uint8_t ItemEntity::get_color() const +{ + const auto &baseitem = this->get_baseitem(); + const auto flavor = baseitem.flavor; + if (flavor != 0) { + return BaseitemList::get_instance().get_baseitem(flavor).symbol_config.color; + } + + const auto &symbol_config = baseitem.symbol_config; + auto has_attr = this->is_valid(); + has_attr &= this->is_corpse(); + has_attr &= symbol_config.color == TERM_DARK; + if (!has_attr) { + return symbol_config.color; + } + + return monraces_info[i2enum(this->pval)].symbol_config.color; +} + +/* + * @brief アイテムシンボルを取得する + * @details 未鑑定名のないアイテム (魔法書等)はベースアイテム定義そのまま + * 未鑑定名のあるアイテム (薬等)は、未鑑定名の割り当てられたシンボル + * 以上について、設定で変更しているシンボルならばそれを、していないならば定義シンボルを返す + */ +char ItemEntity::get_character() const +{ + const auto &baseitem = this->get_baseitem(); + const auto flavor = baseitem.flavor; + return flavor ? BaseitemList::get_instance().get_baseitem(flavor).symbol_config.character : baseitem.symbol_config.character; +} diff --git a/src/system/item-entity.h b/src/system/item-entity.h index 55f952223..f0ebc3425 100644 --- a/src/system/item-entity.h +++ b/src/system/item-entity.h @@ -27,6 +27,7 @@ enum class RandomArtActType : short; class ActivationType; class ArtifactType; class BaseitemInfo; +class DisplaySymbol; class EgoItemDefinition; class ItemEntity { public: @@ -126,8 +127,7 @@ public: bool is_spell_book() const; bool is_glove_same_temper(const ItemEntity *j_ptr) const; bool can_pile(const ItemEntity *j_ptr) const; - TERM_COLOR get_color() const; - char get_symbol() const; + DisplaySymbol get_symbol() const; int get_price() const; bool is_specific_artifact(FixedArtifactId id) const; bool has_unidentified_name() const; @@ -169,4 +169,6 @@ private: std::string build_timeout_description(const ActivationType &act) const; std::string build_activation_description(const ActivationType &act) const; std::string build_activation_description_dragon_breath() const; + uint8_t get_color() const; + char get_character() const; }; diff --git a/src/view/display-inventory.cpp b/src/view/display-inventory.cpp index 55032b4e2..c4f36854b 100644 --- a/src/view/display-inventory.cpp +++ b/src/view/display-inventory.cpp @@ -106,9 +106,7 @@ COMMAND_CODE show_inventory(PlayerType *player_ptr, int target_item, BIT_FLAGS m put_str(tmp_val, j + 1, col); cur_col = col + 3; if (show_item_graph) { - const auto a = o_ptr->get_color(); - const auto c = o_ptr->get_symbol(); - term_queue_bigchar(cur_col, j + 1, { { a, c }, {} }); + term_queue_bigchar(cur_col, j + 1, { o_ptr->get_symbol(), {} }); if (use_bigtile) { cur_col++; } @@ -177,9 +175,7 @@ void display_inventory(PlayerType *player_ptr, const ItemTester &item_tester) } if (show_item_graph) { - const auto a = o_ptr->get_color(); - const auto c = o_ptr->get_symbol(); - term_queue_bigchar(cur_col, i, { { a, c }, {} }); + term_queue_bigchar(cur_col, i, { o_ptr->get_symbol(), {} }); if (use_bigtile) { cur_col++; } diff --git a/src/view/display-map.cpp b/src/view/display-map.cpp index d484dc03e..13038b8aa 100644 --- a/src/view/display-map.cpp +++ b/src/view/display-map.cpp @@ -253,7 +253,7 @@ DisplaySymbolPair map_info(PlayerType *player_ptr, const Pos2D &pos) } } - symbol_pair.symbol_foreground = { o_ptr->get_color(), o_ptr->get_symbol() }; + symbol_pair.symbol_foreground = o_ptr->get_symbol(); feat_priority = 20; if (is_hallucinated) { symbol_pair.symbol_foreground = image_object(); diff --git a/src/view/display-player.cpp b/src/view/display-player.cpp index 0b2a2caba..bc8c280ea 100644 --- a/src/view/display-player.cpp +++ b/src/view/display-player.cpp @@ -331,13 +331,12 @@ void display_player_equippy(PlayerType *player_ptr, TERM_LEN y, TERM_LEN x, BIT_ const auto max_i = (mode & DP_WP) ? INVEN_BOW + 1 : INVEN_TOTAL; for (int i = INVEN_MAIN_HAND; i < max_i; i++) { const auto &item = player_ptr->inventory_list[i]; - auto a = item.get_color(); - auto c = item.get_symbol(); + auto symbol = item.get_symbol(); if (!equippy_chars || !item.is_valid()) { - c = ' '; - a = TERM_DARK; + symbol.color = TERM_DARK; + symbol.character = ' '; } - term_putch(x + i - INVEN_MAIN_HAND, y, a, c); + term_putch(x + i - INVEN_MAIN_HAND, y, symbol.color, symbol.character); } } diff --git a/src/view/display-store.cpp b/src/view/display-store.cpp index 8d0fade73..23f2870f1 100644 --- a/src/view/display-store.cpp +++ b/src/view/display-store.cpp @@ -50,10 +50,7 @@ void display_entry(PlayerType *player_ptr, int pos, StoreSaleType store_num) int cur_col = 3; if (show_item_graph) { - const auto a = o_ptr->get_color(); - const auto c = o_ptr->get_symbol(); - - term_queue_bigchar(cur_col, i + 6, { { a, c }, {} }); + term_queue_bigchar(cur_col, i + 6, { o_ptr->get_symbol(), {} }); if (use_bigtile) { cur_col++; } diff --git a/src/window/display-sub-windows.cpp b/src/window/display-sub-windows.cpp index 301a39dc3..745767bee 100644 --- a/src/window/display-sub-windows.cpp +++ b/src/window/display-sub-windows.cpp @@ -345,9 +345,7 @@ static void display_equipment(PlayerType *player_ptr, const ItemTester &item_tes } if (show_item_graph) { - const auto a = o_ptr->get_color(); - const auto c = o_ptr->get_symbol(); - term_queue_bigchar(cur_col, cur_row, { { a, c }, {} }); + term_queue_bigchar(cur_col, cur_row, { o_ptr->get_symbol(), {} }); if (use_bigtile) { cur_col++; } @@ -683,10 +681,9 @@ static void display_found_item_list(PlayerType *player_ptr) term_gotoxy(0, term_y); // アイテムシンボル表示 - const auto symbol_code = item->get_symbol(); - const auto symbol = format(" %c ", symbol_code); - const auto color_code_for_symbol = item->get_color(); - term_addstr(-1, color_code_for_symbol, symbol); + const auto symbol = item->get_symbol(); + const auto symbol_str = format(" %c ", symbol.character); + term_addstr(-1, symbol.color, symbol_str); const auto item_name = describe_flavor(player_ptr, item, 0); const auto color_code_for_item = tval_to_attr[enum2i(item->bi_key.tval()) % 128]; diff --git a/src/window/main-window-equipments.cpp b/src/window/main-window-equipments.cpp index 051f561b8..da1570aea 100644 --- a/src/window/main-window-equipments.cpp +++ b/src/window/main-window-equipments.cpp @@ -110,9 +110,7 @@ COMMAND_CODE show_equipment(PlayerType *player_ptr, int target_item, BIT_FLAGS m put_str(tmp_val, j + 1, col); int cur_col = col + 3; if (show_item_graph) { - const auto a = o_ptr->get_color(); - const auto c = o_ptr->get_symbol(); - term_queue_bigchar(cur_col, j + 1, { { a, c }, {} }); + term_queue_bigchar(cur_col, j + 1, { o_ptr->get_symbol(), {} }); if (use_bigtile) { cur_col++; } -- 2.11.0