本文整理汇总了C++中FileParser类的典型用法代码示例。如果您正苦于以下问题:C++ FileParser类的具体用法?C++ FileParser怎么用?C++ FileParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readGameSlot
void GameStateLoad::readGameSlot(int slot) {
stringstream filename;
FileParser infile;
// abort if not a valid slot number
if (slot < 0 || slot >= GAME_SLOT_MAX) return;
// save slots are named save#.txt
filename << PATH_USER;
if (GAME_PREFIX.length() > 0)
filename << GAME_PREFIX << "_";
filename << "save" << (slot+1) << ".txt";
if (!infile.open(filename.str(),false, true, "")) return;
while (infile.next()) {
// load (key=value) pairs
if (infile.key == "name")
stats[slot].name = infile.val;
else if (infile.key == "class")
stats[slot].character_class = infile.val;
else if (infile.key == "xp")
stats[slot].xp = atoi(infile.val.c_str());
else if (infile.key == "build") {
stats[slot].physical_character = atoi(infile.nextValue().c_str());
stats[slot].mental_character = atoi(infile.nextValue().c_str());
stats[slot].offense_character = atoi(infile.nextValue().c_str());
stats[slot].defense_character = atoi(infile.nextValue().c_str());
}
else if (infile.key == "equipped") {
string repeat_val = infile.nextValue();
while (repeat_val != "") {
equipped[slot].push_back(toInt(repeat_val));
repeat_val = infile.nextValue();
}
}
else if (infile.key == "option") {
stats[slot].base = infile.nextValue();
stats[slot].head = infile.nextValue();
stats[slot].portrait = infile.nextValue();
}
else if (infile.key == "spawn") {
current_map[slot] = getMapName(infile.nextValue());
}
else if (infile.key == "permadeath") {
stats[slot].permadeath = (toInt(infile.val) == 1);
}
}
infile.close();
stats[slot].recalc();
loadPreview(slot);
}
示例2: update
void MenuActionBar::update() {
// Read data from config file
FileParser infile;
if (infile.open(mods->locate("menus/actionbar.txt"))) {
while (infile.next()) {
infile.val = infile.val + ',';
if (infile.key == "slot1") {
slots[0].x = window_area.x+eatFirstInt(infile.val, ',');
slots[0].y = window_area.y+eatFirstInt(infile.val, ',');
slots[0].w = eatFirstInt(infile.val, ',');
slots[0].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot2") {
slots[1].x = window_area.x+eatFirstInt(infile.val, ',');
slots[1].y = window_area.y+eatFirstInt(infile.val, ',');
slots[1].w = eatFirstInt(infile.val, ',');
slots[1].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot3") {
slots[2].x = window_area.x+eatFirstInt(infile.val, ',');
slots[2].y = window_area.y+eatFirstInt(infile.val, ',');
slots[2].w = eatFirstInt(infile.val, ',');
slots[2].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot4") {
slots[3].x = window_area.x+eatFirstInt(infile.val, ',');
slots[3].y = window_area.y+eatFirstInt(infile.val, ',');
slots[3].w = eatFirstInt(infile.val, ',');
slots[3].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot5") {
slots[4].x = window_area.x+eatFirstInt(infile.val, ',');
slots[4].y = window_area.y+eatFirstInt(infile.val, ',');
slots[4].w = eatFirstInt(infile.val, ',');
slots[4].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot6") {
slots[5].x = window_area.x+eatFirstInt(infile.val, ',');
slots[5].y = window_area.y+eatFirstInt(infile.val, ',');
slots[5].w = eatFirstInt(infile.val, ',');
slots[5].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot7") {
slots[6].x = window_area.x+eatFirstInt(infile.val, ',');
slots[6].y = window_area.y+eatFirstInt(infile.val, ',');
slots[6].w = eatFirstInt(infile.val, ',');
slots[6].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot8") {
slots[7].x = window_area.x+eatFirstInt(infile.val, ',');
slots[7].y = window_area.y+eatFirstInt(infile.val, ',');
slots[7].w = eatFirstInt(infile.val, ',');
slots[7].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot9") {
slots[8].x = window_area.x+eatFirstInt(infile.val, ',');
slots[8].y = window_area.y+eatFirstInt(infile.val, ',');
slots[8].w = eatFirstInt(infile.val, ',');
slots[8].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot10") {
slots[9].x = window_area.x+eatFirstInt(infile.val, ',');
slots[9].y = window_area.y+eatFirstInt(infile.val, ',');
slots[9].w = eatFirstInt(infile.val, ',');
slots[9].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot_M1") {
slots[10].x = window_area.x+eatFirstInt(infile.val, ',');
slots[10].y = window_area.y+eatFirstInt(infile.val, ',');
slots[10].w = eatFirstInt(infile.val, ',');
slots[10].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "slot_M2") {
slots[11].x = window_area.x+eatFirstInt(infile.val, ',');
slots[11].y = window_area.y+eatFirstInt(infile.val, ',');
slots[11].w = eatFirstInt(infile.val, ',');
slots[11].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "char_menu") {
menus[0].x = window_area.x+eatFirstInt(infile.val, ',');
menus[0].y = window_area.y+eatFirstInt(infile.val, ',');
menus[0].w = eatFirstInt(infile.val, ',');
menus[0].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "inv_menu") {
menus[1].x = window_area.x+eatFirstInt(infile.val, ',');
menus[1].y = window_area.y+eatFirstInt(infile.val, ',');
menus[1].w = eatFirstInt(infile.val, ',');
menus[1].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "powers_menu") {
menus[2].x = window_area.x+eatFirstInt(infile.val, ',');
menus[2].y = window_area.y+eatFirstInt(infile.val, ',');
menus[2].w = eatFirstInt(infile.val, ',');
menus[2].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "log_menu") {
menus[3].x = window_area.x+eatFirstInt(infile.val, ',');
menus[3].y = window_area.y+eatFirstInt(infile.val, ',');
menus[3].w = eatFirstInt(infile.val, ',');
menus[3].h = eatFirstInt(infile.val, ',');
} else if (infile.key == "numberArea") {
numberArea.x = window_area.x+eatFirstInt(infile.val, ',');
numberArea.w = eatFirstInt(infile.val, ',');
numberArea.h = eatFirstInt(infile.val, ',');
} else if (infile.key == "mouseArea") {
mouseArea.x = window_area.x+eatFirstInt(infile.val, ',');
mouseArea.w = eatFirstInt(infile.val, ',');
mouseArea.h = eatFirstInt(infile.val, ',');
} else if (infile.key == "menuArea") {
menuArea.x = window_area.x+eatFirstInt(infile.val, ',');
menuArea.w = eatFirstInt(infile.val, ',');
//.........这里部分代码省略.........
示例3: GameState
GameStateNew::GameStateNew() : GameState() {
game_slot = 0;
current_option = 0;
option_count = 0;
tip_buf.clear();
modified_name = false;
// set up buttons
button_exit = new WidgetButton("images/menus/buttons/button_default.png");
button_exit->label = msg->get("Cancel");
button_exit->pos.x = VIEW_W_HALF - button_exit->pos.w;
button_exit->pos.y = VIEW_H - button_exit->pos.h;
button_exit->refresh();
button_create = new WidgetButton("images/menus/buttons/button_default.png");
button_create->label = msg->get("Create");
button_create->pos.x = VIEW_W_HALF;
button_create->pos.y = VIEW_H - button_create->pos.h;
button_create->enabled = false;
button_create->refresh();
button_prev = new WidgetButton("images/menus/buttons/left.png");
button_next = new WidgetButton("images/menus/buttons/right.png");
input_name = new WidgetInput();
button_permadeath = new WidgetCheckBox("images/menus/buttons/checkbox_default.png");
if (DEATH_PENALTY_PERMADEATH) {
button_permadeath->enabled = false;
button_permadeath->Check();
}
class_list = new WidgetListBox (HERO_CLASSES.size(), 12, "images/menus/buttons/listbox_default.png");
class_list->can_deselect = false;
class_list->selected[0] = true;
show_classlist = true;
tip = new WidgetTooltip();
// Read positions from config file
FileParser infile;
if (infile.open("menus/gamenew.txt")) {
while (infile.next()) {
infile.val = infile.val + ',';
if (infile.key == "button_prev") {
button_prev->pos.x = eatFirstInt(infile.val, ',');
button_prev->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "button_next") {
button_next->pos.x = eatFirstInt(infile.val, ',');
button_next->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "button_permadeath") {
button_permadeath->pos.x = eatFirstInt(infile.val, ',');
button_permadeath->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "name_input") {
name_pos.x = eatFirstInt(infile.val, ',');
name_pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "portrait_label") {
portrait_label = eatLabelInfo(infile.val);
}
else if (infile.key == "name_label") {
name_label = eatLabelInfo(infile.val);
}
else if (infile.key == "permadeath_label") {
permadeath_label = eatLabelInfo(infile.val);
}
else if (infile.key == "classlist_label") {
classlist_label = eatLabelInfo(infile.val);
}
else if (infile.key == "portrait") {
portrait_pos.x = eatFirstInt(infile.val, ',');
portrait_pos.y = eatFirstInt(infile.val, ',');
portrait_pos.w = eatFirstInt(infile.val, ',');
portrait_pos.h = eatFirstInt(infile.val, ',');
}
else if (infile.key == "class_list") {
class_list->pos.x = eatFirstInt(infile.val, ',');
class_list->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "show_classlist") {
int show_cl = eatFirstInt(infile.val, ',');
if (show_cl == 1)
show_classlist = true;
else
show_classlist = false;
}
}
infile.close();
}
button_prev->pos.x += (VIEW_W - FRAME_W)/2;
button_prev->pos.y += (VIEW_H - FRAME_H)/2;
button_next->pos.x += (VIEW_W - FRAME_W)/2;
button_next->pos.y += (VIEW_H - FRAME_H)/2;
//.........这里部分代码省略.........
示例4: load
/**
* load a statblock, typically for an enemy definition
*/
void StatBlock::load(const std::string& filename) {
// @CLASS StatBlock: Enemies|Description of enemies in enemies/
FileParser infile;
if (!infile.open(filename))
return;
bool clear_loot = true;
while (infile.next()) {
if (infile.new_section) {
// APPENDed file
clear_loot = true;
}
int num = toInt(infile.val);
float fnum = toFloat(infile.val);
bool valid = loadCoreStat(&infile) || loadSfxStat(&infile);
// @ATTR name|string|Name
if (infile.key == "name") name = msg->get(infile.val);
// @ATTR humanoid|boolean|This creature gives human traits when transformed into, such as the ability to talk with NPCs.
else if (infile.key == "humanoid") humanoid = toBool(infile.val);
// @ATTR level|integer|Level
else if (infile.key == "level") level = num;
// enemy death rewards and events
// @ATTR xp|integer|XP awarded upon death.
else if (infile.key == "xp") xp = num;
else if (infile.key == "loot") {
// @ATTR loot|[currency:item (integer)], chance (integer), min (integer), max (integer)|Possible loot that can be dropped on death.
// loot entries format:
// loot=[id],[percent_chance]
// optionally allow range:
// loot=[id],[percent_chance],[count_min],[count_max]
if (clear_loot) {
loot_table.clear();
clear_loot = false;
}
loot_table.push_back(Event_Component());
loot->parseLoot(infile, &loot_table.back(), &loot_table);
}
// @ATTR defeat_status|string|Campaign status to set upon death.
else if (infile.key == "defeat_status") defeat_status = infile.val;
// @ATTR convert_status|string|Campaign status to set upon being converted to a player ally.
else if (infile.key == "convert_status") convert_status = infile.val;
// @ATTR first_defeat_loot|integer|Drops this item upon first death.
else if (infile.key == "first_defeat_loot") first_defeat_loot = num;
// @ATTR quest_loot|[requires status (string), requires not status (string), item (integer)|Drops this item when campaign status is met.
else if (infile.key == "quest_loot") {
quest_loot_requires_status = infile.nextValue();
quest_loot_requires_not_status = infile.nextValue();
quest_loot_id = toInt(infile.nextValue());
}
// combat stats
// @ATTR cooldown|integer|Cooldown between attacks in 'ms' or 's'.
else if (infile.key == "cooldown") cooldown = parse_duration(infile.val);
// behavior stats
// @ATTR flying|boolean|Creature can move over gaps/water.
else if (infile.key == "flying") flying = toBool(infile.val);
// @ATTR intangible|boolean|Creature can move through walls.
else if (infile.key == "intangible") intangible = toBool(infile.val);
// @ATTR facing|boolean|Creature can turn to face their target.
else if (infile.key == "facing") facing = toBool(infile.val);
// @ATTR waypoint_pause|duration|Duration to wait at each waypoint in 'ms' or 's'.
else if (infile.key == "waypoint_pause") waypoint_pause = parse_duration(infile.val);
// @ATTR turn_delay|duration|Duration it takes for this creature to turn and face their target in 'ms' or 's'.
else if (infile.key == "turn_delay") turn_delay = parse_duration(infile.val);
// @ATTR chance_pursue|integer|Percentage change that the creature will chase their target.
else if (infile.key == "chance_pursue") chance_pursue = num;
// @ATTR chance_flee|integer|Percentage chance that the creature will run away from their target.
else if (infile.key == "chance_flee") chance_flee = num;
// @ATTR chance_melee_phys|integer|Percentage chance that the creature will use their physical melee power.
else if (infile.key == "chance_melee_phys") power_chance[MELEE_PHYS] = num;
// @ATTR chance_melee_ment|integer|Percentage chance that the creature will use their mental melee power.
else if (infile.key == "chance_melee_ment") power_chance[MELEE_MENT] = num;
// @ATTR chance_ranged_phys|integer|Percentage chance that the creature will use their physical ranged power.
else if (infile.key == "chance_ranged_phys") power_chance[RANGED_PHYS] = num;
// @ATTR chance_ranged_ment|integer|Percentage chance that the creature will use their mental ranged power.
else if (infile.key == "chance_ranged_ment") power_chance[RANGED_MENT] = num;
// @ATTR power_melee_phys|integer|Power index for the physical melee power.
else if (infile.key == "power_melee_phys") power_index[MELEE_PHYS] = powers->verifyID(num, &infile);
// @ATTR power_melee_ment|integer|Power index for the mental melee power.
else if (infile.key == "power_melee_ment") power_index[MELEE_MENT] = powers->verifyID(num, &infile);
// @ATTR power_ranged_phys|integer|Power index for the physical ranged power.
else if (infile.key == "power_ranged_phys") power_index[RANGED_PHYS] = powers->verifyID(num, &infile);
// @ATTR power_ranged_ment|integer|Power index for the mental ranged power.
else if (infile.key == "power_ranged_ment") power_index[RANGED_MENT] = powers->verifyID(num, &infile);
// @ATTR power_beacon|integer|Power index of a "beacon" power used to aggro nearby creatures.
else if (infile.key == "power_beacon") power_index[BEACON] = powers->verifyID(num, &infile);
//.........这里部分代码省略.........
示例5: GameState
GameStateConfig::GameStateConfig ()
: GameState(),
child_widget(),
ok_button(NULL),
defaults_button(NULL),
cancel_button(NULL),
imgFileName(mods->locate("images/menus/config.png"))
{
// Load background image
SDL_Surface * tmp = IMG_Load(imgFileName.c_str());
if (NULL == tmp) {
fprintf(stderr, "Could not load image \"%s\" error \"%s\"\n",
imgFileName.c_str(), IMG_GetError());
SDL_Quit();
exit(1);
}
background = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);
// Initialize Widgets
tabControl = new WidgetTabControl(5);
ok_button = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
defaults_button = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
cancel_button = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
for (unsigned int i = 0; i < 41; i++) {
settings_lb[i] = new WidgetLabel();
}
for (unsigned int i = 0; i < 3; i++) {
settings_sl[i] = new WidgetSlider(mods->locate("images/menus/buttons/slider_default.png"));
}
for (unsigned int i = 0; i < 6; i++) {
settings_cb[i] = new WidgetCheckBox(mods->locate("images/menus/buttons/checkbox_default.png"));
}
for (unsigned int i = 0; i < 50; i++) {
settings_key[i] = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
}
keyboard_layout = new WidgetComboBox(2, mods->locate("images/menus/buttons/combobox_default.png"));
keyboard_layout->set(0, "QWERTY");
keyboard_layout->set(1, "AZERTY");
input_scrollbox = new WidgetScrollBox(600, 230, 780);
input_scrollbox->pos.x = (VIEW_W - 640)/2 + 10;
input_scrollbox->pos.y = (VIEW_H - 480)/2 + 150;
input_scrollbox->refresh();
settings_btn[0] = new WidgetButton(mods->locate("images/menus/buttons/up.png"));
settings_btn[1] = new WidgetButton(mods->locate("images/menus/buttons/down.png"));
settings_btn[2] = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
settings_btn[3] = new WidgetButton(mods->locate("images/menus/buttons/button_default.png"));
// Allocate Joycticks ComboBox
settings_cmb[0] = new WidgetComboBox(SDL_NumJoysticks(), mods->locate("images/menus/buttons/combobox_default.png"));
// Allocate Resolution ComboBox
int resolutions = getVideoModes();
if (resolutions < 1) fprintf(stderr, "Unable to get resolutions list!\n");
settings_cmb[1] = new WidgetComboBox(resolutions, mods->locate("images/menus/buttons/combobox_default.png"));
// Allocate Languages ComboBox
int langCount = getLanguagesNumber();
language_ISO = new std::string[langCount];
language_full = new std::string[langCount];
settings_cmb[2] = new WidgetComboBox(langCount, mods->locate("images/menus/buttons/combobox_default.png"));
// Allocate Mods ListBoxes
vector<string> mod_dirs;
getDirList(PATH_DATA + "mods", mod_dirs);
settings_lstb[0] = new WidgetListBox(mod_dirs.size(), 5, mods->locate("images/menus/buttons/listbox_default.png"));
settings_lstb[1] = new WidgetListBox(mod_dirs.size(), 5, mods->locate("images/menus/buttons/listbox_default.png"));
//Load the menu configuration from file
int x1;
int y1;
int x2;
int y2;
int setting_num;
int offset_x;
int offset_y;
FileParser infile;
if (infile.open(mods->locate("menus/config.txt"))) {
while (infile.next()) {
infile.val = infile.val + ',';
x1 = eatFirstInt(infile.val, ',');
y1 = eatFirstInt(infile.val, ',');
x2 = eatFirstInt(infile.val, ',');
y2 = eatFirstInt(infile.val, ',');
setting_num = -1;
if (infile.key == "fullscreen") setting_num = 1;
else if (infile.key == "mouse_move") setting_num = 2;
//.........这里部分代码省略.........
示例6: bar
MenuStatBar::MenuStatBar(short _type)
: bar(NULL)
, label(new WidgetLabel())
, stat_min(0)
, stat_cur(0)
, stat_cur_prev(0)
, stat_max(0)
, orientation(HORIZONTAL)
, custom_text_pos(false) // label will be placed in the middle of the bar
, custom_string("")
, bar_gfx("")
, bar_gfx_background("")
, type(_type)
{
std::string type_filename;
if (type == TYPE_HP)
type_filename = "hp";
else if (type == TYPE_MP)
type_filename = "mp";
else if (type == TYPE_XP)
type_filename = "xp";
// Load config settings
FileParser infile;
// @CLASS MenuStatBar|Description of menus/hp.txt, menus/mp.txt, menus/xp.txt
if(!type_filename.empty() && infile.open("menus/" + type_filename + ".txt", FileParser::MOD_FILE, FileParser::ERROR_NORMAL)) {
while(infile.next()) {
if (parseMenuKey(infile.key, infile.val))
continue;
// @ATTR bar_pos|rectangle|Position and dimensions of the bar graphics.
if(infile.key == "bar_pos") {
bar_pos = Parse::toRect(infile.val);
}
// @ATTR text_pos|label|Position of the text displaying the current value of the relevant stat.
else if(infile.key == "text_pos") {
custom_text_pos = true;
text_pos = Parse::popLabelInfo(infile.val);
}
// @ATTR orientation|bool|True is vertical orientation; false is horizontal.
else if(infile.key == "orientation") {
orientation = Parse::toBool(infile.val);
}
// @ATTR bar_gfx|filename|Filename of the image to use for the "fill" of the bar.
else if (infile.key == "bar_gfx") {
bar_gfx = infile.val;
}
// @ATTR bar_gfx_background|filename|Filename of the image to use for the base of the bar.
else if (infile.key == "bar_gfx_background") {
bar_gfx_background = infile.val;
}
// @ATTR hide_timeout|duration|Hide HP and MP bar if full mana or health, after given amount of seconds; Hide XP bar if no changes in XP points for given amount of seconds. 0 disable hiding.
else if (infile.key == "hide_timeout") {
timeout.setDuration(Parse::toDuration(infile.val));
}
else {
infile.error("MenuStatBar: '%s' is not a valid key.", infile.key.c_str());
}
}
infile.close();
}
loadGraphics();
align();
}
示例7: loadSets
void ItemManager::loadSets(const string& filename) {
FileParser infile;
if (!infile.open(filename)) {
fprintf(stderr, "Unable to open %s!\n", filename.c_str());
return;
}
int id = 0;
bool id_line;
while (infile.next()) {
if (infile.key == "id") {
id_line = true;
id = toInt(infile.val);
if (id > 0 && id >= (int)item_sets.size()) {
// *2 to amortize the resizing to O(log(n)).
item_sets.resize((2*id) + 1);
}
} else id_line = false;
if (id < 1) {
if (id_line) fprintf(stderr, "Item set index out of bounds 1-%d, skipping\n", INT_MAX);
continue;
}
if (id_line) continue;
if (infile.key == "name") {
item_sets[id].name = msg->get(infile.val);
}
else if (infile.key == "items") {
string item_id = infile.nextValue();
while (item_id != "") {
if (toInt(item_id) > 0) {
items[toInt(item_id)].set = id;
item_sets[id].items.push_back(toInt(item_id));
item_id = infile.nextValue();
} else fprintf(stderr, "Item index inside item set %s definition out of bounds 1-%d, skipping item\n", item_sets[id].name.c_str(), INT_MAX);
}
}
else if (infile.key == "color") {
item_sets[id].color.r = toInt(infile.nextValue());
item_sets[id].color.g = toInt(infile.nextValue());
item_sets[id].color.b = toInt(infile.nextValue());
}
else if (infile.key == "bonus") {
Set_bonus bonus;
bonus.requirement = toInt(infile.nextValue());
bonus.bonus_stat = infile.nextValue();
bonus.bonus_val = toInt(infile.nextValue());
item_sets[id].bonus.push_back(bonus);
}
}
infile.close();
}
示例8: loadSets
/**
* Load a specific item sets file
*
* @param filename The (full) path and name of the file to load
*/
void ItemManager::loadSets(const std::string& filename, bool locateFileName) {
FileParser infile;
// @CLASS ItemManager: Sets|Definition of a item sets, items/sets.txt...
if (!infile.open(filename, locateFileName))
return;
bool clear_bonus = true;
int id = 0;
bool id_line;
while (infile.next()) {
if (infile.key == "id") {
// @ATTR id|integer|A uniq id for the item set.
id_line = true;
id = toInt(infile.val);
if (id > 0) {
size_t new_size = id+1;
if (item_sets.size() <= new_size)
item_sets.resize(new_size);
}
clear_bonus = true;
}
else id_line = false;
if (id < 1) {
if (id_line) infile.error("ItemManager: Item set index out of bounds 1-%d, skipping set.", INT_MAX);
continue;
}
if (id_line) continue;
assert(item_sets.size() > std::size_t(id));
if (infile.key == "name") {
// @ATTR name|string|Name of the item set.
item_sets[id].name = msg->get(infile.val);
}
else if (infile.key == "items") {
// @ATTR items|[item_id,...]|List of item id's that is part of the set.
item_sets[id].items.clear();
std::string item_id = infile.nextValue();
while (item_id != "") {
int temp_id = toInt(item_id);
if (temp_id > 0 && temp_id < static_cast<int>(items.size())) {
items[temp_id].set = id;
item_sets[id].items.push_back(temp_id);
}
else {
const int maxsize = static_cast<int>(items.size()-1);
infile.error("ItemManager: Item index out of bounds 1-%d, skipping item.", maxsize);
}
item_id = infile.nextValue();
}
}
else if (infile.key == "color") {
// @ATTR color|color|A specific of color for the set.
item_sets[id].color = toRGB(infile.val);
}
else if (infile.key == "bonus") {
// @ATTR bonus|[requirements (integer), bonus stat (string), bonus (integer)]|Bonus to append to items in the set.
if (clear_bonus) {
item_sets[id].bonus.clear();
clear_bonus = false;
}
Set_bonus bonus;
bonus.requirement = toInt(infile.nextValue());
parseBonus(bonus, infile);
item_sets[id].bonus.push_back(bonus);
}
else {
infile.error("ItemManager: '%s' is not a valid key.", infile.key.c_str());
}
}
infile.close();
}
示例9: loadItems
/**
* Load a specific items file
*
* @param filename The (full) path and name of the file to load
*/
void ItemManager::loadItems(const std::string& filename, bool locateFileName) {
FileParser infile;
// @CLASS ItemManager: Items|Description about the class and it usage, items/items.txt...
if (!infile.open(filename, locateFileName))
return;
// used to clear vectors when overriding items
bool clear_req_stat = true;
bool clear_bonus = true;
bool clear_loot_anim = true;
bool clear_replace_power = true;
int id = 0;
bool id_line = false;
while (infile.next()) {
if (infile.key == "id") {
// @ATTR id|integer|An uniq id of the item used as reference from other classes.
id_line = true;
id = toInt(infile.val);
addUnknownItem(id);
clear_req_stat = true;
clear_bonus = true;
clear_loot_anim = true;
clear_replace_power = true;
}
else id_line = false;
if (id < 1) {
if (id_line) infile.error("ItemManager: Item index out of bounds 1-%d, skipping item.", INT_MAX);
continue;
}
if (id_line) continue;
assert(items.size() > std::size_t(id));
if (infile.key == "name") {
// @ATTR name|string|Item name displayed on long and short tooltips.
items[id].name = msg->get(infile.val);
items[id].has_name = true;
}
else if (infile.key == "flavor")
// @ATTR flavor|string|A description of the item.
items[id].flavor = msg->get(infile.val);
else if (infile.key == "level")
// @ATTR level|integer|The item's level. Has no gameplay impact. (Deprecated?)
items[id].level = toInt(infile.val);
else if (infile.key == "icon") {
// @ATTR icon|integer|An id for the icon to display for this item.
items[id].icon = toInt(infile.nextValue());
}
else if (infile.key == "book") {
// @ATTR book|string|A book file to open when this item is activated.
items[id].book = infile.val;
}
else if (infile.key == "quality") {
// @ATTR quality|string|Item quality matching an id in items/qualities.txt
items[id].quality = infile.val;
}
else if (infile.key == "item_type") {
// @ATTR item_type|string|Equipment slot [artifact, head, chest, hands, legs, feets, main, off, ring] or base item type [gem, consumable]
items[id].type = infile.val;
}
else if (infile.key == "equip_flags") {
// @ATTR equip_flags|flag (string), ...|A comma separated list of flags to set when this item is equipped. See engine/equip_flags.txt.
items[id].equip_flags.clear();
std::string flag = popFirstString(infile.val);
while (flag != "") {
items[id].equip_flags.push_back(flag);
flag = popFirstString(infile.val);
}
}
else if (infile.key == "dmg_melee") {
// @ATTR dmg_melee|[min (integer), max (integer)]|Defines the item melee damage, if only min is specified the melee damage is fixed.
items[id].dmg_melee_min = toInt(infile.nextValue());
if (infile.val.length() > 0)
items[id].dmg_melee_max = toInt(infile.nextValue());
else
items[id].dmg_melee_max = items[id].dmg_melee_min;
}
else if (infile.key == "dmg_ranged") {
// @ATTR dmg_ranged|[min (integer), max (integer)]|Defines the item ranged damage, if only min is specified the ranged damage is fixed.
items[id].dmg_ranged_min = toInt(infile.nextValue());
if (infile.val.length() > 0)
items[id].dmg_ranged_max = toInt(infile.nextValue());
else
items[id].dmg_ranged_max = items[id].dmg_ranged_min;
}
else if (infile.key == "dmg_ment") {
// @ATTR dmg_ment|[min (integer), max (integer)]|Defines the item mental damage, if only min is specified the ranged damage is fixed.
items[id].dmg_ment_min = toInt(infile.nextValue());
if (infile.val.length() > 0)
items[id].dmg_ment_max = toInt(infile.nextValue());
//.........这里部分代码省略.........
示例10: loadLootTables
void LootManager::loadLootTables() {
std::vector<std::string> filenames = mods->list("loot", false);
for (unsigned i=0; i<filenames.size(); i++) {
FileParser infile;
if (!infile.open(filenames[i]))
continue;
std::vector<Event_Component> *ec_list = &loot_tables[filenames[i]];
Event_Component *ec = NULL;
bool skip_to_next = false;
while (infile.next()) {
if (infile.section == "") {
if (infile.key == "loot") {
ec_list->push_back(Event_Component());
ec = &ec_list->back();
parseLoot(infile, ec, ec_list);
}
}
else if (infile.section == "loot") {
if (infile.new_section) {
ec_list->push_back(Event_Component());
ec = &ec_list->back();
ec->type = "loot";
skip_to_next = false;
}
if (skip_to_next || ec == NULL)
continue;
if (infile.key == "id") {
ec->s = infile.val;
if (ec->s == "currency")
ec->c = CURRENCY_ID;
else if (toInt(ec->s, -1) != -1)
ec->c = toInt(ec->s);
else {
skip_to_next = true;
infile.error("LootManager: Invalid item id for loot.");
}
}
else if (infile.key == "chance") {
if (infile.val == "fixed")
ec->z = 0;
else
ec->z = toInt(infile.val);
}
else if (infile.key == "quantity") {
ec->a = toInt(infile.nextValue());
clampFloor(ec->a, 1);
ec->b = toInt(infile.nextValue());
clampFloor(ec->b, ec->a);
}
}
}
infile.close();
}
}
示例11: WidgetLabel
MenuCharacter::MenuCharacter(StatBlock *_stats) {
stats = _stats;
// Labels for major stats
cstat_labels[CSTAT_NAME] = "Name";
cstat_labels[CSTAT_LEVEL] = "Level";
cstat_labels[CSTAT_PHYSICAL] = "Physical";
cstat_labels[CSTAT_MENTAL] = "Mental";
cstat_labels[CSTAT_OFFENSE] = "Offense";
cstat_labels[CSTAT_DEFENSE] = "Defense";
skill_points = 0;
visible = false;
newPowerNotification = false;
for (int i=0; i<CSTAT_COUNT; i++) {
cstat[i].label = new WidgetLabel();
cstat[i].value = new WidgetLabel();
cstat[i].hover.x = cstat[i].hover.y = 0;
cstat[i].hover.w = cstat[i].hover.h = 0;
cstat[i].visible = true;
}
for (int i=0; i<STATLIST_COUNT; i++) {
show_stat[i] = true;
}
statlist_rows = 10;
statlist_scrollbar_offset = 0;
closeButton = new WidgetButton("images/menus/buttons/button_x.png");
// Upgrade buttons
for (int i=0; i<4; i++) {
upgradeButton[i] = new WidgetButton("images/menus/buttons/upgrade.png");
upgradeButton[i]->enabled = false;
show_upgrade[i] = true;
}
physical_up = false;
mental_up = false;
offense_up = false;
defense_up = false;
// menu title
labelCharacter = new WidgetLabel();
// unspent points
labelUnspent = new WidgetLabel();
// Load config settings
FileParser infile;
// @CLASS MenuCharacter|Description of menus/character.txt
if (infile.open("menus/character.txt")) {
while(infile.next()) {
if (parseMenuKey(infile.key, infile.val))
continue;
// @ATTR close|x (integer), y (integer)|Position of the close button.
if(infile.key == "close") close_pos = toPoint(infile.val);
// @ATTR label_title|label|Position of the "Character" text.
else if(infile.key == "label_title") title = eatLabelInfo(infile.val);
// @ATTR upgrade_physical|x (integer), y (integer)|Position of the button used to add a stat point to Physical.
else if(infile.key == "upgrade_physical") upgrade_pos[0] = toPoint(infile.val);
// @ATTR upgrade_mental|x (integer), y (integer)|Position of the button used to add a stat point to Mental.
else if(infile.key == "upgrade_mental") upgrade_pos[1] = toPoint(infile.val);
// @ATTR upgrade_offense|x (integer), y (integer)|Position of the button used to add a stat point to Offense.
else if(infile.key == "upgrade_offense") upgrade_pos[2] = toPoint(infile.val);
// @ATTR upgrade_defense|x (integer), y (integer)|Position of the button used to add a stat point to Defense.
else if(infile.key == "upgrade_defense") upgrade_pos[3] = toPoint(infile.val);
// @ATTR statlist|x (integer), y (integer)|Position of the scrollbox containing non-primary stats.
else if(infile.key == "statlist") statlist_pos = toPoint(infile.val);
// @ATTR statlist_rows|integer|The height of the statlist in rows.
else if (infile.key == "statlist_rows") statlist_rows = toInt(infile.val);
// @ATTR statlist_scrollbar_offset|integer|Right margin in pixels for the statlist's scrollbar.
else if (infile.key == "statlist_scrollbar_offset") statlist_scrollbar_offset = toInt(infile.val);
// @ATTR label_name|label|Position of the "Name" text.
else if(infile.key == "label_name") {
label_pos[0] = eatLabelInfo(infile.val);
cstat[CSTAT_NAME].visible = !label_pos[0].hidden;
}
// @ATTR label_level|label|Position of the "Level" text.
else if(infile.key == "label_level") {
label_pos[1] = eatLabelInfo(infile.val);
cstat[CSTAT_LEVEL].visible = !label_pos[1].hidden;
}
// @ATTR label_physical|label|Position of the "Physical" text.
else if(infile.key == "label_physical") {
label_pos[2] = eatLabelInfo(infile.val);
cstat[CSTAT_PHYSICAL].visible = !label_pos[2].hidden;
}
// @ATTR label_mental|label|Position of the "Mental" text.
else if(infile.key == "label_mental") {
label_pos[3] = eatLabelInfo(infile.val);
cstat[CSTAT_MENTAL].visible = !label_pos[3].hidden;
}
// @ATTR label_offense|label|Position of the "Offense" text.
else if(infile.key == "label_offense") {
label_pos[4] = eatLabelInfo(infile.val);
cstat[CSTAT_OFFENSE].visible = !label_pos[4].hidden;
}
//.........这里部分代码省略.........
示例12: parseLoot
void LootManager::parseLoot(FileParser &infile, Event_Component *e, std::vector<Event_Component> *ec_list) {
if (e == NULL) return;
std::string chance;
bool first_is_filename = false;
e->s = infile.nextValue();
if (e->s == "currency")
e->c = CURRENCY_ID;
else if (toInt(e->s, -1) != -1)
e->c = toInt(e->s);
else if (ec_list) {
// load entire loot table
std::string filename = e->s;
// remove the last event component, since getLootTable() will create a new one
if (e == &ec_list->back())
ec_list->pop_back();
getLootTable(filename, ec_list);
first_is_filename = true;
}
if (!first_is_filename) {
// make sure the type is "loot"
e->type = "loot";
// drop chance
chance = infile.nextValue();
if (chance == "fixed") e->z = 0;
else e->z = toInt(chance);
// quantity min/max
e->a = toInt(infile.nextValue());
clampFloor(e->a, 1);
e->b = toInt(infile.nextValue());
clampFloor(e->b, e->a);
}
// add repeating loot
if (ec_list) {
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
ec_list->push_back(Event_Component());
Event_Component *ec = &ec_list->back();
ec->type = infile.key;
ec->s = repeat_val;
if (ec->s == "currency")
ec->c = CURRENCY_ID;
else if (toInt(ec->s, -1) != -1)
ec->c = toInt(ec->s);
else {
// remove the last event component, since getLootTable() will create a new one
ec_list->pop_back();
getLootTable(repeat_val, ec_list);
repeat_val = infile.nextValue();
continue;
}
chance = infile.nextValue();
if (chance == "fixed") ec->z = 0;
else ec->z = toInt(chance);
ec->a = toInt(infile.nextValue());
clampFloor(ec->a, 1);
ec->b = toInt(infile.nextValue());
clampFloor(ec->b, ec->a);
repeat_val = infile.nextValue();
}
}
}
示例13: loadAnimations
/**
* Load the entity's animation from animation definition file
*/
void Entity::loadAnimations(const string& filename) {
FileParser parser;
if (!parser.open(mods->locate(filename).c_str())) {
cout << "Error loading animation definition file: " << filename << endl;
SDL_Quit();
exit(1);
}
string name = "";
int position = 0;
int frames = 0;
int duration = 0;
Point render_size;
Point render_offset;
string type = "";
string firstAnimation = "";
int active_frame = 0;
// Parse the file and on each new section create an animation object from the data parsed previously
parser.next();
parser.new_section = false; // do not create the first animation object until parser has parsed first section
do {
// create the animation if finished parsing a section
if (parser.new_section) {
animations.push_back(new Animation(name, render_size, render_offset, position, frames, duration, type, active_frame));
}
if (parser.key == "position") {
if (isInt(parser.val)) {
position = atoi(parser.val.c_str());
}
}
else if (parser.key == "frames") {
if (isInt(parser.val)) {
frames = atoi(parser.val.c_str());
}
}
else if (parser.key == "duration") {
if (isInt(parser.val)) {
int ms_per_frame = atoi(parser.val.c_str());
duration = (int)round((float)ms_per_frame / (1000.0 / (float)FRAMES_PER_SEC));
// adjust duration according to the entity's animation speed
duration = (duration * 100) / stats.animationSpeed;
// TEMP: if an animation is too fast, display one frame per fps anyway
if (duration < 1) duration=1;
}
}
else if (parser.key == "type") {
type = parser.val;
}
else if (parser.key == "render_size_x") {
if (isInt(parser.val)) {
render_size.x = atoi(parser.val.c_str());
}
}
else if (parser.key == "render_size_y") {
if (isInt(parser.val)) {
render_size.y = atoi(parser.val.c_str());
}
}
else if (parser.key == "render_offset_x") {
if (isInt(parser.val)) {
render_offset.x = atoi(parser.val.c_str());
}
}
else if (parser.key == "render_offset_y") {
if (isInt(parser.val)) {
render_offset.y = atoi(parser.val.c_str());
}
}
else if (parser.key == "active_frame") {
active_frame = atoi(parser.val.c_str());
}
if (name == "") {
// This is the first animation
firstAnimation = parser.section;
}
name = parser.section;
}
while (parser.next());
// add final animation
animations.push_back(new Animation(name, render_size, render_offset, position, frames, duration, type, active_frame));
// set the default animation
if (firstAnimation != "") {
setAnimation(firstAnimation);
}
//.........这里部分代码省略.........
示例14: GameState
GameStateLoad::GameStateLoad() : GameState() {
items = new ItemManager();
portrait = NULL;
loading_requested = false;
loading = false;
loaded = false;
label_loading = new WidgetLabel();
for (int i = 0; i < GAME_SLOT_MAX; i++) {
label_name[i] = new WidgetLabel();
label_level[i] = new WidgetLabel();
label_map[i] = new WidgetLabel();
}
// Confirmation box to confirm deleting
confirm = new MenuConfirm(msg->get("Delete Save"), msg->get("Delete this save?"));
button_exit = new WidgetButton("images/menus/buttons/button_default.png");
button_exit->label = msg->get("Exit to Title");
button_exit->pos.x = VIEW_W_HALF - button_exit->pos.w/2;
button_exit->pos.y = VIEW_H - button_exit->pos.h;
button_exit->refresh();
button_action = new WidgetButton("images/menus/buttons/button_default.png");
button_action->label = msg->get("Choose a Slot");
button_action->enabled = false;
button_alternate = new WidgetButton("images/menus/buttons/button_default.png");
button_alternate->label = msg->get("Delete Save");
button_alternate->enabled = false;
// Set up tab list
tablist = TabList(HORIZONTAL);
tablist.add(button_exit);
// Read positions from config file
FileParser infile;
if (infile.open("menus/gameload.txt")) {
while (infile.next()) {
infile.val = infile.val + ',';
if (infile.key == "action_button") {
button_action->pos.x = eatFirstInt(infile.val, ',');
button_action->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "atlernate_button") {
button_alternate->pos.x = eatFirstInt(infile.val, ',');
button_alternate->pos.y = eatFirstInt(infile.val, ',');
}
else if (infile.key == "portrait") {
portrait_pos.x = eatFirstInt(infile.val, ',');
portrait_pos.y = eatFirstInt(infile.val, ',');
portrait_pos.w = eatFirstInt(infile.val, ',');
portrait_pos.h = eatFirstInt(infile.val, ',');
}
else if (infile.key == "gameslot") {
gameslot_pos.x = eatFirstInt(infile.val, ',');
gameslot_pos.y = eatFirstInt(infile.val, ',');
gameslot_pos.w = eatFirstInt(infile.val, ',');
gameslot_pos.h = eatFirstInt(infile.val, ',');
}
else if (infile.key == "preview") {
preview_pos.x = eatFirstInt(infile.val, ',');
preview_pos.y = eatFirstInt(infile.val, ',');
preview_pos.w = eatFirstInt(infile.val, ',');
preview_pos.h = eatFirstInt(infile.val, ',');
// label positions within each slot
}
else if (infile.key == "name") {
name_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "level") {
level_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "map") {
map_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "loading_label") {
loading_pos = eatLabelInfo(infile.val);
// Position for the avatar preview image in each slot
}
else if (infile.key == "sprite") {
sprites_pos.x = eatFirstInt(infile.val, ',');
sprites_pos.y = eatFirstInt(infile.val, ',');
}
}
infile.close();
}
// Load the MenuConfirm positions and alignments from menus/menus.txt
if (infile.open("menus/menus.txt")) {
int menu_index = -1;
while (infile.next()) {
if (infile.key == "id") {
if (infile.val == "confirm") menu_index = 0;
else menu_index = -1;
}
if (menu_index == -1)
//.........这里部分代码省略.........
示例15: readGameSlot
void GameStateLoad::readGameSlot(int slot) {
stringstream filename;
FileParser infile;
// abort if not a valid slot number
if (slot < 0 || slot >= GAME_SLOT_MAX) return;
// save slots are named save#.txt
filename << "save" << (slot+1) << ".txt";
if (!infile.open(PATH_USER + filename.str())) return;
while (infile.next()) {
// load (key=value) pairs
if (infile.key == "name")
stats[slot].name = infile.val;
else if (infile.key == "xp")
stats[slot].xp = atoi(infile.val.c_str());
else if (infile.key == "build") {
stats[slot].physical_character = atoi(infile.nextValue().c_str());
stats[slot].mental_character = atoi(infile.nextValue().c_str());
stats[slot].offense_character = atoi(infile.nextValue().c_str());
stats[slot].defense_character = atoi(infile.nextValue().c_str());
}
else if (infile.key == "equipped") {
equipped[slot][0] = atoi(infile.nextValue().c_str());
equipped[slot][1] = atoi(infile.nextValue().c_str());
equipped[slot][2] = atoi(infile.nextValue().c_str());
}
else if (infile.key == "option") {
stats[slot].base = infile.nextValue();
stats[slot].head = infile.nextValue();
stats[slot].portrait = infile.nextValue();
}
else if (infile.key == "spawn") {
current_map[slot] = getMapName(infile.nextValue());
}
}
infile.close();
stats[slot].recalc();
loadPreview(slot);
}