本文整理汇总了C++中FileParser::getRawLine方法的典型用法代码示例。如果您正苦于以下问题:C++ FileParser::getRawLine方法的具体用法?C++ FileParser::getRawLine怎么用?C++ FileParser::getRawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileParser
的用法示例。
在下文中一共展示了FileParser::getRawLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadLayer
void Map::loadLayer(FileParser &infile, maprow **current_layer) {
if (infile.key == "type") {
// @ATTR layer.type|string|Map layer type.
*current_layer = new maprow[w];
layers.push_back(*current_layer);
layernames.push_back(infile.val);
}
else if (infile.key == "format") {
// @ATTR layer.format|string|Format for map layer, must be 'dec'
if (infile.val != "dec") {
fprintf(stderr, "ERROR: maploading: The format of a layer must be \"dec\"!\n");
SDL_Quit();
exit(1);
}
}
else if (infile.key == "data") {
// @ATTR layer.data|raw|Raw map layer data
// layer map data handled as a special case
// The next h lines must contain layer data. TODO: err
for (int j=0; j<h; j++) {
std::string val = infile.getRawLine() + ',';
for (int i=0; i<w; i++)
(*current_layer)[i][j] = eatFirstInt(val, ',');
}
}
}
示例2: loadLayer
void Map::loadLayer(FileParser &infile) {
if (infile.key == "type") {
// @ATTR layer.type|string|Map layer type.
layers.resize(layers.size()+1);
layers.back().resize(w);
for (size_t i=0; i<layers.back().size(); ++i) {
layers.back()[i].resize(h);
}
layernames.push_back(infile.val);
if (infile.val == "collision")
collision_layer = static_cast<int>(layernames.size())-1;
}
else if (infile.key == "format") {
// @ATTR layer.format|string|Format for map layer, must be 'dec'
if (infile.val != "dec") {
infile.error("Map: The format of a layer must be 'dec'!");
logErrorDialog("Map: The format of a layer must be 'dec'!");
mods->resetModConfig();
Exit(1);
}
}
else if (infile.key == "data") {
// @ATTR layer.data|raw|Raw map layer data
// layer map data handled as a special case
// The next h lines must contain layer data.
for (int j=0; j<h; j++) {
std::string val = infile.getRawLine();
infile.incrementLineNum();
if (!val.empty() && val[val.length()-1] != ',') {
val += ',';
}
// verify the width of this row
int comma_count = 0;
for (unsigned i=0; i<val.length(); ++i) {
if (val[i] == ',') comma_count++;
}
if (comma_count != w) {
infile.error("Map: A row of layer data has a width not equal to %d.", w);
mods->resetModConfig();
Exit(1);
}
for (int i=0; i<w; i++)
layers.back()[i][j] = static_cast<unsigned short>(popFirstInt(val));
}
}
else {
infile.error("Map: '%s' is not a valid key.", infile.key.c_str());
}
}
示例3: load
/**
* load
*/
int MapRenderer::load(string filename) {
FileParser infile;
string val;
string cur_layer;
string data_format;
clearEvents();
bool collider_set = false;
if (infile.open(mods->locate("maps/" + filename))) {
while (infile.next()) {
if (infile.new_section) {
data_format = "dec"; // default
if (enemy_awaiting_queue) {
enemies.push(new_enemy);
enemy_awaiting_queue = false;
}
if (npc_awaiting_queue) {
npcs.push(new_npc);
npc_awaiting_queue = false;
}
if (group_awaiting_queue) {
push_enemy_group(new_group);
group_awaiting_queue = false;
}
// for sections that are stored in collections, add a new object here
if (infile.section == "enemy") {
new_enemy.clear();
enemy_awaiting_queue = true;
}
else if (infile.section == "enemygroup") {
new_group.clear();
group_awaiting_queue = true;
}
else if (infile.section == "npc") {
new_npc.clear();
npc_awaiting_queue = true;
}
else if (infile.section == "event") {
events.push_back(Map_Event());
}
}
if (infile.section == "header") {
if (infile.key == "title") {
this->title = msg->get(infile.val);
}
else if (infile.key == "width") {
this->w = atoi(infile.val.c_str());
}
else if (infile.key == "height") {
this->h = atoi(infile.val.c_str());
}
else if (infile.key == "tileset") {
this->tileset = infile.val;
}
else if (infile.key == "music") {
if (this->music_filename == infile.val) {
this->new_music = false;
}
else {
this->music_filename = infile.val;
this->new_music = true;
}
}
else if (infile.key == "location") {
spawn.x = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn.y = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn_dir = atoi(infile.nextValue().c_str());
}
}
else if (infile.section == "layer") {
if (infile.key == "type") {
cur_layer = infile.val;
}
else if (infile.key == "format") {
data_format = infile.val;
}
else if (infile.key == "data") {
// layer map data handled as a special case
// The next h lines must contain layer data. TODO: err
if (data_format == "hex") {
for (int j=0; j<h; j++) {
val = infile.getRawLine() + ',';
for (int i=0; i<w; i++) {
if (cur_layer == "background") background[i][j] = eatFirstHex(val, ',');
else if (cur_layer == "object") object[i][j] = eatFirstHex(val, ',');
else if (cur_layer == "collision") collision[i][j] = eatFirstHex(val, ',');
}
}
}
else if (data_format == "dec") {
for (int j=0; j<h; j++) {
//.........这里部分代码省略.........
示例4: load
//.........这里部分代码省略.........
this->tileset = infile.val;
}
else if (infile.key == "music") {
if (this->music_filename == infile.val) {
this->new_music = false;
}
else {
this->music_filename = infile.val;
this->new_music = true;
}
}
else if (infile.key == "location") {
spawn.x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn.y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn_dir = toInt(infile.nextValue());
}
}
else if (infile.section == "layer") {
if (infile.key == "type") {
cur_layer = new maprow[w];
if (infile.val == "background") background = cur_layer;
else if (infile.val == "fringe") fringe = cur_layer;
else if (infile.val == "object") object = cur_layer;
else if (infile.val == "foreground") foreground = cur_layer;
else if (infile.val == "collision") collision = cur_layer;
}
else if (infile.key == "format") {
data_format = infile.val;
}
else if (infile.key == "data") {
// layer map data handled as a special case
// The next h lines must contain layer data. TODO: err
for (int j=0; j<h; j++) {
val = infile.getRawLine() + ',';
for (int i=0; i<w; i++)
cur_layer[i][j] = eatFirstInt(val, ',', (data_format == "hex" ? std::hex : std::dec));
}
if (cur_layer == collision)
collider.setmap(collision, w, h);
}
}
else if (infile.section == "enemy") {
if (infile.key == "type") {
new_enemy.type = infile.val;
}
else if (infile.key == "location") {
new_enemy.pos.x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
new_enemy.pos.y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
}
else if (infile.key == "direction") {
new_enemy.direction = toInt(infile.val);
}
else if (infile.key == "waypoints") {
string none = "";
string a = infile.nextValue();
string b = infile.nextValue();
while (a != none) {
Point p;
p.x = toInt(a) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
p.y = toInt(b) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
new_enemy.waypoints.push(p);
a = infile.nextValue();
b = infile.nextValue();
}
} else if (infile.key == "wander_area") {