Class: Reight::Project
- Inherits:
-
Object
- Object
- Reight::Project
- Includes:
- Xot::Inspectable
- Defined in:
- lib/reight/project.rb
Instance Attribute Summary collapse
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #chips ⇒ Object
- #chips_image ⇒ Object
- #chips_image_height ⇒ Object
- #chips_image_name ⇒ Object
- #chips_image_path ⇒ Object
- #chips_image_width ⇒ Object
- #chips_json_name ⇒ Object
- #chips_json_path ⇒ Object
- #chips_npages ⇒ Object
- #chips_page_height ⇒ Object
- #chips_page_width ⇒ Object
- #clear_all_sprites ⇒ Object
- #code_paths ⇒ Object
- #codes ⇒ Object
- #font ⇒ Object
- #font_size ⇒ Object
-
#initialize(project_dir) ⇒ Project
constructor
A new instance of Project.
- #maps ⇒ Object
- #maps_json_name ⇒ Object
- #maps_json_path ⇒ Object
- #palette_colors ⇒ Object
- #project_path ⇒ Object
- #save ⇒ Object
- #sounds ⇒ Object
- #sounds_json_name ⇒ Object
- #sounds_json_path ⇒ Object
Constructor Details
#initialize(project_dir) ⇒ Project
Returns a new instance of Project.
8 9 10 11 12 13 |
# File 'lib/reight/project.rb', line 8 def initialize(project_dir) raise 'the project directory is required' unless project_dir @project_dir = project_dir @settings = {} load end |
Instance Attribute Details
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
15 16 17 |
# File 'lib/reight/project.rb', line 15 def project_dir @project_dir end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
15 16 17 |
# File 'lib/reight/project.rb', line 15 def settings @settings end |
Instance Method Details
#chips ⇒ Object
31 32 33 |
# File 'lib/reight/project.rb', line 31 def chips() @chips ||= load_chips end |
#chips_image ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/reight/project.rb', line 43 def chips_image() @chips_image ||= -> { create_graphics(chips_image_width, chips_image_height).tap do |g| g.begin_draw {g.background 0, 0, 0, 0} img = load_image chips_image_path g.begin_draw {g.image img, 0, 0} rescue Rays::RaysError end }.call end |
#chips_image_height ⇒ Object
41 |
# File 'lib/reight/project.rb', line 41 def chips_image_height = settings[__method__] || 1024 |
#chips_image_name ⇒ Object
35 |
# File 'lib/reight/project.rb', line 35 def chips_image_name = settings[__method__] || 'chips.png' |
#chips_image_path ⇒ Object
37 |
# File 'lib/reight/project.rb', line 37 def chips_image_path = "#{project_dir}/#{chips_image_name}" |
#chips_image_width ⇒ Object
39 |
# File 'lib/reight/project.rb', line 39 def chips_image_width = settings[__method__] || 1024 |
#chips_json_name ⇒ Object
27 |
# File 'lib/reight/project.rb', line 27 def chips_json_name = settings[__method__] || 'chips.json' |
#chips_json_path ⇒ Object
29 |
# File 'lib/reight/project.rb', line 29 def chips_json_path = "#{project_dir}/#{chips_json_name}" |
#chips_npages ⇒ Object
58 59 60 61 62 63 |
# File 'lib/reight/project.rb', line 58 def chips_npages() w = chips_image_width / chips_page_width .to_f h = chips_image_height / chips_page_height.to_f raise unless w == w.to_i && h == h.to_i (w * h).to_i end |
#chips_page_height ⇒ Object
56 |
# File 'lib/reight/project.rb', line 56 def chips_page_height = settings[__method__] || 256 |
#chips_page_width ⇒ Object
54 |
# File 'lib/reight/project.rb', line 54 def chips_page_width = settings[__method__] || 256 |
#clear_all_sprites ⇒ Object
87 88 89 90 |
# File 'lib/reight/project.rb', line 87 def clear_all_sprites() chips.each(&:clear_sprite) maps.each(&:clear_sprites) end |
#code_paths ⇒ Object
19 |
# File 'lib/reight/project.rb', line 19 def code_paths = settings[__method__]&.then {[_1].flatten} || ['game.rb'] |
#codes ⇒ Object
21 22 23 24 25 |
# File 'lib/reight/project.rb', line 21 def codes() code_paths .map {File. _1, project_dir} .map {File.read _1 rescue nil} end |
#font ⇒ Object
81 |
# File 'lib/reight/project.rb', line 81 def font = @font ||= create_font(nil, font_size) |
#font_size ⇒ Object
83 |
# File 'lib/reight/project.rb', line 83 def font_size = 8 |
#maps ⇒ Object
69 70 71 |
# File 'lib/reight/project.rb', line 69 def maps() @maps ||= load_maps end |
#maps_json_name ⇒ Object
65 |
# File 'lib/reight/project.rb', line 65 def maps_json_name = settings[__method__] || 'maps.json' |
#maps_json_path ⇒ Object
67 |
# File 'lib/reight/project.rb', line 67 def maps_json_path = "#{project_dir}/#{maps_json_name}" |
#palette_colors ⇒ Object
85 |
# File 'lib/reight/project.rb', line 85 def palette_colors = Reight::App::PALETTE_COLORS.dup |
#project_path ⇒ Object
17 |
# File 'lib/reight/project.rb', line 17 def project_path = "#{project_dir}/project.json" |
#save ⇒ Object
92 93 94 95 96 97 |
# File 'lib/reight/project.rb', line 92 def save() File.write project_path, to_json_string(@settings) save_chips save_maps save_sounds end |
#sounds ⇒ Object
77 78 79 |
# File 'lib/reight/project.rb', line 77 def sounds() @sounds ||= load_sounds end |
#sounds_json_name ⇒ Object
73 |
# File 'lib/reight/project.rb', line 73 def sounds_json_name = settings[__method__] || 'sounds.json' |
#sounds_json_path ⇒ Object
75 |
# File 'lib/reight/project.rb', line 75 def sounds_json_path = "#{project_dir}/#{sounds_json_name}" |