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:
16
lib/event_handlers/entity_lifecycle.rb
Normal file
16
lib/event_handlers/entity_lifecycle.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class IMICFPS
|
||||
class EventHandler
|
||||
class EntityLifeCycle < EventHandler
|
||||
def handles
|
||||
[:create, :entity_move, :destroy]
|
||||
end
|
||||
|
||||
def handle(subscriber, context, *args)
|
||||
return unless subscriber.entity == args.first.first
|
||||
event = EventHandler::Event.new(entity: subscriber.entity, context: context)
|
||||
|
||||
subscriber.trigger(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
24
lib/event_handlers/input.rb
Normal file
24
lib/event_handlers/input.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class IMICFPS
|
||||
class EventHandler
|
||||
class Input < EventHandler
|
||||
def handles
|
||||
[:button_down, :button_up]
|
||||
end
|
||||
|
||||
def handle(subscriber, context, *args)
|
||||
action = subscriber.args.flatten.first
|
||||
key = args.flatten.first
|
||||
|
||||
event = EventHandler::Event.new(entity: subscriber.entity, context: context, player: context)
|
||||
|
||||
if action.is_a?(Numeric) && action == key
|
||||
subscriber.trigger(event)
|
||||
else
|
||||
if InputMapper.get(action) == key
|
||||
subscriber.trigger(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user