Class: Reight::Project

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/reight/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dirObject (readonly)

Returns the value of attribute project_dir.



15
16
17
# File 'lib/reight/project.rb', line 15

def project_dir
  @project_dir
end

#settingsObject (readonly)

Returns the value of attribute settings.



15
16
17
# File 'lib/reight/project.rb', line 15

def settings
  @settings
end

Instance Method Details

#chipsObject



31
32
33
# File 'lib/reight/project.rb', line 31

def chips()
  @chips ||= load_chips
end

#chips_imageObject



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_heightObject



41
# File 'lib/reight/project.rb', line 41

def chips_image_height = settings[__method__] || 1024

#chips_image_nameObject



35
# File 'lib/reight/project.rb', line 35

def chips_image_name   = settings[__method__] || 'chips.png'

#chips_image_pathObject



37
# File 'lib/reight/project.rb', line 37

def chips_image_path   = "#{project_dir}/#{chips_image_name}"

#chips_image_widthObject



39
# File 'lib/reight/project.rb', line 39

def chips_image_width  = settings[__method__] || 1024

#chips_json_nameObject



27
# File 'lib/reight/project.rb', line 27

def chips_json_name   = settings[__method__] || 'chips.json'

#chips_json_pathObject



29
# File 'lib/reight/project.rb', line 29

def chips_json_path   = "#{project_dir}/#{chips_json_name}"

#chips_npagesObject



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_heightObject



56
# File 'lib/reight/project.rb', line 56

def chips_page_height = settings[__method__] || 256

#chips_page_widthObject



54
# File 'lib/reight/project.rb', line 54

def chips_page_width  = settings[__method__] || 256

#clear_all_spritesObject



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_pathsObject



19
# File 'lib/reight/project.rb', line 19

def code_paths   = settings[__method__]&.then {[_1].flatten} || ['game.rb']

#codesObject



21
22
23
24
25
# File 'lib/reight/project.rb', line 21

def codes()
  code_paths
    .map {File.expand_path _1, project_dir}
    .map {File.read _1 rescue nil}
end

#fontObject



81
# File 'lib/reight/project.rb', line 81

def font           = @font ||= create_font(nil, font_size)

#font_sizeObject



83
# File 'lib/reight/project.rb', line 83

def font_size      = 8

#mapsObject



69
70
71
# File 'lib/reight/project.rb', line 69

def maps()
  @maps ||= load_maps
end

#maps_json_nameObject



65
# File 'lib/reight/project.rb', line 65

def maps_json_name = settings[__method__] || 'maps.json'

#maps_json_pathObject



67
# File 'lib/reight/project.rb', line 67

def maps_json_path = "#{project_dir}/#{maps_json_name}"

#palette_colorsObject



85
# File 'lib/reight/project.rb', line 85

def palette_colors = Reight::App::PALETTE_COLORS.dup

#project_pathObject



17
# File 'lib/reight/project.rb', line 17

def project_path = "#{project_dir}/project.json"

#saveObject



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

#soundsObject



77
78
79
# File 'lib/reight/project.rb', line 77

def sounds()
  @sounds ||= load_sounds
end

#sounds_json_nameObject



73
# File 'lib/reight/project.rb', line 73

def sounds_json_name = settings[__method__] || 'sounds.json'

#sounds_json_pathObject



75
# File 'lib/reight/project.rb', line 75

def sounds_json_path = "#{project_dir}/#{sounds_json_name}"