Skip to content

Commit

Permalink
Moves width and height from command-line arguments to config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Apr 12, 2013
1 parent a888256 commit 1c56c4b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from controllers import *
from timer import Timer

def safe_add_to_config(section, option, default_value):

def get_or_update_config(section, option, default_value, conv=str):
try:
user_value = globals.config.get(section, option)
user_value = conv(globals.config.get(section, option))
except NoSectionError:
globals.config.add_section(section)
except NoOptionError:
Expand All @@ -48,13 +49,18 @@ def get_key(key_name):


def initialize_config():
safe_add_to_config('World', 'flat', 'false') # dont make mountains, make a flat world
safe_add_to_config('World', 'size', '64')
safe_add_to_config('World', 'show_fog', 'true')
globals.WINDOW_WIDTH = get_or_update_config(
'Graphics', 'width', globals.WINDOW_WIDTH, conv=int)
globals.WINDOW_HEIGHT = get_or_update_config(
'Graphics', 'height', globals.WINDOW_HEIGHT, conv=int)

get_or_update_config('World', 'flat', 'false') # dont make mountains, make a flat world
get_or_update_config('World', 'size', '64')
get_or_update_config('World', 'show_fog', 'true')

# Adds missing keys to configuration file and converts to pyglet keys.
for control, default_key_name in globals.KEY_BINDINGS.items():
key_name = safe_add_to_config('Controls', control, default_key_name)
key_name = get_or_update_config('Controls', control, default_key_name)
try:
pyglet_key = get_key(key_name)
except InvalidKey:
Expand All @@ -67,8 +73,9 @@ def initialize_config():


class Window(pyglet.window.Window):
def __init__(self, width, height, launch_fullscreen=False, show_gui=True,**kwargs):
super(Window, self).__init__(width, height, **kwargs)
def __init__(self, launch_fullscreen=False, show_gui=True, **kwargs):
super(Window, self).__init__(
globals.WINDOW_WIDTH, globals.WINDOW_HEIGHT, **kwargs)
self.exclusive = False
self.reticle = None
self.controller = None
Expand Down Expand Up @@ -130,7 +137,7 @@ def main(options):
globals.TERRAIN = globals.TERRAIN_CHOICES[options.terrain]

if options.flat:
safe_add_to_config('World', 'flat', 'true')
get_or_update_config('World', 'flat', 'true')

if options.fast:
globals.TIME_RATE /= 20
Expand All @@ -157,10 +164,10 @@ def main(options):

# try:
# window_config = Config(sample_buffers=1, samples=4) #, depth_size=8) #, double_buffer=True) #TODO Break anti-aliasing/multisampling into an explicit menu option
# window = Window(show_gui=options.show_gui, width=options.width, height=options.height, caption='pyCraftr', resizable=True, config=window_config, save=save_object)
# window = Window(show_gui=options.show_gui, caption='pyCraftr', resizable=True, config=window_config, save=save_object)
# except pyglet.window.NoSuchConfigException:
window = Window(
options.width, options.height, launch_fullscreen=options.fullscreen,
launch_fullscreen=options.fullscreen,
show_gui=options.show_gui, caption=globals.APP_NAME, resizable=True,
vsync=False)

Expand All @@ -173,8 +180,6 @@ def main(options):
parser = argparse.ArgumentParser(description='Play a Python made Minecraft clone.')

display_group = parser.add_argument_group('Display options')
display_group.add_argument("--width", type=int, default=globals.WINDOW_WIDTH, help="Set the window width.")
display_group.add_argument("--height", type=int, default=globals.WINDOW_HEIGHT, help="Set the window height.")
display_group.add_argument("--show-gui", action="store_true", default=True, help="Enabled by default.")
display_group.add_argument("--draw-distance", choices=globals.DRAW_DISTANCE_CHOICES, default=globals.DEFAULT_DRAW_DISTANCE_CHOICE, help="How far to draw the map.")
display_group.add_argument("--fullscreen", action="store_true", default=False, help="Runs the game in fullscreen. Press 'Q' to exit the game.")
Expand Down

0 comments on commit 1c56c4b

Please sign in to comment.