gamefic-tty 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +37 -0
- data/CHANGELOG.md +6 -0
- data/README.md +55 -55
- data/gamefic-tty.gemspec +46 -46
- data/lib/gamefic-tty/engine.rb +25 -13
- data/lib/gamefic-tty/user.rb +5 -0
- data/lib/gamefic-tty/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7727ff76e6d99f185d104a500d1da91868062c852ae8fc340026ac0829b5d4a9
|
4
|
+
data.tar.gz: 718beb405d92d0b45bf551f3dca48ae54538c35afa2873e97fda9c559a4909e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ecfab661beff414d0bf7a06178ef23802206e03b0cf85fc2fb109342d4a6c45ea674807a5e912422fe9e9b412bcd5ab54081b6b49b114f3867bc0574588206
|
7
|
+
data.tar.gz: bae7168adddd34eb26291aeb1f64ec450ca5be09007c57ec1c3e6d08243874e7101bc3d645c079a4607a2c1e777711635040be5159d70497475f330f433f322a
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with rspec.
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: RSpec
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: false
|
34
|
+
- name: Install dependencies
|
35
|
+
run: bundle install
|
36
|
+
- name: Run Ruby tests
|
37
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
# Gamefic TTY
|
2
|
-
|
3
|
-
A Gamefic engine for games that run on IO.
|
4
|
-
|
5
|
-
**Features:**
|
6
|
-
|
7
|
-
* Works with the `gamefic-standard` library
|
8
|
-
* Converts Gamefic's default HTML output to ANSI text
|
9
|
-
|
10
|
-
**Common uses:**
|
11
|
-
|
12
|
-
* Run a game on the command line.
|
13
|
-
* Attach IO streams to run the game over other processes.
|
14
|
-
|
15
|
-
## Installation
|
16
|
-
|
17
|
-
Add this line to your application's Gemfile:
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
gem 'gamefic-tty'
|
21
|
-
```
|
22
|
-
|
23
|
-
And then execute:
|
24
|
-
|
25
|
-
$ bundle
|
26
|
-
|
27
|
-
Or install it yourself as:
|
28
|
-
|
29
|
-
$ gem install gamefic-tty
|
30
|
-
|
31
|
-
## Usage
|
32
|
-
|
33
|
-
The easiest way to get started with Gamefic TTY is with the Gamefic SDK. See the [SDK README](https://github.com/castwide/gamefic-sdk) for more information.
|
34
|
-
|
35
|
-
An example script that runs a game on the command line:
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
require 'gamefic-tty'
|
39
|
-
|
40
|
-
Gamefic
|
41
|
-
introduction do |actor|
|
42
|
-
actor.tell "Hello, world!"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Gamefic::Tty::Engine.run
|
47
|
-
```
|
48
|
-
|
49
|
-
## Contributing
|
50
|
-
|
51
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-tty.
|
52
|
-
|
53
|
-
## License
|
54
|
-
|
55
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1
|
+
# Gamefic TTY
|
2
|
+
|
3
|
+
A Gamefic engine for games that run on IO.
|
4
|
+
|
5
|
+
**Features:**
|
6
|
+
|
7
|
+
* Works with the `gamefic-standard` library
|
8
|
+
* Converts Gamefic's default HTML output to ANSI text
|
9
|
+
|
10
|
+
**Common uses:**
|
11
|
+
|
12
|
+
* Run a game on the command line.
|
13
|
+
* Attach IO streams to run the game over other processes.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'gamefic-tty'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install gamefic-tty
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
The easiest way to get started with Gamefic TTY is with the Gamefic SDK. See the [SDK README](https://github.com/castwide/gamefic-sdk) for more information.
|
34
|
+
|
35
|
+
An example script that runs a game on the command line:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'gamefic-tty'
|
39
|
+
|
40
|
+
class Example < Gamefic::Plot
|
41
|
+
introduction do |actor|
|
42
|
+
actor.tell "Hello, world!"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Gamefic::Tty::Engine.run(plot: Example.new)
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-tty.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/gamefic-tty.gemspec
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "gamefic-tty/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "gamefic-tty"
|
8
|
-
spec.version = Gamefic::Tty::VERSION
|
9
|
-
spec.authors = ["Fred Snyder"]
|
10
|
-
spec.email = ["fsnyder@castwide.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Gamefic TTY engine}
|
13
|
-
spec.description = %q{Components for running Gamefic om a terminal}
|
14
|
-
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
|
22
|
-
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
-
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
-
# else
|
26
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
-
# "public gem pushes."
|
28
|
-
# end
|
29
|
-
|
30
|
-
# Specify which files should be added to the gem when it is released.
|
31
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
-
end
|
35
|
-
# spec.bindir = "exe"
|
36
|
-
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
-
spec.require_paths = [
|
38
|
-
|
39
|
-
spec.add_runtime_dependency 'gamefic', '~>
|
40
|
-
spec.add_runtime_dependency 'html_to_ansi', '~> 0.
|
41
|
-
|
42
|
-
spec.add_development_dependency
|
43
|
-
spec.add_development_dependency
|
44
|
-
spec.add_development_dependency
|
45
|
-
spec.add_development_dependency
|
46
|
-
end
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gamefic-tty/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gamefic-tty"
|
8
|
+
spec.version = Gamefic::Tty::VERSION
|
9
|
+
spec.authors = ["Fred Snyder"]
|
10
|
+
spec.email = ["fsnyder@castwide.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gamefic TTY engine}
|
13
|
+
spec.description = %q{Components for running Gamefic om a terminal}
|
14
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
# else
|
26
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
# "public gem pushes."
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
# spec.bindir = "exe"
|
36
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ['lib']
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'gamefic', '~> 3.0'
|
40
|
+
spec.add_runtime_dependency 'html_to_ansi', '~> 0.2.0'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
43
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
44
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
+
spec.add_development_dependency 'simplecov', '~> 0.14'
|
46
|
+
end
|
data/lib/gamefic-tty/engine.rb
CHANGED
@@ -1,29 +1,46 @@
|
|
1
1
|
module Gamefic
|
2
2
|
module Tty
|
3
|
+
# A simple engine for running turn-based, single-character Gamefic plots.
|
4
|
+
#
|
3
5
|
class Engine
|
6
|
+
# @return [Plot]
|
4
7
|
attr_reader :plot
|
8
|
+
|
9
|
+
# @return [User]
|
5
10
|
attr_reader :user
|
11
|
+
|
12
|
+
# @return [Character]
|
6
13
|
attr_reader :character
|
7
14
|
|
15
|
+
# @param plot [Plot]
|
16
|
+
# @param user [User]
|
8
17
|
def initialize(plot: Gamefic::Plot.new, user: Gamefic::Tty::User.new)
|
9
18
|
@plot = plot
|
10
19
|
@user = user
|
11
|
-
@character = @plot.
|
12
|
-
@plot.introduce @character
|
20
|
+
@character = @plot.introduce
|
13
21
|
@plot.ready
|
14
22
|
end
|
15
23
|
|
24
|
+
# Run the plot to its conclusion.
|
25
|
+
#
|
16
26
|
def run
|
17
|
-
turn until @
|
27
|
+
turn until @plot.concluding?
|
18
28
|
@user.update @character.output
|
19
29
|
end
|
20
30
|
|
21
|
-
|
22
|
-
|
31
|
+
# Create an engine and run the plot.
|
32
|
+
#
|
33
|
+
# @param plot [Plot]
|
34
|
+
# @param user [User]
|
35
|
+
# @return [Engine]
|
36
|
+
def self.run(plot: Gamefic::Plot.new, user: Gamefic::Tty::User.new)
|
37
|
+
engine = new(plot: plot, user: user)
|
23
38
|
engine.run
|
24
39
|
engine
|
25
40
|
end
|
26
41
|
|
42
|
+
# Run a single turn.
|
43
|
+
#
|
27
44
|
def turn
|
28
45
|
send_and_receive
|
29
46
|
@plot.update
|
@@ -34,14 +51,9 @@ module Gamefic
|
|
34
51
|
|
35
52
|
def send_and_receive
|
36
53
|
@user.update @character.output
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@user.update @character.output
|
41
|
-
end
|
42
|
-
return if @character.concluded?
|
43
|
-
input = @user.query("#{@character.output[:prompt]} ")
|
44
|
-
@character.queue.push input unless input.nil?
|
54
|
+
return unless @character.queue.empty?
|
55
|
+
|
56
|
+
@character.queue.push @user.query("#{@character.output[:prompt]} ")
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
data/lib/gamefic-tty/user.rb
CHANGED
@@ -3,8 +3,13 @@ require 'html_to_ansi'
|
|
3
3
|
|
4
4
|
module Gamefic
|
5
5
|
module Tty
|
6
|
+
# An interface for passing IO between an engine and a client.
|
7
|
+
#
|
6
8
|
class User
|
9
|
+
# @return [IO]
|
7
10
|
attr_reader :input
|
11
|
+
|
12
|
+
# @return [IO]
|
8
13
|
attr_reader :output
|
9
14
|
|
10
15
|
# @param input [IO] The stream that receives input
|
data/lib/gamefic-tty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamefic-tty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gamefic
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: html_to_ansi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/workflows/rspec.yml"
|
104
105
|
- ".gitignore"
|
105
106
|
- ".rspec"
|
106
107
|
- ".travis.yml"
|
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
136
|
- !ruby/object:Gem::Version
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.3.7
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Gamefic TTY engine
|