Class: RubyArmor::ReviewCode
- Inherits:
-
Fidgit::DialogState
- Object
- Fidgit::DialogState
- RubyArmor::ReviewCode
- Defined in:
- lib/ruby_armor/states/review_code.rb
Constant Summary collapse
- LEVELS =
(1..9).to_a + [:EPIC]
Class Method Summary collapse
- .path_for_level(profile, level) ⇒ Object
-
.saved_levels?(profile) ⇒ Boolean
Check if there are levels saved that can be recalled.
Instance Method Summary collapse
-
#initialize(profile) ⇒ ReviewCode
constructor
A new instance of ReviewCode.
- #path_for_level(level) ⇒ Object
Constructor Details
#initialize(profile) ⇒ ReviewCode
Returns a new instance of ReviewCode.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_armor/states/review_code.rb', line 16 def initialize(profile) super(shadow_full: true) on_input :escape, :hide @profile = profile vertical spacing: 10, align: :center, border_thickness: 4, background_color: Color::BLACK do label "Reviewing code that completed levels in #{profile.tower.name} tower", font_height: 20 @tab_group = group do @tab_buttons = horizontal padding: 0, spacing: 4 do LEVELS.each do |level| if File.exists?(path_for_level(level)) level.to_s, level, border_thickness: 0, tip: "View code used to complete level #{level}" else level.to_s, border_thickness: 0, enabled: false, tip: "No code saved for level #{level}" end end horizontal padding_left: 50, padding: 0 do "copy", tip: "Copy displayed code to clipboard", font_height: 12, border_thickness: 0, padding: 4 do Clipboard.copy @code.stripped_text end end end subscribe :changed do |_, value| = @tab_buttons.each.grep Fidgit::RadioButton current = .find {|b| b.value == value } .each {|b| b.enabled = (b != current) } current.color, current.background_color = current.background_color, current.color @code.text = File.read path_for_level(value) end end # Contents of those tabs. vertical padding: 0 do scroll_window width: 700, height: 430 do @code = text_area width: 680 end end "Close", shortcut: :auto, shortcut_color: Play::SHORTCUT_COLOR, align_h: :center, border_thickness: 0 do hide end # Pick the last level we have completed (and saved the code). @tab_group.value = LEVELS.to_a.reverse.find {|level| File.exists? path_for_level(level) } end end |
Class Method Details
.path_for_level(profile, level) ⇒ Object
6 7 8 |
# File 'lib/ruby_armor/states/review_code.rb', line 6 def path_for_level(profile, level) File.join(profile.player_path, "ruby_armor/player_#{level.is_a?(Symbol) ? level : level.to_s.rjust(3, '0')}.rb") end |
.saved_levels?(profile) ⇒ Boolean
Check if there are levels saved that can be recalled.
11 12 13 |
# File 'lib/ruby_armor/states/review_code.rb', line 11 def saved_levels?(profile) LEVELS.any? {|level| File.exists? path_for_level(profile, level) } end |
Instance Method Details
#path_for_level(level) ⇒ Object
71 72 73 |
# File 'lib/ruby_armor/states/review_code.rb', line 71 def path_for_level(level) self.class.path_for_level @profile, level end |