Re-add image path function ~L() (revert 2011-12-16T03:38:59Z!alinkmaze@gmail.com)

Also adapt it to a recent change and remove an old limitation: now the
lightmap can have any size and is just resized to the image.  This
make it easy to use ~L() on animated units, making it more useful
This commit is contained in:
Ali El Gariani 2011-12-16 18:15:41 +00:00
parent cd9d141c3a
commit 7347c81e19
3 changed files with 70 additions and 0 deletions

View file

@ -255,6 +255,23 @@ int mask_modification::get_y() const
return y_;
}
surface light_modification::operator()(const surface& src) const {
if(src == NULL) { return NULL; }
//light_surface wants a neutral surface having same dimensions
surface nsurf;
if(surf_->w != src->w || surf_->h != src->h)
nsurf = scale_surface(surf_, src->w, src->h, false);
else
nsurf = make_neutral_surface(surf_);
return light_surface(src, nsurf);;
}
const surface& light_modification::get_surface() const
{
return surf_;
}
surface scale_modification::operator()(const surface& src) const
{
const int old_w = src->w;
@ -653,6 +670,19 @@ REGISTER_MOD_PARSER(MASK, args)
return new mask_modification(surf, x, y);
}
// Light
REGISTER_MOD_PARSER(L, args)
{
if(args.empty()){
ERR_DP << "no arguments passed to the ~L() function\n";
return NULL;
}
surface surf = get_image(args);
return new light_modification(surf);
}
// Scale
REGISTER_MOD_PARSER(SCALE, args)
{

View file

@ -229,6 +229,24 @@ private:
int y_;
};
/**
* LIGHT (L) modification.
*/
class light_modification : public modification
{
public:
light_modification(const surface& surf)
: surf_(surf)
{}
virtual surface operator()(const surface& src) const;
const surface& get_surface() const;
private:
surface surf_;
};
/**
* Scale (SCALE) modification.
*/

View file

@ -608,6 +608,28 @@ BOOST_AUTO_TEST_CASE(test_l_modification_decoding_no_args)
BOOST_CHECK_EQUAL(queue.size(), 0);
}
/** Tests if the L modification with one argument is correctly decoded
*
* @todo check if the surface is correct
*/
BOOST_AUTO_TEST_CASE(test_l_modification_decoding_1_arg)
{
environment_setup env_setup;
modification_queue queue = modification::decode("~L(wesnoth-icon.png)");
BOOST_REQUIRE_EQUAL(queue.size(), 1);
light_modification* mod = dynamic_cast<light_modification*>(queue.top());
// The dynamic_cast returns NULL if the argument doesn't match the type
BOOST_REQUIRE(mod != NULL);
BOOST_CHECK(!mod->get_surface().null());
delete mod;
}
/// Tests if the SCALE modification without arguments is ignored
BOOST_AUTO_TEST_CASE(test_scale_modification_decoding_no_args)
{