Skip to content

Commit

Permalink
Merge pull request #110 from nskins/scaffold
Browse files Browse the repository at this point in the history
Generate minimal scaffolding (Resolves #109)
  • Loading branch information
nskins authored Aug 19, 2017
2 parents e21e54f + ff411c9 commit 4bcf2a2
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exe/goby
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require 'goby'
Goby::Scaffold::simple "goby-project"
2 changes: 1 addition & 1 deletion goby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/nskins/goby"
spec.license = "MIT"

spec.files = Dir["{lib}/**/*", "LICENSE", "README.md" ]
spec.files = Dir["{exe}/**/*", "{lib}/**/*", "{res}/**/*", "LICENSE", "README.md" ]
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Expand Down
1 change: 1 addition & 0 deletions lib/goby.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Import order matters.

require 'goby/scaffold'
require 'goby/extension'
require 'goby/util'
require 'goby/world_command'
Expand Down
36 changes: 36 additions & 0 deletions lib/goby/scaffold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Goby

# Functions for scaffolding starter projects.
module Scaffold

# Simple starter project w/o testing.
#
# @param [String] project the project name.
def self.simple(project)

# TODO: detect existence of project folder.

# Make the directory structure.
Dir.mkdir project
dirs = [ '', 'battle', 'entity',
'event', 'item', 'map' ]
dirs.each do |dir|
Dir.mkdir "#{project}/src/#{dir}"
end

# Create the source files.
gem_location = %x[gem which goby].chomp "/lib/goby.rb\n"
files = { '.gitignore': '../gitignore',
'src/main.rb': 'main.rb',
'src/map/farm.rb': 'farm.rb' }
files.each do |dest, source|
File.open("#{project}/#{dest.to_s}", 'w') do |w|
w.write(File.read "#{gem_location}/res/scaffold/simple/#{source}")
end
end

end

end

end
50 changes: 50 additions & 0 deletions res/scaffold/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Used by dotenv library to load environment variables.
# .env

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
15 changes: 15 additions & 0 deletions res/scaffold/simple/farm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is an example of how to create a Map. You can
# define the name, where to respawn, and the 2D display of
# the Map - each point is referred to as a Tile.
class Farm < Map
def initialize
super(name: "Farm", regen_location: Couple.new(2,2))

# Define the main tiles on this map.
grass = Tile.new(description: "You are standing on some grass.")

# Fill the map with "grass."
@tiles = Array.new(5) { Array.new(5) { grass.clone } }

end
end
37 changes: 37 additions & 0 deletions res/scaffold/simple/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'goby'

include Goby

require_relative 'map/farm.rb'

# Set this to true in order to use BGM.
Music::set_playback(false)

# By default, we've included no music files.
# The Music module also includes a function
# to change the music-playing program.

# Clear the terminal.
system("clear")

# Allow the player to load an existing game.
if File.exists?("player.yaml")
print "Load the saved file?: "
input = player_input
if input.is_positive?
player = load_game("player.yaml")
describe_tile(player)
end
end

# No load? Create a new player.
if player.nil?

# Use the Player constructor to set the
# initial Map, (y,x) location, stats,
# gold, inventory, and more.
player = Player.new(map: Farm.new, location: Couple.new(2,2))

end

run_driver(player)
30 changes: 30 additions & 0 deletions spec/goby/scaffold_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'goby'
require 'fileutils'

RSpec.describe Scaffold do

context "simple" do
it "should create the appropriate directories & files" do

project = "goby-project"
Scaffold::simple project

# Ensure all of the directories exist.
expect(Dir.exists? "#{project}").to be true
[ '', 'battle', 'entity',
'event', 'item', 'map' ].each do |dir|
expect(Dir.exist? "#{project}/src/#{dir}").to be true
end

# Ensure all of the files exist.
[ '.gitignore', 'src/main.rb', 'src/map/farm.rb' ].each do |file|
expect(File.exist? "#{project}/#{file}").to be true
end

# Clean up the scaffolding.
FileUtils.remove_dir project

end
end

end

0 comments on commit 4bcf2a2

Please sign in to comment.