HackerExperience / Helix

GNU Affero General Public License v3.0
53 stars 10 forks source link

Implement ObjectListener #268

Closed renatomassaro closed 6 years ago

renatomassaro commented 6 years ago

The idea behind ObjectListener is to create a global listener on game objects that react to certain events, registering a callback when that event occurs.

Sample use case:

Solution: Add a listener:

listener file_id, [:delete, :hide, :encrypt], &regenerate/1

def regenerate(event) do
  # Regenerate the file, change mission metadata, etc.
end

Also possibly useful:

ObjectBlocker. Similar to Listener, but performs the check before the action, blocking it in some cases. So, on the above example, it would be possible to not allow the file X to be deleted on the first place.

obj_block file_id, [:delete, :hide, :encrypt], "reason"

All macros for illustrative purposes only.

renatomassaro commented 6 years ago

ObjectBlocker cannot be implemented in a similar fashion to ObjectListener, it would be extremely inefficient.

Contrast this to ObjectListener, which:

So, if a ObjectBlocker-like behavior is desired, it must be implemented at the Henforcer level: