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
|
# File 'lib/entityjs/commands/comp.rb', line 5
def self.generate(name)
if !Dirc.game?
return 2
end
if name.nil?
return 4
end
if name.is_a? Array
name = name.first
end
if name[0] == '/'
name = name[1..-1]
end
filename = name
if name.index('.').nil?
filename += '.js'
end
dir = Config.scripts_folder
Dirc.create_dir(dir, true)
folders = filename.split('/')
filename = folders.pop
if folders.size > 0
folders.each do |i|
Dirc.create_dir(i, true)
end
end
if File.exists?(filename)
return 3
end
comp_name = filename.split('.').shift
File.open(filename, 'w') do |f|
f.write(%Q(re.c\('#{comp_name}'\)
.requires\(''\)
.defines\({
}\)
.init\(function\(\){
}\)
.dispose\(function\(\){
}\);
))
f.close
end
puts "Created comp: #{filename}"
Dir.chdir(Dirc.game_root)
Entityjs::Command.run('test', [name])
return 0
end
|