gamefic 1.1.0 → 1.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
  SHA1:
3
- metadata.gz: b365a88c85293650a4450cb905443a222aa1fa23
4
- data.tar.gz: 2e299521b31b1c357651c52b7d2978c69988f306
3
+ metadata.gz: 6840c99f360ddbe9171237724e2462369b6e9436
4
+ data.tar.gz: dae8127b46901506eaf847fbb1c56db6591d69af
5
5
  SHA512:
6
- metadata.gz: 5839d40d6211f3327e7f0d79667e591456e44a72da1f622f87af99127dcc97a207b6cefe06f6beb5edb75e135d85b1517a8731504b032fa706062f86d4c69e0b
7
- data.tar.gz: 6ad1537348f09477915daab0a77b1709cea1380145323ab4d803565898f9ab693bd0fd065dd33eef57d94d09d104355d64e7119978e2f57fba359c58a599fde5
6
+ metadata.gz: 7276ad50d8871721e1999184e3e37ae6fafd8523a816d35708a2c0ac3766c1453cbe3449a73c2205481266cf2200c14309f53accc8ad15573ae1db4cdfc85f33
7
+ data.tar.gz: d5ce49c27cff38d30024bd418b2b979e20b3acd78f2c14e2b16ff82662086084965fa767a4d8bbe6e6b6bc4ff88cb48952cdb7f5bf349d64577a922005d9bd3e
data/bin/gamefic CHANGED
@@ -3,8 +3,7 @@
3
3
  require 'gamefic'
4
4
  require 'gamefic/shell'
5
5
 
6
- shell = Gamefic::Shell.new
6
+ # Make play the default command if the first argument is an existing file
7
+ args = %w(play help).include?(ARGV[0]) || ARGV.count.zero? || !File.exist?(ARGV[0]) ? ARGV : ARGV.dup.unshift('play')
7
8
 
8
- shell.register "play", Gamefic::Shell::Command::Play
9
-
10
- shell.execute
9
+ Gamefic::Shell.start(args)
data/lib/gamefic/shell.rb CHANGED
@@ -1,25 +1,75 @@
1
+ require 'thor'
2
+ require 'gamefic/engine/tty'
3
+ require 'zip'
4
+ require 'tmpdir'
5
+ require 'yaml'
6
+
1
7
  module Gamefic
8
+ class Shell < Thor
9
+ map %w[--version -v] => :version
2
10
 
3
- class Shell
4
- autoload :Command, 'gamefic/shell/command'
11
+ desc "--version, -v", "Print the version"
12
+ def version
13
+ puts "gamefic #{Gamefic::VERSION}"
14
+ end
5
15
 
6
- def initialize
7
- @commands = {}
16
+ desc 'play FILE_NAME', 'Execute a compiled (.gfic) game'
17
+ option :verbose, type: :boolean, aliases: :v, desc: "Don't suppress Ruby exceptions"
18
+ def play(file)
19
+ Dir.mktmpdir 'gamefic_' do |dir|
20
+ puts 'Loading...'
21
+ decompress file, dir
22
+ run_game(dir)
23
+ end
24
+ rescue StandardError => e
25
+ puts "'#{file}' does not appear to be a valid Gamefic file."
26
+ show_exception(e) if options[:verbose]
27
+ end
28
+
29
+ desc 'info FILE_NAME', 'Print information about a (.gfic) game'
30
+ option :verbose, type: :boolean, aliases: :v, desc: "Don't suppress Ruby exceptions"
31
+ def info(file)
32
+ Dir.mktmpdir 'gamefic_' do |dir|
33
+ decompress file, dir
34
+ metadata = YAML.load_file File.join(dir, 'metadata.yaml')
35
+ metadata.each { |k, v|
36
+ puts "#{k}: #{v}"
37
+ }
38
+ end
39
+ rescue StandardError, Zip::Error => e
40
+ puts "'#{file}' does not appear to be a valid Gamefic file."
41
+ show_exception(e) if options[:verbose]
8
42
  end
9
43
 
10
- def register cmd, cls
11
- @commands[cmd] = cls
44
+ # Custom error message for invalid command or filename
45
+ def method_missing(symbol, *args)
46
+ raise UndefinedCommandError, "Could not find command or file named \"#{symbol}\"."
12
47
  end
13
48
 
14
- def execute
15
- command = ARGV[0]
16
- cls = @commands[command]
17
- if cls.nil?
18
- Gamefic::Shell::Command::Play.new.run(['play'] + ARGV)
19
- else
20
- cls.new.run ARGV
49
+ private
50
+
51
+ def show_exception(exception)
52
+ puts exception.inspect
53
+ puts exception.backtrace.join("\n")
54
+ end
55
+
56
+ def decompress(zipfile, destination)
57
+ Zip::File.open(zipfile) do |z|
58
+ z.each do |entry|
59
+ FileUtils.mkdir_p File.join(destination, File.dirname(entry.name))
60
+ full_path = File.join(destination, entry.name)
61
+ entry.extract full_path unless File.exist?(full_path)
62
+ end
21
63
  end
22
64
  end
65
+
66
+ def run_game(directory)
67
+ story = Plot.new(Source::File.new(File.join(directory, 'scripts')))
68
+ story.script 'main'
69
+ story.metadata = YAML.load_file File.join(directory, 'metadata.yaml')
70
+ engine = Tty::Engine.new story
71
+ puts "\n"
72
+ engine.run
73
+ end
23
74
  end
24
-
25
75
  end
@@ -1,3 +1,3 @@
1
1
  module Gamefic
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/gamefic.rb CHANGED
@@ -15,4 +15,5 @@ require "gamefic/director"
15
15
  require "gamefic/plot"
16
16
  require "gamefic/engine"
17
17
  require "gamefic/direction"
18
- require "gamefic/version"
18
+
19
+ require 'gamefic/version'
metadata CHANGED
@@ -1,57 +1,129 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: slop
14
+ name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '0.19'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.19.4
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.19'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '4.0'
32
+ version: 0.19.4
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rubyzip
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '>='
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 1.2.0
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - '>='
47
+ - - "~>"
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: '1.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.2.0
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: rspec
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - '>='
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.5'
60
+ - - ">="
46
61
  - !ruby/object:Gem::Version
47
- version: '0'
62
+ version: 3.5.0
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - '>='
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.5'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.5.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: rake
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '11.3'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 11.3.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '11.3'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 11.3.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: poltergeist
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.11'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.11'
107
+ - !ruby/object:Gem::Dependency
108
+ name: codeclimate-test-reporter
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.0'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 1.0.0
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.0'
124
+ - - ">="
53
125
  - !ruby/object:Gem::Version
54
- version: '0'
126
+ version: 1.0.0
55
127
  description: An adventure game and interactive fiction framework
56
128
  email: fsnyder@gamefic.com
57
129
  executables:
@@ -129,10 +201,6 @@ files:
129
201
  - lib/gamefic/script/text.rb
130
202
  - lib/gamefic/serialized.rb
131
203
  - lib/gamefic/shell.rb
132
- - lib/gamefic/shell/command.rb
133
- - lib/gamefic/shell/command/base.rb
134
- - lib/gamefic/shell/command/play.rb
135
- - lib/gamefic/shell/registry.rb
136
204
  - lib/gamefic/source.rb
137
205
  - lib/gamefic/source/base.rb
138
206
  - lib/gamefic/source/file.rb
@@ -152,19 +220,18 @@ require_paths:
152
220
  - lib
153
221
  required_ruby_version: !ruby/object:Gem::Requirement
154
222
  requirements:
155
- - - '>='
223
+ - - ">="
156
224
  - !ruby/object:Gem::Version
157
- version: 2.0.0
225
+ version: 2.1.0
158
226
  required_rubygems_version: !ruby/object:Gem::Requirement
159
227
  requirements:
160
- - - '>='
228
+ - - ">="
161
229
  - !ruby/object:Gem::Version
162
230
  version: '0'
163
231
  requirements: []
164
232
  rubyforge_project:
165
- rubygems_version: 2.6.8
233
+ rubygems_version: 2.5.1
166
234
  signing_key:
167
235
  specification_version: 4
168
236
  summary: Gamefic
169
237
  test_files: []
170
- has_rdoc:
@@ -1,38 +0,0 @@
1
- require 'gamefic/shell'
2
- require 'slop'
3
-
4
- class Gamefic::Shell::Command::Base
5
- # Execute the command
6
- #
7
- def run input
8
- raise "Unimplemented command"
9
- end
10
-
11
- # Get the options for the command
12
- #
13
- # @return [Slop::Options]
14
- def options
15
- @options ||= Slop::Options.new
16
- end
17
-
18
- # Get the help documentation for this command.
19
- #
20
- # @return [String]
21
- def help
22
- optons.to_s
23
- end
24
-
25
- protected
26
-
27
- # @return [Slope::Result]
28
- def parse input
29
- parser.parse input
30
- end
31
-
32
- private
33
-
34
- # @return [Slop::Parser]
35
- def parser
36
- @parser ||= Slop::Parser.new(options)
37
- end
38
- end
@@ -1,51 +0,0 @@
1
- require 'zip'
2
- require 'tmpdir'
3
- require 'gamefic/engine/tty'
4
- require 'gamefic/shell'
5
- require 'yaml'
6
-
7
- class Gamefic::Shell::Command::Play < Gamefic::Shell::Command::Base
8
- include Gamefic
9
-
10
- def run input
11
- result = parse input
12
- file = result.arguments[1]
13
- raise "File not specified." if file.nil?
14
- raise "'#{file}' does not exist." if !File.exist?(file)
15
- raise "'#{file}' is a directory." if File.directory?(file)
16
- play file
17
- end
18
-
19
- private
20
-
21
- def decompress(zipfile, destination)
22
- Zip::File.open(zipfile) do |z|
23
- z.each do |entry|
24
- FileUtils.mkdir_p File.join(destination, File.dirname(entry.name))
25
- full_path = File.join(destination, entry.name)
26
- if !File.exist?(full_path)
27
- entry.extract full_path
28
- end
29
- end
30
- end
31
- end
32
-
33
- def play file
34
- Dir.mktmpdir 'gamefic_' do |dir|
35
- puts "Loading..."
36
- story = Plot.new(Source::File.new(File.join(dir, 'scripts')))
37
- begin
38
- decompress file, dir
39
- rescue Exception => e
40
- puts "'#{file}' does not appear to be a valid Gamefic file."
41
- #puts "Error: #{e.message}"
42
- #exit 1
43
- end
44
- story.script 'main'
45
- story.metadata = YAML.load_file File.join(dir, 'metadata.yaml')
46
- engine = Tty::Engine.new story
47
- puts "\n"
48
- engine.run
49
- end
50
- end
51
- end
@@ -1,4 +0,0 @@
1
- module Gamefic::Shell::Command
2
- autoload :Base, 'gamefic/shell/command/base'
3
- autoload :Play, 'gamefic/shell/command/play'
4
- end
@@ -1,13 +0,0 @@
1
- module Gamefic
2
- class Shell
3
- module Registry
4
- @commands = {}
5
- def self.register cmd, cls
6
- @commands[cmd] = cls
7
- end
8
- def self.get_command_class cmd
9
- @commands[cmd]
10
- end
11
- end
12
- end
13
- end