More or less standardised separator comments in the code

This commit is contained in:
Maruno17
2024-06-27 21:21:26 +01:00
parent 225549bfce
commit 509a414f37
198 changed files with 1907 additions and 1263 deletions

View File

@@ -42,24 +42,26 @@
module EventHandlers
@@events = {}
module_function
# Add a named callback for the given event.
def self.add(event, key, proc)
def add(event, key, proc)
@@events[event] = NamedEvent.new if !@@events.has_key?(event)
@@events[event].add(key, proc)
end
# Remove a named callback from the given event.
def self.remove(event, key)
def remove(event, key)
@@events[event]&.remove(key)
end
# Clear all callbacks for the given event.
def self.clear(key)
def clear(key)
@@events[key]&.clear
end
# Trigger all callbacks from an Event if it has been defined.
def self.trigger(event, *args)
def trigger(event, *args)
return @@events[event]&.trigger(*args)
end
end
@@ -80,25 +82,27 @@ end
module MenuHandlers
@@handlers = {}
def self.add(menu, option, hash)
module_function
def add(menu, option, hash)
@@handlers[menu] = HandlerHash.new if !@@handlers.has_key?(menu)
@@handlers[menu].add(option, hash)
end
def self.remove(menu, option)
def remove(menu, option)
@@handlers[menu]&.remove(option)
end
def self.clear(menu)
def clear(menu)
@@handlers[menu]&.clear
end
def self.each(menu)
def each(menu)
return if !@@handlers.has_key?(menu)
@@handlers[menu].each { |option, hash| yield option, hash }
end
def self.each_available(menu, *args)
def each_available(menu, *args)
return if !@@handlers.has_key?(menu)
options = @@handlers[menu]
keys = options.keys
@@ -115,7 +119,7 @@ module MenuHandlers
end
end
def self.call(menu, option, function, *args)
def call(menu, option, function, *args)
option_hash = @@handlers[menu][option]
return nil if !option_hash || !option_hash[function]
return option_hash[function].call(*args)