gamefic-tty 2.0.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.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gamefic-tty.gemspec +46 -0
- data/lib/gamefic-tty.rb +5 -0
- data/lib/gamefic-tty/engine.rb +43 -0
- data/lib/gamefic-tty/text.rb +8 -0
- data/lib/gamefic-tty/user.rb +61 -0
- data/lib/gamefic-tty/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e51cc73835e18a0910192ab0bcbf4e63ba0430018d7cfa73038acd7d1ab379c8
|
4
|
+
data.tar.gz: f85f4950731e1b5f04df53c4d566d0b8c88d6ed173e13b74adb36262c747913e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b79e9be2c5060ee9c6300f8c4fb41be29bc92f3753472885d76a39cb425a6305734ff8c6054b2c62bf0299065fa9c7ab7dbc49b5868fb4d922c7ff5e144399d
|
7
|
+
data.tar.gz: cb0cb202fcc7598ef0af0ddd2fe10485dd8178d5701ff4908745240f54318e9c9cd8e76310d24de4ba99bfd0df534d3360061e704917b67f946b48e55ffa9a56
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Fred Snyder
|
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.
|
data/README.md
ADDED
@@ -0,0 +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.script do
|
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).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gamefic/tty"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gamefic-tty.gemspec
ADDED
@@ -0,0 +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 = ["lib"]
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'gamefic', '~> 2.0'
|
40
|
+
spec.add_runtime_dependency 'html_to_ansi', '~> 0.1.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.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Gamefic
|
2
|
+
module Tty
|
3
|
+
class Engine
|
4
|
+
attr_reader :plot
|
5
|
+
attr_reader :user
|
6
|
+
attr_reader :character
|
7
|
+
|
8
|
+
def initialize(plot: Gamefic::Plot.new, user: Gamefic::Tty::User.new)
|
9
|
+
@plot = plot
|
10
|
+
@user = user
|
11
|
+
@character = @plot.get_player_character
|
12
|
+
@plot.introduce @character
|
13
|
+
@plot.ready
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
turn until @character.concluded?
|
18
|
+
@user.update @character.output
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run **args
|
22
|
+
engine = new(**args)
|
23
|
+
engine.run
|
24
|
+
engine
|
25
|
+
end
|
26
|
+
|
27
|
+
def turn
|
28
|
+
send_and_receive
|
29
|
+
@plot.update
|
30
|
+
@plot.ready
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def send_and_receive
|
36
|
+
@user.update @character.state
|
37
|
+
return if @character.concluded?
|
38
|
+
input = @user.query("#{@character.state[:prompt]} ")
|
39
|
+
@character.queue.push input unless input.nil?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'html_to_ansi'
|
3
|
+
|
4
|
+
module Gamefic
|
5
|
+
module Tty
|
6
|
+
class User
|
7
|
+
attr_reader :input
|
8
|
+
attr_reader :output
|
9
|
+
|
10
|
+
# @param input [IO] The stream that receives input
|
11
|
+
# @param output [IO] The stream that sends output
|
12
|
+
def initialize input: STDIN, output: STDOUT
|
13
|
+
@input = input
|
14
|
+
@output = output
|
15
|
+
end
|
16
|
+
|
17
|
+
# Update the user with a hash of data representing the current game state.
|
18
|
+
#
|
19
|
+
# @param data [Hash]
|
20
|
+
# @return [void]
|
21
|
+
def update state
|
22
|
+
@output.write state_to_text(state)
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_to_text state
|
26
|
+
output = state[:messages].to_s
|
27
|
+
unless state[:options].nil?
|
28
|
+
list = '<ol class="multiple_choice">'
|
29
|
+
state[:options].each { |o|
|
30
|
+
list += "<li><a href=\"#\" rel=\"gamefic\" data-command=\"#{o}\">#{o}</a></li>"
|
31
|
+
}
|
32
|
+
list += "</ol>"
|
33
|
+
output += list
|
34
|
+
end
|
35
|
+
HtmlToAnsi.convert output
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get input from the user.
|
39
|
+
#
|
40
|
+
# @return [String, nil]
|
41
|
+
def query prompt = '> '
|
42
|
+
@output.print prompt
|
43
|
+
@input.gets
|
44
|
+
end
|
45
|
+
|
46
|
+
# @todo Save and restore aren't ready yet
|
47
|
+
|
48
|
+
# def save filename, snapshot
|
49
|
+
# File.open(filename, 'w') do |file|
|
50
|
+
# file << snapshot.to_json
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
# def restore filename
|
55
|
+
# json = File.read(filename)
|
56
|
+
# snapshot = JSON.parse(json, symbolize_names: true)
|
57
|
+
# engine.restore snapshot
|
58
|
+
# end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gamefic-tty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fred Snyder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gamefic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: html_to_ansi
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.14'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.14'
|
97
|
+
description: Components for running Gamefic om a terminal
|
98
|
+
email:
|
99
|
+
- fsnyder@castwide.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- gamefic-tty.gemspec
|
114
|
+
- lib/gamefic-tty.rb
|
115
|
+
- lib/gamefic-tty/engine.rb
|
116
|
+
- lib/gamefic-tty/text.rb
|
117
|
+
- lib/gamefic-tty/user.rb
|
118
|
+
- lib/gamefic-tty/version.rb
|
119
|
+
homepage:
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.0.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Gamefic TTY engine
|
142
|
+
test_files: []
|