gamefic-sdk 3.1.0 → 3.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: a1a52e09b3e29c8c869f67561d732d54493043a4ee04e75a49eade71d4396ddf
4
- data.tar.gz: 8085b05a412924f4c4783bdcc09d9a6f9e97ef5aadc719257ed9a34b0a77e5a0
3
+ metadata.gz: 4b98f8d00bed8b7baaadddfceade62d8974c805e425e63b174f335bb0baa1874
4
+ data.tar.gz: f9b74e8df206e6b648316a06c4a9481873af3acade70a6d15a1cec794d216fcb
5
5
  SHA512:
6
- metadata.gz: 4b0f9ac162876dd92ed56ae979d9f4fcaa16ae49e0aa1550be1f5c61a82ba486190c22cff45b1617eb1e275af4141cef4393a6c352dd26e2e356f51ab06a33c8
7
- data.tar.gz: d263b78b4dca96bb0994bc8a9b3ff1d9734ac84380e312e3987f3ac7747f9374660c64ccda2c642a72e8c86dd33bb08d9e3557b9f29d2485984809bd403a70f7
6
+ metadata.gz: 36e1db4ce3268b0e86fa3a20f30a91b339d31a092ef8f598a23ea7bfbffd0cbbca6403032cad866d1d7f5a5d04560ed5013331656890346674204e9d7842bfdb
7
+ data.tar.gz: fbcd4fe1d2f68fdd64540d725cbee8d107ed9d17817fdc6abc3bd93d3a961951f2dfcb69150b8ecbd42f14e2d30e272f188fd0b23295debb3d99c42981867368
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.2.0 - July 20, 2024
2
+ - Optional specs in project scaffold
3
+ - Reorganize project requirements
4
+
1
5
  ## 3.1.0 - July 13, 2024
2
6
  - Plot and Subplot classes in scaffold
3
7
  - Scaffold requires ostruct
data/gamefic-sdk.gemspec CHANGED
@@ -1,42 +1,46 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'gamefic-sdk/version'
4
4
  require 'date'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = 'gamefic-sdk'
8
- s.version = Gamefic::Sdk::VERSION
9
- s.date = Date.today.strftime("%Y-%m-%d")
10
- s.summary = "Gamefic SDK"
11
- s.description = "Development and command-line tools for Gamefic"
12
- s.authors = ["Fred Snyder"]
13
- s.email = 'fsnyder@gamefic.com'
14
- s.homepage = 'http://gamefic.com'
15
- s.license = 'MIT'
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gamefic-sdk'
8
+ spec.version = Gamefic::Sdk::VERSION
9
+ spec.date = Date.today.strftime('%Y-%m-%d')
10
+ spec.summary = 'Gamefic SDK'
11
+ spec.description = 'Development and command-line tools for Gamefic'
12
+ spec.authors = ['Fred Snyder']
13
+ spec.email = 'fsnyder@gamefic.com'
14
+ spec.homepage = 'https://gamefic.com'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['homepage_uri'] = 'https://gamefic.com'
18
+ spec.metadata['source_code_uri'] = 'https://github.com/castwide/gamefic-sdk'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/castwide/gamefic-sdk/blob/master/CHANGELOG.md'
16
20
 
17
21
  # Specify which files should be added to the gem when it is released.
18
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|examples|guides)/}) }
21
25
  end
22
- s.executables = ['gamefic']
23
- s.require_paths = ['lib']
26
+ spec.executables = ['gamefic']
27
+ spec.require_paths = ['lib']
24
28
 
25
- s.required_ruby_version = '>= 2.7.0'
29
+ spec.required_ruby_version = '>= 2.7.0'
26
30
 
27
- s.add_runtime_dependency 'gamefic', '~> 3.0'
28
- s.add_runtime_dependency 'gamefic-standard', '~> 3.0'
29
- s.add_runtime_dependency 'gamefic-tty', '~> 3.0'
30
- s.add_runtime_dependency 'listen', '~> 3.0'
31
- s.add_runtime_dependency 'opal', '~> 1.1'
32
- s.add_runtime_dependency 'puma', '~> 6'
33
- s.add_runtime_dependency 'sinatra', '~> 2'
34
- s.add_runtime_dependency 'thor', '~> 1.0'
31
+ spec.add_runtime_dependency 'gamefic', '~> 3.0'
32
+ spec.add_runtime_dependency 'gamefic-standard', '~> 3.0'
33
+ spec.add_runtime_dependency 'gamefic-tty', '~> 3.0'
34
+ spec.add_runtime_dependency 'listen', '~> 3.0'
35
+ spec.add_runtime_dependency 'opal', '~> 1.1'
36
+ spec.add_runtime_dependency 'puma', '~> 6'
37
+ spec.add_runtime_dependency 'sinatra', '~> 2'
38
+ spec.add_runtime_dependency 'thor', '~> 1.0'
35
39
 
36
- s.add_development_dependency 'bundler', '~> 2.0'
37
- s.add_development_dependency 'capybara', '~> 3.3'
38
- s.add_development_dependency 'rake', '~> 13.0'
39
- s.add_development_dependency 'rspec', '~> 3.0'
40
- s.add_development_dependency 'selenium-webdriver', '~> 4.2'
41
- s.add_development_dependency 'simplecov', '~> 0.14'
40
+ spec.add_development_dependency 'bundler', '~> 2.0'
41
+ spec.add_development_dependency 'capybara', '~> 3.3'
42
+ spec.add_development_dependency 'rake', '~> 13.0'
43
+ spec.add_development_dependency 'rspec', '~> 3.0'
44
+ spec.add_development_dependency 'selenium-webdriver', '~> 4.2'
45
+ spec.add_development_dependency 'simplecov', '~> 0.14'
42
46
  end
@@ -1,5 +1,6 @@
1
- require 'fileutils'
1
+ require 'bundler'
2
2
  require 'erb'
3
+ require 'fileutils'
3
4
  require 'ostruct'
4
5
  require 'pathname'
5
6
  require 'securerandom'
@@ -26,28 +27,33 @@ module Gamefic
26
27
 
27
28
  def render(file, data)
28
29
  template = File.read(file)
29
- erb = ERB.new(template)
30
+ erb = ERB.new(template, trim_mode: '-')
30
31
  erb.result(data.get_binding)
31
32
  end
32
33
 
33
34
  def custom_copy origin, destination, data
34
35
  FileUtils.mkdir_p File.dirname(destination)
35
36
  if origin.end_with?('.gf.erb')
36
- File.write destination[0..-8], render(origin, data)
37
+ content = render(origin, data)
38
+ return if content.empty?
39
+
40
+ File.write destination[0..-8], content
37
41
  else
38
42
  FileUtils.cp_r origin, destination
39
43
  end
40
44
  end
41
45
 
42
- def build name, destination
46
+ def build name, destination, **opts
43
47
  dir = File.join(SCAFFOLDS_PATH, name)
44
48
  raise LoadError, "Scaffold `#{name}` does not exist" unless File.directory?(dir)
45
49
 
46
50
  path = Pathname.new('.').join(destination).realdirpath
47
- data = Binder.new(name: File.basename(path))
51
+ data = Binder.new(name: File.basename(path), **opts)
48
52
  files = Dir.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH).select { |entry| File.file?(entry) }
49
53
  map = {}
50
54
  files.each do |file|
55
+ next if file.include?('/spec') && !opts[:specs]
56
+
51
57
  rename = File.join(File.dirname(file), File.basename(file)).gsub('__name__', data.name)
52
58
  dst = File.join(destination, rename[dir.length..-1])
53
59
  raise "Gamefic generation would overwrite existing file #{rename}" if File.file?(dst)
@@ -55,7 +61,9 @@ module Gamefic
55
61
  map[file] = dst
56
62
  end
57
63
  map.each_pair { |src, dst| custom_copy src, dst, data }
58
- system "cd #{Shellwords.escape(destination)} && bundle install"
64
+ Bundler.with_unbundled_env do
65
+ Dir.chdir(path) { system 'bundle install' }
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -14,9 +14,10 @@ module Gamefic
14
14
 
15
15
  desc 'init DIRECTORY_NAME', 'Create a new project in DIRECTORY_NAME'
16
16
  option :gem, type: :boolean, aliases: [:g, :library, :rubygem], desc: 'Make a gem project'
17
+ option :specs, type: :boolean, desc: 'Add RSpec and Opal::RSpec test suites', default: true
17
18
  def init(directory_name)
18
19
  scaffold = options[:gem] ? 'library' : 'project'
19
- Gamefic::Sdk::Scaffold.build scaffold, directory_name
20
+ Gamefic::Sdk::Scaffold.build scaffold, directory_name, specs: options[:specs]
20
21
  puts "Gamefic project initialized at #{File.realpath(directory_name)}"
21
22
  end
22
23
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gamefic
4
4
  module Sdk
5
- VERSION = '3.1.0'
5
+ VERSION = '3.2.0'
6
6
  end
7
7
  end
@@ -1,2 +1,4 @@
1
- build
2
- node_modules
1
+ /coverage
2
+ /ruby/build
3
+ /web/build
4
+ /web/node_modules
@@ -0,0 +1,4 @@
1
+ <% if specs %>
2
+ --color
3
+ --require spec_helper
4
+ <% end %>
@@ -8,5 +8,13 @@ gem 'gamefic-standard'
8
8
  group :development do
9
9
  gem 'gamefic-sdk'
10
10
  gem 'gamefic-tty'
11
+ <% if specs -%>
12
+ gem 'opal-rspec'
13
+ gem 'opal-sprockets'
14
+ <% end -%>
11
15
  gem 'rake'
16
+ <% if specs -%>
17
+ gem 'rspec'
18
+ gem 'simplecov'
19
+ <% end -%>
12
20
  end
@@ -39,6 +39,18 @@ Open http://localhost:9000 in a browser.
39
39
 
40
40
  The application will be saved in the `web/build` directory.
41
41
 
42
+ ## Unit Tests
43
+
44
+ To run the test suite with Ruby:
45
+
46
+ $ rspec
47
+
48
+ To run the test suite with Opal:
49
+
50
+ $ rake opal
51
+
52
+ The Opal tests can be useful for finding bugs in the web build that do not occur in standard Ruby.
53
+
42
54
  ## More Information
43
55
 
44
56
  Go to https://gamefic.com for documentation.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'bundler/setup'
5
+ require 'gamefic-sdk'
6
+ require 'opal/rspec/rake_task'
7
+
8
+ # Add the default Gamefic tasks for building and running games
9
+ # Run `rake --tasks` for a list of commands and descriptions
10
+ Gamefic::Sdk::Tasks.define_all
11
+ <% if specs %>
12
+ Opal::RSpec::RakeTask.new(:opal) do |_, config|
13
+ Bundler.definition
14
+ .dependencies_for([:default])
15
+ .each { |dep| Opal.use_gem dep.name }
16
+ Opal.append_path __dir__
17
+ Opal.append_path File.join(__dir__, 'lib')
18
+ config.pattern = 'spec/**/*_spec.rb'
19
+ config.requires = ['spec/opal_helper']
20
+ end
21
+ <% end %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic'
4
+ require 'gamefic-standard'
5
+
6
+ module <%= camelcase(name) %>
7
+ require '<%= name %>/plot'
8
+ require '<%= name %>/subplot'
9
+ end
@@ -3,11 +3,7 @@
3
3
  lib = File.expand_path('./lib', File.dirname(__FILE__))
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require 'gamefic'
7
- require 'gamefic-standard'
8
-
9
- require '<%= name %>/plot'
10
- require '<%= name %>/subplot'
6
+ require '<%= name %>'
11
7
 
12
8
  # The Gamefic SDK uses this constant to select the main Plot for game engines.
13
9
  GAMEFIC_PLOT_CLASS = <%= camelcase(name) %>::Plot
@@ -0,0 +1,24 @@
1
+ RSpec.describe <%= camelcase(name) %>::Plot do
2
+ let(:plot) { <%= camelcase(name) %>::Plot.new }
3
+
4
+ it 'gives all entities a description' do
5
+ undescribed = plot.entities
6
+ .reject(&:has_description?)
7
+
8
+ expect(undescribed).to be_empty
9
+ end
10
+
11
+ it 'uniquely identifies entities by name' do
12
+ actor = plot.introduce
13
+
14
+ plot.entities.that_are(Openable).each { |entity| entity.open = true }
15
+
16
+ plot.entities.that_are(Room).each do |room|
17
+ actor.parent = room
18
+ plot.available.select(actor).each do |entity|
19
+ result = plot.available(ambiguous: true).query(actor, entity.name)
20
+ expect(result.match).to eq([entity])
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ RSpec.describe <%= camelcase(name) %>::Subplot do
2
+ let(:plot) { <%= camelcase(name) %>::Plot.new }
3
+
4
+ it 'branches from plots' do
5
+ actor = plot.introduce
6
+ subplot = plot.branch(<%= camelcase(name) %>::Subplot, introduce: actor)
7
+ expect(plot.subplots).to eq([subplot])
8
+ expect(subplot.players).to eq([actor])
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.describe 'gameplay' do
2
+ let(:plot) { GAMEFIC_PLOT_CLASS.new }
3
+
4
+ let(:commands) do
5
+ # Customize this array of commands to reach a conclusion
6
+ [
7
+ 'look around'
8
+ ]
9
+ end
10
+
11
+ it 'reaches a conclusion' do
12
+ player = plot.introduce
13
+ player.queue.concat commands
14
+ plot.ready
15
+ until player.queue.empty?
16
+ plot.update
17
+ plot.ready
18
+ end
19
+ expect(plot).to be_concluding
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'shared_helper'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../main'
4
+
5
+ RSpec.configure do |config|
6
+ # Run specs in random order to surface order dependencies. If you find an
7
+ # order dependency and want to debug it, you can fix the order by providing
8
+ # the seed, which is printed after each run.
9
+ # --seed 1234
10
+ # config.order = :random
11
+
12
+ # Seed global randomization in this process using the `--seed` CLI option.
13
+ # Setting this allows you to use `--seed` to deterministically reproduce
14
+ # test failures related to randomization by passing the same `--seed` value
15
+ # as the one that triggered the failure.
16
+ # Kernel.srand config.seed
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require_relative 'shared_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.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: 2024-07-13 00:00:00.000000000 Z
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gamefic
@@ -242,16 +242,27 @@ files:
242
242
  - scaffolds/library/lib/__name__.rb.gf.erb
243
243
  - scaffolds/library/lib/__name__/version.rb.gf.erb
244
244
  - scaffolds/project/.gitignore
245
- - scaffolds/project/Gemfile
245
+ - scaffolds/project/.rspec.gf.erb
246
+ - scaffolds/project/Gemfile.gf.erb
246
247
  - scaffolds/project/README.md.gf.erb
247
- - scaffolds/project/Rakefile
248
+ - scaffolds/project/Rakefile.gf.erb
249
+ - scaffolds/project/lib/__name__.rb.gf.erb
248
250
  - scaffolds/project/lib/__name__/plot.rb.gf.erb
249
251
  - scaffolds/project/lib/__name__/subplot.rb.gf.erb
250
252
  - scaffolds/project/main.rb.gf.erb
251
- homepage: http://gamefic.com
253
+ - scaffolds/project/spec/__name__/plot_spec.rb.gf.erb
254
+ - scaffolds/project/spec/__name__/subplot_spec.rb.gf.erb
255
+ - scaffolds/project/spec/gameplay_spec.rb
256
+ - scaffolds/project/spec/opal_helper.rb
257
+ - scaffolds/project/spec/shared_helper.rb
258
+ - scaffolds/project/spec/spec_helper.rb
259
+ homepage: https://gamefic.com
252
260
  licenses:
253
261
  - MIT
254
- metadata: {}
262
+ metadata:
263
+ homepage_uri: https://gamefic.com
264
+ source_code_uri: https://github.com/castwide/gamefic-sdk
265
+ changelog_uri: https://github.com/castwide/gamefic-sdk/blob/master/CHANGELOG.md
255
266
  post_install_message:
256
267
  rdoc_options: []
257
268
  require_paths:
@@ -1,6 +0,0 @@
1
- require 'bundler/setup'
2
- require 'gamefic-sdk'
3
-
4
- # Add the default Gamefic tasks for building and running games
5
- # Run `rake --tasks` for a list of commands and descriptions
6
- Gamefic::Sdk::Tasks.define_all