コード例 #1
0
ファイル: terraform.py プロジェクト: hovatterz/Reactor-3
def regenerate_world():
	gfx.title('Generating...')
	reload(mapgen)
	
	pre_setup_world()
	
	try:
		mapgen.generate_map(size=(450, 450, 10),
			                towns=1,
			                factories=0,
			                outposts=2,
			                forests=1,
			                skip_zoning=True,
			                skip_chunking=True,
			                hotload=True)
	except:
		import traceback
		traceback.print_exc()
		
		SETTINGS['running'] = 1
		return False
	
	post_setup_world()
	gfx.refresh_view('map')
	
	return True
コード例 #2
0
ファイル: terraform.py プロジェクト: athros/Reactor-3
def regenerate_world(build_test=False):
	gfx.title('Generating...')
	
	reload(mapgen)
	
	if build_test:
		mapgen.create_buildings()
	
	pre_setup_world()
	
	try:
		mapgen.generate_map(towns=1,
			                factories=0,
			                outposts=2,
			                forests=1,
			                skip_zoning=True,
			                skip_chunking=True,
			                hotload=True,
		                     build_test=build_test)
	except:
		import traceback
		traceback.print_exc()
		SETTINGS['running'] = 1
		
		return False
	
	post_setup_world()
	gfx.refresh_view('map')
	
	return True
コード例 #3
0
ファイル: terraform.py プロジェクト: penny64/Reactor-3
def regenerate_world(build_test=False):
    gfx.title('Generating...')

    reload(mapgen)

    if build_test:
        mapgen.create_buildings()

    pre_setup_world()

    try:
        mapgen.generate_map(towns=1,
                            factories=0,
                            outposts=2,
                            forests=1,
                            skip_zoning=True,
                            skip_chunking=True,
                            hotload=True,
                            build_test=build_test)
    except:
        import traceback
        traceback.print_exc()
        SETTINGS['running'] = 1

        return False

    post_setup_world()
    gfx.refresh_view('map')

    return True
コード例 #4
0
ファイル: worldgen.py プロジェクト: athros/Reactor-3
def save_world(create=False):
	gfx.title('Saving...')
	logging.debug('Offloading world...')
	
	if create:
		maps.cache_all_clusters()
	
	_config_directory, _worlds_directory = profiles.has_reactor3()
	_version_file = os.path.join(_worlds_directory, WORLD_INFO['id'], 'version.txt')
	
	with open(_version_file, 'w') as version_file:
		version_file.write(VERSION)

	logging.debug('Saving items...')
	items.save_all_items()
	
	maps.save_map('map', base_dir=profiles.get_world_directory(WORLD_INFO['id']))
	
	logging.debug('Saving life...')
	_life = life.save_all_life()
	
	with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'life.dat'), 'w') as e:
		e.write(_life)
	
	with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items.dat'), 'w') as e:
		e.write(json.dumps(ITEMS))
	
	#cache.commit_cache('items')
	#cache.save_cache('items')
	
	items.reload_all_items()
	
	logging.info('World saved.')
コード例 #5
0
ファイル: terraform.py プロジェクト: athros/Reactor-3
def building_type_selected(entry):
	gfx.title('Loading...')
	
	#pre_setup_world()
	regenerate_world(build_test=entry['key'])
	#mapgen.generate_map(build_test=entry['key'], skip_chunking=True, skip_zoning=True)
	#post_setup_world()
	gfx.refresh_view('map')
	
	SETTINGS['running'] = 2
コード例 #6
0
ファイル: terraform.py プロジェクト: penny64/Reactor-3
def building_type_selected(entry):
    gfx.title('Loading...')

    #pre_setup_world()
    regenerate_world(build_test=entry['key'])
    #mapgen.generate_map(build_test=entry['key'], skip_chunking=True, skip_zoning=True)
    #post_setup_world()
    gfx.refresh_view('map')

    SETTINGS['running'] = 2
コード例 #7
0
ファイル: terraform.py プロジェクト: athros/Reactor-3
def menu_item_selected(entry):
	if MENUS:
		menus.delete_active_menu()
	
	gfx.title('Loading...')
	
	pre_setup_world()
	maps.load_map(entry['key'])
	post_setup_world()
	
	SETTINGS['running'] = 2
コード例 #8
0
ファイル: terraform.py プロジェクト: penny64/Reactor-3
def menu_item_selected(entry):
    if MENUS:
        menus.delete_active_menu()

    gfx.title('Loading...')

    pre_setup_world()
    maps.load_map(entry['key'])
    post_setup_world()

    SETTINGS['running'] = 2
コード例 #9
0
ファイル: setup.py プロジェクト: 220111/Sam-s-Battle-Sim
 def start():
     title()
     time.sleep(1)
     start = input("(s)tart, (q)uit")
     if start == 'S':
         print("please use lowercase letters")
         start()
     elif start == 's':
         time.sleep(1)
         print("A monster approaches")
         mone = 3
         one()
     else:
         sys.exit()
コード例 #10
0
ファイル: mainmenu.py プロジェクト: hovatterz/Reactor-3
def worldgen_menu_select(entry):
	key = entry['key']
	value = entry['values'][entry['value']]
	
	if key == 'Generate':
		graphics.title('Setting up world...')
		generate_world()
		switch_to_main_menu()
	elif key == 'Combat Test':
		graphics.title('Creating combat test...')
		generate_world(combat_test=True)
		switch_to_main_menu()
	elif key == 'Back':
		switch_to_main_menu()
コード例 #11
0
def worldgen_menu_select(entry):
    key = entry['key']
    value = entry['values'][entry['value']]

    if key == 'Generate':
        graphics.title('Setting up world...')
        generate_world()
        switch_to_main_menu()
    elif key == 'Combat Test':
        graphics.title('Creating combat test...')
        generate_world(combat_test=True)
        switch_to_main_menu()
    elif key == 'Back':
        switch_to_main_menu()
コード例 #12
0
def load_world(world):
    global LOADED_CHUNKS

    gfx.title('Loading...')

    LOADED_CHUNKS = {}
    WORLD_INFO['id'] = world
    maps.load_map('map', base_dir=profiles.get_world_directory(world))

    logging.debug('Loading life from disk...')
    with open(
            os.path.join(profiles.get_world_directory(WORLD_INFO['id']),
                         'life.dat'), 'r') as e:
        LIFE.update(json.loads(e.readline()))

    logging.debug('Loading items from disk...')
    with open(
            os.path.join(profiles.get_world_directory(WORLD_INFO['id']),
                         'items.dat'), 'r') as e:
        ITEMS.update(json.loads(e.readline()))

    logging.debug('Loading historic items...')
    #with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items_history.dat'), 'r') as e:
    #	ITEMS_HISTORY.update(json.loads(''.join(e.readlines())))

    maps.reset_lights()

    SETTINGS['controlling'] = None
    SETTINGS['following'] = None
    for life in LIFE.values():
        if life['dead']:
            continue

        if 'player' in life:
            SETTINGS['controlling'] = life['id']
            lfe.focus_on(life)
            break

    lfe.load_all_life()
    items.reload_all_items()

    if SETTINGS['chunk_handler']:
        SETTINGS['chunk_handler'].check_chunks(force=True)

    #logging.debug('Rendering map slices...')
    #maps.render_map_slices()

    logging.info('World loaded.')
コード例 #13
0
ファイル: zones.py プロジェクト: penny64/Reactor-3
def connect_ramps():
	_i = 1
	
	for _slice in WORLD_INFO['slices']:
		#print 'Connecting:','Zone %s' % _slice, '@ z-level',WORLD_INFO['slices'][_slice]['z'], '(%s ramp(s))' % len(WORLD_INFO['slices'][_slice]['ramps'])
		gfx.title('Connecting: %s\%s' % (_i, len(WORLD_INFO['slices'].keys())))
		
		_i += 1
		
		for x,y,z in WORLD_INFO['slices'][_slice]['ramps']:
			for _matched_slice in get_slices_at_z(z):
				if _matched_slice['id']>0:
					if not _matched_slice['id'] in WORLD_INFO['slices'][_slice]['neighbors']:
						WORLD_INFO['slices'][_slice]['neighbors'][_matched_slice['id']] = [(x, y)]
					elif not (x, y) in WORLD_INFO['slices'][_slice]['neighbors'][_matched_slice['id']]:
						WORLD_INFO['slices'][_slice]['neighbors'][_matched_slice['id']].append((x, y))
		
		del WORLD_INFO['slices'][_slice]['ramps']
コード例 #14
0
ファイル: worldgen.py プロジェクト: flags/Reactor-3
def load_world(world):
	global LOADED_CHUNKS
	
	gfx.title('Loading...')
	
	LOADED_CHUNKS = {}
	WORLD_INFO['id'] = world
	maps.load_map('map', base_dir=profiles.get_world_directory(world))

	logging.debug('Loading life from disk...')
	with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'life.dat'), 'r') as e:
		LIFE.update(json.loads(e.readline()))

	logging.debug('Loading items from disk...')
	with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items.dat'), 'r') as e:
		ITEMS.update(json.loads(e.readline()))
	
	logging.debug('Loading historic items...')
	#with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items_history.dat'), 'r') as e:
	#	ITEMS_HISTORY.update(json.loads(''.join(e.readlines())))
	
	maps.reset_lights()
	
	SETTINGS['controlling'] = None
	SETTINGS['following'] = None
	for life in LIFE.values():
		if life['dead']:
			continue
		
		if 'player' in life:
			SETTINGS['controlling'] = life['id']
			lfe.focus_on(life)
			break
	
	lfe.load_all_life()
	items.reload_all_items()
	
	if SETTINGS['chunk_handler']:
		SETTINGS['chunk_handler'].check_chunks(force=True)
	
	#logging.debug('Rendering map slices...')
	#maps.render_map_slices()
	
	logging.info('World loaded.')
コード例 #15
0
ファイル: zones.py プロジェクト: penny64/Reactor-3
def create_zone_map():
	WORLD_INFO['slices'] = {}
	#WORLD_INFO['slice_map'] = maps.create_map()
	WORLD_INFO['zoneid'] = 1
	
	if SETTINGS['running']:
		tcod.console_set_default_foreground(0, tcod.white)
		tcod.console_flush()
	
	_t = time.time()
	if SETTINGS['smp']:
		smp.create_zone_maps()
	else:
		for z in range(MAP_SIZE[2]):
			gfx.title('Zoning: %s\%s' % (z+1, MAP_SIZE[2]))
			process_slice(z)
	
		if SETTINGS['running']:
			tcod.console_print(0, 0, 0, '              ')
	
	print 'Zone gen took',time.time()-_t
コード例 #16
0
def save_world(create=False):
    gfx.title('Saving...')
    logging.debug('Offloading world...')

    if create:
        maps.cache_all_clusters()

    _config_directory, _worlds_directory = profiles.has_reactor3()
    _version_file = os.path.join(_worlds_directory, WORLD_INFO['id'],
                                 'version.txt')

    with open(_version_file, 'w') as version_file:
        version_file.write(VERSION)

    logging.debug('Saving items...')
    items.save_all_items()

    maps.save_map('map',
                  base_dir=profiles.get_world_directory(WORLD_INFO['id']))

    logging.debug('Saving life...')
    _life = life.save_all_life()

    with open(
            os.path.join(profiles.get_world_directory(WORLD_INFO['id']),
                         'life.dat'), 'w') as e:
        e.write(_life)

    with open(
            os.path.join(profiles.get_world_directory(WORLD_INFO['id']),
                         'items.dat'), 'w') as e:
        e.write(json.dumps(ITEMS))

    #cache.commit_cache('items')
    #cache.save_cache('items')

    items.reload_all_items()

    logging.info('World saved.')
コード例 #17
0
ファイル: reactor-3.py プロジェクト: penny64/Reactor-3
def main():
    _player_moved = False
    _refresh_map = False

    get_input()
    handle_input()

    if not LIFE[SETTINGS['controlling']]['dead']:
        if LIFE[SETTINGS['controlling']]['asleep']:
            gfx.fade_to_black(255)
            gfx.start_of_frame()
            gfx.end_of_frame()

        while LIFE[SETTINGS['controlling']]['asleep']:
            _played_moved = True
            _refresh_map = True

            gfx.title(LIFE[SETTINGS['controlling']]['asleep_reason'])
            logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True)

            if LIFE[SETTINGS['controlling']]['dead']:
                break
    else:
        _player_moved = True

    if _refresh_map:
        gfx.refresh_view('map')

    if not _player_moved:
        if logic.tick_all_objects(ignore_tickrate=True):
            _player_moved = True

    draw_targeting()
    move_camera(SETTINGS['camera_track'])

    #TODO: Deselect so we can get rid of this call
    if SELECTED_TILES[0]:
        gfx.refresh_view('map')

    if not SETTINGS['last_camera_pos'] == SETTINGS['camera_track'][:]:
        if EVENTS or MENUS:
            _visible_chunks = sight.scan_surroundings(
                LIFE[SETTINGS['following']], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS['following']],
                             'visible_chunks',
                             value=_visible_chunks)

            _cam_x = numbers.clip(
                LIFE[SETTINGS['following']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2,
                0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2)
            _cam_y = numbers.clip(
                LIFE[SETTINGS['following']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2,
                0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2)

        else:
            _visible_chunks = sight.scan_surroundings(
                LIFE[SETTINGS['controlling']], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS['controlling']],
                             'visible_chunks',
                             value=_visible_chunks)

        SETTINGS['last_camera_pos'] = SETTINGS['camera_track'][:]

    _cam_x = numbers.clip(
        LIFE[SETTINGS['controlling']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0,
        MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2)
    _cam_y = numbers.clip(
        LIFE[SETTINGS['controlling']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0,
        MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2)

    maps.render_lights()

    if '--worldmap' in sys.argv:
        render_map.render_map(WORLD_INFO['map'],
                              force_camera_pos=(_cam_x, _cam_y, 2))
    else:
        render_map.render_map(WORLD_INFO['map'],
                              los=LIFE[SETTINGS['controlling']]['fov'],
                              force_camera_pos=(_cam_x, _cam_y, 2))

    items.draw_items()
    life.draw_life()

    if LIFE[SETTINGS['controlling']]['dead'] and not EVENTS:
        if not death():
            return False

    if SETTINGS['draw life info'] and SETTINGS['following']:
        life.draw_life_info()

    gfx.draw_message_box()

    menus.align_menus()
    menus.draw_menus()

    gfx.draw_status_line()
    gfx.draw_console()
    gfx.start_of_frame()
    gfx.end_of_frame()

    if '--fps' in sys.argv:
        print tcod.sys_get_fps()

    if (SETTINGS['recording'] and _player_moved and not EVENTS
            and not MENUS) or '--worldmap' in sys.argv:
        gfx.screenshot()

        if '--worldmap' in sys.argv:
            SETTINGS['running'] = False
コード例 #18
0
ファイル: reactor-3.py プロジェクト: hovatterz/Reactor-3
def main():
    _player_moved = False
    _refresh_map = False

    get_input()
    handle_input()

    if not LIFE[SETTINGS["controlling"]]["dead"]:
        if LIFE[SETTINGS["controlling"]]["asleep"]:
            gfx.fade_to_black(255)
            gfx.start_of_frame()
            gfx.end_of_frame()

        while LIFE[SETTINGS["controlling"]]["asleep"]:
            _played_moved = True
            _refresh_map = True

            gfx.title(LIFE[SETTINGS["controlling"]]["asleep_reason"])
            logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True)

            if LIFE[SETTINGS["controlling"]]["dead"]:
                break
    else:
        _player_moved = True

    if _refresh_map:
        gfx.refresh_view("map")

    if not _player_moved:
        logic.tick_all_objects(ignore_tickrate=True)

    draw_targeting()
    move_camera(SETTINGS["camera_track"])

    # TODO: Deselect so we can get rid of this call
    if SELECTED_TILES[0]:
        gfx.refresh_view("map")

    if not SETTINGS["last_camera_pos"] == SETTINGS["camera_track"][:]:
        if EVENTS or MENUS:
            _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["following"]], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS["following"]], "visible_chunks", value=_visible_chunks)

            _cam_x = numbers.clip(
                LIFE[SETTINGS["following"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2
            )
            _cam_y = numbers.clip(
                LIFE[SETTINGS["following"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2
            )

        else:
            _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["controlling"]], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS["controlling"]], "visible_chunks", value=_visible_chunks)

        SETTINGS["last_camera_pos"] = SETTINGS["camera_track"][:]

    _cam_x = numbers.clip(
        LIFE[SETTINGS["controlling"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2
    )
    _cam_y = numbers.clip(
        LIFE[SETTINGS["controlling"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2
    )

    maps.render_lights()

    if "--worldmap" in sys.argv:
        render_map.render_map(WORLD_INFO["map"], force_camera_pos=(_cam_x, _cam_y, 2))
    else:
        render_map.render_map(
            WORLD_INFO["map"], los=LIFE[SETTINGS["controlling"]]["fov"], force_camera_pos=(_cam_x, _cam_y, 2)
        )

    items.draw_items()
    life.draw_life()

    if LIFE[SETTINGS["controlling"]]["dead"] and not EVENTS:
        if not death():
            return False

    if SETTINGS["draw life info"] and SETTINGS["following"]:
        life.draw_life_info()

    gfx.draw_message_box()

    menus.align_menus()
    menus.draw_menus()

    gfx.draw_status_line()
    gfx.draw_console()
    gfx.start_of_frame()
    gfx.end_of_frame()

    if "--fps" in sys.argv:
        print tcod.sys_get_fps()

    if (SETTINGS["recording"] and logic.can_tick()) or "--worldmap" in sys.argv:
        gfx.screenshot()

        if "--worldmap" in sys.argv:
            SETTINGS["running"] = False
コード例 #19
0
ファイル: terraform.py プロジェクト: penny64/Reactor-3
def handle_input():
    global PLACING_TILE, RUNNING, SETTINGS, KEYBOARD_STRING

    if gfx.window_is_closed():
        SETTINGS['running'] = False

        return True

    elif INPUT['\x1b'] or INPUT['q']:
        if not ACTIVE_MENU['menu'] == -1 and not SETTINGS['running'] == 1:
            ACTIVE_MENU['menu'] = -1

            return True

        SETTINGS['running'] = False

        return True

    elif INPUT['-']:
        if SETTINGS['draw console']:
            SETTINGS['draw console'] = False
        else:
            SETTINGS['draw console'] = True

    elif SETTINGS['draw console']:
        return

    elif INPUT['up']:
        if not ACTIVE_MENU['menu'] == -1:
            menus.move_up(MENUS[ACTIVE_MENU['menu']],
                          MENUS[ACTIVE_MENU['menu']]['index'])
        else:
            CURSOR_POS[1] -= SETTINGS['cursor speed']

    elif INPUT['down']:
        if not ACTIVE_MENU['menu'] == -1:
            menus.move_down(MENUS[ACTIVE_MENU['menu']],
                            MENUS[ACTIVE_MENU['menu']]['index'])
        else:
            CURSOR_POS[1] += SETTINGS['cursor speed']

    elif INPUT['right']:
        if not ACTIVE_MENU['menu'] == -1:
            menus.next_item(MENUS[ACTIVE_MENU['menu']],
                            MENUS[ACTIVE_MENU['menu']]['index'])
            menus.item_changed(ACTIVE_MENU['menu'],
                               MENUS[ACTIVE_MENU['menu']]['index'])
        else:
            CURSOR_POS[0] += SETTINGS['cursor speed']

    elif INPUT['left']:
        if not ACTIVE_MENU['menu'] == -1:
            menus.previous_item(MENUS[ACTIVE_MENU['menu']],
                                MENUS[ACTIVE_MENU['menu']]['index'])
            menus.item_changed(ACTIVE_MENU['menu'],
                               MENUS[ACTIVE_MENU['menu']]['index'])
        else:
            CURSOR_POS[0] -= SETTINGS['cursor speed']

    elif INPUT[' ']:
        menus.activate_menu_by_name('Buildings')

    elif INPUT['n']:
        for alife in LIFE:
            life.memory(alife,
                        'focus_on_chunk',
                        chunk_key=life.get_current_chunk_id(
                            LIFE[SETTINGS['controlling']]))

    elif INPUT['\r']:
        if ACTIVE_MENU['menu'] == -1:
            return False

        menus.item_selected(ACTIVE_MENU['menu'],
                            MENUS[ACTIVE_MENU['menu']]['index'])
        ACTIVE_MENU['menu'] = -1

    elif INPUT['\t']:
        pass

    elif INPUT['c']:
        CURSOR_POS[0] = MAP_SIZE[0] / 2
        CURSOR_POS[1] = MAP_SIZE[1] / 2

    elif INPUT['m']:
        if SETTINGS['running'] == 2:
            gfx.add_view_to_scene_by_name('chunk_map')
            gfx.set_active_view('chunk_map')

            SETTINGS['running'] = 3
        elif SETTINGS['running'] == 3:
            gfx.remove_view_from_scene_by_name('chunk_map')
            gfx.set_active_view('map')
            SETTINGS['running'] = 2

    elif INPUT['r']:
        if regenerate_world():
            SETTINGS['running'] = 2

    elif INPUT['s']:
        items.save_all_items()

        gfx.title('Generating Chunk Map')
        maps.update_chunk_map()

        gfx.title('Zoning...')
        zones.create_zone_map()

        gfx.title('Saving...')
        maps.save_map(str(time.time()), only_cached=False)
        items.reload_all_items()

    elif INPUT['l']:
        SUN_BRIGHTNESS[0] += 4

    elif INPUT['k']:
        SUN_BRIGHTNESS[0] -= 4

    elif INPUT['1']:
        CAMERA_POS[2] = 1
        gfx.refresh_view('map')

    elif INPUT['2']:
        CAMERA_POS[2] = 2
        gfx.refresh_view('map')

    elif INPUT['3']:
        CAMERA_POS[2] = 3
        gfx.refresh_view('map')

    elif INPUT['4']:
        CAMERA_POS[2] = 4
        gfx.refresh_view('map')

    elif INPUT['5']:
        CAMERA_POS[2] = 5
        gfx.refresh_view('map')

    elif INPUT['6']:
        CAMERA_POS[2] = 6
        gfx.refresh_view('map')

    elif INPUT['7']:
        CAMERA_POS[2] = 7
        gfx.refresh_view('map')

    elif INPUT['8']:
        CAMERA_POS[2] = 8
        gfx.refresh_view('map')

    elif INPUT['9']:
        CAMERA_POS[2] = 9
        gfx.refresh_view('map')

    elif INPUT['0']:
        CAMERA_POS[2] = 0
        gfx.refresh_view('map')
コード例 #20
0
ファイル: worldgen.py プロジェクト: athros/Reactor-3
def cleanup():
	if not WORLD_INFO['id']:
		return False
	
	gfx.title('Saving cache...')
	cache.save_cache('items')
コード例 #21
0
ファイル: terraform.py プロジェクト: athros/Reactor-3
def handle_input():
	global PLACING_TILE,RUNNING,SETTINGS,KEYBOARD_STRING

	if gfx.window_is_closed():
		SETTINGS['running'] = False
		
		return True
	
	elif INPUT['\x1b'] or INPUT['q']:
		if not ACTIVE_MENU['menu'] == -1 and not SETTINGS['running'] == 1:
			ACTIVE_MENU['menu'] = -1
			
			return True
			
		SETTINGS['running'] = False
		
		return True
	
	elif INPUT['-']:
		if SETTINGS['draw console']:
			SETTINGS['draw console'] = False
		else:
			SETTINGS['draw console'] = True
	
	elif SETTINGS['draw console']:
		return

	elif INPUT['up']:
		if not ACTIVE_MENU['menu'] == -1:
			menus.move_up(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index'])
		else:
			CURSOR_POS[1] -= SETTINGS['cursor speed']

	elif INPUT['down']:
		if not ACTIVE_MENU['menu'] == -1:
			menus.move_down(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index'])
		else:
			CURSOR_POS[1] += SETTINGS['cursor speed']

	elif INPUT['right']:
		if not ACTIVE_MENU['menu'] == -1:
			menus.next_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index'])
			menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
		else:
			CURSOR_POS[0] += SETTINGS['cursor speed']

	elif INPUT['left']:
		if not ACTIVE_MENU['menu'] == -1:
			menus.previous_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index'])
			menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
		else:
			CURSOR_POS[0] -= SETTINGS['cursor speed']

	elif INPUT[' ']:
		menus.activate_menu_by_name('Buildings')
	
	elif INPUT['n']:
		for alife in LIFE:
			life.memory(alife, 'focus_on_chunk', chunk_key=life.get_current_chunk_id(LIFE[SETTINGS['controlling']]))
	
	elif INPUT['\r']:
		if ACTIVE_MENU['menu'] == -1:
			return False
		
		menus.item_selected(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
		ACTIVE_MENU['menu'] = -1
	
	elif INPUT['\t']:
		pass

	elif INPUT['c']:
		CURSOR_POS[0] = MAP_SIZE[0]/2
		CURSOR_POS[1] = MAP_SIZE[1]/2

	elif INPUT['m']:
		if SETTINGS['running'] == 2:
			gfx.add_view_to_scene_by_name('chunk_map')
			gfx.set_active_view('chunk_map')
			
			SETTINGS['running'] = 3
		elif SETTINGS['running'] == 3:
			gfx.remove_view_from_scene_by_name('chunk_map')
			gfx.set_active_view('map')
			SETTINGS['running'] = 2

	elif INPUT['r']:
		if regenerate_world():
			SETTINGS['running'] = 2

	elif INPUT['s']:
		items.save_all_items()
		
		gfx.title('Generating Chunk Map')
		maps.update_chunk_map()
		
		gfx.title('Zoning...')
		zones.create_zone_map()
		
		gfx.title('Saving...')
		maps.save_map(str(time.time()), only_cached=False)
		items.reload_all_items()

	elif INPUT['l']:
		SUN_BRIGHTNESS[0] += 4
	
	elif INPUT['k']:
		SUN_BRIGHTNESS[0] -= 4

	elif INPUT['1']:
		CAMERA_POS[2] = 1
		gfx.refresh_view('map')

	elif INPUT['2']:
		CAMERA_POS[2] = 2
		gfx.refresh_view('map')

	elif INPUT['3']:
		CAMERA_POS[2] = 3
		gfx.refresh_view('map')

	elif INPUT['4']:
		CAMERA_POS[2] = 4
		gfx.refresh_view('map')

	elif INPUT['5']:
		CAMERA_POS[2] = 5
		gfx.refresh_view('map')
	
	elif INPUT['6']:
		CAMERA_POS[2] = 6
		gfx.refresh_view('map')
	
	elif INPUT['7']:
		CAMERA_POS[2] = 7
		gfx.refresh_view('map')
	
	elif INPUT['8']:
		CAMERA_POS[2] = 8
		gfx.refresh_view('map')
	
	elif INPUT['9']:
		CAMERA_POS[2] = 9
		gfx.refresh_view('map')
	
	elif INPUT['0']:
		CAMERA_POS[2] = 0
		gfx.refresh_view('map')
コード例 #22
0
def cleanup():
    if not WORLD_INFO['id']:
        return False

    gfx.title('Saving cache...')
    cache.save_cache('items')