terminal_game_engine 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.markdown +4 -0
- data/lib/terminal_game_engine/engine.rb +8 -5
- data/lib/terminal_game_engine/sound.rb +11 -3
- data/lib/terminal_game_engine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6c929b4edebdc771f660f1d814c1487018e813f
|
4
|
+
data.tar.gz: 2fa244fc2b24b6759283a87545e4b8c473a0112d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6145fa6de0cfb0d7eaa3b6bd951d2461612c77d65ba45ca8d5f8858acec5541da0dac7c0bb9b22915ef0c095dd607c8d6db532db6cc8355f6e1e0e871ee0db38
|
7
|
+
data.tar.gz: 106a35ce83d7f4a01df5d6c66df5d878a87577c16bcb8eb80be4d31b17e386ce9898797c1d732b2a916f7f1480d39853c97edbda9773910bdd13b3e97be6a26f
|
data/README.markdown
CHANGED
@@ -19,3 +19,7 @@ Or install it yourself as:
|
|
19
19
|
## License
|
20
20
|
|
21
21
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
22
|
+
|
23
|
+
## Origins
|
24
|
+
|
25
|
+
Most of this code was originally written as part of [hrdlr](https://github.com/twe4ked/hrdlr) at Railscamp by [@jasoncodes](https://github.com/jasoncodes), [@nathanaelkane](https://github.com/nathanaelkane), and [@twe4ked](https://github.com/twe4ked). It was then mostly copied into [snek](https://github.com/twe4ked/snek) by [@twe4ked](https://github.com/twe4ked) and then extracted into this gem.
|
@@ -1,21 +1,24 @@
|
|
1
1
|
module TerminalGameEngine
|
2
2
|
class Engine
|
3
|
-
|
3
|
+
DEFAULT_TICK_SLEEP = 0.1
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
attr_accessor :tick, :tick_sleep
|
6
|
+
|
7
|
+
def self.tick(*args, &block)
|
8
|
+
self.new(*args, &block).tap(&:call)
|
7
9
|
end
|
8
10
|
|
9
|
-
def initialize(&block)
|
11
|
+
def initialize(tick_sleep: DEFAULT_TICK_SLEEP, &block)
|
10
12
|
@tick = 0
|
11
13
|
@block = block
|
14
|
+
@tick_sleep = tick_sleep
|
12
15
|
end
|
13
16
|
|
14
17
|
def call
|
15
18
|
loop do
|
16
19
|
@block.call @tick
|
17
20
|
@tick += 1
|
18
|
-
sleep
|
21
|
+
sleep tick_sleep
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -1,11 +1,19 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module TerminalGameEngine
|
2
4
|
class Sound
|
3
|
-
def self.play(
|
5
|
+
def self.play(path, logger: Logger.new('/dev/null'))
|
4
6
|
case RUBY_PLATFORM
|
5
7
|
when /darwin/
|
6
|
-
|
8
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3('afplay', path)
|
7
9
|
when /linux/
|
8
|
-
|
10
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3('command -v mplayer >/dev/null 2>&1 && mplayer -msglevel all=-1 -nolirc', path)
|
11
|
+
end
|
12
|
+
|
13
|
+
Thread.new do
|
14
|
+
while line = stderr.readline
|
15
|
+
logger.error line.chomp
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal_game_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Dutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|