author_engine 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdf3e00f6f0e8840311bc2fb5c77c7dfe56c0bf9de8efa7cb310468b649d4ff4
4
- data.tar.gz: b32cfb362b8bdfe3c408ac8e113082c94c68faaa2475afbc91b8e97ffdee2ffe
3
+ metadata.gz: f4708e029c91cdcb46645b45bf91a957c24a0fa5f9526a4160da593d0a1ac109
4
+ data.tar.gz: 5270d1b8af030bf17c53a8d332e8e07dfd84b70aaf505580a52c094856bd69c3
5
5
  SHA512:
6
- metadata.gz: 0ddf727d607cd61cf2aa34551c8489cc8af8af44c26c263eed9faac1f0ac7ff0563ccbe8ea400a4762d050f08f6a76e40d874484770ee833d28340de3bdb66fd
7
- data.tar.gz: 91335c5c61622bb198535bb62bd15b5ad3db5eb10f2aa290dfc3b7ff7bc05e96b5ed270834eca6ee25721d1ace97bd30c9587746eabaa3f4217cfd236a8d7560
6
+ metadata.gz: d2f1290dd9488db2e3fbb6c7af5ba34e1b2f2ea441f76cc8bb22b3ae6f42040d6230e68c514a7a05677b1f0336574ab4e6207f33bb4d47f49a690a7a8ff46b1d
7
+ data.tar.gz: 584f14bc9da7a63e19cbd633f65a8c6e1fc6d05e2b5aa9c152dc05d67bf7c09031c01db94cd0543848c10d828fb220452be1db583c4fa70b780aaa84d973aa62
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- author_engine (0.6.0)
4
+ author_engine (0.6.1)
5
5
  coderay (~> 1.1.2)
6
6
  gosu (~> 0.14.4)
7
7
  opal (~> 0.11.4)
@@ -11,9 +11,9 @@ GEM
11
11
  specs:
12
12
  ast (2.4.0)
13
13
  coderay (1.1.2)
14
- gosu (0.14.4)
14
+ gosu (0.14.5)
15
15
  hike (1.2.3)
16
- minitest (5.11.3)
16
+ minitest (5.13.0)
17
17
  opal (0.11.4)
18
18
  ast (>= 2.3.0)
19
19
  hike (~> 1.2)
@@ -34,4 +34,4 @@ DEPENDENCIES
34
34
  rake (~> 10.0)
35
35
 
36
36
  BUNDLED WITH
37
- 1.17.2
37
+ 1.17.3
@@ -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(image_or_blob)
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 = "red"
106
+ collision_color = "purple"
98
107
  end
99
108
  paint_color = color
100
109
  # EDGE: TOP
@@ -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) > 0
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
@@ -32,10 +32,7 @@ class AuthorEngine
32
32
  size = 16
33
33
  @levels.each {|level| level.each {|sprite| sprite.x = sprite.x * size; sprite.y = sprite.y * size}}
34
34
 
35
- @collision_detection = CollisionDetection.new(@sprites, @levels)
36
-
37
- @sprites.each {|sprite| @collision_detection.add_sprite(sprite) }
38
- @levels.each {|level| @collision_detection.add_level(level) }
35
+ @collision_detection = CollisionDetection.new(@sprites, @levels, Window.instance.container.savefile.sprites)
39
36
  end
40
37
 
41
38
  @background_color = black
@@ -45,7 +45,7 @@ body {
45
45
  // cursor: none;
46
46
  }
47
47
  #loading {
48
- font-family: Connection, sans serif;
48
+ font-family: Connection, sans-serif;
49
49
  color: white;
50
50
  text-align: center;
51
51
 
@@ -62,8 +62,10 @@ body {
62
62
  end
63
63
 
64
64
  def project
65
+ file = File.read(@project_file)
66
+
65
67
  %{
66
- var projectString = `#{File.open(@project_file).read}`;
68
+ var projectString = `#{file}`;
67
69
  }
68
70
  end
69
71
 
@@ -36,11 +36,9 @@ class AuthorEngine
36
36
  build_spritesheet_and_sprites_list
37
37
  resize_canvas
38
38
 
39
- @collision_detection = AuthorEngine::CollisionDetection.new(@sprites, @levels)
39
+ @collision_detection = AuthorEngine::CollisionDetection.new(@sprites, @levels, @save_file.sprites)
40
40
  @game.collision_detection = @collision_detection
41
41
 
42
- @levels.each {|level| @collision_detection.add_level(level) }
43
-
44
42
  @game.init
45
43
 
46
44
  @show_touch_controls = false
@@ -191,7 +189,6 @@ class AuthorEngine
191
189
  (width/size).times do |x|
192
190
  `#{temp_canvas_context}.clearRect(0,0, #{size}, #{size})`
193
191
  `#{temp_canvas_context}.drawImage(#{@spritesheet}, #{x * size}, #{y * size}, #{size}, #{size}, 0, 0, #{size}, #{size})`
194
- @collision_detection.add_sprite(`#{temp_canvas_context}.getImageData(0,0, #{size}, #{size}).data`)
195
192
 
196
193
  `createImageBitmap(#{@spritesheet}, #{x * size}, #{y * size}, #{size}, #{size}).then(sprite => { #{@sprites.push(`sprite`)} })`
197
194
  end
@@ -54,7 +54,7 @@ class AuthorEngine
54
54
 
55
55
  @buttons << Button.new(label: ">", x: @buttons.last.x + @buttons.last.width + @offset, y: @y + @offset*2, z: 18, tooltip: "→ Next Level", color: Gosu::Color::GRAY) do
56
56
  @active_level+=1
57
- @active_level = 0 if @active_level >= LevelEditor.instance.levels.size - 1
57
+ @active_level = 0 unless @active_level < LevelEditor.instance.levels.size
58
58
  end
59
59
  end
60
60
 
@@ -15,11 +15,12 @@ class AuthorEngine
15
15
  end
16
16
  end
17
17
 
18
- attr_reader :file
18
+ attr_reader :file, :mode
19
19
  attr_reader :code, :sprites, :levels
20
20
  def initialize(file)
21
21
  @file = file
22
22
  @buffer = ""
23
+ @mode = :compact # or :inflated
23
24
 
24
25
  @code, @sprites, @levels = nil, nil, nil
25
26
 
@@ -27,6 +28,7 @@ class AuthorEngine
27
28
  end
28
29
 
29
30
  def save
31
+ @buffer = "# inflated\n" if inflated?
30
32
  save_code
31
33
  save_spritesheet
32
34
  save_levels
@@ -39,16 +41,58 @@ class AuthorEngine
39
41
  puts "Saved #{file}"
40
42
  end
41
43
 
42
- def save_code
43
- @buffer+= "___CODE___\n"
44
- @buffer+= CodeEditor.instance.code
44
+ def inflate!
45
+ load
46
+ @mode = :inflated
47
+ save_code(@code)
48
+ save_spritesheet(Gosu::Image.new(@sprites, retro: true))
49
+
50
+ file = File.read(@file)
51
+ unless file.lines.first.include?("# inflated")
52
+ File.open(@file, "w") do |f|
53
+ f.write "# inflated\n"
54
+ f.write file
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ def inflated?
61
+ @mode == :inflated
62
+ end
63
+
64
+ def project_name
65
+ File.basename(@file, ".authorengine")
66
+ end
67
+
68
+ def project_path
69
+ File.expand_path(@file).sub(File.basename(@file), "")
70
+ end
71
+
72
+ # code is a String
73
+ def save_code(code = CodeEditor.instance.code)
74
+ if inflated?
75
+ @buffer+= "___CODE___?#{project_path}#{project_name}.rb\n"
76
+ File.write("#{project_path}#{project_name}.rb", code)
77
+ puts "Saved code to #{project_path}#{project_name}.rb"
78
+ else
79
+ @buffer+= "___CODE___\n"
80
+ end
81
+ @buffer+= code
45
82
  # @buffer+="\n" # CodeEditor always has this newline
46
83
  end
47
84
 
48
- def save_spritesheet
49
- sheet = SpriteEditor.instance.spritesheet
85
+ # sheet is a Gosu::Image
86
+ def save_spritesheet(sheet = SpriteEditor.instance.spritesheet)
87
+
88
+ if inflated?
89
+ @buffer+= "___SPRITES___?#{project_path}#{project_name}.png\n"
90
+ sheet.save("#{project_path}#{project_name}.png")
91
+ puts "Saved spritesheet to #{project_path}#{project_name}.png"
92
+ else
93
+ @buffer+= "___SPRITES___\n"
94
+ end
50
95
 
51
- @buffer+= "___SPRITES___\n"
52
96
  @buffer+="#{sheet.width}x#{sheet.height}"
53
97
  @buffer+="\n"
54
98
 
@@ -78,16 +122,32 @@ class AuthorEngine
78
122
  string = data
79
123
  end
80
124
 
125
+ identify_mode(string)
126
+
81
127
  load_code(string)
82
128
  load_spritesheet(string)
83
129
  load_levels(string)
84
130
  end
85
131
 
132
+ def identify_mode(string)
133
+ if RUBY_ENGINE != "opal" && string.lines.size > 0 && string.lines.first.include?("# inflated")
134
+ @mode = :inflated
135
+ else
136
+ @mode = :compact
137
+ end
138
+ end
139
+
86
140
  def load_code(string)
87
141
  buffer = ""
88
142
  in_code= false
89
143
  string.each_line do |line|
90
144
  if line.start_with?("___CODE___")
145
+ if line.strip.include?("?") && inflated?
146
+ # load from file
147
+ puts "Loading code from: #{line.strip.split("?").last}"
148
+ buffer = File.read(line.strip.split("?").last)
149
+ break
150
+ end
91
151
  in_code = true
92
152
  next
93
153
  end
@@ -109,6 +169,14 @@ class AuthorEngine
109
169
 
110
170
  string.each_line do |line|
111
171
  if line.strip.start_with?("___SPRITES___")
172
+ if line.strip.include?("?") && inflated?
173
+ # load from file
174
+ puts "Loading spritesheet from: #{line.strip.split("?").last}"
175
+ image = Gosu::Image.new(line.strip.split("?").last, retro: true)
176
+ buffer = image.to_blob
177
+ width, height = image.width, image.height
178
+ break
179
+ end
112
180
  in_sprites = true
113
181
  next
114
182
  end
@@ -131,7 +199,11 @@ class AuthorEngine
131
199
 
132
200
  stream = nil
133
201
  if RUBY_ENGINE != "opal"
134
- stream = buffer.scan(/../).map { |x| x.hex }.pack('c*')
202
+ if inflated?
203
+ stream = buffer
204
+ else
205
+ stream = buffer.scan(/../).map { |x| x.hex }.pack('c*')
206
+ end
135
207
  else
136
208
  stream = buffer.scan(/../).map { |x| Integer(x.hex) }
137
209
  end
@@ -145,6 +217,12 @@ class AuthorEngine
145
217
 
146
218
  string.each_line do |line|
147
219
  if line.start_with?("___LEVELS___")
220
+ # if line.strip.start_with?("__LEVELS___?")
221
+ # # load from file
222
+ # puts "Loading level data from: #{line.strip.split("?").last}"
223
+
224
+ # break
225
+ # end
148
226
  in_level = true
149
227
  next
150
228
  end
@@ -1,3 +1,3 @@
1
1
  class AuthorEngine
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: author_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyberarm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-26 00:00:00.000000000 Z
11
+ date: 2019-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -189,8 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.7.8
192
+ rubygems_version: 3.0.4
194
193
  signing_key:
195
194
  specification_version: 4
196
195
  summary: A virtual console that you code in Ruby.