Beispiel #1
0
def gen_modelmap(allitems):
	modelmap = {}
	schema = VDF()
	for key in allitems:
		item = allitems[key]

		# Get model name.
		if 'model_world' in item:
			modelmap[item['model_world']] = [key]
		if 'model_player' in item:
			modelmap[item['model_player']] = [key]
		if 'model_player_per_class' in item:
			for model in item['model_player_per_class'].values():
				modelmap[model] = [key]
		if 'visuals' in item and 'styles' in item['visuals']:
			for style in item['visuals']['styles'].values():
				if 'model_player' in style:
					if 'name' not in style:
						pass
						# modelmap[modelname] = [key, {
						# 	'coin_summer2015_gravel': 'Gun Mettle Campaign Coin (Gravel)',
						# 	'coin_summer2015_bronze': 'Gun Mettle Campaign Coin (Bronze)',
						# 	'coin_summer2015_silver': 'Gun Mettle Campaign Coin (Silver)',
						# 	'coin_summer2015_gold': 'Gun Mettle Campaign Coin (Gold)',
						# 	'stamp_winter2016': 'Tough Break Stamp',
						# }[modelname]]
					else:
						modelmap[style['model_player']] = [key, style['name']]
				if 'model_player_per_class' in style:
					for model in item['model_player_per_class'].values():
						modelmap[model] = [key, style['name']]

	# Convert the model name to a readable string. This is using .keys() and .values() because we change the dict during iteration.
	for (key, value) in zip(modelmap.keys(), modelmap.values()):
		del modelmap[key]
		propername = schema.get_localized_item_name(allitems[value[0]]['item_name'])
		if propername == 'The Essential Accessories':
			propername = 'Essential Accessories'
		if propername == 'The Superfan':
			propername = 'Superfan'
		if propername == 'The Athletic Supporter':
			propername = 'Athletic Supporter'
		elif propername == 'Teleporter':
			propername = 'Teleporters'
		if len(value) == 2: # Styles add-in
			style = schema.get_localized_item_name(value[1])
			if style:
				propername += '|style='+style
		if 'level' in allitems[value[0]]: # Hack for engineer buildings
			propername += '|level='+allitems[value[0]]['level']
		if 'vision_filter_flags' in allitems[value[0]]: # Romevision bot armor
			continue
		modelname = re.search('/([a-zA-Z0-9_]*)\.mdl', key)
		if modelname:
			modelmap[modelname.group(1)] = [value[0], propername]

	return modelmap
def add_items():
    schema = VDF()
    prefabs = schema.get_prefabs()
    allitems = dict(schema.get_items(), **prefabs)

    global regionsDict
    for item in allitems:
        item = allitems[item]
        if 'item_name' in item:
            TF_classlist = {}
            if 'used_by_classes' in item:
                TF_classlist = item['used_by_classes']
            itemname = schema.get_localized_item_name(item['item_name'])
            if verbose:
                print 'Processing', itemname
            if 'equip_region' in item:
                if isinstance(item['equip_region'], dict): # Valve are silly and on rare occasions put multiple regions in this field
                    for region in item['equip_region']:
                        if region != 'hat':
                            add_region(itemname, TF_classlist, region.lower())
                else:
                    if item['equip_region'] != 'hat':
                        add_region(itemname, TF_classlist, item['equip_region'].lower())
            elif 'equip_regions' in item:
                regions = item['equip_regions']
                if isinstance(regions, basestring): # Valve are also silly because sometimes they put a single region string here
                    if regions != 'hat':
                        add_region(itemname, TF_classlist, regions.lower())
                else:
                    for region in regions:
                        if region != 'hat':
                            add_region(itemname, TF_classlist, region.lower())
            elif 'prefab' in item:
                if isinstance(item['prefab'], list): # Valve are even sillier because sometimes they put their own name in the prefabs list
                    item['prefab'] = item['prefab'][1]
                if item['prefab'] in prefabs:
                    prefab = prefabs[item['prefab']]
                    if 'used_by_classes' in prefab:
                        TF_classlist.update(prefab['used_by_classes'])
                    if 'equip_region' in prefab and prefab['equip_region'] != 'hat':
                        region = prefab['equip_region']
                        add_region(itemname, TF_classlist, region)
                if item['prefab'] in ['misc', 'valve misc', 'base_misc', 'base_hat', 'ash_remains base_misc']:
                    if verbose:
                        print 'Item', itemname, 'has no equip region. Prefab is:', item['prefab']
                    add_region(itemname, TF_classlist, 'none')
def upload_item_icons(wikiUsername, wikiPassword, folder, wikiAddress = r'http://wiki.tf2.com/w/', wikiApi = r'http://wiki.tf2.com/w/api.php'):
	""" Crops and uploads item icons to wiki. """
	uploader = wikiUpload.wikiUploader(wikiUsername, wikiPassword, wikiAddress)
	wiki = wikitools.wiki.Wiki(wikiApi)
	wiki.login(wikiUsername, wikiPassword)
	schema = VDF()
	fails = False
	allitems = schema.get_items()
	for file in get_file_list(folder):
		imgname = re.sub(r'_large\.png', '', file)
		print imgname
		item = get_item_from_inventory(allitems, imgname)
		if item is None:
			f = open('faileditemiconuploads.txt', 'ab').write(file + '\n')
			fails = True
			continue
		itemname = schema.get_localized_item_name(item['item_name']).encode('utf8')
		newfilename = r'Item icon {0}.png'.format(itemname)
		crop_image(file, folder, newfilename)
		if pngcrush:
			process = Popen(['pngcrush', '-rem', 'gAMA', '-rem', 'cHRM', '-rem', 'iCCP', '-rem', 'sRGB', '-brute', folder + os.sep + newfilename, folder + os.sep + newfilename + 'temp'], stdout = subprocess.PIPE).communicate()[0]
			os.remove(folder + os.sep + newfilename)
			os.rename(folder + os.sep + newfilename + 'temp', folder + os.sep + newfilename)

		success = False
		n = 0
		while n < 5 and not success:
			try:
				uploader.upload(folder + os.sep + newfilename, 'File:' + newfilename, 'Uploaded new TF2B icon', '', overwrite=True)
				success = True
			except:
				n += 1
		if not success:
			print 'Could not upload', newfilename
	if fails:
		print 'Some files could not be uploaded. Please see faileditemiconuploads.txt'
Beispiel #4
0
import os
from vdfparser import VDF
schema = VDF()
items = schema.get_items()
prefabs = schema.get_prefabs()
allitems = dict(items, **prefabs)
max = [0]*14
modelmap = {}
allitems.update({ # Extra data for engineer buildings
	'Sentry Gun Level 1': {
		'model_world': 'models/buildings/sentry1.mdl',
		'item_name': '#TF_Object_Sentry',
		'level': '1',
		'used_by_classes': {
			'engineer': '1'
		},
		'item_slot': 'building2'
	},
	'Sentry Gun Level 2': {
		'model_world': 'models/buildings/sentry2_optimized.mdl',
		'item_name': '#TF_Object_Sentry',
		'level': '2',
		'used_by_classes': {
			'engineer': '1'
		},
		'item_slot': 'building2'
	},
	'Sentry Gun Level 3': {
		'model_world': 'models/buildings/sentry3_optimized.mdl',
		'item_name': '#TF_Object_Sentry',
		'level': '3',
Beispiel #5
0
# -*- coding: utf-8 -*-
# Generates the equip regions table found at
# http://wiki.tf/Template:Equip_region_table on the wiki

import re, copy
from vdfparser import VDF

schema = VDF()
items = schema.get_items()
prefabs = schema.get_prefabs()
allitems = dict(items, **prefabs)

er_none = {'misc', 'valve misc', 'base_misc', 'base_hat', 'ash_remains base_misc'} # A list of prefabs which can be defined for an item which has no equip region.
regionsDict = {}
TF_classes = ['scout', 'soldier', 'pyro', 'demoman', 'heavy', 'engineer', 'medic', 'sniper', 'spy', 'allclass'] # This table is dynamic, which is to say none of the rest of the code explicitly relies on the order or size of it.
verbose = False

def add_region(itemname, TF_classlist, region):
    for TF_class in TF_classes:
        if re.search('^'+TF_class, region):
            region = '{{void|'+str(TF_classes.index(TF_class))+'}}'+region
        if re.search('^demo', region):
            region = '{{void|'+str(TF_classes.index('demoman'))+'}}'+region
        if re.search('^medigun', region):
            region = '{{void|'+str(TF_classes.index('medic'))+'}}'+region
        if region == 'none':
            region = '{{void}}none'
    if len(TF_classlist) == len(TF_classes)-1:
        TF_classlist = {'allclass': '1'} # Mimics the style of the actual items_game
    if region not in regionsDict:
        regionsDict[region] = {}
Beispiel #6
0
def gen_allitems():
	schema = VDF()
	items = schema.get_items()
	prefabs = schema.get_prefabs()
	allitems = dict(items, **prefabs)

	# Fix for some broken weapons
	for key in allitems:
		item = allitems[key]
		if 'prefab' in item and 'extra_wearable' not in item:
			prefab = item['prefab']
			if isinstance(prefab, list) and prefab[0] == 'valve': # Valve are silly and occasionally put their name into the prefabs
				prefab = prefab[1]
			if prefab[-11:] == ' marketable':
				prefab = prefab[:-11]
			prefab = prefab.rpartition(' ')[2]
			if prefab == 'weapon_melee_allclass' or prefab == 'weapon_shotgun': # Malformed & duplicate prefabs
				continue
			if prefab[:7] == 'weapon_' or prefab in ['holy_mackerel', 'axtinguisher', 'buff_banner', 'sandvich', 'ubersaw', 'frontier_justice', 'huntsman', 'ambassador']:
				item['item_slot'] = prefabs[prefab]['item_slot']
				item['used_by_classes'] = prefabs[prefab]['used_by_classes']

	# Some hard-coded additions. This _vaguely_ mimics the schema's true format.
	buildings = {
		'Sentry Gun Level 1': {
			'model_world': 'models/buildables/sentry1.mdl',
			'item_name': '#TF_Object_Sentry',
			'level': '1',
		},
		'Sentry Gun Level 2': {
			'model_world': 'models/buildables/sentry2_optimized.mdl',
			'item_name': '#TF_Object_Sentry',
			'level': '2',
		},
		'Sentry Gun Level 3': {
			'model_world': 'models/buildables/sentry3_optimized.mdl',
			'item_name': '#TF_Object_Sentry',
			'level': '3',
		},
		'Dispenser Level 1': {
			'model_world': 'models/buildables/dispenser_toolbox.mdl',
			'item_name': '#TF_Object_Dispenser',
			'level': '1',
		},
		'Dispenser Level 2': {
			'model_world': 'models/buildables/dispenser_lvl2.mdl',
			'item_name': '#TF_Object_Dispenser',
			'level': '2',
		},
		'Dispenser Level 3': {
			'model_world': 'models/buildables/dispenser_lvl3.mdl',
			'item_name': '#TF_Object_Dispenser',
			'level': '3',
		},
		'Teleporter': {
			'model_world': 'models/buildables/teleporter.mdl',
			'item_name': '#TF_Object_Tele',
		},
	}
	for building in buildings:
		buildings[building]['used_by_classes'] = {'engineer': '1'}
		buildings[building]['item_slot'] = 'building2'
	allitems.update(buildings)
	for TF_class in TF_classes:
		allitems[TF_class.title()] = {
			'model_world': 'models/player/%s.mdl' % TF_class,
			'model_player': 'models/player/%s_morphs_high.mdl' % TF_class,
			'item_name': '#TF_class_Name_%s' % TF_class,
			'used_by_classes': {TF_class: '1'},
			'item_slot': 'class'
		}
	# Exceptions to exceptions
	allitems['Demoman']['model_player'] = 'models/player/demo.mdl'
	allitems['Demoman']['model_world'] = 'models/player/demo_morphs_high.mdl'
	allitems['Heavy']['item_name'] = '#TF_class_Name_HWGuy'
	return allitems