You've already forked q3stats
Q3Stats is now open source! :)
This commit is contained in:
99
utils/extract_icons.py
Normal file
99
utils/extract_icons.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2017 Tomek Wójcik <tomek@bthlabs.pl>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
import six
|
||||
|
||||
CPMA_ZIPBALL_URL = 'http://playmorepromode.org/CPMA148.zip'
|
||||
|
||||
ICONS_ROOT = os.path.abspath('frontend/img')
|
||||
|
||||
PAK_FILE_TO_ICON = {
|
||||
'icons/iconh_green.tga': 'items/GH.png',
|
||||
'icons/iconh_mega.tga': 'items/MH.png',
|
||||
'icons/iconh_red.tga': 'items/RH.png',
|
||||
'icons/iconh_yellow.tga': 'items/YH.png',
|
||||
'icons/iconr_green.tga': 'items/GA.png',
|
||||
'icons/iconr_red.tga': 'items/RA.png',
|
||||
'icons/iconr_shard.tga': 'items/SA.png',
|
||||
'icons/iconr_yellow.tga': 'items/YA.png',
|
||||
'icons/iconw_bfg.tga': 'weapons/BFG.png',
|
||||
'icons/iconw_gauntlet.tga': 'weapons/G.png',
|
||||
'icons/iconw_grenade.tga': 'weapons/GL.png',
|
||||
'icons/iconw_lightning.tga': 'weapons/LG.png',
|
||||
'icons/iconw_machinegun.tga': 'weapons/MG.png',
|
||||
'icons/iconw_plasma.tga': 'weapons/PG.png',
|
||||
'icons/iconw_railgun.tga': 'weapons/RG.png',
|
||||
'icons/iconw_rocket.tga': 'weapons/RL.png',
|
||||
'icons/iconw_shotgun.tga': 'weapons/SG.png',
|
||||
'icons/quad.tga': 'powerups/Quad.png',
|
||||
'icons/regen.tga': 'items/Regen.png'
|
||||
}
|
||||
|
||||
|
||||
def convert(src_path, dest_path, cwd):
|
||||
proc = subprocess.Popen(
|
||||
shlex.split('convert %s %s' % (src_path, dest_path))
|
||||
)
|
||||
|
||||
return proc.wait()
|
||||
|
||||
|
||||
def download_cpma():
|
||||
proc = subprocess.Popen(shlex.split('wget %s' % CPMA_ZIPBALL_URL))
|
||||
result = proc.wait()
|
||||
|
||||
if result != 0:
|
||||
raise RuntimeError('Failed to download CPMA :(')
|
||||
|
||||
proc = subprocess.Popen(shlex.split('unzip CPMA148.zip'))
|
||||
return proc.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
work_dir = os.path.abspath(tempfile.mkdtemp())
|
||||
os.chdir(work_dir)
|
||||
|
||||
cpma_pak_path = None
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
download_cpma()
|
||||
cpma_pak_path = os.path.join(work_dir, 'cpma', 'z-cpma-pak148.pk3')
|
||||
else:
|
||||
cpma_pak_path = sys.argv[1]
|
||||
|
||||
with zipfile.ZipFile(cpma_pak_path, 'r') as pak:
|
||||
for src, dest in six.iteritems(PAK_FILE_TO_ICON):
|
||||
six.print_('%s -> %s' % (src, dest))
|
||||
|
||||
src_path = pak.extract(src)
|
||||
dest_path = os.path.join(ICONS_ROOT, dest)
|
||||
|
||||
convert(src_path, dest_path, work_dir)
|
||||
|
||||
shutil.rmtree(work_dir)
|
||||
Reference in New Issue
Block a user