gamefic-sdk 3.0.1 → 3.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d90eb96a94149551b573259fd78410c1f0332b0a5ecaa9d559cc091a8962629
4
- data.tar.gz: 4547e88ec7f62bcbe08d60d6411461327d1ff9f27c50755c47135c98cb4b1806
3
+ metadata.gz: 4b98f8d00bed8b7baaadddfceade62d8974c805e425e63b174f335bb0baa1874
4
+ data.tar.gz: f9b74e8df206e6b648316a06c4a9481873af3acade70a6d15a1cec794d216fcb
5
5
  SHA512:
6
- metadata.gz: '01081048d9c32716574e9ff9d906ee03cf07259875d608ea36fb73bea310440d43760c4d12f8e33159dfc346b31a33bf5eabf50c042c06bb169204aa5f8d98c4'
7
- data.tar.gz: 6fadb23c6b9cfeeb855bfb082a932ae6abde7c722ebb194d20b3902900d8c50b679ce52e4205a04d6ac7544386e8c41baa47587d7323f9cfa9157ff43c8ea8f1
6
+ metadata.gz: 36e1db4ce3268b0e86fa3a20f30a91b339d31a092ef8f598a23ea7bfbffd0cbbca6403032cad866d1d7f5a5d04560ed5013331656890346674204e9d7842bfdb
7
+ data.tar.gz: fbcd4fe1d2f68fdd64540d725cbee8d107ed9d17817fdc6abc3bd93d3a961951f2dfcb69150b8ecbd42f14e2d30e272f188fd0b23295debb3d99c42981867368
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 3.2.0 - July 20, 2024
2
+ - Optional specs in project scaffold
3
+ - Reorganize project requirements
4
+
5
+ ## 3.1.0 - July 13, 2024
6
+ - Plot and Subplot classes in scaffold
7
+ - Scaffold requires ostruct
8
+ - Support for lib path in web project
9
+
1
10
  ## 3.0.1 - April 10, 2024
2
11
  - Updates to README in project scaffold
3
12
 
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,7 @@
1
- require 'fileutils'
1
+ require 'bundler'
2
2
  require 'erb'
3
+ require 'fileutils'
4
+ require 'ostruct'
3
5
  require 'pathname'
4
6
  require 'securerandom'
5
7
  require 'shellwords'
@@ -25,28 +27,33 @@ module Gamefic
25
27
 
26
28
  def render(file, data)
27
29
  template = File.read(file)
28
- erb = ERB.new(template)
30
+ erb = ERB.new(template, trim_mode: '-')
29
31
  erb.result(data.get_binding)
30
32
  end
31
33
 
32
34
  def custom_copy origin, destination, data
33
35
  FileUtils.mkdir_p File.dirname(destination)
34
36
  if origin.end_with?('.gf.erb')
35
- 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
36
41
  else
37
42
  FileUtils.cp_r origin, destination
38
43
  end
39
44
  end
40
45
 
41
- def build name, destination
46
+ def build name, destination, **opts
42
47
  dir = File.join(SCAFFOLDS_PATH, name)
43
48
  raise LoadError, "Scaffold `#{name}` does not exist" unless File.directory?(dir)
44
49
 
45
50
  path = Pathname.new('.').join(destination).realdirpath
46
- data = Binder.new(name: File.basename(path))
51
+ data = Binder.new(name: File.basename(path), **opts)
47
52
  files = Dir.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH).select { |entry| File.file?(entry) }
48
53
  map = {}
49
54
  files.each do |file|
55
+ next if file.include?('/spec') && !opts[:specs]
56
+
50
57
  rename = File.join(File.dirname(file), File.basename(file)).gsub('__name__', data.name)
51
58
  dst = File.join(destination, rename[dir.length..-1])
52
59
  raise "Gamefic generation would overwrite existing file #{rename}" if File.file?(dst)
@@ -54,7 +61,9 @@ module Gamefic
54
61
  map[file] = dst
55
62
  end
56
63
  map.each_pair { |src, dst| custom_copy src, dst, data }
57
- system "cd #{Shellwords.escape(destination)} && bundle install"
64
+ Bundler.with_unbundled_env do
65
+ Dir.chdir(path) { system 'bundle install' }
66
+ end
58
67
  end
59
68
  end
60
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gamefic-tty'
2
4
  require 'tmpdir'
3
5
  require 'zlib'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'listen'
2
4
 
3
5
  module Gamefic
@@ -16,7 +18,7 @@ module Gamefic
16
18
  FileUtils.mkdir_p web_path
17
19
  Dir.chdir web_path do
18
20
  name = File.basename(absolute_path)
19
- system 'npx', 'react-gamefic', '--name', name, '--class', 'GAMEFIC_PLOT_CLASS'
21
+ system 'npx', 'react-gamefic', '--name', name, '--class', 'GAMEFIC_PLOT_CLASS', '--path', '../lib'
20
22
  puts 'The web app is ready.'
21
23
  puts 'Run `rake web:run` to start the app in dev mode.'
22
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gamefic
4
4
  module Sdk
5
- VERSION = '3.0.1'
5
+ VERSION = '3.2.0'
6
6
  end
7
7
  end
@@ -1,2 +1,4 @@
1
- builds
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
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gamefic'
4
- require 'gamefic-standard'
3
+ lib = File.expand_path('./lib', File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require_relative '<%= name %>/plot'
7
- require_relative '<%= name %>/subplot'
6
+ require '<%= name %>'
8
7
 
9
8
  # The Gamefic SDK uses this constant to select the main Plot for game engines.
10
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.0.1
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-04-10 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/__name__/plot.rb.gf.erb
249
- - scaffolds/project/__name__/subplot.rb.gf.erb
248
+ - scaffolds/project/Rakefile.gf.erb
249
+ - scaffolds/project/lib/__name__.rb.gf.erb
250
+ - scaffolds/project/lib/__name__/plot.rb.gf.erb
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