Skip to content

Commit

Permalink
[#87267412] add $PROGRAM_NAME/../___assets__ to find asset path.
Browse files Browse the repository at this point in the history
  • Loading branch information
takaokouji committed Jun 12, 2015
1 parent 4e58adc commit a90e47d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/smalruby/character.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ def next_costume

# コスチュームを( )にする
def switch_costume(name)
if (index = @costume_name__index[name])
self.costume_index = index
if @costume_name__index.key?(name)
index = @costume_name__index[name]
else
index = 0
end
self.costume_index = index
end

def costume_index=(val)
Expand Down Expand Up @@ -564,6 +567,7 @@ def sync_angle(x, y)
def asset_path(name)
program_path = Pathname($PROGRAM_NAME).expand_path(Dir.pwd)
paths = [Pathname("../#{name}").expand_path(program_path),
Pathname("../__assets__/#{name}").expand_path(program_path),
Pathname("../../../assets/#{name}").expand_path(__FILE__)]
paths.find { |path| path.file? }.to_s
end
Expand Down
Binary file added samples/__assets__/extra_car2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions samples/costume2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
require 'smalruby'

car1 = Character.new(x: 0, y: 0, costume: 'extra_car2.png')

car1.on(:start) do
loop do
move(5)
if reach_wall?
turn
end
end
end

0 comments on commit a90e47d

Please sign in to comment.