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.')
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.')
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.')
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.')
def post_setup_world(): items.reload_all_items() weather.change_weather() maps.create_position_maps() WORLD_INFO['real_time_of_day'] = WORLD_INFO['length_of_day']/2
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')
def post_setup_world(): items.reload_all_items() weather.change_weather() maps.create_position_maps() WORLD_INFO['real_time_of_day'] = WORLD_INFO['length_of_day'] / 2
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')