Example #1
0
def load_map(map_name, base_dir=MAP_DIR, cache_map=False):
    _map_dir = os.path.join(base_dir, map_name)

    WORLD_INFO['map'] = []

    with open(os.path.join(_map_dir, 'world.meta'), 'r') as _map_file:
        for line in _map_file.readlines():
            line = line.rstrip()
            value = line.split(':')

            if line.startswith('chunk'):
                WORLD_INFO['chunk_map'][value[1]] = json.loads(':'.join(
                    value[2:]))
            #elif line.startswith('slice_map'):
            #	WORLD_INFO['slice_map'] = json.loads(':'.join(value[1:]))
            elif line.startswith('slice'):
                WORLD_INFO['slices'][value[1]] = json.loads(':'.join(
                    value[2:]))
            elif line.startswith('world_info'):
                WORLD_INFO.update(json.loads(':'.join(value[1:])))

        if 'items' in WORLD_INFO:
            ITEMS.update(WORLD_INFO['items'])

        MAP_SIZE[0] = WORLD_INFO['map_size'][0]
        MAP_SIZE[1] = WORLD_INFO['map_size'][1]
        MAP_SIZE[2] = WORLD_INFO['map_size'][2]

        WORLD_INFO['chunk_map'].update(WORLD_INFO['chunk_map'])

        if WORLD_INFO['weather']:
            weather.create_light_map(WORLD_INFO['weather'])

    logging.debug('Caching zones...')
    zones.cache_zones()
    logging.debug('Done!')

    logging.debug('Creating position maps...')
    create_position_maps()
    logging.debug('Done!')

    logging.debug('Reloading references...')
    reload_reference_maps()
    logging.debug('Done!')

    WORLD_INFO['map'] = create_map(blank=True)
    SETTINGS['base_dir'] = _map_dir

    if cache_map:
        cache_all_clusters()

    logging.info('Map \'%s\' loaded.' % map_name)
    gfx.log('Map \'%s\' loaded.' % map_name)
Example #2
0
def load_map(map_name, base_dir=MAP_DIR, cache_map=False):
	_map_dir = os.path.join(base_dir, map_name)

	WORLD_INFO['map'] = []

	with open(os.path.join(_map_dir, 'world.meta'),'r') as _map_file:
		for line in _map_file.readlines():
			line = line.rstrip()
			value = line.split(':')
			
			if line.startswith('chunk'):
				WORLD_INFO['chunk_map'][value[1]] = json.loads(':'.join(value[2:]))
			#elif line.startswith('slice_map'):
			#	WORLD_INFO['slice_map'] = json.loads(':'.join(value[1:]))
			elif line.startswith('slice'):
				WORLD_INFO['slices'][value[1]] = json.loads(':'.join(value[2:]))
			elif line.startswith('world_info'):
				WORLD_INFO.update(json.loads(':'.join(value[1:])))
		
		if 'items' in WORLD_INFO:
			ITEMS.update(WORLD_INFO['items'])
		
		MAP_SIZE[0] = WORLD_INFO['map_size'][0]
		MAP_SIZE[1] = WORLD_INFO['map_size'][1]
		MAP_SIZE[2] = WORLD_INFO['map_size'][2]
		
		WORLD_INFO['chunk_map'].update(WORLD_INFO['chunk_map'])
		
		if WORLD_INFO['weather']:
			weather.create_light_map(WORLD_INFO['weather'])
	
	logging.debug('Caching zones...')
	zones.cache_zones()
	logging.debug('Done!')
	
	logging.debug('Creating position maps...')
	create_position_maps()
	logging.debug('Done!')
	
	logging.debug('Reloading references...')
	reload_reference_maps()
	logging.debug('Done!')
	
	WORLD_INFO['map'] = create_map(blank=True)
	SETTINGS['base_dir'] = _map_dir
	
	if cache_map:
		cache_all_clusters()
	
	logging.info('Map \'%s\' loaded.' % map_name)
	gfx.log('Map \'%s\' loaded.' % map_name)
Example #3
0
def load_map(map_name, base_dir=DATA_DIR):
	_map_dir = os.path.join(base_dir,'maps')
	if not map_name.count('.dat'):
		map_name+='.dat'
		
	WORLD_INFO['map'] = []

	with open(os.path.join(_map_dir,map_name),'r') as _map_file:
		#try:
		#WORLD_INFO.update(json.loads(' '.join(_map_file.readlines())))
		for line in _map_file.readlines():
			line = line.rstrip()
			value = line.split(':')
			
			if line.startswith('chunk'):
				WORLD_INFO['chunk_map'][value[1]] = json.loads(':'.join(value[2:]))
			elif line.startswith('map'):
				WORLD_INFO['map'].append(json.loads(':'.join(value[2:])))
			elif line.startswith('slice'):
				WORLD_INFO['slices'][value[1]] = json.loads(':'.join(value[2:]))
			elif line.startswith('world_info'):
				WORLD_INFO.update(json.loads(':'.join(value[1:])))
		
		if 'items' in WORLD_INFO:
			ITEMS.update(WORLD_INFO['items'])
				
		#if not (x, y) in zone['map']:
		#for slice 
		
		_map_size = maputils.get_map_size(WORLD_INFO['map'])
		MAP_SIZE[0] = _map_size[0]
		MAP_SIZE[1] = _map_size[1]
		MAP_SIZE[2] = _map_size[2]
		
		reload_slices()
		
		WORLD_INFO['chunk_map'].update(WORLD_INFO['chunk_map'])
		
		alife.chunks.generate_cache()
		
		if WORLD_INFO['weather']:
			weather.create_light_map(WORLD_INFO['weather'])
		
		_map_size = maputils.get_map_size(WORLD_INFO['map'])
		
		for x in range(MAP_SIZE[0]):
			for y in range(MAP_SIZE[1]):
				for z in range(MAP_SIZE[2]):
					if not WORLD_INFO['map'][x][y][z]:
						continue
					
					for key in TILE_STRUCT_DEP:
						if key in WORLD_INFO['map'][x][y][z]:
							del WORLD_INFO['map'][x][y][z][key]
					
					for key in TILE_STRUCT:
						if not key in WORLD_INFO['map'][x][y][z]:
							WORLD_INFO['map'][x][y][z][key] = copy.copy(TILE_STRUCT[key])
		
		zones.cache_zones()
		create_position_maps()
		logging.info('Map \'%s\' loaded.' % map_name)
		gfx.log('Map \'%s\' loaded.' % map_name)

		return True