kugutsu 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fa90d5a4b736b27a1c74fd75f33f277cd3af4c784bcc8bc2ec9450158a8ecc5
4
- data.tar.gz: 83c238563d42f682b784ebdcf9f10b73a326b0497875be3315ad16c578b8cf57
3
+ metadata.gz: 80bd4a9e2074891d27683232bb0cf0b974015ba5518a69cf9f989d15fdd68083
4
+ data.tar.gz: 76d9eccd60613fd8afeb22fa886951ce3f0aed7a5e7020924d8b3289a84ea2b8
5
5
  SHA512:
6
- metadata.gz: 54e66de0d187d5f15aaae09a9288c516882ae40f9d0ffc985c3ce33e35b6e7ca603c9c6da87061e5eafe88eb5e691e4973f59e876af6c288a71d146f4fd0bbc4
7
- data.tar.gz: e36fe3459a322b180d929e63f06613544103139a8b6cba17701f2df6513e6262058280050ba43da8e47cd1e9905b3d023027720f29d9526311f16f0be94f4f79
6
+ metadata.gz: c916da2d48a0340689b9599f2cd9c926227a5758d5c32dedbb7c8ceffadf1a9848f03537f6f81cf8b8af43862d724f2069c1441b6079846182af9a6eb44ecf77
7
+ data.tar.gz: 120ba42b2ff07873ba869ebf86e028b7c8750ee0c14233b46b0d8e195cc6b34673e7ac47f1864e965d1147cdefe301ace5ce63edf3be4928ad73e9c0299ac2e7
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
@@ -0,0 +1,8 @@
1
+ # 0.2.0
2
+
3
+ * Add parser to deserialize scene files
4
+ * Add script object to manage enabling and completion of actions
5
+
6
+ # 0.1.0
7
+
8
+ * Initial commit of empty project
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 John Tuttle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
  spec.add_development_dependency 'pry-byebug', '~> 3.5.0'
26
+
27
+ spec.add_dependency 'miru', '~> 0.1.0'
26
28
  end
@@ -6,6 +6,11 @@ module Kugutsu
6
6
  rescue LoadError
7
7
  # development dependencies
8
8
  end
9
-
9
+
10
+ require 'json'
11
+ require 'set'
12
+
13
+ require 'miru'
14
+
10
15
  Gem.find_files("kugutsu/**/*.rb").each { |path| require path }
11
16
  end
@@ -0,0 +1,36 @@
1
+ module Kugutsu
2
+ class Action
3
+ include Miru::EventDispatcher
4
+
5
+ attr_reader :id, :conditions
6
+ attr_accessor :children
7
+
8
+ def initialize(action_data, event_bus)
9
+ @id = action_data['id']
10
+ @conditions = action_data['conditions'] || []
11
+ @event_bus = event_bus
12
+
13
+ @children = []
14
+ end
15
+
16
+ def enable
17
+
18
+ end
19
+
20
+ def complete
21
+ dispatch_event(:complete, self)
22
+ end
23
+
24
+ def transient_effect
25
+
26
+ end
27
+
28
+ def persistent_effect
29
+
30
+ end
31
+
32
+ def to_s
33
+ "<#{self.class} id: #{@id}>"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Kugutsu
2
+ class EventBus
3
+ include Miru::EventDispatcher
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Kugutsu
2
+ class Scene
3
+ attr_reader :id, :actions
4
+
5
+ def initialize(id, actions)
6
+ @id = id
7
+ @actions = actions
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ module Kugutsu
2
+ class SceneParser
3
+ def parse(file, event_bus)
4
+ scene = JSON.parse(file.read)
5
+
6
+ actions = deserialize_actions(scene['actions'], event_bus)
7
+
8
+ Scene.new(scene['id'], actions)
9
+ end
10
+
11
+ private
12
+
13
+ def deserialize_actions(actions_data, event_bus)
14
+ actions_data.map do |action_data|
15
+ klass = to_class_string(action_data['type'])
16
+ Object::const_get(klass).new(action_data, event_bus)
17
+ end
18
+ end
19
+
20
+ def to_class_string(action_type_raw)
21
+ action_type_formatted =
22
+ action_type_raw.split(":").
23
+ map { |str| to_pascal_case(str) }.
24
+ join("::")
25
+
26
+ "::#{action_type_formatted}Action"
27
+ end
28
+
29
+ def to_pascal_case(str)
30
+ str.split("_").map(&:capitalize).join
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,62 @@
1
+ module Kugutsu
2
+ class Script
3
+ attr_reader :event_bus
4
+
5
+ def initialize
6
+ @action_index = {}
7
+ @enabled_actions = Set.new
8
+ @completed_actions = {}
9
+
10
+ @event_bus = EventBus.new
11
+ end
12
+
13
+ def load_scene_file(scene_file)
14
+ scene = SceneParser.new.parse(scene_file, @event_bus)
15
+
16
+ scene.actions.each do |action|
17
+ add_action!(action)
18
+ end
19
+ end
20
+
21
+ def enable_actions
22
+ @action_index.values.each do |action|
23
+ enable_action(action) if is_enabled?(action)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def add_action!(action)
30
+ action.add_event_listener(:complete, method(:on_action_complete))
31
+
32
+ action.conditions.each do |parent_id|
33
+ @action_index[parent_id].children << action.id
34
+ end
35
+
36
+ @action_index[action.id] = action
37
+ end
38
+
39
+ def is_enabled?(action)
40
+ !@completed_actions[action.id] &&
41
+ action.conditions.map { |condition| @completed_actions[condition] }.all?
42
+ end
43
+
44
+ def enable_action(action)
45
+ if @enabled_actions.include?(action)
46
+ raise StandardError.new("Action #{action.id} already enabled.")
47
+ end
48
+
49
+ @enabled_actions << action
50
+ action.enable
51
+ end
52
+
53
+ def on_action_complete(action)
54
+ @completed_actions[action.id] = true
55
+
56
+ action.children.each do |child_id|
57
+ child_action = @action_index[child_id]
58
+ enable_action(child_action) if is_enabled?(child_action)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Kugutsu
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kugutsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Tuttle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2019-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: miru
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.0
69
83
  description: A scripting system for Ruby
70
84
  email:
71
85
  - jtuttle.develops@gmail.com
@@ -73,10 +87,18 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
90
+ - ".gitignore"
91
+ - CHANGELOG.md
76
92
  - Gemfile
93
+ - LICENSE.txt
77
94
  - README.md
78
95
  - kugutsu.gemspec
79
96
  - lib/kugutsu.rb
97
+ - lib/kugutsu/action.rb
98
+ - lib/kugutsu/event_bus.rb
99
+ - lib/kugutsu/scene.rb
100
+ - lib/kugutsu/scene_parser.rb
101
+ - lib/kugutsu/script.rb
80
102
  - lib/kugutsu/version.rb
81
103
  homepage: https://github.com/jtuttle/kugutsu
82
104
  licenses: