/
assembly.rb
178 lines (155 loc) · 3.75 KB
/
assembly.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
require 'fileutils'
$file_content = ''
$output_name = 'Ramu.js'
$looking = false
$core = [
File.join('core', 'header.js'),
File.join('utils', 'keyCode.js'),
File.join('utils', 'rect.js'),
File.join('core', 'ramu', 'declaration.js'),
File.join('core', 'ramu', 'init.js'),
File.join('core', 'ramu', 'input.js'),
File.join('core', 'ramu', 'loop.js'),
File.join('core', 'ramu', 'engine.js'),
File.join('core', 'ramu', 'destroy.js'),
File.join('utils', 'math.js'),
File.join('utils', 'utils.js'),
File.join('core', 'gameObject.js'),
File.join('core', 'drawable.js'),
File.join('core', 'collider.js')
]
$complete = [
File.join('collision', 'simpleRectCollider.js'),
File.join('collision', 'raycast.js'),
File.join('sprite', 'sprite.js'),
File.join('sprite', 'spritesheet.js'),
File.join('sprite', 'animation', 'spriteAnimation.js'),
File.join('sprite', 'animation', 'spritesheetAnimation.js'),
File.join('sprite', 'animation', 'animator.js'),
File.join('event', 'mouse', 'clickable.js'),
File.join('event', 'mouse', 'simpleButtonBase.js'),
File.join('event', 'mouse', 'simpleSpriteButton.js'),
File.join('event', 'mouse', 'simpleSpritesheetButton.js'),
File.join('utils', 'destroyer.js')
]
$other = [
File.join('other', 'audio.js'),
File.join('other', 'panorama.js'),
File.join('other', 'text.js'),
File.join('other', 'simpleParticle.js')
]
def get_file_text file
if File.exist?(file)
File::open(file, 'r') { |a| return a.read}
end
end
def create_file
if $file_content == ''
puts "\nNo mount command found"
exit(0)
end
File::open($output_name, 'w') { |a| a.write($file_content) }
end
def assembly_core
$core.each { |s| $file_content += get_file_text(s) + "\n" }
end
def assembly_complete
$complete.each { |s| $file_content += get_file_text(s) + "\n" }
end
def assembly_other
$other.each { |s| $file_content += get_file_text(s) + "\n" }
end
def assembly_module
all = [].concat($core).concat($complete).concat($other)
index = ARGV.index('-module') + 1
if ARGV[index] == nil
puts "\nCannot mount a file with no modules"
exit(0)
end
modules = ARGV[index].split(',')
modules.each do |mod|
all.each do |item|
if File.basename(item) == mod + '.js'
index = all.index(item)
$file_content += get_file_text(all[index]) + "\n"
end
end
end
end
def command_file
index = ARGV.index('-file') + 1
if ARGV[index] == nil
puts "\nCannot mount a file with no name"
exit(0)
end
$output_name = ARGV[index] + '.js'
end
def command cmd
case cmd
when '-look'
$looking = true
when '-core'
assembly_core
when '-complete'
assembly_core
assembly_complete
when '-other'
assembly_core
assembly_complete
assembly_other
when '-module'
assembly_module
when '-file'
command_file
end
end
def print_help
puts "\n"
puts "\nTo mount type:"
puts "\n\t-core to add just the minimum scripts to make it work"
puts "\t-complete to add the default sprite and collision scripts"
puts "\t-other to add everything"
puts "\t-module <filename1,filename2> to expecific modules"
puts "\n"
puts "\t-file <filename> (optional) new file name"
puts "\n"
puts "\t-look remount the file every 5 seconds"
end
def every(n)
loop do
before = Time.now
yield
interval = n - (Time.now - before)
sleep(interval) if interval > 0
end
end
def look
puts "\nRecreating the file, type 'ctr + c' to stop"
begin
every 5 do
$file_content = ''
ARGV.each { |arg| command arg }
create_file
end
rescue Interrupt
puts 'Recreation aborted.'
rescue Errno::EINVAL
puts 'File open error, the program will try again.'
look
end
end
def main
print "Moroboshi - Ramu's File Mounting Utility"
if ARGV.length > 0
ARGV.each { |arg| command arg }
if $looking
look
else
create_file
print ' - done.'
end
else
print_help
end
end
main