This repository has been archived on 2025-09-12. You can view files and clone it, but cannot push or open issues or pull requests.
ld48/game/GroupMessenger.gd
2021-04-17 22:36:22 +02:00

29 lines
831 B
GDScript

# Copyright 2020 Outfrost
# This work is free software. It comes without any warranty, to the extent
# permitted by applicable law. You can redistribute it and/or modify it under
# the terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the LICENSE.WTFPL file for more details.
class_name GroupMessenger
var message: String
var groups: Array = []
var owner: Node
func _init(owner: Node, message: String, groups: Array = []):
self.owner = owner
self.message = message
self.groups = groups
func add_group(group: String):
groups.push_back(group)
func remove_group(group: String):
var i = groups.find(group)
if i != -1:
groups.remove(i)
func dispatch(args: Array = []):
var tree = owner.get_tree()
for group in groups:
tree.call_group(group, "on_" + message, args)