OSDN Git Service

[Refactor] Spoiler File作成時のメッセージを分離
authordis- <dis.rogue@gmail.com>
Mon, 15 Feb 2021 10:38:53 +0000 (19:38 +0900)
committerdis- <dis.rogue@gmail.com>
Mon, 15 Feb 2021 14:17:54 +0000 (23:17 +0900)
デバッグモードのSpoiler File出力の途中でmsg_print()処理をしているので、コマンドラインからコールするときに邪魔である。
ファイル出力の結果をenumで返してメッセージは関数外部で表示するよう変更する。

src/cmd-io/cmd-lore.c
src/view/display-lore.h
src/wizard/fixed-artifacts-spoiler.c
src/wizard/fixed-artifacts-spoiler.h
src/wizard/items-spoiler.c
src/wizard/items-spoiler.h
src/wizard/monster-info-spoiler.c
src/wizard/monster-info-spoiler.h
src/wizard/spoiler-util.h
src/wizard/wizard-spoiler.c

index 39faebe..fb257fd 100644 (file)
@@ -205,4 +205,4 @@ void do_cmd_query_symbol(player_type *creature_ptr)
 
     C_KILL(who, max_r_idx, MONRACE_IDX);
     prt(buf, 0, 0);
-}
\ No newline at end of file
+}
index 6824d01..e1199b0 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once
 
-#include "system/angband.h"
 #include "lore/lore-util.h"
+#include "system/angband.h"
 
 void roff_top(MONRACE_IDX r_idx);
 void screen_roff(player_type *player_ptr, MONRACE_IDX r_idx, monster_lore_mode mode);
index 7764518..47b1c0c 100644 (file)
@@ -142,11 +142,9 @@ static void spoiler_print_art(obj_desc_list *art_ptr)
 /*!
  * @brief アーティファクト情報のスポイラー出力を行うメインルーチン /
  * Create a spoiler file for artifacts
- * @param player_ptr プレーヤーへの参照ポインタ
  * @param fname 生成ファイル名
- * @return なし
  */
-void spoil_fixed_artifact(concptr fname)
+spoiler_output_status spoil_fixed_artifact(concptr fname)
 {
     player_type dummy;
     object_type forge;
@@ -156,8 +154,7 @@ void spoil_fixed_artifact(concptr fname)
     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
     spoiler_file = angband_fopen(buf, "w");
     if (!spoiler_file) {
-        msg_print("Cannot create spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FOPEN;
     }
 
     print_header();
@@ -184,9 +181,7 @@ void spoil_fixed_artifact(concptr fname)
     }
 
     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
-        msg_print("Cannot close spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FCLOSE;
     }
-
-    msg_print("Successfully created a spoiler file.");
-}
\ No newline at end of file
+    return SPOILER_OUTPUT_SUCCESS;
+}
index 5bd649d..caed619 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "system/angband.h"
+#include "wizard/spoiler-util.h"
 
 void spoiler_outlist(concptr header, concptr *list, char separator);
-void spoil_fixed_artifact(concptr fname);
+spoiler_output_status spoil_fixed_artifact(concptr fname);
index 0ff15dd..4c0635b 100644 (file)
@@ -84,20 +84,17 @@ static void kind_info(player_type *player_ptr, char *buf, char *dam, char *wgt,
 
 /*!
  * @brief 各ベースアイテムの情報を一行毎に記述する /
- * @param player_ptr プレーヤーへの参照ポインタ
  * Create a spoiler file for items
  * @param fname ファイル名
- * @return なし
  */
-void spoil_obj_desc(concptr fname)
+spoiler_output_status spoil_obj_desc(concptr fname)
 {
     player_type dummy;
     char buf[1024];
     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
     spoiler_file = angband_fopen(buf, "w");
     if (!spoiler_file) {
-        msg_print("Cannot create spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FOPEN;
     }
 
     char title[200];
@@ -163,9 +160,7 @@ void spoil_obj_desc(concptr fname)
     }
 
     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
-        msg_print("Cannot close spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FCLOSE;
     }
-
-    msg_print("Successfully created a spoiler file.");
-}
\ No newline at end of file
+    return SPOILER_OUTPUT_SUCCESS;
+}
index 275799e..6192798 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 
 #include "system/angband.h"
+#include "wizard/spoiler-util.h"
 
-void spoil_obj_desc(concptr fname);
+spoiler_output_status spoil_obj_desc(concptr fname);
index 5b32e3b..0de1b20 100644 (file)
@@ -9,7 +9,6 @@
 #include "util/sort.h"
 #include "view/display-lore.h"
 #include "view/display-messages.h"
-#include "wizard/spoiler-util.h"
 
 /*!
  * @brief シンボル職の記述名を返す /
@@ -70,9 +69,8 @@ static concptr attr_to_text(monster_race *r_ptr)
  * @brief モンスター簡易情報のスポイラー出力を行うメインルーチン /
  * Create a spoiler file for monsters   -BEN-
  * @param fname 生成ファイル名
- * @return なし
  */
-void spoil_mon_desc(concptr fname)
+spoiler_output_status spoil_mon_desc(concptr fname)
 {
     player_type dummy;
     u16b why = 2;
@@ -88,8 +86,7 @@ void spoil_mon_desc(concptr fname)
     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
     spoiler_file = angband_fopen(buf, "w");
     if (!spoiler_file) {
-        msg_print("Cannot create spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FOPEN;
     }
 
     char title[200];
@@ -144,11 +141,9 @@ void spoil_mon_desc(concptr fname)
     fprintf(spoiler_file, "\n");
     C_KILL(who, max_r_idx, s16b);
     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
-        msg_print("Cannot close spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FCLOSE;
     }
-
-    msg_print("Successfully created a spoiler file.");
+    return SPOILER_OUTPUT_SUCCESS;
 }
 
 /*!
@@ -170,15 +165,14 @@ static void roff_func(TERM_COLOR attr, concptr str)
  * @param fname ファイル名
  * @return なし
  */
-void spoil_mon_info(concptr fname)
+spoiler_output_status spoil_mon_info(concptr fname)
 {
     player_type dummy;
     char buf[1024];
     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
     spoiler_file = angband_fopen(buf, "w");
     if (!spoiler_file) {
-        msg_print("Cannot create spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FOPEN;
     }
 
     char title[200];
@@ -245,9 +239,7 @@ void spoil_mon_info(concptr fname)
 
     C_KILL(who, max_r_idx, s16b);
     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
-        msg_print("Cannot close spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FCLOSE;
     }
-
-    msg_print("Successfully created a spoiler file.");
-}
\ No newline at end of file
+    return SPOILER_OUTPUT_SUCCESS;
+}
index 84a095c..340be5b 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "system/angband.h"
+#include "wizard/spoiler-util.h"
 
-void spoil_mon_desc(concptr fname);
-void spoil_mon_info(concptr fname);
+spoiler_output_status spoil_mon_desc(concptr fname);
+spoiler_output_status spoil_mon_info(concptr fname);
index 6f8fa37..3f2e231 100644 (file)
@@ -46,3 +46,10 @@ extern FILE *spoiler_file;
 void spoiler_blanklines(int n);
 void spoiler_underline(concptr str);
 void spoil_out(concptr str);
+
+typedef enum spoiler_output_status {
+    SPOILER_OUTPUT_CANCEL,
+    SPOILER_OUTPUT_SUCCESS,
+    SPOILER_OUTPUT_FAIL_FOPEN,
+    SPOILER_OUTPUT_FAIL_FCLOSE
+} spoiler_output_status;
index 4ac633e..a514350 100644 (file)
@@ -79,7 +79,7 @@ static bool is_partial_tree(int *tree, int *partial_tree)
  * @param fname 出力ファイル名
  * @return なし
  */
-static void spoil_mon_evol(concptr fname)
+static spoiler_output_status spoil_mon_evol(concptr fname)
 {
     char buf[1024];
     monster_race *r_ptr;
@@ -89,8 +89,7 @@ static void spoil_mon_evol(concptr fname)
     path_build(buf, sizeof buf, ANGBAND_DIR_USER, fname);
     spoiler_file = angband_fopen(buf, "w");
     if (!spoiler_file) {
-        msg_print("Cannot create spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FOPEN;
     }
 
     char title[200];
@@ -157,11 +156,9 @@ static void spoil_mon_evol(concptr fname)
     C_KILL(evol_tree_zero, max_r_idx * (max_evolution_depth + 1), int);
     C_KILL(evol_tree, max_r_idx, int *);
     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
-        msg_print("Cannot close spoiler file.");
-        return;
+        return SPOILER_OUTPUT_FAIL_FCLOSE;
     }
-
-    msg_print("Successfully created a spoiler file.");
+    return SPOILER_OUTPUT_SUCCESS;
 }
 
 /*!
@@ -173,6 +170,7 @@ void exe_output_spoilers(void)
 {
     screen_save();
     while (TRUE) {
+        spoiler_output_status status = SPOILER_OUTPUT_CANCEL;
         term_clear();
         prt("Create a spoiler file.", 2, 0);
         prt("(1) Brief Object Info (obj-desc.txt)", 5, 5);
@@ -186,25 +184,36 @@ void exe_output_spoilers(void)
             screen_load();
             return;
         case '1':
-            spoil_obj_desc("obj-desc.txt");
+            status = spoil_obj_desc("obj-desc.txt");
             break;
         case '2':
-            spoil_fixed_artifact("artifact.txt");
+            status = spoil_fixed_artifact("artifact.txt");
             break;
         case '3':
-            spoil_mon_desc("mon-desc.txt");
+            status = spoil_mon_desc("mon-desc.txt");
             break;
         case '4':
-            spoil_mon_info("mon-info.txt");
+            status = spoil_mon_info("mon-info.txt");
             break;
         case '5':
-            spoil_mon_evol("mon-evol.txt");
+            status = spoil_mon_evol("mon-evol.txt");
             break;
         default:
             bell();
             break;
         }
 
+        switch (status) {
+        case SPOILER_OUTPUT_FAIL_FOPEN:
+            msg_print("Cannot create spoiler file.");
+            break;
+        case SPOILER_OUTPUT_FAIL_FCLOSE:
+            msg_print("Cannot close spoiler file.");
+            break;
+        case SPOILER_OUTPUT_SUCCESS:
+            msg_print("Successfully created a spoiler file.");
+            break;
+        }
         msg_erase();
     }
-}
\ No newline at end of file
+}