mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
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:
40
lib/subscription.rb
Normal file
40
lib/subscription.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
class IMICFPS
|
||||
class Subscription
|
||||
attr_reader :entity, :event, :args, :block
|
||||
def initialize(entity)
|
||||
@entity = entity
|
||||
|
||||
@event = nil
|
||||
@args = nil
|
||||
@block = nil
|
||||
end
|
||||
|
||||
def method_missing(event, *args, &block)
|
||||
return unless subscribable_events.include?(event)
|
||||
|
||||
@event, @args, @block = event, args, block
|
||||
Publisher.subscribe(self)
|
||||
end
|
||||
|
||||
def trigger(event, *args)
|
||||
if @block
|
||||
@block.call(event, *args)
|
||||
end
|
||||
end
|
||||
|
||||
private def subscribable_events
|
||||
[
|
||||
:tick,
|
||||
:create,
|
||||
:destroy,
|
||||
:button_down, :button_up,
|
||||
:mouse_move,
|
||||
:entity_move,
|
||||
:interact,
|
||||
:player_join, :player_leave, :player_die,
|
||||
:pickup_item, :use_item, :drop_item,
|
||||
:enter_vehicle, :exit_vehicle,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user