solarus-games / solarus

This repository was moved to GitLab: https://gitlab.com/solarus-games/solarus
http://www.solarus-games.org
Other
711 stars 133 forks source link

Add function item:is_being_used() #879

Open Diarandor opened 8 years ago

Diarandor commented 8 years ago

Add function item:is_being_used(), returning a boolean, so we can know if an item is being used. The return value will be set to true after the event on_started, and to false after the event on_finished.

In my opinion, this may be quite useful (to make the code cleaner) when using combined custom items, like sword + feather, boots + feather, boots + sword, etc.

ghost commented 8 years ago

Diarandor likely means set_finished(), not on_finished(). The request as-is will just make is_being_used() return true until the game stops.

Diarandor commented 8 years ago

Yes, sorry for the mistake. I meant that.

christopho commented 8 years ago

Maybe we prefer hero:is_using_item(item) and/or hero:get_item_used() instead. (Because one day there might be several heroes.)

ghost commented 8 years ago

I think it makes sense to have it in the item API. That way you can have items that have some behaviour tied to it being used -- regardless of the entity that's using it. That way it will work both with different heroes, and with NPCs, or whatever.

I do think having something similar in the hero and the npc APIs could prove useful as well.

Diarandor commented 8 years ago

But the hero may be using several items. For instance, sword + jump, boots + sword, bow + bombs, etc.

So "hero:get_item_used()" should be better a list of items? I am not sure which would be the best option.

Diarandor commented 8 years ago

But yes, hero:is_using_item(item) is surely the best option, IMO.

ghost commented 8 years ago

I think it makes much more sense to encode this on the item API. When I'm denoting the maturity of a banana, I don't want to go through the forest, where the gorilla whose hand is currently holding the banana resides, in order to obtain the banana. hero:using_item(item) would end up as a massive case analysis. I don't think this smells like particularly good design, but it might be useful too.

Renkineko commented 8 years ago

In the case of multiple hero, the function in item would be "is_used_by(hero)" I think to return a boolean. Agreed about the "is_being_used" on item, and we can have another method in hero like "get_items_used", denoting the plural name to get the list of item.