37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# easyinput.py
|
|
#
|
|
# These are just some simple helper functions for doing input. They produce a prompt, allow default values,
|
|
# and allow conditional prompting based on the presence or absence of data in a list
|
|
|
|
|
|
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
|
|
full_prompt = prompt
|
|
if default != None and show_default:
|
|
full_prompt = full_prompt + ' [{}]'.format(default)
|
|
full_prompt = full_prompt + '{} '.format(prompt_str)
|
|
|
|
data = raw_input(full_prompt)
|
|
if not data:
|
|
if default == None:
|
|
print 'Error: you must provide a value!'
|
|
return input_str(prompt, default, show_default, prompt_str)
|
|
else:
|
|
return default
|
|
else:
|
|
return data
|
|
|
|
|
|
def input_int(prompt, default=None, show_default=True, prompt_str=':'):
|
|
return int(input_str(prompt, default, show_default))
|
|
|
|
|
|
def do_data_input_str(data, index, prompt, default=None, show_default=False, prompt_str=':'):
|
|
if len(data) >= index + 1:
|
|
return data[index]
|
|
else:
|
|
return input_str(prompt, default, show_default, prompt_str)
|
|
|
|
|
|
def do_data_input_int(battle, data, index, prompt, default=None, show_default=True, prompt_str=':'):
|
|
return int(do_data_select_str(battle, data, index, prompt, default, show_default, prompt_str))
|