-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from nskins/scaffold
Generate minimal scaffolding (Resolves #109)
- Loading branch information
Showing
8 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |