예제 #1
0
파일: view_region.py 프로젝트: Teifion/Rob3
def main(cursor):
	build		= int(common.get_val('build', 0))
	region_name	= common.get_val('region', '').lower()
	
	the_map = mapper.Map_maker()
	
	if build != 0:# Remote mode
		the_map.icon_path = 'images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	use_map_xy(map_x, map_y);"""
	
	source_dict = region_data.get_source_dict(the_map, region_name, build)
	source_dict["build"]		= build
	source_dict["onclick_js"]	= onclick_js
	source_dict["output"]		= the_map.map_grid(cursor)
	
	return mapper.map_source(source_dict)
예제 #2
0
파일: team_map.py 프로젝트: Teifion/Rob3
def _draw_map(cursor, team_id, build):
	minx, maxx = 999999, -9999999
	miny, maxy = 999999, -9999999
	
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=False)
	for city_id, the_city in city_dict.items():
		minx = min(minx, the_city.x)
		maxx = max(maxx, the_city.x)
		
		miny = min(miny, the_city.y)
		maxy = max(maxy, the_city.y)
	
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=False)
	for army_id, the_army in army_dict.items():
		minx = min(minx, the_army.x)
		maxx = max(maxx, the_army.x)
		
		miny = min(miny, the_army.y)
		maxy = max(maxy, the_army.y)
	
	centre = (int((maxx+minx)/2), int((maxy+miny)/2))
	radius = max((maxx-minx), (maxy-miny)) + 300
	
	the_map = mapper.Map_maker()
	the_map.centre = centre
	the_map.centre_radius = radius
	the_map.personalise	= [team_id]
	
	if build != 0:# Remote mode
		the_map.icon_path = '../map/images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	
	use_map_xy(map_x, map_y);"""
	
	source_dict = {
		"build":				build,
		"onclick_js":			onclick_js,
		
		"output":				the_map.map_grid(cursor),
		
		# 'map_path':				"../map/images/theMap.jpg",
		# 'jquery':				"../includes/jquery.js",
		# 'transparent_path':		"../map/images/trans75.png",
		# 'key_path':				"../map/images/key.png",
	}
	
	source_dict['map_legend']	= ''
	
	source_dict["left"]			= the_map.left * 2.5
	source_dict["right"]		= the_map.right
	source_dict["top"]			= the_map.top * 2.5
	source_dict["bottom"]		= the_map.bottom
	
	source_dict["map_width"]	= the_map.width*2.5
	source_dict["map_height"]	= the_map.height*2.5
	
	x_diff = map_data.dimensions['left'] - the_map.left
	y_diff = map_data.dimensions['top'] - the_map.top
	source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
	source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5
	
	if build:
		source_dict['map_path']			= '../map/images/theMap.jpg'
		source_dict['jquery']			= "../includes/jquery.js"
		source_dict['transparent_path']	= "../map/images/trans75.png"
		source_dict['key_path']			= "../map/images/key.png"
	
	output = mapper.map_source(source_dict)
	
	return output
예제 #3
0
파일: view_map.py 프로젝트: Teifion/Rob3
def _draw_map(cursor, build, centre, centre_radius):
	the_map = mapper.Map_maker()
	
	if centre != "":
		centre = centre.split(",")
		the_map.centre = (int(centre[0]), int(centre[1]))
		
		if centre_radius > 0:
			the_map.centre_radius = centre_radius
	
	if build != 0:# Remote mode
		the_map.icon_path = 'images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	
	use_map_xy(map_x, map_y);"""
	
	# new_mode is used when we want to select a location for something
	new_mode = common.get_val('new_mode', "")
	new_mode_form_fields = ""
	
	if new_mode == "edit_city":
		new_mode_form_fields = '<input type="hidden" name="city" value="%s" />' % int(common.get_val('city', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode == "edit_army":
		new_mode_form_fields = '<input type="hidden" name="army" value="%s" />' % int(common.get_val('army', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode =="list_armies" or new_mode =="list_cities":
		new_mode_form_fields = '<input type="hidden" name="team" value="%s" />' % int(common.get_val('team', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode == "setup_battle":
		new_mode_form_fields = '<input type="hidden" name="battle" value="%s" />' % int(common.get_val('battle', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	else:
		if new_mode != '':
			print("No handler for new_mode of '%s' in web.map.view_map" % new_mode)
			exit()
	
	source_dict = {
		"build":				build,
		"onclick_js":			onclick_js,
		
		"new_mode":				new_mode,
		# "map_click_handler":	map_click_handler,
		"new_mode_form_fields": new_mode_form_fields,
		
		"output":				the_map.map_grid(cursor),
	}
	
	if centre != "":
		source_dict['map_legend']	= ''
		
		source_dict["left"]			= the_map.left
		source_dict["right"]		= the_map.right
		source_dict["top"]			= the_map.top
		source_dict["bottom"]		= the_map.bottom
		
		source_dict["map_width"]	= the_map.width*2.5
		source_dict["map_height"]	= the_map.height*2.5
		
		x_diff = map_data.dimensions['left'] - the_map.left
		y_diff = map_data.dimensions['top'] - the_map.top
		source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
		source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5
		
		# print("")
		# print(source_dict)
		
	try:
		if map_click_handler:
			source_dict['map_click_handler'] = map_click_handler
	except Exception:
		pass
	
	return mapper.map_source(source_dict)
예제 #4
0
파일: path_map.py 프로젝트: Teifion/Rob3
def main(cursor):
	points			= common.get_val('points', "")
	move_speed		= common.get_val('move_speed', "Marching")
	move_type		= common.get_val('move_type', "Medium foot")
	
	if points == "":
		page_data['Header'] = True
		page_data['Title'] = "Path map"
		
		# name, elements = {}, element_order = [], tab_index = -1, onchange="", custom_id = "<>", selected=""
		speed_dropdown = common.option_box('move_speed', map_data.move_speed_list, selected="Marching")
		type_dropdown = common.option_box('move_type', map_data.move_type_list, selected="Medium foot")
		
		return """
		<form action="web.py" method="get" accept-charset="utf-8" style="padding:5px;">
			<input type="hidden" name="mode" value="path_map" />
			<table border="0" cellspacing="0" cellpadding="5">
				<tr>
					<td><label for="points">Waypoints:</label></td>
					<td><input type="text" id="points" name="points" value="" size="40"/></td>
				</tr>
				<tr>
					<td><label for="move_speed">Speed:</label></td>
					<td>
						{move_speed}
					</td>
				</tr>
				<tr>
					<td><label for="move_type">Type:</label></td>
					<td>
						{move_type}
					</td>
				</tr>
				<tr>
					<td><input type="submit" value="View" /></td>
					<td>&nbsp;</td>
				</tr>
			</table>
		</form>
		{onload}
		""".format(
			move_speed=speed_dropdown,
			move_type=type_dropdown,
			onload=common.onload("$('#points').focus();")
		)
	
	try:
		move_speed		= map_data.move_speed_list[int(move_speed)]
	except Exception as e:
		pass
	
	try:
		move_type		= map_data.move_type_list[int(move_type)]
	except Exception as e:
		pass
	
	waypoints = []
	points_list = points.split(",")
	for p in range(0, len(points_list), 2):
		waypoints.append((int(points_list[p]), int(points_list[p+1])))

	path_data = path_f.path(cursor, waypoints, move_speed=move_speed, move_type=move_type)
	
	
	float_div = """<div style="background-color:#CCC;position:absolute;top:0px;left:0px;padding:5px;">
	<a href="web.py?mode=path_map">Reset</a><br />
	Distance: {distance}<br />
	Time taken: {time}<br />
	</div>""".format(
		distance = format(path_data.walk_distance, ','),
		time = path_data.time_cost,
	)
	
	
	dimensions = {
		"left":		999999,
		"top":		999999,
		"right":	-999999,
		"bottom":	-999999,
	}

	# Need to work out how big the map will actually be
	radius = 300
	for s in path_data.steps:
		dimensions['left'] = min(dimensions['left'], s['tile'][0] - radius)
		dimensions['right'] = max(dimensions['right'], s['tile'][0] + radius)
	
		dimensions['top'] = min(dimensions['top'], s['tile'][1] - radius)
		dimensions['bottom'] = max(dimensions['bottom'], s['tile'][1] + radius)

	# Make map object
	the_map = mapper.Map_maker()
	the_map.path_data = path_data

	the_map.left	= max(dimensions['left'], the_map.left)
	the_map.right	= min(dimensions['right'], the_map.right)

	the_map.top		= max(dimensions['top'], the_map.top)
	the_map.bottom	= min(dimensions['bottom'], the_map.bottom)


	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);

	use_map_xy(map_x, map_y);"""
	
	source_dict = {
		# "build":				False,
		"onclick_js":			onclick_js,
	
		# "map_click_handler":	map_click_handler,
	
		"output":				the_map.map_grid(cursor),
	}

	source_dict['map_legend']	= ''
	
	source_dict["left"]			= the_map.left * 2.5
	source_dict["right"]		= the_map.right
	source_dict["top"]			= the_map.top * 2.5
	source_dict["bottom"]		= the_map.bottom

	source_dict["map_width"]	= the_map.width*2.5
	source_dict["map_height"]	= the_map.height*2.5

	x_diff = map_data.dimensions['left'] - the_map.left
	y_diff = map_data.dimensions['top'] - the_map.top
	source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
	source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5

	return "%s%s" % (float_div, mapper.map_source(source_dict))
예제 #5
0
파일: cli_f.py 프로젝트: Teifion/Rob3
def output_map(options, the_world=None, skip_upload=False):
	from classes import mapper
	from rules import region_data
	
	if the_world != None:
		cursor = the_world.cursor
	else:
		cursor = database.get_cursor()
	files = {}
	
	#	Map Selector
	#------------------------
	from pages.map import map_select
	f = open('%s/map/index.html' % common.data['woa_folder'], 'w')
	f.write(map_select.make_map_select(cursor))
	f.write(padding)
	f.close()
	
	files['index.html'] = '%s/map/index.html' % common.data['woa_folder']
	
	#	Big map
	#------------------------
	the_map = mapper.Map_maker()
	the_map.icon_path = 'images/teamIcons/'
	source_dict = {
		"build":				1,
		"output":				the_map.map_grid(cursor),
	}
	
	map_source = mapper.map_source(source_dict)
	
	f = open('%s/map/latest.html' % common.data['woa_folder'], 'w')
	f.write(map_source)
	f.write(padding)
	
	f = open('%s/map/turn_%d_normal.html' % (common.data['woa_folder'], common.current_turn()), 'w')
	f.write(map_source)
	f.write(padding)
	
	f.close()
	
	files['latest.html'] = '%s/map/latest.html' % common.data['woa_folder']
	files['turn_%d_normal.html' % common.current_turn()] = '%s/map/turn_%d_normal.html' % (common.data['woa_folder'], common.current_turn())
	
	# Now to make all the region maps
	# for r in region_data.region_list:
	for r in progressbar(region_data.region_list, "Creating Maps: ", 60, True):
		the_map = mapper.Map_maker()
		the_map.icon_path = 'images/teamIcons/'
		
		source_dict = region_data.get_source_dict(the_map, r.name)
		source_dict["output"] = the_map.map_grid(cursor)
		source_dict["build"] = 1
		
		map_source = mapper.map_source(source_dict)
		
		f = open('%s/map/latest_%s.html' % (common.data['woa_folder'], r.name.lower()), 'w')
		f.write(map_source)
		f.write(padding)
		f.close()
		
		f = open('%s/map/turn_%s_%s.html' % (common.data['woa_folder'], common.current_turn(), r.name.lower()), 'w')
		f.write(map_source)
		f.write(padding)
		f.close()
		
		files['latest_%s.html' % r.name.lower()] = '%s/map/latest_%s.html' % (common.data['woa_folder'], r.name.lower())
		files['turn_%s_%s.html' % (common.current_turn(), r.name.lower())] = '%s/map/turn_%s_%s.html' % (common.data['woa_folder'], common.current_turn(), r.name.lower())
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['map'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Map uploaded[/g]'))
예제 #6
0
def map_source(source_dict, zoom=1):
	return mapper.map_source(source_dict, zoom)