battleman.py: Broke program into multiple components - data classes and input functions are now in separate modules.
This commit is contained in:
parent
109e967987
commit
cdb245df99
3 changed files with 662 additions and 650 deletions
36
lib/easyinput.py
Normal file
36
lib/easyinput.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# 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))
|
Loading…
Add table
Add a link
Reference in a new issue