seh 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.yardopts +3 -0
- data/Gemfile +0 -1
- data/README.md +13 -0
- data/lib/seh.rb +3 -3
- data/lib/seh/event.rb +31 -3
- data/lib/seh/event_target.rb +2 -1
- data/lib/seh/version.rb +2 -1
- data/seh.gemspec +2 -15
- metadata +21 -34
- data/README.org +0 -4
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/README.md
ADDED
data/lib/seh.rb
CHANGED
@@ -5,17 +5,17 @@ require "seh/event"
|
|
5
5
|
|
6
6
|
module Seh
|
7
7
|
class << self
|
8
|
-
# alias
|
8
|
+
# @note alias of {EventType::And}
|
9
9
|
def and( *types )
|
10
10
|
EventType::And.new *types
|
11
11
|
end
|
12
12
|
|
13
|
-
# alias
|
13
|
+
# @note alias of {EventType::Or}
|
14
14
|
def or( *types )
|
15
15
|
EventType::Or.new *types
|
16
16
|
end
|
17
17
|
|
18
|
-
# alias
|
18
|
+
# @note alias of {EventType::Not}
|
19
19
|
def not( type )
|
20
20
|
EventType::Not.new type
|
21
21
|
end
|
data/lib/seh/event.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module Seh
|
4
|
-
|
4
|
+
# @private
|
5
|
+
module Private
|
5
6
|
START = 0
|
6
7
|
BEFORE = 100
|
7
8
|
|
@@ -18,10 +19,11 @@ module Seh
|
|
18
19
|
FINISH = 1000
|
19
20
|
|
20
21
|
class EventData
|
21
|
-
attr_accessor :types, :target, :time, :staged_handlers, :success
|
22
|
+
attr_accessor :types, :type_map, :target, :time, :staged_handlers, :success
|
22
23
|
|
23
24
|
def initialize
|
24
25
|
@types = []
|
26
|
+
@type_map = {}
|
25
27
|
@target = nil
|
26
28
|
@time = Time.now
|
27
29
|
@success = true
|
@@ -35,6 +37,26 @@ module Seh
|
|
35
37
|
class << self
|
36
38
|
def type( data, t )
|
37
39
|
data.types << t
|
40
|
+
apply_type_map data
|
41
|
+
end
|
42
|
+
|
43
|
+
def type_map( data, map = {} )
|
44
|
+
map.each_pair do |type, implied_types|
|
45
|
+
data.type_map[type] ||= []
|
46
|
+
data.type_map[type].concat implied_types
|
47
|
+
data.type_map[type].uniq!
|
48
|
+
end
|
49
|
+
apply_type_map data
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def apply_type_map( data )
|
54
|
+
while true
|
55
|
+
original_size = data.types.size
|
56
|
+
data.type_map.each_pair { |type, implied_types| data.types.concat implied_types if data.types.include? type }
|
57
|
+
data.types.uniq!
|
58
|
+
break if original_size = data.types.size
|
59
|
+
end
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
@@ -66,7 +88,7 @@ module Seh
|
|
66
88
|
end
|
67
89
|
|
68
90
|
def dispatch
|
69
|
-
raise "Event may only be
|
91
|
+
raise "Event#dispatch may only be called once" unless @state == Private::EventStateReady
|
70
92
|
@state = Private::EventStateInflight
|
71
93
|
collect_targets.each { |t| t.each_bind { |bind| bind.block.call self if bind.event_type.match @data.types } }
|
72
94
|
@data.staged_handlers.each_key.sort.each { |stage| @data.staged_handlers[stage].each { |block| block.call self } }
|
@@ -79,6 +101,12 @@ module Seh
|
|
79
101
|
|
80
102
|
def type( event_type )
|
81
103
|
@state.type @data, event_type
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
def type_map( map )
|
108
|
+
@state.type_map @data, map
|
109
|
+
nil
|
82
110
|
end
|
83
111
|
|
84
112
|
def match_type( event_type )
|
data/lib/seh/event_target.rb
CHANGED
data/lib/seh/version.rb
CHANGED
data/seh.gemspec
CHANGED
@@ -8,16 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Ryan Berckmans"]
|
9
9
|
s.email = ["ryan.berckmans@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/ryanberckmans/seh"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "
|
13
|
-
+ event handling in a synchronous specific order
|
14
|
-
+ event targets can have multiple parents and common ancestors; event propagation does a breadth first search traversal over a directed acyclic event target graph
|
15
|
-
+ staged callbacks: event.before { .. }; event.after { .. }
|
16
|
-
+ staged callbacks allow for an ancestor to influence affect of event on a descendant: ancestor.before { |event| event.x = 5 }; descendant.after { |event| puts event.x }
|
17
|
-
+ events can have multiple types, and types can inherit from other types
|
18
|
-
+ bind callbacks using event type filtering: node.bind(overcast AND (rain OR snow)) { |event| callback! }
|
19
|
-
+ optional event failure: event.success { yay! }; event.failure { oops! }
|
20
|
-
+ events on stack don't care about other events above/below - event A, currently executing, can create/dispatch/finish another event B"
|
11
|
+
s.summary = "Structured event handler. Pure ruby event handling similar to w3c dom events; alpha wip."
|
12
|
+
s.description = "#{s.summary} Lots of bells and whistles to support complex event handling as required by stuff like video games. Event handling in a synchronous specific order. Events 'bubble', and event targets can have multiple parents and common ancestors. Staged event callbacks: event.before { 'the united states of' }; event.after { 'america' }. Staged callbacks allow an ancestor to influence affect of event on a descendant: ancestor.before { |event| event.damage *= 2 }; descendant.after { |event| player.health -= event.damage }. Events use 'tag-style' types: event.type :hostile ; event.type :spell. Handle only events which pass a filter: player.bind( Seh::and :hostile, Seh::not( :spell ) ) { |event| 'Hostile non-spell!!' }. Optional event failure: event.fail; event.success { 'yay!' }; event.failure { 'oops!' }. Event inherits from OpenStruct for dynamic properties: event.omgs = 'omgs a dynamic attribute'"
|
21
13
|
|
22
14
|
s.rubyforge_project = "seh"
|
23
15
|
|
@@ -25,9 +17,4 @@ Gem::Specification.new do |s|
|
|
25
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
19
|
s.require_paths = ["lib"]
|
28
|
-
|
29
|
-
s.has_rdoc = true
|
30
|
-
s.rdoc_options << '--title' << 'Seh - Structured Event Handling' \
|
31
|
-
<< '--main' << 'README.org'
|
32
|
-
s.extra_rdoc_files = ['README.org']
|
33
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,42 +9,32 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-19 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description: ! 'Pure ruby event handling similar to w3c
|
15
|
-
and whistles to support complex event handling
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
+ events can have multiple types, and types can inherit from other types
|
29
|
-
|
30
|
-
+ bind callbacks using event type filtering: node.bind(overcast AND (rain OR snow))
|
31
|
-
{ |event| callback! }
|
32
|
-
|
33
|
-
+ optional event failure: event.success { yay! }; event.failure { oops! }
|
34
|
-
|
35
|
-
+ events on stack don''t care about other events above/below - event A, currently
|
36
|
-
executing, can create/dispatch/finish another event B'
|
14
|
+
description: ! 'Structured event handler. Pure ruby event handling similar to w3c
|
15
|
+
dom events; alpha wip. Lots of bells and whistles to support complex event handling
|
16
|
+
as required by stuff like video games. Event handling in a synchronous specific
|
17
|
+
order. Events ''bubble'', and event targets can have multiple parents and common
|
18
|
+
ancestors. Staged event callbacks: event.before { ''the united states of'' }; event.after
|
19
|
+
{ ''america'' }. Staged callbacks allow an ancestor to influence affect of event
|
20
|
+
on a descendant: ancestor.before { |event| event.damage *= 2 }; descendant.after
|
21
|
+
{ |event| player.health -= event.damage }. Events use ''tag-style'' types: event.type
|
22
|
+
:hostile ; event.type :spell. Handle only events which pass a filter: player.bind(
|
23
|
+
Seh::and :hostile, Seh::not( :spell ) ) { |event| ''Hostile non-spell!!'' }. Optional
|
24
|
+
event failure: event.fail; event.success { ''yay!'' }; event.failure { ''oops!''
|
25
|
+
}. Event inherits from OpenStruct for dynamic properties: event.omgs = ''omgs a
|
26
|
+
dynamic attribute'''
|
37
27
|
email:
|
38
28
|
- ryan.berckmans@gmail.com
|
39
29
|
executables: []
|
40
30
|
extensions: []
|
41
|
-
extra_rdoc_files:
|
42
|
-
- README.org
|
31
|
+
extra_rdoc_files: []
|
43
32
|
files:
|
44
33
|
- .gitignore
|
45
34
|
- .rvmrc
|
35
|
+
- .yardopts
|
46
36
|
- Gemfile
|
47
|
-
- README.
|
37
|
+
- README.md
|
48
38
|
- Rakefile
|
49
39
|
- lib/seh.rb
|
50
40
|
- lib/seh/event.rb
|
@@ -56,11 +46,7 @@ files:
|
|
56
46
|
homepage: https://github.com/ryanberckmans/seh
|
57
47
|
licenses: []
|
58
48
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
- --title
|
61
|
-
- Seh - Structured Event Handling
|
62
|
-
- --main
|
63
|
-
- README.org
|
49
|
+
rdoc_options: []
|
64
50
|
require_paths:
|
65
51
|
- lib
|
66
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -80,5 +66,6 @@ rubyforge_project: seh
|
|
80
66
|
rubygems_version: 1.8.5
|
81
67
|
signing_key:
|
82
68
|
specification_version: 3
|
83
|
-
summary:
|
69
|
+
summary: Structured event handler. Pure ruby event handling similar to w3c dom events;
|
70
|
+
alpha wip.
|
84
71
|
test_files: []
|
data/README.org
DELETED