Пример #1
0
def message(request, game, player, message_id):
    """
	Display message
	"""

    message = player.message_set.get(pk=message_id)

    message.html, _ = parse_markdown(message.content)
    message.html = mark_safe(message.html)

    return {"message": message}
Пример #2
0
def message(request, game, player, message_id):
	"""
	Display message
	"""

	message = player.message_set.get(pk=message_id)

	message.html, _ = parse_markdown(message.content)
	message.html = mark_safe(message.html)

	return {
		"message": message
	}
Пример #3
0
def player(request, game, player, player_id):
	"""
	Player datas
	"""
	player = Player.objects.select_related('influence', 'citizenship__corporation').get(pk=player_id, game_id=game.pk)
	corporations = Corporation.objects.filter(game=player.game, share__player=player).annotate(qty_share=Count('share')).order_by('-qty_share')

	rp, _ = parse_markdown(player.rp)
	rp = mark_safe(rp)

	return {
		"player": player,
		"rp": rp,
		"corporations": corporations
	}
Пример #4
0
def player(request, game, player, player_id):
    """
	Player datas
	"""
    player = Player.objects.select_related(
        'influence', 'citizenship__corporation').get(pk=player_id,
                                                     game_id=game.pk)
    corporations = Corporation.objects.filter(
        game=player.game, share__player=player).annotate(
            qty_share=Count('share')).order_by('-qty_share')

    rp, _ = parse_markdown(player.rp)
    rp = mark_safe(rp)

    return {"player": player, "rp": rp, "corporations": corporations}
Пример #5
0
	def get_display(self, display_context, is_personal=False):
		"""
		Return a formatted string with the Log values, according to is_personal (are we displaying this for the player who triggered the action ?) and display_context (is the reader already aware of the corporation? The corporationmarket?)
		"""

		if is_personal:
			path_personal = 'personal'
		else:
			path_personal = 'not_personal'

		# Read file data
		file_name = self.event_type
		path = '%s/logs/templates/logs/%s/%s/%s.md' % (settings.BASE_DIR, path_personal, display_context, file_name.lower())
		raw_template = read_file_from_path(path)

		# Parse template
		context = Context(json.loads(self.data))
		template = Template(raw_template)
		text = template.render(context)

		html, _ = parse_markdown(text)
		return html
Пример #6
0
def index(request, page):

	# On récupère le game id si on l'a en session pour accéder aux onglets de la session en cours
	gameid = None
	try:
		gameid = request.session['gameid']
	except:
		pass

	if page == '':
		page = 'index'

	page = '%s/data/docs/%s.md' % (settings.BASE_DIR, page.replace('.', ''))

	raw = ""
	try:
		raw = read_file_from_path(page)
	except IOError:
		raise Http404("No documentation on this subject.")

	# Replace custom {{ corporations }} markup with a list of corporations:
	def list_corporation_as_markdown():
		strings = ["* [%s](corporations/%s.md)" % (c.name, c.slug) for c in BaseCorporation.retrieve_all()]
		return "\n".join(strings)
	raw = raw.replace('{{ corporations }}', list_corporation_as_markdown())
	content, metas = parse_markdown(raw)

	try:
		title = metas['title'][0]
	except:
		title = "Corporate Game"

	title = mark_safe(title)
	content = mark_safe(content)

	data = get_base_data()
	data.update({"content": content, "title": title, "gameid": gameid, "request": request})
	return render(request, 'docs/index.html', data)
Пример #7
0
	def as_html(self):
		content, _ = parse_markdown(self.content)
		return mark_safe(content)
Пример #8
0
def player(request, player, game, player_id, turn):
	"""
	Player data
	"""

	# Set the game_id in session to always display all tabs
	request.session['gameid'] = game.pk

	player_profile = Player.objects.get(pk=player_id, game_id=game.pk)
	corporations = Corporation.objects.filter(game=player.game, share__player=player_profile).annotate(qty_share=Count('share')).order_by('-qty_share')

	rp, _ = parse_markdown(player_profile.rp)
	rp = mark_safe(rp)

	events = Log.objects.for_player(player=player_profile, asking_player=player, turn=turn)

	if player == player_profile:
		money = unicode(get_current_money(player_profile, turn)) + u" k"
		help_text_money = u"Argent disponible"
	else:
		# The money is supposed to be a personal information.
		# If you have used a information  operation to get the money next turn on a player you are supposed to see it
		# But only the money at start of the turn, not the money left on player right now
		help_text_money = u"Argent disponible pour le tour"
		# We have to find a log that is linked to both players
		concernedPlayer = ConcernedPlayer.objects.filter(log__event_type=game.MONEY_NEXT_TURN, log__game=game, log__turn=turn - 1).order_by('log')
		is_target = False
		is_spy = False
		last_log = None
		for m2m in concernedPlayer:
			if last_log != m2m.log:
				is_target = False
				is_spy = False
				last_log = m2m.log
			if m2m.player == player:
				is_spy = True
			if m2m.player == player_profile and m2m.personal:
				is_target = True
			if is_target and is_spy:
				break

		if is_target and is_spy:
			data = Log.objects.filter(event_type=game.MONEY_NEXT_TURN, game=game, turn=turn - 1, concernedplayer__player=player_profile, concernedplayer__personal=True)[0].data
			context = json.loads(data)
			money = unicode(context['money']) + u" k"
		else:
			money = '?'

	# We do not display the background as long as the viewer doesn't used an information opération to see it
	# The targeted player is saved in database as a string in the data field which is a json serialized
	# We will rebuild the piece of string we need and find if it exists in the string stored in database
	piece_of_string = u'"player_id": ' + unicode(player_profile.id)
	if player == player_profile or Log.objects.filter(event_type=game.BACKGROUND, game=game, data__contains=piece_of_string, concernedplayer__player=player).count() > 0:
		background = player_profile.background
	else:
		background = u"Vous devez lancer une opération d'information contre ce joueur pour connaitre son background"

	return {
		"player_profile": player_profile,
		"money": money,
		"rp": rp,
		"corporations": corporations,
		"qty_shares": sum([corporation.qty_share for corporation in corporations]),
		"events": events,
		"request": request,
		"citizenship": player_profile.citizenship.corporation,
		"pods": ['d_inc', 'current_player', 'players', ],
		"turn": game.current_turn,
		"background": background,
		"help_text_money": help_text_money,
	}