本文整理汇总了C++中FileParser::getFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ FileParser::getFileName方法的具体用法?C++ FileParser::getFileName怎么用?C++ FileParser::getFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileParser
的用法示例。
在下文中一共展示了FileParser::getFileName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseEnemyFilesAndStore
void EnemyGroupManager::parseEnemyFilesAndStore() {
FileParser infile;
if (!infile.open("enemies", true, false))
return;
Enemy_Level new_enemy;
infile.new_section = true;
while (infile.next()) {
if (infile.new_section) {
const string fname = infile.getFileName();
const int firstpos = fname.rfind("/") + 1;
const int len = fname.length() - firstpos - 4; //removes the ".txt" from the filename
new_enemy.type = fname.substr(firstpos, len);
}
if (infile.key == "level") {
new_enemy.level = atoi(infile.val.c_str());
}
else if (infile.key == "rarity") {
new_enemy.rarity = infile.val.c_str();
}
else if (infile.key == "categories") {
string cat;
while ( (cat = infile.nextValue()) != "") {
_categories[cat].push_back(new_enemy);
}
}
}
infile.close();
}
示例2: parseEnemyFilesAndStore
void EnemyGroupManager::parseEnemyFilesAndStore() {
FileParser infile;
// @CLASS enemies|Describing enemies files in enemies/
if (!infile.open("enemies", true, false))
return;
Enemy_Level new_enemy;
infile.new_section = true;
bool first = true;
while (infile.next()) {
if (infile.new_section || first) {
const string fname = infile.getFileName();
const int firstpos = fname.rfind("/") + 1;
const int len = fname.length() - firstpos - 4; //removes the ".txt" from the filename
new_enemy.type = fname.substr(firstpos, len);
first = false;
}
if (infile.key == "level") {
// @ATTR level|integer|Level of the enemy
new_enemy.level = toInt(infile.val);
}
else if (infile.key == "rarity") {
// @ATTR rarity|[common,uncommon,rare]|Enemy rarity
new_enemy.rarity = infile.val;
}
else if (infile.key == "categories") {
// @ATTR categories|string,...|Comma separated list of enemy categories
string cat;
while ( (cat = infile.nextValue()) != "") {
_categories[cat].push_back(new_enemy);
}
}
}
infile.close();
}
示例3: load
bool GameStateCutscene::load(std::string filename) {
FileParser infile;
// @CLASS Cutscene|Description of cutscenes in cutscenes/
if (!infile.open(filename))
return false;
// parse the cutscene file
while (infile.next()) {
if (infile.new_section) {
if (infile.section == "scene")
scenes.push(Scene());
}
if (infile.section.empty()) {
// allow having an empty section (globals such as scale_gfx might be set here
}
else if (infile.section == "scene") {
SceneComponent sc = SceneComponent();
if (infile.key == "caption") {
// @ATTR scene.caption|string|A caption that will be shown.
sc.type = infile.key;
sc.s = msg->get(infile.val);
}
else if (infile.key == "image") {
// @ATTR scene.image|string|An image that will be shown.
sc.type = infile.key;
sc.s = infile.val;
}
else if (infile.key == "pause") {
// @ATTR scene.pause|duration|Pause before next component
sc.type = infile.key;
sc.x = parse_duration(infile.val);
}
else if (infile.key == "soundfx") {
// @ATTR scene.soundfx|string|A sound that will be played
sc.type = infile.key;
sc.s = infile.val;
}
if (sc.type != "")
scenes.back().components.push(sc);
}
else {
fprintf(stderr, "unknown section %s in file %s\n", infile.section.c_str(), infile.getFileName().c_str());
}
if (infile.key == "scale_gfx") {
// @ATTR scale_gfx|bool|The graphics will be scaled to fit screen width
scale_graphics = toBool(infile.val);
}
else if (infile.key == "caption_margins") {
// @ATTR caption_margins|[x,y]|Percentage-based margins for the caption text based on screen size
caption_margins.x = toFloat(infile.nextValue())/100.0f;
caption_margins.y = toFloat(infile.val)/100.0f;
}
}
if (scenes.empty()) {
fprintf(stderr, "No scenes defined in cutscene file %s\n", filename.c_str());
return false;
}
return true;
}
示例4: load
//.........这里部分代码省略.........
compressed_loading = false;
}
if (parser.key == "image") {
if (sprite) {
printf("multiple images specified in %s, dragons be here!\n", name.c_str());
SDL_Quit();
exit(128);
}
imagefile = parser.val;
imag->increaseCount(imagefile);
sprite = imag->getSurface(imagefile);
}
else if (parser.key == "position") {
position = toInt(parser.val);
}
else if (parser.key == "frames") {
frames = toInt(parser.val);
}
else if (parser.key == "duration") {
duration = toInt(parser.val);
// 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") {
render_size.x = toInt(parser.nextValue());
render_size.y = toInt(parser.nextValue());
}
else if (parser.key == "render_offset") {
render_offset.x = toInt(parser.nextValue());
render_offset.y = toInt(parser.nextValue());
}
else if (parser.key == "active_frame") {
active_frames.clear();
string nv = parser.nextValue();
if (nv == "all") {
active_frames.push_back(-1);
}
else {
while (nv != "") {
active_frames.push_back(toInt(nv));
nv = parser.nextValue();
}
sort(active_frames.begin(), active_frames.end());
active_frames.erase(unique(active_frames.begin(), active_frames.end()), active_frames.end());
}
}
else if (parser.key == "frame") {
if (compressed_loading == false) { // first frame statement in section
newanim = new Animation(_name, type, sprite);
newanim->setup(frames, duration);
if (!active_frames.empty())
newanim->setActiveFrames(active_frames);
active_frames.clear();
animations.push_back(newanim);
compressed_loading = true;
}
// frame = index, direction, x, y, w, h, offsetx, offsety
SDL_Rect r;
Point offset;
const int index = toInt(parser.nextValue());
const int direction = toInt(parser.nextValue());
r.x = toInt(parser.nextValue());
r.y = toInt(parser.nextValue());
r.w = toInt(parser.nextValue());
r.h = toInt(parser.nextValue());
offset.x = toInt(parser.nextValue());
offset.y = toInt(parser.nextValue());
newanim->addFrame(index, direction, r, offset);
}
else {
fprintf(stderr, "animations definitions (%s): Key %s not supported!\n", parser.getFileName().c_str(), parser.key.c_str());
}
if (_name == "") {
// This is the first animation
starting_animation = parser.section;
}
_name = parser.section;
}
while (parser.next());
if (!compressed_loading) {
// add final animation
Animation *a = new Animation(_name, type, sprite);
a->setupUncompressed(render_size, render_offset, position, frames, duration);
if (!active_frames.empty())
a->setActiveFrames(active_frames);
active_frames.clear();
animations.push_back(a);
}
if (starting_animation != "") {
Animation *a = getAnimation(starting_animation);
delete defaultAnimation;
defaultAnimation = a;
}
}
示例5: loadTitles
void GameStatePlay::loadTitles() {
FileParser infile;
if (infile.open("engine/titles.txt")) {
while (infile.next()) {
if (infile.new_section && infile.section == "title") {
Title t;
titles.push_back(t);
}
if (titles.empty()) continue;
if (infile.key == "title") titles.back().title = infile.val;
else if (infile.key == "level") titles.back().level = toInt(infile.val);
else if (infile.key == "power") titles.back().power = toInt(infile.val);
else if (infile.key == "requires_status") titles.back().requires_status = infile.val;
else if (infile.key == "requires_not_status") titles.back().requires_not = infile.val;
else if (infile.key == "primary_stat") titles.back().primary_stat = infile.val;
else fprintf(stderr, "GameStatePlay: Unknown key value in title definitons: %s in file %s in section %s\n", infile.key.c_str(), infile.getFileName().c_str(), infile.section.c_str());
}
infile.close();
}
}
示例6: loadPowers
//.........这里部分代码省略.........
// @ATTR spawn_type|string|Type of spawn.
powers[input_id].spawn_type = infile.val;
else if (infile.key == "target_neighbor")
// @ATTR target_neighbor|int|Neigbor target.
powers[input_id].target_neighbor = toInt(infile.val);
else if (infile.key == "spawn_limit") {
// @ATTR spawn_limit|[fixed:stat:unlimited],stat[physical:mental:offense:defens]|
std::string mode = popFirstString(infile.val);
if (mode == "fixed") powers[input_id].spawn_limit_mode = SPAWN_LIMIT_MODE_FIXED;
else if (mode == "stat") powers[input_id].spawn_limit_mode = SPAWN_LIMIT_MODE_STAT;
else if (mode == "unlimited") powers[input_id].spawn_limit_mode = SPAWN_LIMIT_MODE_UNLIMITED;
else fprintf(stderr, "unknown spawn_limit_mode %s\n", mode.c_str());
if(powers[input_id].spawn_limit_mode != SPAWN_LIMIT_MODE_UNLIMITED) {
powers[input_id].spawn_limit_qty = popFirstInt(infile.val);
if(powers[input_id].spawn_limit_mode == SPAWN_LIMIT_MODE_STAT) {
powers[input_id].spawn_limit_every = popFirstInt(infile.val);
std::string stat = popFirstString(infile.val);
if (stat == "physical") powers[input_id].spawn_limit_stat = SPAWN_LIMIT_STAT_PHYSICAL;
else if (stat == "mental") powers[input_id].spawn_limit_stat = SPAWN_LIMIT_STAT_MENTAL;
else if (stat == "offense") powers[input_id].spawn_limit_stat = SPAWN_LIMIT_STAT_OFFENSE;
else if (stat == "defense") powers[input_id].spawn_limit_stat = SPAWN_LIMIT_STAT_DEFENSE;
else fprintf(stderr, "unknown spawn_limit_stat %s\n", stat.c_str());
}
}
}
else if (infile.key == "spawn_level") {
std::string mode = popFirstString(infile.val);
if (mode == "default") powers[input_id].spawn_level_mode = SPAWN_LEVEL_MODE_DEFAULT;
else if (mode == "fixed") powers[input_id].spawn_level_mode = SPAWN_LEVEL_MODE_FIXED;
else if (mode == "stat") powers[input_id].spawn_level_mode = SPAWN_LEVEL_MODE_STAT;
else if (mode == "level") powers[input_id].spawn_level_mode = SPAWN_LEVEL_MODE_LEVEL;
else fprintf(stderr, "unknown spawn_level_mode %s\n", mode.c_str());
if(powers[input_id].spawn_level_mode != SPAWN_LEVEL_MODE_DEFAULT) {
powers[input_id].spawn_level_qty = popFirstInt(infile.val);
if(powers[input_id].spawn_level_mode != SPAWN_LEVEL_MODE_FIXED) {
powers[input_id].spawn_level_every = popFirstInt(infile.val);
if(powers[input_id].spawn_level_mode == SPAWN_LEVEL_MODE_STAT) {
std::string stat = popFirstString(infile.val);
if (stat == "physical") powers[input_id].spawn_level_stat = SPAWN_LEVEL_STAT_PHYSICAL;
else if (stat == "mental") powers[input_id].spawn_level_stat = SPAWN_LEVEL_STAT_MENTAL;
else if (stat == "offense") powers[input_id].spawn_level_stat = SPAWN_LEVEL_STAT_OFFENSE;
else if (stat == "defense") powers[input_id].spawn_level_stat = SPAWN_LEVEL_STAT_DEFENSE;
else fprintf(stderr, "unknown spawn_level_stat %s\n", stat.c_str());
}
}
}
}
else if (infile.key == "target_party")
// @ATTR target_party|bool|
powers[input_id].target_party = toBool(infile.val);
else if (infile.key == "target_categories") {
// @ATTR target_categories|string,...|
string cat;
while ((cat = infile.nextValue()) != "") {
powers[input_id].target_categories.push_back(cat);
}
}
else if (infile.key == "modifier_accuracy") {
// @ATTR modifier_accuracy|[multiply:add:absolute], integer|
std::string mode = popFirstString(infile.val);
if(mode == "multiply") powers[input_id].mod_accuracy_mode = STAT_MODIFIER_MODE_MULTIPLY;
else if(mode == "add") powers[input_id].mod_accuracy_mode = STAT_MODIFIER_MODE_ADD;
else if(mode == "absolute") powers[input_id].mod_accuracy_mode = STAT_MODIFIER_MODE_ABSOLUTE;
else fprintf(stderr, "unknown stat_modifier_mode %s\n", mode.c_str());
powers[input_id].mod_accuracy_value = popFirstInt(infile.val);
}
else if (infile.key == "modifier_damage") {
// @ATTR modifier_damage|[multiply:add:absolute], integer|
std::string mode = popFirstString(infile.val);
if(mode == "multiply") powers[input_id].mod_damage_mode = STAT_MODIFIER_MODE_MULTIPLY;
else if(mode == "add") powers[input_id].mod_damage_mode = STAT_MODIFIER_MODE_ADD;
else if(mode == "absolute") powers[input_id].mod_damage_mode = STAT_MODIFIER_MODE_ABSOLUTE;
else fprintf(stderr, "unknown stat_modifier_mode %s\n", mode.c_str());
powers[input_id].mod_damage_value_min = popFirstInt(infile.val);
powers[input_id].mod_damage_value_max = popFirstInt(infile.val);
}
else if (infile.key == "modifier_critical") {
// @ATTR modifier_critical|[multiply:add:absolute], integer|
std::string mode = popFirstString(infile.val);
if(mode == "multiply") powers[input_id].mod_crit_mode = STAT_MODIFIER_MODE_MULTIPLY;
else if(mode == "add") powers[input_id].mod_crit_mode = STAT_MODIFIER_MODE_ADD;
else if(mode == "absolute") powers[input_id].mod_crit_mode = STAT_MODIFIER_MODE_ABSOLUTE;
else fprintf(stderr, "unknown stat_modifier_mode %s\n", mode.c_str());
powers[input_id].mod_crit_value = popFirstInt(infile.val);
}
else
fprintf(stderr, "ignoring unknown key %s set to %s in file %s\n",
infile.key.c_str(), infile.val.c_str(), infile.getFileName().c_str());
}
infile.close();
}
示例7: loadEventComponent
//.........这里部分代码省略.........
e = &evnt->components.back();
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
}
else if (infile.key == "remove_currency") {
// @ATTR event.remove_currency|integer|Removes specified amount of currency from hero inventory
e->x = toInt(infile.val);
clampFloor(e->x, 0);
}
else if (infile.key == "remove_item") {
// @ATTR event.remove_item|integer,...|Removes specified item from hero inventory
e->x = toInt(infile.nextValue());
// add repeating remove_item
if (evnt) {
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
evnt->components.push_back(Event_Component());
e = &evnt->components.back();
e->type = infile.key;
e->x = toInt(repeat_val);
repeat_val = infile.nextValue();
}
}
}
else if (infile.key == "reward_xp") {
// @ATTR event.reward_xp|integer|Reward hero with specified amount of experience points.
e->x = toInt(infile.val);
clampFloor(e->x, 0);
}
else if (infile.key == "reward_currency") {
// @ATTR event.reward_currency|integer|Reward hero with specified amount of currency.
e->x = toInt(infile.val);
clampFloor(e->x, 0);
}
else if (infile.key == "reward_item") {
// @ATTR event.reward_item|x(integer),y(integer)|Reward hero with y number of item x.
e->x = toInt(infile.nextValue());
e->y = toInt(infile.val);
clampFloor(e->y, 0);
}
else if (infile.key == "restore") {
// @ATTR event.restore|string|Restore the hero's HP, MP, and/or status.
e->s = infile.val;
}
else if (infile.key == "power") {
// @ATTR event.power|power_id|Specify power coupled with event.
e->x = toInt(infile.val);
}
else if (infile.key == "spawn") {
// @ATTR event.spawn|[string,x(integer),y(integer)], ...|Spawn specified enemies at location
e->s = infile.nextValue();
e->x = toInt(infile.nextValue());
e->y = toInt(infile.nextValue());
// add repeating spawn
if (evnt) {
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
evnt->components.push_back(Event_Component());
e = &evnt->components.back();
e->type = infile.key;
e->s = repeat_val;
e->x = toInt(infile.nextValue());
e->y = toInt(infile.nextValue());
repeat_val = infile.nextValue();
}
}
}
else if (infile.key == "stash") {
// @ATTR event.stash|string|
e->s = infile.val;
}
else if (infile.key == "npc") {
// @ATTR event.npc|string|
e->s = infile.val;
}
else if (infile.key == "music") {
// @ATTR event.music|string|Change background music to specified file.
e->s = infile.val;
}
else if (infile.key == "cutscene") {
// @ATTR event.cutscene|string|Show specified cutscene.
e->s = infile.val;
}
else if (infile.key == "repeat") {
// @ATTR event.repeat|string|
e->s = infile.val;
}
else {
fprintf(stderr, "EventManager: Unknown key value: %s in file %s in section %s\n", infile.key.c_str(), infile.getFileName().c_str(), infile.section.c_str());
}
}
示例8: loadEvent
void EventManager::loadEvent(FileParser &infile, Event* evnt) {
if (!evnt) return;
if (infile.key == "type") {
// @ATTR event.type|[on_trigger:on_mapexit:on_leave:on_load:on_clear]|Type of map event.
std::string type = infile.val;
evnt->type = type;
if (type == "on_trigger");
else if (type == "on_mapexit"); // no need to set keep_after_trigger to false correctly, it's ignored anyway
else if (type == "on_leave");
else if (type == "on_load") {
evnt->keep_after_trigger = false;
}
else if (type == "on_clear") {
evnt->keep_after_trigger = false;
}
else {
fprintf(stderr, "EventManager: Loading event in file %s\nEvent type %s unknown, change to \"on_trigger\" to suppress this warning.\n", infile.getFileName().c_str(), type.c_str());
}
}
else if (infile.key == "location") {
// @ATTR event.location|[x,y,w,h]|Defines the location area for the event.
evnt->location.x = toInt(infile.nextValue());
evnt->location.y = toInt(infile.nextValue());
evnt->location.w = toInt(infile.nextValue());
evnt->location.h = toInt(infile.nextValue());
evnt->center.x = evnt->location.x + (float)evnt->location.w/2;
evnt->center.y = evnt->location.y + (float)evnt->location.h/2;
}
else if (infile.key == "hotspot") {
// @ATTR event.hotspot|[ [x, y, w, h] : location ]|Event uses location as hotspot or defined by rect.
if (infile.val == "location") {
evnt->hotspot.x = evnt->location.x;
evnt->hotspot.y = evnt->location.y;
evnt->hotspot.w = evnt->location.w;
evnt->hotspot.h = evnt->location.h;
}
else {
evnt->hotspot.x = toInt(infile.nextValue());
evnt->hotspot.y = toInt(infile.nextValue());
evnt->hotspot.w = toInt(infile.nextValue());
evnt->hotspot.h = toInt(infile.nextValue());
}
}
else if (infile.key == "cooldown") {
// @ATTR event.cooldown|duration|Duration for event cooldown.
evnt->cooldown = parse_duration(infile.val);
}
else if (infile.key == "reachable_from") {
// @ATTR event.reachable_from|[x,y,w,h]|If the hero is inside this rectangle, they can activate the event.
evnt->reachable_from.x = toInt(infile.nextValue());
evnt->reachable_from.y = toInt(infile.nextValue());
evnt->reachable_from.w = toInt(infile.nextValue());
evnt->reachable_from.h = toInt(infile.nextValue());
}
else {
loadEventComponent(infile, evnt, NULL);
}
}
示例9: load
//.........这里部分代码省略.........
if (sprite != NULL) {
printf("multiple images specified in %s, dragons be here!\n", name.c_str());
SDL_Quit();
exit(128);
}
sprite = render_device->loadImage(parser.val);
}
else if (parser.key == "position") {
// @ATTR position|integer|Number of frames to the right to use as the first frame. Unpacked animations only.
position = toInt(parser.val);
}
else if (parser.key == "frames") {
// @ATTR frames|integer|The total number of frames
frames = toInt(parser.val);
}
else if (parser.key == "duration") {
// @ATTR duration|integer|The duration of each frame.
duration = parse_duration(parser.val);
}
else if (parser.key == "type")
// @ATTR type|[play_once, back_forth, looped]|How to loop (or not loop) this animation.
type = parser.val;
else if (parser.key == "render_size") {
// @ATTR render_size|w (integer), h (integer)|Width and height of animation.
render_size.x = toInt(parser.nextValue());
render_size.y = toInt(parser.nextValue());
}
else if (parser.key == "render_offset") {
// @ATTR render_offset|x (integer), y (integer)|Render x/y offset.
render_offset.x = toInt(parser.nextValue());
render_offset.y = toInt(parser.nextValue());
}
else if (parser.key == "active_frame") {
// @ATTR active_frame|[all:frame (integer), ...]|A list of frames marked as "active". Also, "all" can be used to mark all frames as active.
active_frames.clear();
string nv = parser.nextValue();
if (nv == "all") {
active_frames.push_back(-1);
}
else {
while (nv != "") {
active_frames.push_back(toInt(nv));
nv = parser.nextValue();
}
sort(active_frames.begin(), active_frames.end());
active_frames.erase(unique(active_frames.begin(), active_frames.end()), active_frames.end());
}
}
else if (parser.key == "frame") {
// @ATTR frame|index (integer), direction (integer), x (integer), y (integer), w (integer), h (integer), x offset (integer), y offset (integer)|A single frame of a compressed animation.
if (compressed_loading == false) { // first frame statement in section
newanim = new Animation(_name, type, sprite);
newanim->setup(frames, duration);
if (!active_frames.empty())
newanim->setActiveFrames(active_frames);
active_frames.clear();
animations.push_back(newanim);
compressed_loading = true;
}
// frame = index, direction, x, y, w, h, offsetx, offsety
Rect r;
Point offset;
const int index = toInt(parser.nextValue());
const int direction = toInt(parser.nextValue());
r.x = toInt(parser.nextValue());
r.y = toInt(parser.nextValue());
r.w = toInt(parser.nextValue());
r.h = toInt(parser.nextValue());
offset.x = toInt(parser.nextValue());
offset.y = toInt(parser.nextValue());
newanim->addFrame(index, direction, r, offset);
}
else {
fprintf(stderr, "animations definitions (%s): Key %s not supported!\n", parser.getFileName().c_str(), parser.key.c_str());
}
if (_name == "") {
// This is the first animation
starting_animation = parser.section;
}
_name = parser.section;
}
if (!compressed_loading) {
// add final animation
Animation *a = new Animation(_name, type, sprite);
a->setupUncompressed(render_size, render_offset, position, frames, duration);
if (!active_frames.empty())
a->setActiveFrames(active_frames);
active_frames.clear();
animations.push_back(a);
}
if (starting_animation != "") {
Animation *a = getAnimation(starting_animation);
delete defaultAnimation;
defaultAnimation = a;
}
}
示例10: loadEventComponent
//.........这里部分代码省略.........
e->x = toInt(infile.nextValue());
// add repeating requires_item
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().components.push_back(Event_Component());
e = &events.back().components.back();
e->type = infile.key;
e->x = toInt(repeat_val);
repeat_val = infile.nextValue();
}
}
else if (infile.key == "set_status") {
e->s = infile.nextValue();
// add repeating set_status
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().components.push_back(Event_Component());
e = &events.back().components.back();
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "unset_status") {
e->s = infile.nextValue();
// add repeating unset_status
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().components.push_back(Event_Component());
e = &events.back().components.back();
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "remove_item") {
e->x = toInt(infile.nextValue());
// add repeating remove_item
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().components.push_back(Event_Component());
e = &events.back().components.back();
e->type = infile.key;
e->x = toInt(repeat_val);
repeat_val = infile.nextValue();
}
}
else if (infile.key == "reward_xp") {
e->x = toInt(infile.val);
}
else if (infile.key == "power") {
e->x = toInt(infile.val);
}
else if (infile.key == "spawn") {
e->s = infile.nextValue();
e->x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
e->y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
// add repeating spawn
std::string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().components.push_back(Event_Component());
e = &events.back().components.back();
e->type = infile.key;
e->s = repeat_val;
e->x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
e->y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "stash") {
e->s = infile.val;
}
else if (infile.key == "npc") {
e->s = infile.val;
}
else if (infile.key == "music") {
e->s = infile.val;
}
else if (infile.key == "cutscene") {
e->s = infile.val;
}
else if (infile.key == "repeat") {
e->s = infile.val;
}
else {
fprintf(stderr, "Map: Unknown key value: %s in file %s in section %s\n", infile.key.c_str(), infile.getFileName().c_str(), infile.section.c_str());
}
}
示例11: loadEvent
void Map::loadEvent(FileParser &infile) {
if (infile.key == "type") {
std::string type = infile.val;
events.back().type = type;
if (type == "on_trigger");
else if (type == "on_mapexit"); // no need to set keep_after_trigger to false correctly, it's ignored anyway
else if (type == "on_leave");
else if (type == "on_load") {
events.back().keep_after_trigger = false;
}
else if (type == "on_clear") {
events.back().keep_after_trigger = false;
}
else {
fprintf(stderr, "Map: Loading event in file %s\nEvent type %s unknown, change to \"on_trigger\" to suppress this warning.\n", infile.getFileName().c_str(), type.c_str());
}
}
else if (infile.key == "location") {
events.back().location.x = toInt(infile.nextValue());
events.back().location.y = toInt(infile.nextValue());
events.back().location.w = toInt(infile.nextValue());
events.back().location.h = toInt(infile.nextValue());
}
else if (infile.key == "hotspot") {
if (infile.val == "location") {
events.back().hotspot.x = events.back().location.x;
events.back().hotspot.y = events.back().location.y;
events.back().hotspot.w = events.back().location.w;
events.back().hotspot.h = events.back().location.h;
}
else {
events.back().hotspot.x = toInt(infile.nextValue());
events.back().hotspot.y = toInt(infile.nextValue());
events.back().hotspot.w = toInt(infile.nextValue());
events.back().hotspot.h = toInt(infile.nextValue());
}
}
else if (infile.key == "cooldown") {
events.back().cooldown = parse_duration(infile.val);
}
else {
loadEventComponent(infile);
}
}