burn 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Burn
1
+ # Burn - a handy toolkit to make .nes application from a single text file written in Ruby DSL
2
2
 
3
- Burn is a free and open source framework that allows you to create 8-bit flavored application using Ruby DSL.
3
+ Burn is a free and open source framework that allows you to create 8-bit flavored application(.nes) using Ruby DSL.
4
4
 
5
5
  ```ruby
6
6
  scene do
@@ -12,7 +12,7 @@ Just like Recipe and Cookbook are DSL for Chef rubygem, this dead simple DSL is
12
12
 
13
13
  ![Hello-world pic](http://k.swd.cc/burn/resource/screenshot/hello-world.png)
14
14
 
15
- Here is another example. With Fuel DSL, you can even compose background music in 1 minute.
15
+ Here is another example. With Fuel DSL, you can even compose background music in seconds.
16
16
 
17
17
  ```ruby
18
18
  scene do
@@ -108,9 +108,14 @@ Moreover, the executables built with burn will work at [almost any OS](http://en
108
108
  Internally, burn contains cc65 executables inside its gemfile and calls them to compile. Main workflow is as follows.
109
109
 
110
110
  - translate ruby DSL file into c source code
111
- - compile them to make executable(main.out) by calling cc65
111
+ - compile them to make executable(*.nes) by calling cc65
112
112
  - provide emulator(JSNES) for rpaid application development
113
113
 
114
+ ### Requirements
115
+
116
+ - Ruby1.9.1+
117
+ - gcc(for windows user this is not required)
118
+
114
119
  ## Getting Started
115
120
 
116
121
  ### Installation
@@ -122,13 +127,17 @@ Internally, burn contains cc65 executables inside its gemfile and calls them to
122
127
 
123
128
  echo "scene {label 'hello world'}" > main.rb
124
129
  burn -p
125
- ls tmp/burn/ | grep main.out
130
+ ls tmp/burn/ | grep main.nes
131
+
132
+ `burn -p` command use Firefox primarily. If you'd like to use chrome, type `burn -p -c` instead.
126
133
 
127
- ### Burning Another Sample Fuel DSL
134
+ ### More Example
128
135
 
129
136
  git clone https://github.com/remore/burn.git
130
- cd burn/example/hello_world
131
- burn -p
137
+ cd burn/example/shooting
138
+ burn -p -c
139
+
140
+ `vi main.rb` and customize this simple shooting game if you please.
132
141
 
133
142
  ## Fuel DSL Methods
134
143
 
@@ -491,6 +500,7 @@ TBD(articles about #show, #sprite, #rand and #is_pressed are coming very soon)
491
500
  ### Helpful Folks
492
501
 
493
502
  * Shiru - this project had never been born if I had not found [this article](http://shiru.untergrund.net/articles/programming_nes_games_in_c.htm)
503
+ * My friend from high school - I appreciate him for sending me fine-grained review as always
494
504
 
495
505
  ### License
496
506
 
data/lib/burn/cli.rb CHANGED
@@ -16,34 +16,99 @@ module Burn
16
16
  desc "init", "Initialize environment"
17
17
  option :debug, :type => :string, :aliases => '-d', :desc => "Debug mode"
18
18
  option :verbose, :type => :boolean, :desc => "Print logs as much as possible", :default => false
19
- option :make, :type=>:boolean, :desc=>"Make cc65 binaries from source"
19
+ option :quick, :type=>:boolean, :desc=>"Make cc65 binaries available without gcc(however unstable. This option is not recommended.)"
20
20
  def init
21
21
  env = Burn::Util::Os.new
22
22
  base_path = "#{File.dirname(__FILE__)}/tools"
23
23
  remove_dir base_path+ "/"+env.os_name, :verbose => options[:verbose]
24
24
  Burn::Util::Unpack.new.unpack "#{base_path}/#{env.os_name}.tar.gz", base_path
25
- if options[:make] then
25
+ if !env.is_win? && !options[:quick] then
26
26
  Burn::Util::Unpack.new.unpack "#{base_path}/src.tar.gz", base_path
27
27
  run "/bin/bash #{File.dirname(__FILE__)}/tools/make_exec.sh #{base_path}"
28
28
  copy_file "#{base_path}/src/cc65/cc65", "#{base_path}/#{env.os_name}/cc65/bin/cc65", :force => true
29
29
  copy_file "#{base_path}/src/ca65/ca65", "#{base_path}/#{env.os_name}/cc65/bin/ca65", :force => true
30
30
  copy_file "#{base_path}/src/ld65/ld65", "#{base_path}/#{env.os_name}/cc65/bin/ld65", :force => true
31
31
  end
32
+ say "successfully finished. you've got ready to burn."
32
33
  end
33
34
 
34
35
  desc "make <filename>", "Compile and build application binary from Burn DSL file"
35
- option :preview, :type => :boolean, :aliases => '-p', :desc => "Preview .out application right after compilation"
36
+ option :preview, :type => :boolean, :aliases => '-p', :desc => "Preview .nes application right after compilation"
36
37
  option :debug, :type => :string, :aliases => '-d', :desc => "Debug mode"
37
38
  option :verbose, :type => :boolean, :desc => "Print logs as much as possible", :default => false
38
39
  option :chrome, :type => :boolean, :aliases => '-c', :desc => "Run emulator on chrome instead of firefox", :default => false
39
40
  def make(mainfile=nil)
41
+ env = Burn::Util::Os.new
40
42
  mainfile="main.rb" if mainfile.nil?
41
43
 
42
44
  if !File.exist?(mainfile) then
43
45
  help
44
46
 
47
+ elsif !File.exist?("#{File.dirname(__FILE__)}/tools/#{env.os_name}/cc65/bin/ld65#{".exe" if env.is_win?}") then
48
+ say <<-EOS
49
+ [ERROR] you are not ready to burn, most probably you haven't execute burn init command yet.
50
+ to fix this, try the following command:
51
+
52
+ sudo burn init
53
+
54
+ EOS
55
+
45
56
  else
46
57
 
58
+ # init
59
+ say "running burn v#{VERSION}..."
60
+ remove_dir "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
61
+ empty_directory "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
62
+ #directory File.dirname(__FILE__) + "/workspace_default", "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
63
+ Burn::Util::Unpack.new.unpack "#{File.dirname(__FILE__)}/tools/workspace_default.tar.gz", "#{@workspace_root}/tmp/burn"
64
+
65
+ # compile and build .nes
66
+ say "."
67
+ builder = Builder.new(@workspace_root)
68
+ builder.verbose options[:verbose]
69
+ builder.load File.read("#{@workspace_root}/#{mainfile}")
70
+ builder.generate
71
+
72
+ # Prepare compilers
73
+ say ".."
74
+ directory File.dirname(__FILE__) + "/tools/#{env.os_name}", "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
75
+
76
+ # Finally compile
77
+ say "..."
78
+ redirect = ""
79
+ if env.is_win? then
80
+ command = ""
81
+ ext = "bat"
82
+ redirect = " > nul" if !options[:verbose]
83
+
84
+ else
85
+ command = "/bin/bash "
86
+ ext = "sh"
87
+ redirect = " > /dev/null" if !options[:verbose]
88
+
89
+ # Set permissions to execute compilers
90
+ Dir::glob("#{@workspace_root}/tmp/burn/cc65/bin/*65").each do |f|
91
+ File.chmod(0777, f)
92
+ end
93
+
94
+ end
95
+ run "#{command}#{@workspace_root}/tmp/burn/scripts/compile.#{ext} #{@workspace_root}/tmp/burn #{redirect}", :verbose => options[:verbose]
96
+
97
+ # prepare customized emulator
98
+ say "...."
99
+ require 'base64'
100
+ File.write(
101
+ "#{@workspace_root}/tmp/burn/release/js/emulator.html",
102
+ File.read("#{@workspace_root}/tmp/burn/release/js/emulator.html")
103
+ .gsub(/__@__TITLE__@__/, mainfile)
104
+ .gsub(/__@__ROMDATA__@__/,
105
+ Base64::strict_encode64(
106
+ File.binread("#{@workspace_root}/tmp/burn/main.nes")
107
+ )
108
+ )
109
+ )
110
+ copy_file "#{@workspace_root}/tmp/burn/main.nes", "#{@workspace_root}/tmp/burn/release/js/main.nes", :verbose => options[:verbose]
111
+
47
112
  # used a icon from noun project. Thanks Jenny!
48
113
  # http://thenounproject.com/term/fire/24187/
49
114
  say <<-EOS
@@ -98,66 +163,28 @@ module Burn
98
163
  `-/oo:
99
164
 
100
165
 
166
+
167
+
168
+ Successfully burned. Congratulations!
169
+
170
+ The executable is available at:
171
+
172
+ #{@workspace_root}/tmp/burn/main.nes
173
+
101
174
  EOS
102
- # init
103
- say "."
104
- remove_dir "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
105
- empty_directory "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
106
- #directory File.dirname(__FILE__) + "/workspace_default", "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
107
- Burn::Util::Unpack.new.unpack "#{File.dirname(__FILE__)}/tools/workspace_default.tar.gz", "#{@workspace_root}/tmp/burn"
108
-
109
- # compile and build .out
110
- say ".."
111
- builder = Builder.new(@workspace_root)
112
- builder.verbose options[:verbose]
113
- builder.load File.read("#{@workspace_root}/#{mainfile}")
114
- builder.generate
115
-
116
- # Prepare compilers
117
- say "..."
118
- env = Burn::Util::Os.new
119
- directory File.dirname(__FILE__) + "/tools/#{env.os_name}", "#{@workspace_root}/tmp/burn", :verbose => options[:verbose]
120
-
121
- # Finally compile
122
- say "...."
123
- redirect = ""
124
- if env.is_win? then
125
- command = ""
126
- ext = "bat"
127
- redirect = " > nul" if !options[:verbose]
128
-
175
+
176
+ # run simulator
177
+ if options[:preview] then
178
+ play
129
179
  else
130
- command = "/bin/bash "
131
- ext = "sh"
132
- redirect = " > /dev/null" if !options[:verbose]
133
-
134
- # Set permissions to execute compilers
135
- Dir::glob("#{@workspace_root}/tmp/burn/cc65/bin/*65").each do |f|
136
- File.chmod(0777, f)
137
- end
138
-
180
+ say <<-EOS
181
+ try following command to play the app:
182
+
183
+ burn play
184
+
185
+ EOS
186
+
139
187
  end
140
- run "#{command}#{@workspace_root}/tmp/burn/scripts/compile.#{ext} #{@workspace_root}/tmp/burn #{redirect}", :verbose => options[:verbose]
141
-
142
- # prepare customized emulator
143
- say "....."
144
- require 'base64'
145
- File.write(
146
- "#{@workspace_root}/tmp/burn/release/js/emulator.html",
147
- File.read("#{@workspace_root}/tmp/burn/release/js/emulator.html")
148
- .gsub(/__@__TITLE__@__/, mainfile)
149
- .gsub(/__@__ROMDATA__@__/,
150
- Base64::strict_encode64(
151
- File.binread("#{@workspace_root}/tmp/burn/main.out")
152
- )
153
- )
154
- )
155
- copy_file "#{@workspace_root}/tmp/burn/main.out", "#{@workspace_root}/tmp/burn/release/js/main.out", :verbose => options[:verbose]
156
-
157
- say "Burned."
158
-
159
- # run simulator
160
- play if options[:preview]
161
188
  end
162
189
  end
163
190
 
@@ -169,9 +196,12 @@ EOS
169
196
  server.start
170
197
  end
171
198
 
172
- desc "play <file>", "Invoke application simulator."
199
+ desc "play <file>", "Invoke application simulator."
200
+ option :debug, :type => :string, :aliases => '-d', :desc => "Debug mode"
201
+ option :verbose, :type => :boolean, :desc => "Print logs as much as possible", :default => false
202
+ option :chrome, :type => :boolean, :aliases => '-c', :desc => "Run emulator on chrome instead of firefox", :default => false
173
203
  def play(mainfile=nil)
174
- mainfile="main.out" if mainfile.nil?
204
+ mainfile="main.nes" if mainfile.nil?
175
205
  env = Burn::Util::Os.new
176
206
 
177
207
  # boot up webrick httpserver to download emulator script
@@ -182,6 +212,9 @@ EOS
182
212
  run "#{command} &", :verbose => options[:verbose]
183
213
  end
184
214
 
215
+ # wait for certain period of time to prevent browser from fetching game url too early
216
+ sleep 1
217
+
185
218
  # open up browser
186
219
  uri = "http://127.0.0.1:17890/emulator.html"
187
220
  browser = options[:chrome] ? "chrome" : "firefox"
data/lib/burn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Burn
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: burn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-27 00:00:00.000000000 Z
12
+ date: 2014-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -136,3 +136,4 @@ specification_version: 3
136
136
  summary: Burn is a free and open source framework that allows you to create 8-bit
137
137
  flavored application using Ruby DSL.
138
138
  test_files: []
139
+ has_rdoc: