Example #1
0
Drawable parse_drawable(const YAML::Node& node) {
	const char* err =
			"Expected drawable object, of form \n"
					"     type: image -or- animation -or- directional -or- lua \n"
					"     file: <filename>\n"
					"-or- frames: <drawable list or file pattern>\n"
					"         Note: file patterns are of the form filename(min-max).extension\n"
					"-or- function: <lua function>";
	if (node.Type() == YAML::NodeType::Scalar) {
		return Drawable(new Image(parse_str(node)));
	}

	if (node.Type() != YAML::NodeType::Map) {
		throw YAML::RepresentationException(node.GetMark(), err);
	}

	std::string type = parse_optional(node, "type", std::string());

	if ((type.empty() && yaml_has_node(node, "file")) || type == "image") {
		return Drawable(new Image(parse_image(node)));
	} else if (type == "animation") {
		return Drawable(new Animation(parse_animation(node)));
	} else if (type == "directional") {
		return Drawable(new DirectionalDrawable(parse_directional(node)));
	} else if (type == "lua") {
		return Drawable(new LuaDrawable(parse_luadrawable(node)));
	} else {
		throw YAML::RepresentationException(node.GetMark(), err);
	}

}
void Property::load( const YAML::Node& yaml_node )
{
  if( yaml_node.Type() == YAML::NodeType::Scalar )
  {
    loadValue( yaml_node );
  }
  else if( yaml_node.Type() == YAML::NodeType::Map )
  {
    loadChildren( yaml_node );
  }
  else
  {
    printf( "Property::load() TODO: error handling - unexpected YAML type (Sequence) at line %d, column %d.\n",
            yaml_node.GetMark().line, yaml_node.GetMark().column );
  }
}
Example #3
0
DirectionalDrawable parse_directional(const YAML::Node& node) {
	const YAML::Node* framenode = yaml_find_node(node, "frames");

	if (!framenode) {
		throw YAML::RepresentationException(node.GetMark(),
				"Expected 'frames:' for directional drawable object (has 'type: directional').");
	}

	return DirectionalDrawable(parse_drawable_list(*framenode));
}
Example #4
0
Animation parse_animation(const YAML::Node& node) {
	const YAML::Node* framenode = yaml_find_node(node, "frames");

	if (!framenode) {
		throw YAML::RepresentationException(node.GetMark(),
				"Expected 'frames:' for animation drawable object (has 'type: animation').");
	}

	return Animation(parse_drawable_list(*framenode));
}
Example #5
0
Image parse_image(const YAML::Node& node) {
	const YAML::Node* filenode = yaml_find_node(node, "file");

	if (!filenode) {
		throw YAML::RepresentationException(node.GetMark(),
				"Expected list (eg [\"file.png\"]), or pattern (eg \"file(0-9).png\").");
	}

	return Image(parse_str(*filenode));
}
Example #6
0
LuaDrawable parse_luadrawable(const YAML::Node& node) {
	lua_State* L = ParseContext::luastate();

	const YAML::Node* funcnode = yaml_find_node(node, "function");

	if (!funcnode) {
		throw YAML::RepresentationException(node.GetMark(),
				"Expected 'function:' for lua drawable object (has 'type: lua').");
	}

	return LuaDrawable(L, parse_str(*funcnode));
}
//==============================================================================
/// Parse a single derived dimension definition.
/// 
/// \param [in] dim The YAML map node for the dimension.
/// 
void DefinitionParser::ParseDerivedDimension( const YAML::Node& dim )
{
    QString name;
    dim["name"] >> name;
    QString unit_name;
    dim["unit"] >> unit_name;
    QString derivation;
    dim["derivation"] >> derivation;

    DimensionId id = ParseDerivation( derivation );

    (void)DefineDimension( dim.GetMark(), name, id, unit_name );
}
//==============================================================================
/// Parse a single base dimension definition.
/// 
/// \param [in] dim The YAML map node for the dimension.
/// 
void DefinitionParser::ParseBaseDimension( const YAML::Node& dim )
{
    QString name; 
    dim["name"] >> name;

    QString unit_name; 
    dim["unit"] >> unit_name;

    DimensionId id;
    id[unit_name] = 1;

    (void)DefineDimension( dim.GetMark(), name, id, unit_name );
}
Example #9
0
// If node is a string, loads multiple images based on a pattern
// If node is a list, calls parse_drawable on individual entries
std::vector<Drawable> parse_drawable_list(const YAML::Node& node) {
	std::vector<Drawable> drawables;

	// Error if map
	if (node.Type() == YAML::NodeType::Map) {
		throw YAML::RepresentationException(node.GetMark(),
				"Expected list (eg [\"file.png\"]), or pattern (eg \"file(0-9).png\").");
	}

	// Interpret as file pattern if string
	if (node.Type() == YAML::NodeType::Scalar) {
		std::vector<Image> images;

		if (!filepattern_to_image_list(images, parse_str(node))) {
			throw YAML::RepresentationException(node.GetMark(),
					"Expected list (eg [\"file.png\"]), or pattern (eg \"file(0-9).png\").");
		}

		images_to_drawable_list(drawables, images);
		return drawables;
	}

	// Accumulate from list
	int size = node.size();
	for (int i = 0; i < size; i++) {
		const YAML::Node& child = node[i];

		// Expand any file patterns, or image file names
		if (child.Type() == YAML::NodeType::Scalar) {
			std::vector<Image> images;
			filepattern_to_image_list(images, parse_str(child));
			images_to_drawable_list(drawables, images);
		} else {
			parse_drawable(child);
		}
	}

	return drawables;
}
Example #10
0
// If node is a string, loads as image
// If node is a map, 'type:' indicates drawable type
std::vector<Image> parse_image_list(const YAML::Node& node) {
	std::vector<Image> images;

	// Interpret as file pattern if string
	if (node.Type() == YAML::NodeType::Scalar) {
		if (!filepattern_to_image_list(images, parse_str(node))) {
			throw YAML::RepresentationException(node.GetMark(),
					"Expected list (eg [\"file.png\"]), or pattern (eg \"file(0-9).png\").");
		}
		return images;
	}

	// Accumulate from list
	int size = node.size();
	for (int i = 0; i < size; i++) {
		filepattern_to_image_list(images, parse_str(node[i]));
	}

	return images;
}
Example #11
0
//==============================================================================
/// Parse a single converted unit definition.
/// 
/// \param [in] unit The YAML map node for the unit.
/// 
void DefinitionParser::ParseConvertedUnit( const YAML::Node& unit )
{
    QString name;
    unit["name"] >> name;
    QString base_unit_name;

    const YAML::Node& dim_node( unit["dimension"] );
    QString dim_name;
    dim_node >> dim_name;


    Dimension *dim_p = m_result->GetDimension( dim_name );

    if ( !dim_p )
    {
        const YAML::Mark& mark( dim_node.GetMark() );
        throw ParseError( m_file, mark.line,
            UNDEFINED_DIM_NAME.arg( dim_name ).arg( mark.line ) );
    }

    Unit *unit_p = DefineUnit( unit.GetMark(), name, dim_p );
    ParseConversions( unit["conversion"], unit_p );
}