Skip to content

Commit

Permalink
parser: Parse 'version' argument as common value.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Feb 20, 2023
1 parent 14ce2e7 commit 5805bf0
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 98 deletions.
20 changes: 4 additions & 16 deletions libopenage/renderer/resources/parser/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

namespace openage::renderer::resources::parser {

/**
* Parse the texture attribute.
*
* @param args Arguments from the line with a \p texture attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Struct containing the attribute data.
*/
size_t parse_version(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

TextureData parse_texture(const std::vector<std::string> &args) {
// TODO: Splitting at the space char assumes that the path string contains no
// space. While the space char is not allowed because of nyan naming requirements,
Expand All @@ -26,14 +22,6 @@ TextureData parse_texture(const std::vector<std::string> &args) {
return texture;
}

/**
* Parse the scalefactor attribute.
*
* @param args Arguments from the line with a \p scalefactor attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Scalefactor value.
*/
float parse_scalefactor(const std::vector<std::string> &args) {
return std::stof(args[1]);
}
Expand Down
10 changes: 10 additions & 0 deletions libopenage/renderer/resources/parser/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ struct TextureData {
* Subparsers for arguments.
*/

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_version(const std::vector<std::string> &args);

/**
* Parse the texture attribute.
*
Expand Down
15 changes: 1 addition & 14 deletions libopenage/renderer/resources/parser/parse_blendmask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@

#include "error/error.h"
#include "renderer/resources/parser/common.h"
#include "renderer/resources/parser/parse_sprite.h"
#include "renderer/resources/parser/parse_texture.h"
#include "renderer/resources/texture_data.h"
#include "util/strings.h"

namespace openage::renderer::resources::parser {

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_blendmask_version(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the mask attribute.
*
Expand Down Expand Up @@ -74,7 +61,7 @@ BlendPatternInfo parse_blendmask_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_blendmask_version(args);
size_t version_no = parse_version(args);

if (version_no != 2) {
throw Error(MSG(err) << "Reading .blmask file '"
Expand Down
15 changes: 2 additions & 13 deletions libopenage/renderer/resources/parser/parse_blendtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@
#include <functional>

#include "error/error.h"
#include "renderer/resources/parser/common.h"
#include "renderer/resources/parser/parse_blendmask.h"
#include "renderer/resources/terrain/blendpattern_info.h"
#include "renderer/resources/terrain/blendtable_info.h"
#include "util/strings.h"

namespace openage::renderer::resources::parser {

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_blendtable_version(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the blendtable attribute.
*
Expand Down Expand Up @@ -83,7 +72,7 @@ BlendTableInfo parse_blendtable_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_blendtable_version(args);
size_t version_no = parse_version(args);

if (version_no != 1) {
throw Error(MSG(err) << "Reading .bltable file '"
Expand Down
15 changes: 2 additions & 13 deletions libopenage/renderer/resources/parser/parse_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
#include <functional>

#include "error/error.h"
#include "renderer/resources/parser/common.h"
#include "util/strings.h"

namespace openage::renderer::resources::parser {

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_palette_version(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the entries attribute.
*
Expand Down Expand Up @@ -77,7 +66,7 @@ PaletteInfo parse_palette_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_palette_version(args);
size_t version_no = parse_version(args);

if (version_no != 1) {
throw Error(MSG(err) << "Reading .opal file '"
Expand Down
14 changes: 1 addition & 13 deletions libopenage/renderer/resources/parser/parse_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@

namespace openage::renderer::resources::parser {

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_spriteversion(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the layer attribute.
*
Expand Down Expand Up @@ -154,7 +142,7 @@ Animation2dInfo parse_sprite_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_spriteversion(args);
size_t version_no = parse_version(args);

if (version_no != 2) {
throw Error(MSG(err) << "Reading .sprite file '"
Expand Down
15 changes: 1 addition & 14 deletions libopenage/renderer/resources/parser/parse_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "error/error.h"
#include "renderer/resources/parser/common.h"
#include "renderer/resources/parser/parse_blendtable.h"
#include "renderer/resources/parser/parse_sprite.h"
#include "renderer/resources/parser/parse_texture.h"
#include "renderer/resources/terrain/frame_info.h"
#include "renderer/resources/terrain/layer_info.h"
Expand All @@ -16,18 +15,6 @@

namespace openage::renderer::resources::parser {

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_terrain_version(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the blendtable attribute.
*
Expand Down Expand Up @@ -160,7 +147,7 @@ TerrainInfo parse_terrain_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_terrain_version(args);
size_t version_no = parse_version(args);

if (version_no != 2) {
throw Error(MSG(err) << "Reading .terrain file '"
Expand Down
16 changes: 2 additions & 14 deletions libopenage/renderer/resources/parser/parse_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "parse_texture.h"

#include "error/error.h"
#include "renderer/resources/texture_data.h"
#include "renderer/resources/parser/common.h"
#include "util/strings.h"

namespace openage::renderer::resources::parser {
Expand All @@ -27,18 +27,6 @@ static constexpr size_t guess_row_alignment(size_t width) {
return 4;
}

/**
* Parse the file version attribute.
*
* @param args Arguments from the line with a \p version attribute.
* The first argument is expected to be the attribute keyword.
*
* @return Version number.
*/
size_t parse_texversion(const std::vector<std::string> &args) {
return std::stoul(args[1]);
}

/**
* Parse the imagefile attribute.
*
Expand Down Expand Up @@ -152,7 +140,7 @@ Texture2dInfo parse_texture_file(const util::Path &file) {

auto keywordfuncs = std::unordered_map<std::string, std::function<void(const std::vector<std::string> &)>>{
std::make_pair("version", [&](const std::vector<std::string> &args) {
size_t version_no = parse_texversion(args);
size_t version_no = parse_version(args);

if (version_no != 1) {
throw Error(MSG(err) << "Reading .texture file '"
Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/resources/parser/parse_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "renderer/resources/texture_data.h"
#include "renderer/resources/texture_info.h"
#include "util/path.h"

namespace openage::renderer::resources::parser {
Expand Down

0 comments on commit 5805bf0

Please sign in to comment.