burn 0.2.3 → 0.3.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 +4 -4
- data/lib/burn/cli.rb +45 -34
- data/lib/burn/fuel/telnet/scene.rb +17 -17
- data/lib/burn/generator/telnet/screen.rb +16 -14
- data/lib/burn/generator/telnet_vm.rb +6 -5
- data/lib/burn/pxes/cruby_transpiler.rb +27 -27
- data/lib/burn/util.rb +2 -1
- data/lib/burn/util/txt2fuel.rb +77 -0
- data/lib/burn/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f1690e662e1ea2a9b0aa3d6d53a250b62fc1dd4
|
4
|
+
data.tar.gz: c523a497a57c901f85b19d310f0931dbd229b049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f8621ccb6660118c32b17547ec67deb9be27b51f3565f3391285831bb0029426045c765f1e50c9c870dca797cb13a95ca1d820375e0ce81635b03397bcd7d2
|
7
|
+
data.tar.gz: c04a9bc398b1a8cfe58b3caf38c6d07896e9a06160eaf8b299bdeabb97722f40e00c9d8c35b5430834ec1552542e8855cc8868735b56df61e86d44d42fa10f16
|
data/lib/burn/cli.rb
CHANGED
@@ -4,13 +4,13 @@ module Burn
|
|
4
4
|
class_option :debug, :type => :string, :aliases => '-d', :desc => "Debug mode"
|
5
5
|
class_option :verbose, :type => :boolean, :desc => "Print logs as much as possible", :default => false
|
6
6
|
default_task :fire
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(*args)
|
9
9
|
super
|
10
10
|
@workspace_root = Dir.getwd
|
11
11
|
@os = Util::Os.new
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
desc "init", "Initialize environment"
|
15
15
|
option :quick, :type=>:boolean, :desc=>"Make cc65 binaries available without gcc(however unstable. This option is not recommended.)"
|
16
16
|
def init
|
@@ -31,7 +31,19 @@ successfully finished. you've got ready to burn.
|
|
31
31
|
|
32
32
|
EOS
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
desc "fuel", "Read a textfile from stdin and Convert it to fuel DSL"
|
36
|
+
option :file, :type=>:boolean, :aliases => '-f', :desc=>"Read textfile text from file instead of stdin"
|
37
|
+
option :width, :type=>:numeric, :aliases => '-w', :default=>73, :desc=>"Set screen width"
|
38
|
+
option :height, :type=>:numeric, :aliases => '-h', :default=>13, :desc=>"Set screen height"
|
39
|
+
option :separator, :type=>:string, :aliases => '-s', :default=>"^ *#", :desc=>"Set the delimiter string to split textfile into pages(e.g. '^ *#[^#]' or '---')"
|
40
|
+
option :rabbit_timer, :type=>:numeric, :aliases => '-t', :default=>0, :desc=>"Set estimated time[sec] to give your talk"
|
41
|
+
def fuel(filename=nil)
|
42
|
+
textfile = !filename.nil? ? File.read(filename) : $stdin.read
|
43
|
+
fuel = Util::Txt2Fuel.new(options[:width], options[:height], options[:separator], options[:rabbit_timer])
|
44
|
+
say fuel.convert(textfile)
|
45
|
+
end
|
46
|
+
|
35
47
|
desc "fire", "Create your application and Run them instantly"
|
36
48
|
option :chrome, :type => :boolean, :aliases => '-c', :desc => "[ROM mode only] Run emulator on chrome instead of firefox", :default => false
|
37
49
|
option :preview, :type => :boolean, :aliases => '-p', :desc => "[ROM mode only] Preview mode. By this, you can skip burning fuel DSL and focus on playing rom.", :default => false
|
@@ -41,39 +53,39 @@ EOS
|
|
41
53
|
load_conf_and_options(mainfile)
|
42
54
|
if options[:rom_server] then
|
43
55
|
server "#{@workspace_root}/tmp/burn/release/js/", mainfile
|
44
|
-
|
56
|
+
|
45
57
|
else
|
46
58
|
if @conf.app.target==:rom then
|
47
59
|
make_and_play mainfile, options[:preview]
|
48
|
-
|
60
|
+
|
49
61
|
elsif @conf.app.target==:telnet then
|
50
62
|
say "starting telnet server #{@conf.server.ip_addr}:#{@conf.server.port}...."
|
51
63
|
Server::Telnet.new(File.read("#{@workspace_root}/#{mainfile}"), @conf).start
|
52
64
|
end
|
53
65
|
end
|
54
|
-
|
66
|
+
|
55
67
|
end
|
56
|
-
|
68
|
+
|
57
69
|
desc "version", "Print version"
|
58
70
|
map %w(-v --version) => :version
|
59
71
|
def version
|
60
72
|
say "burn #{Burn::VERSION}"
|
61
73
|
end
|
62
|
-
|
74
|
+
|
63
75
|
# desc "release", "To be designed"
|
64
|
-
|
76
|
+
|
65
77
|
def self.source_root
|
66
78
|
File.dirname(__FILE__) + "/.."
|
67
79
|
end
|
68
|
-
|
80
|
+
|
69
81
|
no_tasks do
|
70
|
-
|
82
|
+
|
71
83
|
def make_and_play(mainfile=nil, preview=true)
|
72
84
|
mainfile="main.rb" if mainfile.nil?
|
73
|
-
|
85
|
+
|
74
86
|
if !File.exist?(mainfile) then
|
75
87
|
help
|
76
|
-
|
88
|
+
|
77
89
|
elsif !File.exist?("#{File.dirname(__FILE__)}/tools/#{@os.name}/cc65/bin/ld65#{".exe" if @os.is_win?}") then
|
78
90
|
say <<-EOS
|
79
91
|
[ERROR] you are not ready to burn, most probably you haven't execute burn init command yet.
|
@@ -82,29 +94,29 @@ to fix this, try the following command:
|
|
82
94
|
#{"sudo " if !@os.is_win?}burn init
|
83
95
|
|
84
96
|
EOS
|
85
|
-
|
97
|
+
|
86
98
|
else
|
87
99
|
_v = @conf.app.verbose
|
88
100
|
if !preview then
|
89
101
|
app_root = "#{@workspace_root}/tmp/burn"
|
90
|
-
|
102
|
+
|
91
103
|
# init
|
92
104
|
say "running burn v#{VERSION}..."
|
93
105
|
remove_dir app_root, :verbose => _v
|
94
106
|
empty_directory app_root, :verbose => _v
|
95
107
|
Util::Unpack.new.unpack "#{File.dirname(__FILE__)}/tools/workspace_default.tar.gz", app_root
|
96
|
-
|
108
|
+
|
97
109
|
# compile and build .nes
|
98
110
|
say "."
|
99
111
|
builder = Generator::RomBuilder.new(@workspace_root)
|
100
112
|
builder.verbose _v
|
101
113
|
builder.load File.read("#{@workspace_root}/#{mainfile}")
|
102
114
|
builder.generate
|
103
|
-
|
115
|
+
|
104
116
|
# Prepare compilers
|
105
117
|
say ".."
|
106
118
|
directory File.dirname(__FILE__) + "/tools/#{@os.name}", app_root, :verbose => _v
|
107
|
-
|
119
|
+
|
108
120
|
# Finally compile
|
109
121
|
say "..."
|
110
122
|
redirect = ""
|
@@ -112,25 +124,25 @@ EOS
|
|
112
124
|
command = ""
|
113
125
|
ext = "bat"
|
114
126
|
redirect = " > nul" if !_v
|
115
|
-
|
127
|
+
|
116
128
|
else
|
117
129
|
command = "/bin/bash "
|
118
130
|
ext = "sh"
|
119
131
|
redirect = " > /dev/null" if !_v
|
120
|
-
|
132
|
+
|
121
133
|
# Set permissions to execute compilers
|
122
134
|
Dir::glob("#{app_root}/cc65/bin/*65").each do |f|
|
123
135
|
File.chmod(0777, f)
|
124
136
|
end
|
125
|
-
|
137
|
+
|
126
138
|
end
|
127
139
|
run "#{command}#{app_root}/scripts/compile.#{ext} #{app_root} #{redirect}", :verbose => _v
|
128
|
-
|
140
|
+
|
129
141
|
# prepare customized emulator
|
130
142
|
say "...."
|
131
143
|
require 'base64'
|
132
144
|
File.write(
|
133
|
-
"#{app_root}/release/js/emulator.html",
|
145
|
+
"#{app_root}/release/js/emulator.html",
|
134
146
|
File.read("#{app_root}/release/js/emulator.html")
|
135
147
|
.gsub(/__@__TITLE__@__/, mainfile)
|
136
148
|
.gsub(/__@__AUTHOR__@__/, "anonymous")
|
@@ -143,7 +155,7 @@ EOS
|
|
143
155
|
)
|
144
156
|
)
|
145
157
|
copy_file "#{app_root}/main.nes", "#{app_root}/release/js/main.nes", :verbose => _v
|
146
|
-
|
158
|
+
|
147
159
|
say <<-EOS
|
148
160
|
|
149
161
|
|
@@ -154,9 +166,9 @@ The executable is available at:
|
|
154
166
|
#{app_root}/main.nes
|
155
167
|
|
156
168
|
EOS
|
157
|
-
|
169
|
+
|
158
170
|
end
|
159
|
-
|
171
|
+
|
160
172
|
# boot up webrick httpserver to download emulator script
|
161
173
|
command = "ruby " + File.dirname(__FILE__) + "/../../bin/burn fire #{mainfile} --rom-server " + (options[:debug] ? "-d" : "")
|
162
174
|
if @os.is_win? then
|
@@ -164,12 +176,12 @@ EOS
|
|
164
176
|
else
|
165
177
|
run "#{command} &", :verbose => _v
|
166
178
|
end
|
167
|
-
|
179
|
+
|
168
180
|
# wait for certain period of time to prevent browser from fetching game url too early
|
169
181
|
# *DEFINITELY* TO BE REFACTORED
|
170
182
|
# maybe better to use :StartCallback of WEBRICK?
|
171
183
|
sleep 1
|
172
|
-
|
184
|
+
|
173
185
|
# open up browser
|
174
186
|
uri = "http://#{@conf.server.ip_addr}:#{@conf.server.port}/emulator.html"
|
175
187
|
browser = options[:chrome] ? "chrome" : "firefox"
|
@@ -181,24 +193,23 @@ EOS
|
|
181
193
|
else
|
182
194
|
run "/usr/bin/#{browser} #{uri}", :verbose => _v
|
183
195
|
end
|
184
|
-
|
196
|
+
|
185
197
|
end
|
186
198
|
end
|
187
|
-
|
199
|
+
|
188
200
|
desc "server <document_root>", "Run simple http server for emulator. This is mainly used by burn rubygem itself, not by user."
|
189
201
|
def server(document_root=nil, mainfile)
|
190
202
|
raise Exception.new("document_root must be specified when you would like to run http server") if document_root.nil?
|
191
203
|
server = Server::Rom.new(document_root,@conf)
|
192
204
|
server.start
|
193
205
|
end
|
194
|
-
|
206
|
+
|
195
207
|
def load_conf_and_options(mainfile)
|
196
208
|
@conf = Configuration::Loader.new(File.read("#{@workspace_root}/#{mainfile}"))
|
197
209
|
@conf.app.debug options[:debug]
|
198
210
|
@conf.app.verbose options[:verbose]
|
199
211
|
end
|
200
|
-
|
212
|
+
|
201
213
|
end
|
202
|
-
|
203
214
|
end
|
204
|
-
end
|
215
|
+
end
|
@@ -6,7 +6,7 @@ module Burn
|
|
6
6
|
BG = 40 # background palette (0x00-0x0f)
|
7
7
|
TEXT = 30 # background palette (0x00-0x0f)
|
8
8
|
# SPRITE = 17 # sprite palette (0x10-0x1f)
|
9
|
-
|
9
|
+
|
10
10
|
# Color Control
|
11
11
|
WHITE = 7
|
12
12
|
LIGHTBLUE = 4
|
@@ -23,7 +23,7 @@ module Burn
|
|
23
23
|
BLUEGREEN = 6
|
24
24
|
GRAY = 7
|
25
25
|
BLACK = 0
|
26
|
-
|
26
|
+
|
27
27
|
# Light Control
|
28
28
|
DARKEST = 60
|
29
29
|
DARKER = 60
|
@@ -33,23 +33,23 @@ module Burn
|
|
33
33
|
def initialize(resource_name, context)
|
34
34
|
super(resource_name, context)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def label(string, x=0, y=1)
|
38
|
-
@context.instance_exec { @opcodes << "@screen.display[#{y}][#{x},#{string.length}] = \"#{string}\"" }
|
38
|
+
@context.instance_exec { @opcodes << "@screen.display[#{y}][#{x},#{string.length}] = \"#{string.gsub(/"/, '\"')}\"" }
|
39
39
|
end
|
40
40
|
|
41
41
|
def wait(interval)
|
42
42
|
@context.instance_exec { @opcodes << "@wait = #{interval}" }
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def method_missing(method_symbol, *args, &block)
|
46
46
|
#TBD if needed
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def goto(scene_name)
|
50
50
|
@context.instance_exec { @opcodes << "@screen.flush_screen && @pc = @opcodes.index(\"##{scene_name}\")" }
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def color(palette, color, lightness=:lighter)
|
54
54
|
target = palette==:bg ? "bg" : "fg"
|
55
55
|
palette=Scene.const_get(palette.upcase)
|
@@ -57,7 +57,7 @@ module Burn
|
|
57
57
|
lightness=Scene.const_get(lightness.upcase)
|
58
58
|
@context.instance_exec { @opcodes << "@screen.#{target}_color = #{palette+color+lightness}" }
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def main_loop(rrb_source=nil)
|
62
62
|
@context.instance_exec(@context,@resource_name) do |c, resource|
|
63
63
|
p=Pxes::CrubyTranspiler.new(Ripper.sexp(rrb_source),c,resource)
|
@@ -68,11 +68,11 @@ module Burn
|
|
68
68
|
@opcodes << "@pc = @opcodes.index(\"#{start_label}\")" #JUMP
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def sprite(resource)
|
73
73
|
@context.instance_exec { @opcodes << "@screen.activated_sprite_objects << @___#{resource} if @screen.activated_sprite_objects.index(@___#{resource}).nil?" }
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def inline(code)
|
77
77
|
@context.instance_exec { @opcodes << code }
|
78
78
|
end
|
@@ -85,31 +85,31 @@ module Burn
|
|
85
85
|
# ].each {|p| @code_blocks.push p}
|
86
86
|
# end
|
87
87
|
# end
|
88
|
-
#
|
88
|
+
#
|
89
89
|
# def fade_out(sec=3)
|
90
90
|
# @context.instance_exec {@code_blocks.push "screen_fade_out(#{sec.to_s});"}
|
91
91
|
# end
|
92
92
|
#
|
93
93
|
# def show(string, x=0, y=0, *args)
|
94
94
|
# end
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# def inline(code)
|
97
97
|
# end
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# def screen(map, vars)
|
100
100
|
# end
|
101
|
-
#
|
101
|
+
#
|
102
102
|
# def paint(dest, palette)
|
103
103
|
# end
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# def rand
|
106
106
|
# @context.instance_exec {@code_blocks.push "rand8()"}
|
107
107
|
# end
|
108
|
-
#
|
108
|
+
#
|
109
109
|
# # utility methods
|
110
110
|
# def range(x_from, y_from, x_to, y_to)
|
111
111
|
# end
|
112
|
-
|
112
|
+
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -8,9 +8,9 @@ module Burn
|
|
8
8
|
JUMPTOHOME = ESC + "[H"
|
9
9
|
RESETALLATTR = ESC + "[0m"
|
10
10
|
CRLF = 13.chr + 10.chr
|
11
|
-
|
11
|
+
|
12
12
|
attr_accessor :display, :fg_color, :bg_color, :activated_sprite_objects
|
13
|
-
|
13
|
+
|
14
14
|
def initialize(conf)
|
15
15
|
@fg_color = 37
|
16
16
|
@bg_color = 40
|
@@ -18,7 +18,7 @@ module Burn
|
|
18
18
|
@conf = conf
|
19
19
|
flush_screen
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def to_terminal
|
23
23
|
#CLEARSCREEN + escape_color(@fg_color) + escape_color(@bg_color) + @display.join("\r\n") + JUMPTOHOME + RESETALLATTR
|
24
24
|
#JUMPTOHOME + RESETALLATTR + CLEARSCREEN + escape_color(@fg_color) + escape_color(@bg_color) + @display.join("\r\n") + ESC + "[#{@conf.app.height};2H" + RESETALLATTR
|
@@ -26,36 +26,38 @@ module Burn
|
|
26
26
|
#JUMPTOHOME + crlf + crlf + crlf + crlf + crlf + crlf + @display.join(crlf)
|
27
27
|
#JUMPTOHOME + crlf + crlf + crlf + crlf + crlf + crlf + @display.join(crlf) + crlf
|
28
28
|
#JUMPTOHOME + @display.join(CRLF) + CRLF
|
29
|
-
|
29
|
+
|
30
30
|
JUMPTOHOME + escape_color(@fg_color) + escape_color(@bg_color) + ppu_emulate + CRLF + RESETALLATTR
|
31
31
|
#JUMPTOHOME + @display.join(CRLF) + CRLF
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def flush_screen
|
35
35
|
@display = Array.new
|
36
36
|
@conf.app.height.times{ @display << Array.new(@conf.app.width){' '}.join }
|
37
37
|
@activated_sprite_objects = []
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def is_pressed(key, user_input)
|
41
41
|
log " ** program is waiting for:" + key.to_s
|
42
42
|
if !user_input.nil? then
|
43
43
|
log " **** confiremd user input:" + user_input.class.to_s, user_input.chr, user_input.to_s
|
44
|
-
if [*'0'..'9', *'a'..'z', *'A'..'Z'].include?(user_input.chr) && key.to_s == user_input.chr then
|
44
|
+
if [*'0'..'9', *'a'..'z', *'A'..'Z',10.chr,13.chr].include?(user_input.chr) && key.to_s == user_input.chr then
|
45
45
|
log "****** is_pressed() returned true"
|
46
46
|
return true
|
47
47
|
end
|
48
48
|
end
|
49
49
|
false
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
private
|
53
|
-
|
53
|
+
|
54
54
|
def escape_color(num)
|
55
|
-
ESC + "[" + num.to_s + ";1m"
|
55
|
+
#ESC + "[" + num.to_s + ";1m"
|
56
|
+
ESC + "[" + num.to_s + ";0m"
|
56
57
|
end
|
57
|
-
|
58
|
+
|
58
59
|
def ppu_emulate
|
60
|
+
@display.map!{|line| line.rstrip.length > 0 ? line.rstrip : line} # rstrip for multibyte character display (without this, space character will be overflowed)
|
59
61
|
if @activated_sprite_objects.count == 0 then
|
60
62
|
@display.join(CRLF)
|
61
63
|
else
|
@@ -64,7 +66,7 @@ module Burn
|
|
64
66
|
obj.tile.split("\n").each_with_index do |line, i|
|
65
67
|
canvas[(obj.y+ i) % @conf.app.height][obj.x % @conf.app.width,line.length] = line.chomp
|
66
68
|
end
|
67
|
-
|
69
|
+
|
68
70
|
# struct_var = "static sprite_schema #{key}={0, 0, {"
|
69
71
|
# @pattern_table_index[key.to_sym] = @pattern_table_pointer
|
70
72
|
# patternizer.patterns.each_with_index do |p, i|
|
@@ -74,12 +76,12 @@ module Burn
|
|
74
76
|
# @pattern_table_pointer+=1
|
75
77
|
# end
|
76
78
|
# struct_var += "128}};"
|
77
|
-
|
79
|
+
|
78
80
|
end
|
79
81
|
canvas.join(CRLF)
|
80
82
|
end
|
81
83
|
end
|
82
|
-
|
84
|
+
|
83
85
|
end
|
84
86
|
end
|
85
87
|
end
|
@@ -3,9 +3,9 @@ module Burn
|
|
3
3
|
class TelnetVm
|
4
4
|
include Generator::Telnet
|
5
5
|
include Debug
|
6
|
-
attr_reader :screen
|
6
|
+
attr_reader :screen, :time
|
7
7
|
attr_accessor :wait
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(source, conf)
|
10
10
|
@pc = 0 # Program Counter
|
11
11
|
@screen = Screen.new(conf)
|
@@ -15,8 +15,9 @@ module Burn
|
|
15
15
|
@user_input = UserInput.new(conf)
|
16
16
|
@conf = conf
|
17
17
|
@finish = false
|
18
|
+
@time = Time.now.to_i
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
def next_frame
|
21
22
|
log @pc
|
22
23
|
if @wait > 0 then
|
@@ -39,12 +40,12 @@ module Burn
|
|
39
40
|
# do nothing
|
40
41
|
end
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
def interrupt(signal)
|
44
45
|
log "INTTERUPT_SETTING:" + @conf.app.user_input.to_s
|
45
46
|
@user_input.receive_signal(signal)
|
46
47
|
end
|
47
|
-
|
48
|
+
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Burn
|
2
2
|
module Pxes
|
3
3
|
class CrubyTranspiler < TranspilerBase
|
4
|
-
|
4
|
+
|
5
5
|
def to_rb
|
6
6
|
parse_sexp(@sexp)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
private
|
10
10
|
#def replace_vcall_to_symbol(sexp_array)
|
11
11
|
# sexp_array.map do |a|
|
@@ -18,15 +18,15 @@ module Burn
|
|
18
18
|
# end
|
19
19
|
# end
|
20
20
|
#end
|
21
|
-
|
21
|
+
|
22
22
|
def invoke_dsl_processing(exp)
|
23
23
|
generator = Generator::Telnet::JitCompiler.new
|
24
24
|
# class(@@)|instance(@) variable inside exp need to be stringified before the #instance_eval.
|
25
|
-
# Without this, variables will be evaluated immediately now (and will get disappered as a result of this) by #instance_eval
|
25
|
+
# Without this, variables will be evaluated immediately now (and will get disappered as a result of this) by #instance_eval
|
26
26
|
Fuel::Telnet::Scene.new(@resource_name, generator).instance_eval exp.gsub(/(@[@\w]*)/, "\"\\1\"")
|
27
27
|
generator.opcodes.join "\n"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def parse_sexp(s)
|
31
31
|
if s.instance_of?(String) then
|
32
32
|
s
|
@@ -36,7 +36,7 @@ module Burn
|
|
36
36
|
case s[0]
|
37
37
|
when :assign
|
38
38
|
parse_sexp(s[1]) + "=" + parse_sexp(s[2])
|
39
|
-
|
39
|
+
|
40
40
|
when :var_field, :var_ref
|
41
41
|
if s[1][0] == :@ident then
|
42
42
|
var_scope = "@___"
|
@@ -44,10 +44,10 @@ module Burn
|
|
44
44
|
var_scope = ""
|
45
45
|
end
|
46
46
|
var_scope + s[1][1]
|
47
|
-
|
47
|
+
|
48
48
|
when :void_stmt
|
49
49
|
"" # this happens when rip "if true then # do nothing end" type of code
|
50
|
-
|
50
|
+
|
51
51
|
when :binary
|
52
52
|
case s[2]
|
53
53
|
when :or
|
@@ -58,10 +58,10 @@ module Burn
|
|
58
58
|
operator = s[2].to_s
|
59
59
|
end
|
60
60
|
parse_sexp(s[1]) + operator + parse_sexp(s[3])
|
61
|
-
|
61
|
+
|
62
62
|
when :opassign
|
63
63
|
parse_sexp(s[1]) + parse_sexp(s[2]) + parse_sexp(s[3])
|
64
|
-
|
64
|
+
|
65
65
|
when :unary
|
66
66
|
case s[1]
|
67
67
|
when :not, :!
|
@@ -69,22 +69,22 @@ module Burn
|
|
69
69
|
else
|
70
70
|
parse_sexp(s[2])
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
when :paren
|
74
74
|
"(" + parse_sexp(s[1][0]) + ")"
|
75
|
-
|
75
|
+
|
76
76
|
when :symbol
|
77
77
|
':' + s[1][1]
|
78
|
-
|
78
|
+
|
79
79
|
when :field, :call
|
80
80
|
parse_sexp(s[1]) + "." + parse_sexp(s[3])
|
81
|
-
|
81
|
+
|
82
82
|
when :@ident, :@int, :@kw, :@op
|
83
83
|
s[1]
|
84
|
-
|
84
|
+
|
85
85
|
when :@tstring_content
|
86
86
|
'"' + s[1] + '"'
|
87
|
-
|
87
|
+
|
88
88
|
# this is why you can't use pre-defined dsl name as a variable name. e.g) you are not allowed to declare variables like show or label or stop. these all are defined dsl.
|
89
89
|
when :vcall
|
90
90
|
if s[1][0] == :@ident then
|
@@ -94,7 +94,7 @@ module Burn
|
|
94
94
|
end
|
95
95
|
s[1][1] = var_scope + s[1][1]
|
96
96
|
parse_sexp(s[1])
|
97
|
-
|
97
|
+
|
98
98
|
# this is why you can't use pre-defined dsl name as a variable name. e.g) you are not allowed to declare variables like show or label or stop. these all are defined dsl.
|
99
99
|
when :command
|
100
100
|
if !Fuel::Telnet::Scene.new(@resource_name,@context).methods.index(s[1][1].to_sym).nil? then
|
@@ -103,7 +103,7 @@ module Burn
|
|
103
103
|
else
|
104
104
|
parse_sexp(s[1]) + "(" + parse_sexp(s[2]) + ")"
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
when :method_add_arg
|
108
108
|
command = s[1][1][1]
|
109
109
|
# check if it matches dsl.
|
@@ -115,10 +115,10 @@ module Burn
|
|
115
115
|
else
|
116
116
|
parse_sexp(s[1]) + "(" + parse_sexp(s[2]) + ")"
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
# Currently pssing block is not supported
|
120
120
|
#when :method_add_block
|
121
|
-
|
121
|
+
|
122
122
|
when :args_add_block
|
123
123
|
a = Array.new
|
124
124
|
s[1].each_with_index do |sexp,i|
|
@@ -127,10 +127,10 @@ module Burn
|
|
127
127
|
a << parse_sexp(sexp)
|
128
128
|
end
|
129
129
|
a.join(",")
|
130
|
-
|
130
|
+
|
131
131
|
when :while
|
132
132
|
"while(" + parse_sexp(s[1]) + "){" + parse_sexp(s[2]) + "}"
|
133
|
-
|
133
|
+
|
134
134
|
when :if, :if_mod, :elsif
|
135
135
|
if s[0]==:elsif then
|
136
136
|
keyword = "else if"
|
@@ -157,17 +157,17 @@ module Burn
|
|
157
157
|
else
|
158
158
|
"@pc = @opcodes.index(\"#{label}\") if !(" + parse_sexp(s[1]) + ")\n" + parse_sexp(s[2]) + "\n#{label}"
|
159
159
|
end
|
160
|
-
|
161
|
-
|
160
|
+
|
161
|
+
|
162
162
|
#when :def
|
163
163
|
# is not supported for to_c as return data type cannot be defined
|
164
|
-
|
164
|
+
|
165
165
|
when :else
|
166
166
|
parse_sexp(s[1])
|
167
|
-
|
167
|
+
|
168
168
|
else
|
169
169
|
parse_sexp(s[1])
|
170
|
-
|
170
|
+
|
171
171
|
end
|
172
172
|
# Safety net
|
173
173
|
elsif s.instance_of?(Array) && s[0].instance_of?(Array) then
|
data/lib/burn/util.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Burn
|
2
|
+
module Util
|
3
|
+
class Txt2Fuel
|
4
|
+
attr_reader :width, :height, :separator, :rabbit_timer
|
5
|
+
|
6
|
+
def initialize(width=73, height=10, separator="^ *#", rabbit_timer=0)
|
7
|
+
@width = width
|
8
|
+
@height = height
|
9
|
+
@separator = separator
|
10
|
+
@rabbit_timer = rabbit_timer
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert(textfile)
|
14
|
+
pages = []
|
15
|
+
pages.push []
|
16
|
+
textfile.encode!('UTF-8')
|
17
|
+
textfile.each_line do |line|
|
18
|
+
pages.push [] if line.match(Regexp.new(@separator)) && pages[pages.count-1].count>0
|
19
|
+
if line =~ /(?:\p{Hiragana}|\p{Katakana}|[一-龠々])/ then # if Multibyte character is contained
|
20
|
+
formatted_text = line.chomp.chars.each_slice((@width-2)/2).map{|a| a.join}
|
21
|
+
else
|
22
|
+
formatted_text = line.chomp.scan(/.{,#{@width-2}}/)
|
23
|
+
end
|
24
|
+
formatted_text.each do |words|
|
25
|
+
if words.length>0 || line==10.chr then
|
26
|
+
pages[pages.count-1].push words
|
27
|
+
end
|
28
|
+
if pages[pages.count-1].count >= @height-2 then
|
29
|
+
pages.push []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
fuel = "
|
35
|
+
config :app do
|
36
|
+
target :telnet
|
37
|
+
user_input :enable
|
38
|
+
frame_rate :extreme
|
39
|
+
height #{@height}
|
40
|
+
width #{@width}
|
41
|
+
end
|
42
|
+
|
43
|
+
config :server do
|
44
|
+
ip_addr '0.0.0.0'
|
45
|
+
max_clients 1000
|
46
|
+
end
|
47
|
+
"
|
48
|
+
pages.each_with_index do |page, i|
|
49
|
+
fuel += ""
|
50
|
+
fuel += "scene 'page_#{i}' do\n"
|
51
|
+
page.each_with_index do |line, index|
|
52
|
+
fuel += " label '#{line.gsub("'", "\\\\'")}', 1, #{index}\n"
|
53
|
+
end
|
54
|
+
page_info_width = ("/"+(pages.count*2).to_s).length-1
|
55
|
+
fuel += " label '#{i+1}/#{pages.count}', #{@width-page_info_width-1}, #{@height-1}\n"
|
56
|
+
if @rabbit_timer>0 then
|
57
|
+
fuel += " label '|' + ('-'*#{@width-page_info_width-4}).to_s + '|', 1, #{@height-1}\n"
|
58
|
+
fuel += " label '@', #{((@width-page_info_width-2)*((i+1).to_f/pages.count.to_f)).to_i}, #{@height-1}\n"
|
59
|
+
end
|
60
|
+
fuel += " main_loop <<-EOH\n"
|
61
|
+
if @rabbit_timer>0 then
|
62
|
+
fuel += %[ inline "self.screen.display[#{@height-1}][(#{@width-page_info_width-1}*(Time.now.to_i - self.time).to_f/#{@rabbit_timer}.to_f).to_i < #{@width-page_info_width-1} ? (#{@width-page_info_width-1}*(Time.now.to_i - self.time).to_f/#{@rabbit_timer}.to_f).to_i + 2 : #{@width-page_info_width-1},1] = '>'"\n]
|
63
|
+
else
|
64
|
+
fuel += %[ inline "self.screen.display[#{@height-1}][1,5] = Time.at(Time.now.to_i - self.time).strftime('%M:%S')"\n]
|
65
|
+
end
|
66
|
+
fuel += %[ goto "page_#{i+1==pages.count ? 0 : i+1}" if is_pressed(10.chr)\n]
|
67
|
+
fuel += %[ goto "page_#{i+1==pages.count ? 0 : i+1}" if is_pressed(13.chr)\n]
|
68
|
+
fuel += %[ goto "page_#{i+1==pages.count ? 0 : i+1}" if is_pressed(:f)\n]
|
69
|
+
fuel += %[ goto "page_#{i-1<0 ? pages.count-1 : i-1}" if is_pressed(:b)\n]
|
70
|
+
fuel += " EOH\n"
|
71
|
+
fuel += "end\n"
|
72
|
+
end
|
73
|
+
fuel
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/burn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kei Sawada(@remore)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/burn/util/logo.rb
|
126
126
|
- lib/burn/util/os.rb
|
127
127
|
- lib/burn/util/patternizer.rb
|
128
|
+
- lib/burn/util/txt2fuel.rb
|
128
129
|
- lib/burn/util/unpack.rb
|
129
130
|
- lib/burn/util.rb
|
130
131
|
- lib/burn/version.rb
|