[Miner] textures are now saved to database.

Added local settings for the miner
This commit is contained in:
Felipe Martín 2013-05-27 16:12:51 +02:00
parent 85a52f23c1
commit 5fa96a08bb
4 changed files with 100 additions and 4 deletions

View File

@ -4,6 +4,7 @@ DEBUG = False
# TEXTURES
###
TEXTURES_PATHS = ['jarfile/textures/blocks', 'jarfile/textures/items']
TEXTURES_EXTRA_SIZES_MULTIPLIER = [2, 4, 6, 8]
###
# ITEMS

View File

@ -0,0 +1,16 @@
LOCAL_SETTINGS = True
from herobrine.settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '../../dev_ddbb.sqlite',
}
}
TEMPLATE_CONTEXT = [
('app_version', '[local development]'),
]

View File

@ -46,8 +46,16 @@ class GameBlock(object):
# TEXTURE
##
class GameTexture(object):
def __init__(self, name):
def __init__(self, name, typ, path):
self.name = self.parse_name(name)
self.path = path
self.type = typ
def __str__(self, *args):
return "<Texture (%s: '%s')>" % (
self.type,
self.name
)
def parse_name(self, name):
return name.split('.')[0]

View File

@ -1,6 +1,11 @@
#!/usr/bin/env python
# General libs
from os import listdir
from os import listdir, environ
from os.path import isfile, join
from sys import path
import json
from PIL import Image
# Tool libs
import conf
@ -8,12 +13,78 @@ from objects import GameTexture
print("=> Phase: textures")
path.append('../../minecraftcodex')
environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
from database.models import Texture
TEXTURES = []
# Old textures for final count
try:
OLD_TEXTURES = json.loads(open('textures.json').read())
except:
OLD_TEXTURES = {}
OLD_TEXTURES['list'] = []
for path in conf.TEXTURES_PATHS:
# GO!
for f in listdir(path):
if isfile(join(path, f)):
TEXTURES.append(GameTexture(f))
# Copy original image
destiny_path = '../../minecraftcodex/database/static/%s' % join(path, f).\
replace('jarfile/', '')
destiny = open(destiny_path, 'w+')
destiny.write(open(join(path, f)).read())
destiny.close()
# making more sizes for the site
try:
modified = Image.open(destiny_path)
for multiplier in conf.TEXTURES_EXTRA_SIZES_MULTIPLIER:
sizes = (modified.size[0] * multiplier, modified.size[1] * multiplier)
modified_path = destiny_path.replace('.png', '_x%d.png' % multiplier)
resized = modified.resize(sizes, Image.NEAREST)
resized.save(modified_path, 'PNG')
except IOError:
pass
print(" Got %d textures" % len(TEXTURES))
TEXTURES.append(
GameTexture(
f,
path.replace('jarfile/textures/', ''),
join(path, f).replace('jarfile/textures/', '')
)
)
for texture in TEXTURES:
try:
item = Texture.objects.get(
name=texture.name,
type=texture.type
)
except Texture.DoesNotExist:
item = Texture(
name=texture.name,
type=texture.type,
image=texture.path
)
item.save()
print(' => Summary')
new_old_data = {}
new_old_data['list'] = []
[new_old_data['list'].append(x.name) for x in TEXTURES]
new_items = len(new_old_data['list'])-len(OLD_TEXTURES['list'])
print(' Fetched %d textures (%d new)' % (len(TEXTURES), new_items))
if new_items > 0:
print(' Modifications:')
for item in TEXTURES:
if item.name not in OLD_TEXTURES['list']:
print(' + %s' % item.name)
for item in OLD_TEXTURES['list']:
if item not in new_old_data['list']:
print(' - %s' % item)
olditems = open('textures.json', 'w')
olditems.write(json.dumps(new_old_data))