Skip to content

Commit

Permalink
[Refactor] hengband#1498 Defined get_expr() to divide View and Model
Browse files Browse the repository at this point in the history
  • Loading branch information
Hourier committed Sep 18, 2021
1 parent 4ddc801 commit 4e473b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/timed-effect/player-stun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ bool PlayerStun::is_stunned() const
return this->get_rank() > StunRank::NONE;
}

std::tuple<term_color_type, std::string_view> PlayerStun::get_expr() const
{
switch (this->get_rank()) {
case StunRank::NONE: // dummy.
return std::make_tuple(TERM_WHITE, " ");
case StunRank::NORMAL:
return std::make_tuple(TERM_ORANGE, _("朦朧 ", "Stun "));
case StunRank::HARD:
return std::make_tuple(TERM_ORANGE, _("ひどく朦朧 ", "Heavy stun "));
case StunRank::UNCONSCIOUS:
return std::make_tuple(TERM_RED, _("意識不明瞭 ", "Knocked out "));
default:
throw("Invalid stun rank is specified!");
}
}

void PlayerStun::set(short value)
{
this->stun = value;
Expand Down
3 changes: 3 additions & 0 deletions src/timed-effect/player-stun.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "term/term-color-types.h"
#include <string>
#include <tuple>

enum class StunRank {
NONE = 0,
Expand All @@ -21,6 +23,7 @@ class PlayerStun {
int decrease_chance() const;
short decrease_damage() const;
bool is_stunned() const;
std::tuple<term_color_type, std::string_view> get_expr() const;
void reset();
void set(short value);

Expand Down
20 changes: 5 additions & 15 deletions src/window/main-window-stat-poster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,17 @@ void print_cut(player_type *player_ptr)
/*!
* @brief プレイヤーの朦朧状態を表示する
* @param player_ptr プレイヤーへの参照ポインタ
* @todo TERM値のenumと文字列はPlayerStunの中へ入れ、ここは可能な限り軽くする.
*/
void print_stun(player_type *player_ptr)
{
int s = player_ptr->effects()->stun()->current();
if (s > 100) {
c_put_str(TERM_RED, _("意識不明瞭 ", "Knocked out "), ROW_STUN, COL_STUN);
auto player_stun = player_ptr->effects()->stun();
if (!player_stun->is_stunned()) {
put_str(" ", ROW_STUN, COL_STUN);
return;
}

if (s > 50) {
c_put_str(TERM_ORANGE, _("ひどく朦朧 ", "Heavy stun "), ROW_STUN, COL_STUN);
return;
}

if (s) {
c_put_str(TERM_ORANGE, _("朦朧 ", "Stun "), ROW_STUN, COL_STUN);
return;
}

put_str(" ", ROW_STUN, COL_STUN);
auto [color, stat] = player_stun->get_expr();
c_put_str(color, stat.data(), ROW_STUN, COL_STUN);
}

/*!
Expand Down

0 comments on commit 4e473b2

Please sign in to comment.