Class: RubyArmor::CreateProfile
- Inherits:
-
Fidgit::DialogState
- Object
- Fidgit::DialogState
- RubyArmor::CreateProfile
- Defined in:
- lib/ruby_armor/states/create_profile.rb
Constant Summary collapse
- DEFAULT_WARRIOR_CLASS =
:valkyrie
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(game, warrior_sprites) ⇒ CreateProfile
constructor
A new instance of CreateProfile.
- #new_profile(name) ⇒ Object
- #play(profile, config) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(game, warrior_sprites) ⇒ CreateProfile
Returns a new instance of CreateProfile.
5 6 7 8 9 10 11 12 13 14 15 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 |
# File 'lib/ruby_armor/states/create_profile.rb', line 5 def initialize(game, warrior_sprites) @game = game super shadow_full: true on_input :escape, :hide on_input [:return, :enter] do .activate if .enabled? end # Option to create a new profile. vertical align: :center, border_thickness: 4, background_color: Color::BLACK do label "Create new profile", font_height: 20 @new_name = text_area width: 300, height: 30, font_height: 20 do |_, text| duplicate = @game.profiles.any? {|p| p.warrior_name.downcase == text.downcase } .enabled = !(text.empty? or duplicate) end # Choose class; just cosmetic. @warrior_class = group align_h: :center do horizontal padding: 0, align_h: :center do DungeonView::WARRIORS.each do |warrior, row| "", warrior, tip: "Play as a #{warrior.capitalize} (The difference between classes is purely cosmetic!)", :icon => warrior_sprites[0, row], :icon_options => { :factor => 4 } end end end horizontal align: :center do "Cancel" do hide end = "Create", justify: :center, tip: "Create a new profile" do play *new_profile(@new_name.text) end end new_name = File.basename File.("~") new_name = "Player" if new_name.empty? @new_name.text = new_name @warrior_class.value = DEFAULT_WARRIOR_CLASS end end |
Instance Method Details
#finalize ⇒ Object
57 58 59 60 |
# File 'lib/ruby_armor/states/create_profile.rb', line 57 def finalize super container.clear end |
#new_profile(name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruby_armor/states/create_profile.rb', line 68 def new_profile(name) new_profile = RubyWarrior::Profile.new new_profile.tower_path = @game.towers[0].path new_profile.warrior_name = name config = WarriorConfig.new new_profile config.warrior_class = @warrior_class.value [new_profile, config] end |
#play(profile, config) ⇒ Object
62 63 64 65 66 |
# File 'lib/ruby_armor/states/create_profile.rb', line 62 def play(profile, config) @game.instance_variable_set :@profile, profile hide push_game_state Play.new(@game, config) end |
#update ⇒ Object
52 53 54 55 |
# File 'lib/ruby_armor/states/create_profile.rb', line 52 def update super @new_name.focus self unless @new_name.focused? end |