Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map metadata #104

Merged
merged 7 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'nodeattr_utils', github: 'alces-software/nodeattr_utils'
gem 'recursive-open-struct'
gem 'rubyzip'
gem 'tty-editor'
gem 'tty-prompt'
gem 'xmlhasher'
gem 'paint'

Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ DEPENDENCIES
recursive-open-struct
rubyzip
tty-editor
tty-prompt
xmlhasher

BUNDLED WITH
Expand Down
25 changes: 25 additions & 0 deletions lib/inventoryware/commands/modifys/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module Commands
module Modifys
class Map < SingleNodeCommand
def action(node)
prompt = TTY::Prompt.new
unless prompt.no?('Would you like to add map metadata? (Default: No)')
get_map_metadata_from_user(node, prompt)
end

map = map_to_string(node.data['mutable']['map'])
map = string_to_map(edit_with_tmp_file(map, :"rvim +'set number'"))
node.data['mutable']['map'] = map
Expand Down Expand Up @@ -63,6 +68,26 @@ def string_to_map(str)
end
return map
end

def get_map_metadata_from_user(node, prompt)
prompt.say('Enter integer values for the dimensions of the map:')

x = prompt.ask('X:') do |q|
q.validate(/^[0-9]+$/, 'Value must be an integer')
end

y = prompt.ask('Y:') do |q|
q.validate(/^[0-9]+$/, 'Value must be an integer')
end

pattern = prompt.select(
'Choose the pattern for the map:',
%w(DownRight RightDown RightUp UpRight)
)

node.data['mutable']['map_dimensions'] = "#{x}x#{y}"
node.data['mutable']['map_pattern'] = pattern
end
end
end
end
Expand Down