Implemented event system, Implemented initial bit of scripting system, Stubbed component system. Entities can now use the scripting system to place their 'decorations'

This commit is contained in:
2019-09-26 12:13:08 -05:00
parent e41a2b6524
commit b6d7a6ebdb
24 changed files with 293 additions and 80 deletions

39
lib/publisher.rb Normal file
View File

@@ -0,0 +1,39 @@
class IMICFPS
class Publisher
def self.subscribe(subscription)
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
Publisher.instance.add_sub(subscription)
end
def self.unsubscribe(subscription)
end
def self.instance
@@instance
end
def initialize
@@instance = self
EventHandler.initiate
Component.initiate
@events = {}
end
def add_sub(subscription)
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
@events[subscription.event] ||= []
@events[subscription.event] << subscription
end
def publish(event, context, *args)
if subscribers = @events.dig(event)
return unless event_handler = EventHandler.get(event)
subscribers.each do |subscriber|
event_handler.handle(subscriber, context, args)
end
end
end
end
end