2 * @file main-win-cfg-reader.cpp
3 * @brief Windows版固有実装(.cfgファイル処理)
6 #include "main-win/main-win-cfg-reader.h"
7 #include "main-win/main-win-define.h"
8 #include "main-win/main-win-file-utils.h"
9 #include "main-win/main-win-tokenizer.h"
10 #include "main-win/main-win-windows.h"
11 #include "term/z-term.h"
12 #include "util/angband-files.h"
14 #include "main/sound-definitions-table.h"
22 * typeを上位16ビット, valを下位16ビットに設定した値をマップのキーとする。
23 * @param type the "actions" value of "term_xtra()". see:z-term.h TERM_XTRA_xxxxx
24 * @param val the 2nd parameter of "term_xtra()"
27 static cfg_key make_cfg_key(int type, int val)
29 return ((type << 16) | (val & 0xffff));
33 * @brief マップのキーに対応する値を取得する
34 * @param key1_type the "actions" value of "term_xtra()". see:z-term.h TERM_XTRA_xxxxx
35 * @param key2_val the 2nd parameter of "term_xtra()"
36 * @return キーに対応する値を返す。登録されていない場合はNULLを返す。
38 static cfg_values *get_map_value(cfg_map *map, int key1_type, int key2_val)
40 cfg_values *value = NULL;
41 auto ite = map->find(make_cfg_key(key1_type, key2_val));
42 if (ite != map->end()) {
49 * @brief 登録されている中からランダムに選択する
50 * @param type the "actions" value of "term_xtra()". see:z-term.h TERM_XTRA_xxxxx
51 * @param val the 2nd parameter of "term_xtra()"
52 * @return キーに対応する値、複数のファイル名の中からからランダムに返す。登録されていない場合はNULLを返す。
54 concptr CfgData::get_rand(int key1_type, int key2_val)
56 cfg_values *filenames = get_map_value(this->map, key1_type, key2_val);
61 return filenames->at(Rand_external(filenames->size()));
64 bool CfgData::has_key(int key1_type, int key2_val)
66 auto ite = map->find(make_cfg_key(key1_type, key2_val));
67 return (ite != map->end());
70 void CfgData::insert(int key1_type, int key2_val, cfg_values *value)
72 this->map->insert(std::make_pair(make_cfg_key(key1_type, key2_val), value));
76 * @param dir .cfgファイルのディレクトリ
77 * @param files .cfgファイル名。複数指定可能で、最初に見つかったファイルから読み取る。
79 CfgReader::CfgReader(concptr dir, std::initializer_list<concptr> files)
82 this->cfg_path = find_any_file(dir, files);
87 * @param sections 読み取るデータの指定
88 * @return 読み込んだデータを登録したCfgDataを返す。
90 CfgData *CfgReader::read_sections(std::initializer_list<cfg_section> sections)
92 CfgData *result = new CfgData();
94 if (!check_file(this->cfg_path.c_str())) {
99 char buf[MAIN_WIN_MAX_PATH];
100 char path[MAIN_WIN_MAX_PATH];
101 char *tokens[SAMPLE_MAX];
103 for (auto §ion : sections) {
105 bool has_data = false;
108 while ((read_key = section.key_at(index, key_buf)) != NULL) {
109 GetPrivateProfileStringA(section.section_name, read_key, "", buf, MAIN_WIN_MAX_PATH, this->cfg_path.c_str());
111 cfg_values *filenames = new cfg_values();
112 const int num = tokenize_whitespace(buf, SAMPLE_MAX, tokens);
113 for (int j = 0; j < num; j++) {
114 path_build(path, MAIN_WIN_MAX_PATH, dir, tokens[j]);
115 if (check_file(path))
116 filenames->push_back(string_make(tokens[j]));
118 if (filenames->empty()) {
121 result->insert(section.action_type, index, filenames);
129 if (section.has_data) {
130 *(section.has_data) = has_data;