示例#1
0
	async def on_map_begin(self, map, **kwargs):
		is_active  = await self.setting_dynatime_active.get_value()

		if not is_active:
			return

		multiplier = await self.setting_dynatime_multiplier.get_value(refresh=True)
		
		mode_settings = await self.instance.mode_manager.get_settings()

		if 'S_TimeLimit' not in mode_settings:
			raise ModeIncompatibe('Current mode doesn\'t support Dynatime. Not TimeAttack?')

		timelimit = int(multiplier * map.time_bronze / 1000)
		timelimit_ms = timelimit * 1000;

		mode_settings['S_TimeLimit'] = timelimit


		bm_time = format_time( time=map.time_bronze, hide_milliseconds=True)
		new_time = format_time( time=timelimit_ms, hide_milliseconds=True)
		mname = style_strip( map.name, STRIP_ALL)
		chat_message = "$FF0$oDynatime$z set new timelimit for map $fff%s$z$ff0 to $fff⏳ %s$ff0, based on the bronze-medal of $fff🏆 %s$z" % ( mname, new_time, bm_time )

		await self.instance.mode_manager.update_settings(mode_settings)
	
		announce = await self.setting_dynatime_announce.get_value()
		if announce:
			await self.instance.chat(chat_message)
示例#2
0
    async def get_data(self):
        first_time = self.app.current_records[0].score if len(
            self.app.current_records) > 0 else None
        record_limit = await self.app.setting_record_limit.get_value()
        if record_limit > 0:
            records = self.app.current_records[:record_limit]
        else:
            records = self.app.current_records

        index = 1
        items = []
        for item in records:
            record_player = item.player
            record_time_difference = ''
            if index > 1:
                record_time_difference = '$f00 + ' + times.format_time(
                    (item.score - first_time))
            items.append({
                'id': item.get_id(),
                'index': index,
                'player_nickname': record_player.nickname,
                'record_time': times.format_time(item.score),
                'record_time_difference': record_time_difference
            })
            index += 1

        return items
示例#3
0
	async def get_context_data(self):
		self.widget_y = 12.5 if self.app.dedimania_enabled else 70.5
		self.title = "Total Time ({})".format(self.map_count)
		context = await super().get_context_data()
		
		
		index_range = 10
		data_length = 0
		datas_length = 0
		player_spot = 0
		toprange = 0
		
		
		global player_index		
		pindex_length = len(self.datas)
		try:
			pindex = [x[0] for x in self.datas].index(player_index)
		except:
			pindex = 0
		index = 1
		list_records = []
		min_index = 0
		max_index = 0
		if self.datas != 0:
			for login, nickname, total in self.datas[:5]:
				list_record = dict()
				list_record['index'] = index	
				list_record['color'] = '$ff0'				
				if login == player_index:
					list_record['color'] = '$0f3'
				list_record['nickname'] = nickname
				list_record['score'] = times.format_time(int(total))
				list_records.append(list_record)
				index += 1
			if pindex_length > 5:
				if pindex > 15 :
					min_index = pindex - 5
					max_index = pindex + 5
					index = pindex - 4
				else:
					min_index = 5
					max_index = 15
					
			for login, nickname, total in self.datas[min_index:max_index]:
				list_record = dict()
				list_record['index'] = index
				list_record['color'] = '$fff'
				if login == player_index:
					list_record['color'] = '$0f3'
				list_record['nickname'] = nickname
				list_record['score'] = times.format_time(int(total))
				list_records.append(list_record)
				index += 1

		context.update({
				'times': list_records
		})	
		
		return context
示例#4
0
	async def get_data(self):
		compare_cps = [int(c) for c in self.compare_record.checkpoints.split(',')]
		own_cps = [int(c) for c in self.own_record.checkpoints.split(',')] \
			if self.own_record else [0 for _ in compare_cps]
		total_cps = len(own_cps)

		return [dict(
				cp='Finish' if (cp + 1) == total_cps else cp + 1,
				own_time=format_time(own) if own else '',
				compare_time=format_time(compare),
				difference=self.get_diff_text(own, compare) if self.own_record else '-'
			) for cp, (own, compare) in enumerate(zip(own_cps, compare_cps))]
示例#5
0
    async def get_data(self):
        own_cps = [int(c) for c in self.own_record.cps.split(',')]
        compare_cps = [int(c) for c in self.compare_record.cps.split(',')]
        total_cps = len(own_cps)

        data = list()
        for cp, (own, compare) in enumerate(zip(own_cps, compare_cps)):
            data.append(
                dict(cp='Finish' if (cp + 1) == total_cps else cp + 1,
                     own_time=format_time(own),
                     compare_time=format_time(compare),
                     difference=self.get_diff_text(own, compare)))

        return data
示例#6
0
    async def get_data(self):
        compare_cps = self.compare_record.cps
        own_cps = self.own_record.cps if self.own_record else [
            None for _ in compare_cps
        ]
        total_cps = len(own_cps)

        return [
            dict(cp='Finish' if (cp + 1) == total_cps else cp + 1,
                 own_time=format_time(own) if own else '',
                 compare_time=format_time(compare),
                 difference=self.get_diff_text(own, compare)
                 if self.own_record else '-')
            for cp, (own, compare) in enumerate(zip(own_cps, compare_cps))
        ]
示例#7
0
 async def get_data(self):
     items = []
     async with self.app.lock:
         first_time = self.app.current_records[0].score
         for index, item in enumerate(self.app.current_records, start=1):
             record_time_difference = ''
             if index > 1:
                 record_time_difference = '$f00 + ' + times.format_time(
                     (item.score - first_time))
             items.append({
                 'index': index,
                 'nickname': item.nickname,
                 'record_time': times.format_time(item.score),
                 'record_time_difference': record_time_difference
             })
     return items
示例#8
0
文件: views.py 项目: lyovav/PyPlanet
    async def get_context_data(self):
        map = self.app.instance.map_manager.current_map
        map_author = map.author_login
        try:
            author = await self.app.instance.player_manager.get_player(
                map.author_login)
            map_author = author.nickname
        except PlayerNotFound:
            if map.author_nickname:
                map_author = map.author_nickname

        context = await super().get_context_data()
        context.update({
            'map_name':
            map.name,
            'map_author':
            map_author,
            'map_authortime':
            times.format_time(map.time_author)
            if map.time_author and map.time_author > 0 else '-',
            'map_environment':
            map.environment,
        })

        return context
示例#9
0
文件: views.py 项目: reaby/PyPlanet
    async def get_context_data(self):
        map = self.app.instance.map_manager.current_map

        # Load related info from other apps if installed and enabled, such as MX link.
        mx_link = None
        if 'mx' in self.app.instance.apps.apps:
            if map.uid in self.mx_link_cache:
                mx_link = self.mx_link_cache[map.uid]
            else:
                # Fetch, validate and make link.
                mx_info = await self.app.instance.apps.apps['mx'].api.map_info(
                    map.uid)
                if mx_info and len(mx_info) >= 1:
                    mx_link = 'https://{}.mania-exchange.com/s/tr/{}'.format(
                        self.app.instance.apps.apps['mx'].api.site,
                        mx_info[0][0])
                self.mx_link_cache[map.uid] = mx_link

        context = await super().get_context_data()
        context.update({
            'map_name':
            map.name,
            'map_mx_link':
            mx_link,
            'map_author':
            map.author_login,
            'map_authortime':
            times.format_time(map.time_author)
            if map.time_author and map.time_author > 0 else '-',
            'map_environment':
            map.environment,
        })

        return context
示例#10
0
 async def get_data(self):
     list_times = self.app.best_cp_times
     return [{
         'index': pcp.cp,
         'player_nickname': pcp.player.nickname,
         'record_time': times.format_time(pcp.time)
     } for pcp in list_times]
示例#11
0
    async def get_context_data(self):
        context = await super().get_context_data()

        # Add facts.
        context.update({'top_entries': self.top_entries})

        record_limit = await self.app.setting_record_limit.get_value()
        if record_limit > 0:
            current_records = self.app.current_records[:record_limit]
        else:
            current_records = self.app.current_records

        if self.app.instance.performance_mode:
            list_records = list()
            records = list(current_records[:self.record_amount])

            index = 1
            for record in records:
                record_player = await record.get_related('player')
                list_record = dict()
                list_record['index'] = index
                list_record['color'] = '$fff'
                if index <= self.top_entries:
                    list_record['color'] = '$ff0'
                list_record['nickname'] = record_player.nickname
                list_record['score'] = times.format_time(int(record.score))
                index += 1
                list_records.append(list_record)

            context.update({'times': list_records})

        return context
示例#12
0
    async def get_context_data(self):
        context = await super().get_context_data()

        # Add facts.
        context.update({'top_entries': self.top_entries})

        if self.app.instance.performance_mode:
            list_records = list()
            records = list(self.app.current_records[:self.record_amount])

            index = 1
            for record in records:
                list_record = dict()
                list_record['index'] = index
                list_record['color'] = '$fff'
                if index <= self.top_entries:
                    list_record['color'] = '$ff0'
                list_record['nickname'] = record.nickname
                list_record['score'] = times.format_time(int(record.score))
                index += 1
                list_records.append(list_record)

            context.update({'times': list_records})

        return context
示例#13
0
 def render_optional_time(row, field):
     value = row[field['index']]
     if value is None:
         return ''
     if isinstance(value, (int, float)) and not math.isnan(value):
         return times.format_time(int(value))
     return 'None'
示例#14
0
    async def get_data(self):
        if self.cache and self.advanced == self.cache_advanced:
            return self.cache

        self.fields, self.map_list, self.folder_info, self.folder_instance = \
         await self.folder_manager.get_folder_code_contents(self.folder_code)

        self.title = 'Folder: ' + self.folder_info['name']

        karma = any(f['index'] == "karma" for f in self.fields)
        length = any(f['index'] == "local_record" for f in self.fields)

        items = []
        for item in self.map_list:
            dict_item = model_to_dict(item)
            if length:
                dict_item['local_record'] = times.format_time(
                    (item.local['first_record'].score
                     if hasattr(item, 'local') and item.local['first_record']
                     else 0))
            if karma and 'karma' in self.app.instance.apps.apps:
                dict_item['karma'] = (await
                                      self.app.instance.apps.apps['karma'].
                                      get_map_karma(item))['map_karma']
            items.append(dict_item)

        self.cache = items
        return self.cache
示例#15
0
 async def get_context_data(self):
     context = await super().get_context_data()
     context.update({
         'best_lap_login': self.best_lap_login,
         'best_lap_time': times.format_time(self.best_lap_time)
     })
     return context
示例#16
0
	async def map_to_dict(self, map):
		dict_item = model_to_dict(map)
		if any(f['index'] == "local_record" for f in self.fields):
			dict_item['local_record'] = times.format_time((map.local['first_record'].score if hasattr(map, 'local') and map.local['first_record'] else 0))
		if any(f['index'] == "karma" for f in self.fields) and 'karma' in self.app.instance.apps.apps:
			dict_item['karma'] = (await self.app.instance.apps.apps['karma'].get_map_karma(map))['map_karma']

		return dict_item
示例#17
0
    async def get_data(self):
        items = []
        list_times = self.app.best_times
        first_time = list_times[0].time
        for idx, pt in enumerate(list_times):
            time_difference = ''
            if idx > 0:
                time_difference = '$f00 + ' + times.format_time(
                    (pt.time - first_time))
            items.append({
                'index': idx + 1,
                'player_nickname': pt.player.nickname,
                'record_time': times.format_time(pt.time),
                'record_time_difference': time_difference
            })

        return items
示例#18
0
    def get_diff_text(self, a, b):
        diff = a - b
        diff_prefix = '$FFF'
        if diff > 0:
            diff_prefix = '$F66+'  # Red
        elif diff < 0:
            diff_prefix = '$6CF- '  # Blue

        return '{}{}'.format(diff_prefix, format_time(abs(diff)))
示例#19
0
    async def show_records_list(self, player, data=None, **kwargs):
        """
		Show record list view to player.

		:param player: Player instance.
		:param data: -
		:param kwargs: -
		:type player: pyplanet.apps.core.maniaplanet.models.Player
		:return: view instance or nothing when there are no records.
		"""
        if not len(self.current_records):
            message = '$i$f00There are currently no dedimania records on this map!'
            await self.instance.chat(message, player)
            return

        # TODO: Move logic to view class.
        index = 1
        view = DedimaniaRecordsListView(self)
        view_data = []

        async with self.lock:
            first_time = self.current_records[0].score
            for item in self.current_records:
                record_time_difference = ''
                if index > 1:
                    record_time_difference = '$f00 + ' + times.format_time(
                        (item.score - first_time))
                view_data.append({
                    'index':
                    index,
                    'nickname':
                    item.nickname,
                    'record_time':
                    times.format_time(item.score),
                    'record_time_difference':
                    record_time_difference
                })
                index += 1
        view.objects_raw = view_data
        view.title = 'Dedimania Records on {}'.format(
            self.instance.map_manager.current_map.name)
        await view.display(player=player.login)
        return view
示例#20
0
def test_time_parsing():
    raw = 14004
    expect = '0:14.004'
    assert times.format_time(raw) == expect

    raw = 20135
    expect = '0:20.135'
    assert times.format_time(raw) == expect

    raw = 65195
    expect = '1:05.195'
    assert times.format_time(raw) == expect

    raw = 605195
    expect = '10:05.195'
    assert times.format_time(raw) == expect

    raw = 6005195
    expect = '01:40:05.195'
    assert times.format_time(raw) == expect
示例#21
0
    async def get_data(self):
        items = []
        list_times = self.app.best_cp_times
        for pcp in list_times:
            items.append({
                'index': pcp.cp,
                'player_nickname': pcp.player.nickname,
                'record_time': times.format_time(pcp.time),
            })

        return items
示例#22
0
	async def get_data(self):
		return [
		    dict(
		        place=idx + 1,
		        player_nickname=player.nickname,
		        total_time=format_time(
		            player.total_playtime * 1000,
		            hide_hours_when_zero=False,
		            hide_milliseconds=True,
		        ),
		    ) for idx, player in enumerate(self.active)
		]
示例#23
0
	async def chat_personal_record(self, player):
		async with self.lock:
			record = [x for x in self.current_records if x.login == player.login]

		if len(record) > 0:
			message = '$0b3You currently hold the $fff{}.$0b3 Dedimania Record: $fff\uf017 {}'.format(
				self.current_records.index(record[0]) + 1, times.format_time(record[0].score)
			)
			return self.instance.chat(message, player)
		else:
			message = '$0b3You don\'t have a Dedimania Record on this map yet.'
			return self.instance.chat(message, player)
示例#24
0
    async def get_all_player_data(self, logins):
        data = await super().get_all_player_data(logins)

        # Calculate the maximum number of rows that can be displayed
        max_n = math.floor((self.size_y - 5.5) / 3.3)

        # Maps a logon to the data that should be displayed
        cps = {}

        for idx, player in enumerate(self.app.instance.player_manager.online):
            last_fin = 0
            list_times = []
            n = 1
            for pcp in self.app.player_cps:
                # Make sure to only display a certain number of entries
                if float(n) >= max_n:
                    break

                # Set time color to green for your own CP time
                list_time = {
                    'index': n,
                    'color':
                    "$0f3" if player.login == pcp.player.login else "$bbb"
                }

                # Display 'fin' when the player crossed the finish line else display the CP number
                if pcp.cp == -1 or (pcp.cp == 0 and pcp.time != 0):
                    list_time['cp'] = 'fin'
                    last_fin += 1
                else:
                    list_time['cp'] = str(pcp.cp)

                list_time['cptime'] = times.format_time(pcp.time)
                list_time['nickname'] = pcp.player.nickname
                list_time['login'] = pcp.player.login

                # Only show top 5 fins but always show the current player
                if (pcp.cp == -1 or
                    (pcp.cp == 0 and pcp.time != 0)) and last_fin > 5:
                    if player.login != pcp.player.login:
                        continue
                    list_times[4] = list_time
                    continue

                list_times.append(list_time)
                n += 1
            cps[player.login] = {'cps': list_times}

        data.update(cps)

        return data
示例#25
0
	async def chat_current_record(self):
		records_amount = len(self.current_records)
		if records_amount > 0:
			first_record = self.current_records[0]
			message = '$0b3Current Dedimania Record: $fff\uf017 {}$z$s$0b3 by $fff{}$z$s$0b3 ($l[http://dedimania.net/tm2stats/?do=stat&UId={}&Show=RECORDS]$fff{}$0b3 records$l)'.format(
				times.format_time(first_record.score), first_record.nickname, self.instance.map_manager.current_map.uid, records_amount
			)
			calls = [self.instance.chat(message)]
			for player in self.instance.player_manager.online:
				calls.append(await self.chat_personal_record(player))
			return await asyncio.gather(*calls)
		else:
			message = '$0b3There is no Dedimania Record on this map yet.'
			return await self.instance.chat(message)
示例#26
0
	async def delete_record(self, player, values, data, view, **kwargs):
		if not await self.app.instance.permission_manager.has_permission(player, 'local_records:manage_records'):
			return await self.app.instance.chat('$ff0You do not have permissions to manage local records!', player)

		try:
			record = await self.app.get_local(id=data['id'])
		except:
			return

		if not await ask_confirmation(player, 'Are you sure you want to remove record {} by {}'.format(
			format_time(record.score), style_strip((await record.get_related('player')).nickname)
		), size='sm'):
			await self.app.delete_record(record)
			await self.app.refresh()
			await self.refresh(player)
示例#27
0
    async def chat_current_record(self):
        records_amount = len(self.current_records)
        if records_amount > 0:
            first_record = self.current_records[0]
            message = '$0b3Current Dedimania Record: $fff\uf017 {}$z$s$0b3 by $fff{}$z$s$0b3 ($fff{}$0b3 records)'.format(
                times.format_time(first_record.score), first_record.nickname,
                records_amount)
            calls = list()
            calls.append(self.instance.chat(message))

            for player in self.instance.player_manager.online:
                calls.append(await self.chat_personal_record(player))
            return await asyncio.gather(*calls)
        else:
            message = '$0b3There is no Dedimania Record on this map yet.'
            return await self.instance.chat(message)
示例#28
0
	def chat_personal_record(self, player, record_limit):
		if record_limit > 0:
			records = self.current_records[:record_limit]
		else:
			records = self.current_records

		record = [x for x in records if x.player_id == player.get_id()]

		if len(record) > 0:
			message = '$0f3You currently hold the $fff{}.$0f3 Local Record: $fff\uf017 {}'.format(
				self.current_records.index(record[0]) + 1, times.format_time(record[0].score)
			)
			return self.instance.chat(message, player)
		else:
			message = '$0f3You don\'t have a Local Record on this map yet.'
			return self.instance.chat(message, player)
示例#29
0
	async def get_all_player_data(self, logins):
		data = await super().get_all_player_data(logins)
		cps = {}
		for idx, player in enumerate(self.app.instance.player_manager.online):
			list_cps = []
			for pcp in self.app.best_cp_times:
				list_time = {
					'index': pcp.cp,
					'color': "$0f3" if player.login == pcp.player.login else "$ff0",
					'cptime': times.format_time(pcp.time),
					'nickname': pcp.player.nickname,
					'login': pcp.player.login
				}
				list_cps.append(list_time)
			cps[player.login] = {'cps': list_cps}

		data.update(cps)
		return data
示例#30
0
    async def chat_current_record(self):
        record_limit = await self.setting_record_limit.get_value()
        if record_limit > 0:
            records_amount = len(self.current_records[:record_limit])
        else:
            records_amount = len(self.current_records)

        if records_amount > 0:
            first_record = self.current_records[0]
            message = '$0f3Current Local Record: $fff\uf017 {}$z$s$0f3 by $fff{}$z$s$0f3 ($fff{}$0f3 records)'.format(
                times.format_time(first_record.score),
                first_record.player.nickname, records_amount)
            calls = [self.instance.chat(message)]
            for player in self.instance.player_manager.online:
                calls.append(self.chat_personal_record(player, record_limit))
            await self.instance.gbx.multicall(*calls)
        else:
            message = '$0f3There is no Local Record on this map yet.'
            await self.instance.chat(message)