OSDN Git Service

[Refactor] #3453 mind-weaponsmith.cpp から呼ばれているget_string をinput_value() に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 24 Jun 2023 09:23:57 +0000 (18:23 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 25 Jun 2023 03:03:17 +0000 (12:03 +0900)
src/mind/mind-weaponsmith.cpp

index b8b33b9..bf9d7ee 100644 (file)
@@ -468,6 +468,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
         return;
     }
 
+    constexpr auto prompt = _("いくつ付加しますか?", "Enchant how many?");
     const auto attribute_flags = Smith::get_effect_tr_flags(effect);
     auto add_essence_count = 1;
     if (attribute_flags.has_any_of(TR_PVAL_FLAG_MASK)) {
@@ -480,23 +481,24 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
             }
             o_ptr->pval = 1;
         } else if (o_ptr->pval == 0) {
-            char tmp_val[8] = "1";
-            auto limit = std::min(5, smith.get_addable_count(effect, o_ptr));
-
-            if (!get_string(format(_("いくつ付加しますか? (1-%d): ", "Enchant how many? (1-%d): "), limit), tmp_val, 1)) {
+            const auto limit = std::min(5, smith.get_addable_count(effect, o_ptr));
+            const auto num_enchants = input_value<short>(prompt, 1, limit, 1);
+            if (!num_enchants.has_value()) {
                 return;
             }
-            o_ptr->pval = static_cast<PARAMETER_VALUE>(std::clamp(atoi(tmp_val), 1, limit));
+
+            o_ptr->pval = num_enchants.value();
         }
 
         add_essence_count = o_ptr->pval;
     } else if (effect == SmithEffectType::SLAY_GLOVE) {
-        char tmp_val[8] = "1";
         const auto max_val = player_ptr->lev / 7 + 3;
-        if (!get_string(format(_("いくつ付加しますか? (1-%d):", "Enchant how many? (1-%d):"), max_val), tmp_val, 2)) {
+        const auto num_enchants = input_value(prompt, 1, max_val, 1);
+        if (!num_enchants.has_value()) {
             return;
         }
-        add_essence_count = std::clamp(atoi(tmp_val), 1, max_val);
+
+        add_essence_count = num_enchants.value();
     }
 
     msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence * add_essence_count);