author_engine 0.5.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/assets/ui/cursor.png +0 -0
- data/author_engine.gemspec +6 -6
- data/lib/author_engine/cli.rb +9 -0
- data/lib/author_engine/collision_detection/collision_detection.rb +28 -19
- data/lib/author_engine/containers/loader.rb +41 -11
- data/lib/author_engine/game/common/parts/collision_detection.rb +7 -7
- data/lib/author_engine/game/common/parts/common.rb +16 -1
- data/lib/author_engine/game/game.rb +18 -13
- data/lib/author_engine/game/gosu/parts/graphics.rb +9 -9
- data/lib/author_engine/game/opal/exporter.rb +55 -50
- data/lib/author_engine/game/opal/game_runner.rb +182 -89
- data/lib/author_engine/game/opal/parts/graphics.rb +18 -18
- data/lib/author_engine/game/opal/touch_button.rb +38 -17
- data/lib/author_engine/game/opal/touch_handler.rb +20 -3
- data/lib/author_engine/game/opal/touch_joystick.rb +118 -0
- data/lib/author_engine/level_picker.rb +1 -1
- data/lib/author_engine/opal.rb +2 -0
- data/lib/author_engine/save_file.rb +86 -8
- data/lib/author_engine/version.rb +1 -1
- data/lib/author_engine/views/level_editor.rb +7 -11
- data/lib/author_engine/views/play_viewer.rb +1 -1
- data/lib/author_engine/views/sprite_editor.rb +5 -1
- data/lib/author_engine/window.rb +3 -4
- data/screenshots/level_editor.png +0 -0
- data/vendor/opal-parser.min.js +1 -0
- data/vendor/opal.min.js +1 -0
- metadata +22 -18
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61261132ab4fc88d6e4c6639443f4cc967cc41cc73956345c20de4091065df5c
|
4
|
+
data.tar.gz: 1c941abf61b677cb4c501285fb414ed6c1d062c0ba8989ba31c2655634383afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef8a21c43402efa405310f0d5ad862ca5becbaebf18d187bc3b431f48d1ec915149b14c1f82507c47f299851c0e601f1418ffdc691f2ababc777aee6bbbf0d9e
|
7
|
+
data.tar.gz: 53c585c3057a349b727a805302dc13599e25eec236bce3b79ff031ac40970b8975303f7f6fc0da425ce49ea74d746d5979e464c86efd9b9bfd75297dc5f3a826
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ A virtual console¹ that you code in Ruby.
|
|
22
22
|
## Sprite Editor
|
23
23
|
![sprite_editor_view](https://raw.githubusercontent.com/cyberarm/author_engineV2/master/screenshots/sprite_editor.png)
|
24
24
|
## Level Editor
|
25
|
-
![level_editor_view](
|
25
|
+
![level_editor_view](https://raw.githubusercontent.com/cyberarm/author_engineV2/master/screenshots/level_editor.png)
|
26
26
|
## Code Editor
|
27
27
|
![code_editor_view](https://raw.githubusercontent.com/cyberarm/author_engineV2/master/screenshots/code_editor.png)
|
28
28
|
|
Binary file
|
data/author_engine.gemspec
CHANGED
@@ -30,13 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
end
|
31
31
|
spec.bindir = "bin"
|
32
32
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
33
|
-
spec.require_paths = ["lib", "assets"]
|
33
|
+
spec.require_paths = ["lib", "assets", "vendor"]
|
34
34
|
|
35
|
-
spec.add_dependency "gosu", "~> 0.
|
35
|
+
spec.add_dependency "gosu", "~> 0.15.0"
|
36
36
|
spec.add_dependency "coderay", "~> 1.1.2"
|
37
|
-
spec.add_dependency "opal", "~> 0.
|
37
|
+
spec.add_dependency "opal", "~> 1.0.0"
|
38
38
|
|
39
|
-
spec.add_development_dependency "bundler", "~>
|
40
|
-
spec.add_development_dependency "rake", "~>
|
41
|
-
spec.add_development_dependency "minitest", "~> 5.
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.13"
|
42
42
|
end
|
data/lib/author_engine/cli.rb
CHANGED
@@ -10,6 +10,15 @@ class AuthorEngine
|
|
10
10
|
puts "author_engine export project [exported_name]"
|
11
11
|
end
|
12
12
|
|
13
|
+
elsif ARGV[0] && ARGV[0] == "inflate"
|
14
|
+
if ARGV[1] && ARGV[1].end_with?(".authorengine")
|
15
|
+
if File.exists?(ARGV[1])
|
16
|
+
savefile = SaveFile.new(ARGV[1])
|
17
|
+
savefile.inflate!
|
18
|
+
puts "Inflated #{ARGV[1]}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
13
22
|
elsif ARGV[0] && ARGV[0].end_with?(".authorengine")
|
14
23
|
# The Loader Container handles loading projects
|
15
24
|
AuthorEngine::Window.new.show
|
@@ -3,7 +3,7 @@ class AuthorEngine
|
|
3
3
|
Color = Struct.new(:red, :green, :blue, :alpha)
|
4
4
|
BoundingBox = Struct.new(:x, :y, :width, :height)
|
5
5
|
|
6
|
-
def initialize(game_sprites, game_levels)
|
6
|
+
def initialize(game_sprites, game_levels, spritesheet)
|
7
7
|
@game_sprites = game_sprites
|
8
8
|
@game_levels = game_levels
|
9
9
|
|
@@ -11,21 +11,30 @@ class AuthorEngine
|
|
11
11
|
@levels = []
|
12
12
|
|
13
13
|
@known_collisions = []
|
14
|
+
|
15
|
+
spritesheet_blob = RUBY_ENGINE == "opal" ? spritesheet.to_blob.each_slice(4).to_a : spritesheet.to_blob.bytes.each_slice(4).to_a
|
16
|
+
(spritesheet.rows / 16).times do |y|
|
17
|
+
(spritesheet.columns / 16).times do |x|
|
18
|
+
blob = []
|
19
|
+
|
20
|
+
16.times do |sy|
|
21
|
+
16.times do |sx|
|
22
|
+
blob << spritesheet_blob[(y * 16 + sy) * spritesheet.columns + (x * 16 + sx)]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
add_sprite(blob.flatten!)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@game_levels.each { |level| add_level(level) }
|
14
31
|
end
|
15
32
|
|
16
33
|
def clear
|
17
34
|
@known_collisions.clear
|
18
35
|
end
|
19
36
|
|
20
|
-
def add_sprite(
|
21
|
-
blob = nil
|
22
|
-
if RUBY_ENGINE != "opal"
|
23
|
-
blob = image_or_blob.to_blob
|
24
|
-
else
|
25
|
-
blob = []
|
26
|
-
`#{image_or_blob}.forEach(function(value) {#{blob << `value`}})`#.each {|n| blob << n}
|
27
|
-
end
|
28
|
-
|
37
|
+
def add_sprite(blob)
|
29
38
|
@sprites << {blob: blob, box: bounding_box(blob)}
|
30
39
|
end
|
31
40
|
|
@@ -94,7 +103,7 @@ class AuthorEngine
|
|
94
103
|
def render_bounding_box(sprite_index, box, sprite_x, sprite_y, edges = {}, z = Float::INFINITY, color = 0xc800ff00, collision_color = 0xc8ff00ff)
|
95
104
|
if RUBY_ENGINE == "opal"
|
96
105
|
color = "green"
|
97
|
-
collision_color = "
|
106
|
+
collision_color = "purple"
|
98
107
|
end
|
99
108
|
paint_color = color
|
100
109
|
# EDGE: TOP
|
@@ -142,13 +151,13 @@ class AuthorEngine
|
|
142
151
|
|
143
152
|
def draw_line(x, y, x2, y2, color, z = 0)
|
144
153
|
if RUBY_ENGINE == "opal"
|
145
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
146
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
154
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.strokeStyle = #{color}`
|
155
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.lineWidth = 1`
|
147
156
|
|
148
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
149
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
150
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
151
|
-
`#{AuthorEngine::GameRunner.instance.game.
|
157
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.beginPath()`
|
158
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.moveTo(#{x}, #{y})`
|
159
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.lineTo(#{x2}, #{y2})`
|
160
|
+
`#{AuthorEngine::GameRunner.instance.game.authorengine_canvas_context}.stroke()`
|
152
161
|
else
|
153
162
|
Gosu.draw_line(x, y, color, x2, y2, color, z)
|
154
163
|
end
|
@@ -158,14 +167,14 @@ class AuthorEngine
|
|
158
167
|
def solid_at?(blob, x, y)
|
159
168
|
width = 16
|
160
169
|
|
161
|
-
blob[(y * width + x) * 4 + 3].ord
|
170
|
+
blob[(y * width + x) * 4 + 3].ord > 0
|
162
171
|
end
|
163
172
|
|
164
173
|
def bounding_box(blob, size = 16)
|
165
174
|
box = BoundingBox.new(size, size, 0, 0)
|
166
175
|
size.times do |y|
|
167
176
|
size.times do |x|
|
168
|
-
if solid_at?(blob, x, y)
|
177
|
+
if solid_at?(blob, x, y)
|
169
178
|
box.x = x if x < box.x
|
170
179
|
box.y = y if y < box.y
|
171
180
|
box.width = x if x > box.width
|
@@ -2,8 +2,17 @@ class AuthorEngine
|
|
2
2
|
class Loader < Container
|
3
3
|
Project = Struct.new(:name, :block)
|
4
4
|
def setup
|
5
|
-
|
6
|
-
|
5
|
+
if ARGV[0] && File.exists?(ARGV[0]) && Gosu.milliseconds < 1500
|
6
|
+
if ARGV[0].end_with?(".authorengine")
|
7
|
+
load(ARGV[0])
|
8
|
+
return
|
9
|
+
elsif File.directory?(ARGV[0])
|
10
|
+
@root_directory = ARGV[0]
|
11
|
+
else
|
12
|
+
puts "AuthorEngine: #{ARGV[0]} is not a compatible file."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
@root_directory ||= Dir.pwd #"#{Dir.home}/AuthorEngineProjects"
|
7
16
|
|
8
17
|
@list = []
|
9
18
|
@files = Dir.glob(@root_directory+"/*.authorengine")
|
@@ -27,13 +36,9 @@ class AuthorEngine
|
|
27
36
|
end
|
28
37
|
@new_button.x = window.width - @new_button.width
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
puts "AuthorEngine: #{ARGV[0]} is not a compatible file."
|
35
|
-
end
|
36
|
-
end
|
39
|
+
@draw_caret = true
|
40
|
+
@last_caret_update = Gosu.milliseconds
|
41
|
+
@caret_interval = 500
|
37
42
|
end
|
38
43
|
|
39
44
|
def load(filename)
|
@@ -53,8 +58,23 @@ class AuthorEngine
|
|
53
58
|
end
|
54
59
|
|
55
60
|
def draw_inputter
|
61
|
+
caret_x = @font.text_width(window.text_input.text[0..window.text_input.caret_pos-1])
|
62
|
+
caret_x = 0 if window.text_input.caret_pos == 0
|
63
|
+
if Gosu.milliseconds > @last_caret_update + @caret_interval
|
64
|
+
@draw_caret = !@draw_caret
|
65
|
+
@last_caret_update = Gosu.milliseconds
|
66
|
+
end
|
67
|
+
|
56
68
|
x = window.width/2 - @font.text_width(window.text_input.text+".authorengine")/2
|
69
|
+
error_x = window.width/2 - @font.text_width(window.text_input.text.strip+".authorengine already exists!")/2
|
57
70
|
y = window.height/2 - @font.height/2
|
71
|
+
|
72
|
+
Gosu.draw_rect(x+caret_x, y, 2, @font.height, Gosu::Color::WHITE) if @draw_caret
|
73
|
+
if window.text_input.text.strip+".authorengine" == @name_exists
|
74
|
+
@font.draw_text(window.text_input.text.strip+".authorengine already exists!", error_x, y - 32, 0, 1,1, red) if @name_exists
|
75
|
+
else
|
76
|
+
@name_exists = false
|
77
|
+
end
|
58
78
|
@font.draw_text(window.text_input.text+".authorengine", x, y, 0)
|
59
79
|
end
|
60
80
|
|
@@ -100,12 +120,22 @@ class AuthorEngine
|
|
100
120
|
@index = 0 if @list.size == 0
|
101
121
|
@index = @index % @list.size-1 if @list.size != 0
|
102
122
|
when Gosu::KbEnter, Gosu::KbReturn
|
123
|
+
filename = window.text_input.text.strip if window.text_input
|
124
|
+
|
103
125
|
if @entering_name
|
104
|
-
|
105
|
-
|
126
|
+
if File.exists?(filename)
|
127
|
+
@name_exists = filename
|
128
|
+
else
|
129
|
+
window.text_input = nil
|
130
|
+
savefile = SaveFile.create(filename+".authorengine")
|
131
|
+
load(filename+".authorengine")
|
132
|
+
end
|
106
133
|
else
|
107
134
|
@list[@index].block.call if @list[@index]&.block
|
108
135
|
end
|
136
|
+
when Gosu::KbEscape
|
137
|
+
@entering_name = false
|
138
|
+
window.text_input = nil
|
109
139
|
end
|
110
140
|
end
|
111
141
|
end
|
@@ -2,31 +2,31 @@ class AuthorEngine
|
|
2
2
|
class Part
|
3
3
|
module CollisionDetection
|
4
4
|
def bounding_box(sprite_index)
|
5
|
-
@
|
5
|
+
@authorengine_collision_detection.box(sprite_index)
|
6
6
|
end
|
7
7
|
|
8
8
|
def colliding_edge(sprite_index, sprite_x, sprite_y, target_sprite_index, target_x, target_y)
|
9
|
-
@
|
9
|
+
@authorengine_collision_detection.colliding_edge(sprite_index, sprite_x, sprite_y, target_sprite_index, target_x, target_y)
|
10
10
|
end
|
11
11
|
|
12
12
|
def sprite_vs_sprite(sprite_index, sprite_x, sprite_y, target_sprite_index, target_x, target_y)
|
13
|
-
@
|
13
|
+
@authorengine_collision_detection.sprite_vs_sprite(sprite_index, sprite_x, sprite_y, target_sprite_index, target_x, target_y)
|
14
14
|
end
|
15
15
|
|
16
16
|
def sprite_vs_level(sprite_index, sprite_x, sprite_y, level)
|
17
|
-
@
|
17
|
+
@authorengine_collision_detection.sprite_vs_level(sprite_index, sprite_x, sprite_y, level)
|
18
18
|
end
|
19
19
|
|
20
20
|
def draw_sprite_box(sprite_index, sprite_x, sprite_y)
|
21
|
-
@
|
21
|
+
@authorengine_collision_detection.debug_draw_sprite(sprite_index, sprite_x, sprite_y)
|
22
22
|
end
|
23
23
|
|
24
24
|
def draw_level_boxes(level_index)
|
25
|
-
@
|
25
|
+
@authorengine_collision_detection.debug_draw_level(level_index)
|
26
26
|
end
|
27
27
|
|
28
28
|
def render_bounding_box(sprite_index, box, sprite_x, sprite_y, edges = {}, z = Float::INFINITY)
|
29
|
-
@
|
29
|
+
@authorengine_collision_detection.render_bounding_box(sprite_index, box, sprite_x, sprite_y, edges, z)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
class AuthorEngine
|
2
2
|
class Part
|
3
3
|
module Common
|
4
|
+
# returns display width
|
4
5
|
def width
|
5
6
|
128
|
6
7
|
end
|
7
8
|
|
9
|
+
# returns display height
|
8
10
|
def height
|
9
11
|
128
|
10
12
|
end
|
11
13
|
|
14
|
+
# returns frames per seconds
|
12
15
|
def fps
|
13
16
|
if RUBY_ENGINE == "opal"
|
14
17
|
AuthorEngine::GameRunner.instance.fps
|
@@ -17,10 +20,22 @@ class AuthorEngine
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
23
|
+
def distance(x1, y1, x2, y2)
|
24
|
+
dx = x2 - x1
|
25
|
+
dy = y2 - y1
|
26
|
+
|
27
|
+
Math.sqrt(dx * dx + dy * dy)
|
28
|
+
end
|
29
|
+
|
30
|
+
def levels
|
31
|
+
@authorengine_levels ? @authorengine_levels : AuthorEngine::GameRunner.instance.levels
|
32
|
+
end
|
33
|
+
|
34
|
+
# returns number of milliseconds since game started
|
20
35
|
def milliseconds
|
21
36
|
if RUBY_ENGINE == "opal"
|
22
37
|
@__initial_milliseconds ||= `performance.now()`
|
23
|
-
(`performance.now()` - @__initial_milliseconds)
|
38
|
+
(`performance.now()` - @__initial_milliseconds)
|
24
39
|
else
|
25
40
|
Gosu.milliseconds
|
26
41
|
end
|
@@ -12,34 +12,39 @@ class AuthorEngine
|
|
12
12
|
include AuthorEngine::Part::GosuInput
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_accessor :
|
16
|
-
attr_accessor :
|
15
|
+
attr_accessor :authorengine_scale, :authorengine_canvas, :authorengine_canvas_context
|
16
|
+
attr_accessor :authorengine_collision_detection
|
17
17
|
def initialize(code:)
|
18
|
+
@authorengine_code = code
|
19
|
+
|
18
20
|
if RUBY_ENGINE == "opal"
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
21
|
+
@authorengine_scale = 1.0
|
22
|
+
@authorengine_canvas = `document.getElementById('canvas')`
|
23
|
+
@authorengine_canvas_context = `#{@authorengine_canvas}.getContext('2d')`
|
22
24
|
end
|
23
25
|
|
24
26
|
if RUBY_ENGINE != "opal"
|
25
|
-
@
|
27
|
+
@authorengine_sprites = SpriteEditor.instance.sprites
|
26
28
|
|
27
|
-
@
|
29
|
+
@authorengine_levels = []
|
28
30
|
# Create a "Deep Copy" to allow for swapping of a level's sprites without corrupting LevelEditor's version
|
29
31
|
LevelEditor.instance.levels.each do |level|
|
30
|
-
@
|
32
|
+
@authorengine_levels << level.sort_by {|sprite| sprite.z}.map {|sprite| sprite.dup}
|
31
33
|
end
|
32
34
|
size = 16
|
33
|
-
@
|
35
|
+
@authorengine_levels.each {|level| level.each {|sprite| sprite.x = sprite.x * size; sprite.y = sprite.y * size}}
|
34
36
|
|
35
|
-
|
37
|
+
spritesheet = SpriteEditor.instance.spritesheet
|
38
|
+
@authorengine_collision_detection = CollisionDetection.new(@authorengine_sprites, @authorengine_levels, SaveFile::SpriteSheetData.new(spritesheet.width, spritesheet.height, spritesheet.to_blob))
|
36
39
|
|
37
|
-
|
38
|
-
@levels.each {|level| @collision_detection.add_level(level) }
|
40
|
+
self.instance_eval(code)
|
39
41
|
end
|
40
42
|
|
41
43
|
@background_color = black
|
42
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
def authorengine_eval_code
|
47
|
+
self.instance_eval(@authorengine_code)
|
43
48
|
end
|
44
49
|
|
45
50
|
def draw_background
|
@@ -6,27 +6,27 @@ class AuthorEngine
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def text(text, x = 0, y = 0, size = 4, z = 0, color = white)
|
9
|
-
@
|
9
|
+
@authorengine_fonts ||= {}
|
10
10
|
|
11
11
|
font = nil
|
12
12
|
|
13
|
-
if @
|
14
|
-
font = @
|
13
|
+
if @authorengine_fonts.dig(size)
|
14
|
+
font = @authorengine_fonts.dig(size)
|
15
15
|
else
|
16
|
-
font = (@
|
16
|
+
font = (@authorengine_fonts[size] = Gosu::Font.new(size, name: Text::FONT_DEFAULT))
|
17
17
|
end
|
18
18
|
|
19
19
|
font.draw_markup(text, x, y, z, 1, 1, color)
|
20
20
|
end
|
21
21
|
|
22
22
|
def sprite(index, x = 0, y = 0, z = 0, alpha = 255)
|
23
|
-
image = @
|
23
|
+
image = @authorengine_sprites[index]
|
24
24
|
raise "No sprite at '#{index}'!" unless image
|
25
25
|
image.draw(x, y, z, 1,1, Gosu::Color.rgba(255,255,255, alpha))
|
26
26
|
end
|
27
27
|
|
28
28
|
def level(index, z = 0)
|
29
|
-
_level = @
|
29
|
+
_level = @authorengine_levels[index]
|
30
30
|
raise "No level at '#{index}'!" unless _level
|
31
31
|
|
32
32
|
_level.each do |sprite|
|
@@ -35,10 +35,10 @@ class AuthorEngine
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def swap(level, current_sprite, replacement_sprite)
|
38
|
-
_level = @
|
38
|
+
_level = @authorengine_levels[level]
|
39
39
|
raise "No level at '#{index}'!" unless _level
|
40
|
-
raise "No sprite at '#{current_sprite}'!" unless @
|
41
|
-
raise "No sprite at '#{current_sprite}'!" unless @
|
40
|
+
raise "No sprite at '#{current_sprite}'!" unless @authorengine_sprites[current_sprite]
|
41
|
+
raise "No sprite at '#{current_sprite}'!" unless @authorengine_sprites[replacement_sprite]
|
42
42
|
|
43
43
|
_level.each {|sprite| sprite.sprite = replacement_sprite if sprite.sprite == current_sprite}
|
44
44
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "opal"
|
2
2
|
require "fileutils"
|
3
|
+
require_relative "../../version"
|
3
4
|
|
4
5
|
class AuthorEngine
|
5
6
|
class OpalExporter
|
@@ -14,16 +15,16 @@ class AuthorEngine
|
|
14
15
|
return name.split("_").map {|n| n.capitalize}.join(" ")
|
15
16
|
end
|
16
17
|
|
17
|
-
# Rebuild
|
18
|
-
def
|
19
|
-
|
18
|
+
# Rebuild author_engine runtime if it doesn't exist or if its out of date
|
19
|
+
def build_authorengine?
|
20
|
+
authorengine_runtime = "#{export_directory}/js/author_engine.js"
|
20
21
|
|
21
|
-
if File.exists?(
|
22
|
-
file = File.open(
|
22
|
+
if File.exists?(authorengine_runtime)
|
23
|
+
file = File.open(authorengine_runtime)
|
23
24
|
version = file.first.gsub("/", "").strip
|
24
25
|
file.close
|
25
26
|
|
26
|
-
|
27
|
+
AuthorEngine::VERSION != version
|
27
28
|
else
|
28
29
|
true
|
29
30
|
end
|
@@ -42,10 +43,10 @@ body {
|
|
42
43
|
#canvas {
|
43
44
|
display: block;
|
44
45
|
margin: 0 auto;
|
45
|
-
|
46
|
+
cursor: none;
|
46
47
|
}
|
47
48
|
#loading {
|
48
|
-
font-family: Connection, sans
|
49
|
+
font-family: Connection, sans-serif;
|
49
50
|
color: white;
|
50
51
|
text-align: center;
|
51
52
|
|
@@ -62,15 +63,15 @@ body {
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def project
|
66
|
+
file = File.read(@project_file)
|
67
|
+
|
65
68
|
%{
|
66
|
-
var projectString = `#{
|
69
|
+
var projectString = `#{file}`;
|
67
70
|
}
|
68
71
|
end
|
69
72
|
|
70
|
-
def
|
73
|
+
def author_engine_runtime
|
71
74
|
program = %{
|
72
|
-
# require "opal"
|
73
|
-
# require "opal-parser"
|
74
75
|
require "author_engine/opal"
|
75
76
|
|
76
77
|
`var callback = function(){
|
@@ -89,32 +90,25 @@ if (
|
|
89
90
|
|
90
91
|
puts "Transpiling to JavaScript using Opal..."
|
91
92
|
|
92
|
-
|
93
|
-
if
|
94
|
-
puts " Building
|
93
|
+
author_engine_builder = nil
|
94
|
+
if build_authorengine?
|
95
|
+
puts " Building AuthorEngine runtime..."
|
96
|
+
|
97
|
+
author_engine_builder = Opal::Builder.new
|
98
|
+
base_path = File.expand_path("../../../..", __FILE__)
|
99
|
+
author_engine_builder.append_paths("#{base_path}")
|
95
100
|
|
96
|
-
|
97
|
-
opal_builder.build("opal")
|
98
|
-
opal_builder.build("opal-parser")
|
101
|
+
author_engine_builder.build_require("author_engine/opal")
|
99
102
|
else
|
100
|
-
puts " Skipping
|
103
|
+
puts " Skipping AuthorEngine runtime. Already exists and up to date (v#{AuthorEngine::VERSION})..."
|
101
104
|
end
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
game_builder.append_paths("#{base_path}")
|
107
|
-
|
108
|
-
game_builder.build_require("author_engine/opal")
|
109
|
-
|
110
|
-
opal_builder_js = nil
|
111
|
-
if opal_builder
|
112
|
-
opal_runtime_js = opal_builder.build_str("", "(inline)").to_s
|
106
|
+
author_engine_js = nil
|
107
|
+
if author_engine_builder
|
108
|
+
author_engine_js = author_engine_builder.build_str(program, "(inline)").to_s
|
113
109
|
end
|
114
110
|
|
115
|
-
author_engine_js
|
116
|
-
|
117
|
-
return {opal_runtime: opal_runtime_js, author_engine_runtime: author_engine_js}
|
111
|
+
return author_engine_js
|
118
112
|
end
|
119
113
|
|
120
114
|
def template
|
@@ -122,6 +116,7 @@ if (
|
|
122
116
|
<!doctype html5>
|
123
117
|
<html>
|
124
118
|
<head>
|
119
|
+
<meta content="width=device-width, initial-scale=1" name="viewport" />
|
125
120
|
<meta charset="utf-8" />
|
126
121
|
<title>#{project_name} | AuthorEngine</title>
|
127
122
|
</head>
|
@@ -138,19 +133,30 @@ if (
|
|
138
133
|
<script>
|
139
134
|
// Add a small delay before loading application in order to finish loading page and show "Loading..."
|
140
135
|
window.setTimeout(function() {
|
141
|
-
console.log("Loading Opal
|
136
|
+
console.log("Loading Opal...");
|
137
|
+
|
138
|
+
var opal = document.createElement('script');
|
139
|
+
opal.onload = function() {
|
140
|
+
console.log("Loading Opal Parser...");
|
142
141
|
|
143
|
-
|
144
|
-
|
145
|
-
|
142
|
+
var opal_parser = document.createElement('script');
|
143
|
+
opal_parser.onload = function() {
|
144
|
+
Opal.load('opal-parser');
|
146
145
|
|
147
|
-
|
148
|
-
|
149
|
-
|
146
|
+
console.log("Loading AuthorEngine runtime...");
|
147
|
+
|
148
|
+
var author_engine_runtime = document.createElement('script');
|
149
|
+
author_engine_runtime.src = "js/author_engine.js";
|
150
|
+
|
151
|
+
document.head.appendChild(author_engine_runtime);
|
152
|
+
}
|
153
|
+
opal_parser.src = "js/opal-parser.min.js";
|
154
|
+
|
155
|
+
document.head.appendChild(opal_parser);
|
150
156
|
}
|
151
|
-
|
157
|
+
opal.src = "js/opal.min.js";
|
152
158
|
|
153
|
-
document.head.appendChild(
|
159
|
+
document.head.appendChild(opal);
|
154
160
|
}, 500);
|
155
161
|
</script>
|
156
162
|
</body>
|
@@ -191,20 +197,19 @@ if (
|
|
191
197
|
file.write(string)
|
192
198
|
end
|
193
199
|
|
194
|
-
|
195
|
-
|
196
|
-
File.open("#{export_path}/js/runtime.js", "w") do |file|
|
197
|
-
file.write("// #{Opal::VERSION}\n")
|
198
|
-
file.write(hash[:opal_runtime])
|
199
|
-
end
|
200
|
-
end
|
200
|
+
local = File.expand_path("../../../../../vendor", __FILE__)
|
201
|
+
FileUtils.cp(["#{local}/opal.min.js", "#{local}/opal.min.js"], "#{export_directory}/js")
|
201
202
|
|
203
|
+
puts " Building game..."
|
202
204
|
File.open("#{export_path}/game.js", "w") do |file|
|
203
205
|
file.write(project)
|
204
206
|
end
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
+
if runtime = author_engine_runtime
|
209
|
+
File.open("#{export_path}/js/author_engine.js", "w") do |file|
|
210
|
+
file.write("// #{AuthorEngine::VERSION}\n")
|
211
|
+
file.write(runtime)
|
212
|
+
end
|
208
213
|
end
|
209
214
|
|
210
215
|
fonts_path = "#{File.expand_path("../../../../../", __FILE__)}/assets/fonts"
|