[utils.miner] Added -sort of- mob miner

This commit is contained in:
Felipe Martín 2013-06-03 17:42:45 +02:00
parent aba1fa1dc0
commit 41e6549742
3 changed files with 130 additions and 1 deletions

View File

@ -33,7 +33,6 @@ LANGUAGES_MASTER_KEYS = [
'language.code',
]
###
# ACHIEVEMENTS
###
@ -41,6 +40,12 @@ ACHIEVEMENTS_FILES = []
ACHIEVEMENTS_JAVA_KEYWORDS = ['onARail', 'flyPig']
ACHIEVEMENTS_PATTERN = "new (?P<code>[a-z]{1,2}\((?P<id>[1-9]{1,3})\, \"(?P<name>\w+)\".*\))"
###
# MOBS
###
MOBS_FILES = []
MOBS_JAVA_KEYWORDS = ['mob/']
MOBS_PATTERN = '(?P<full>\"mob/(?P<name>[a-zA-Z0-9]+)\.png\")'
###
# BLACKLIST

103
utils/miner/mobs.py Normal file
View File

@ -0,0 +1,103 @@
#!/usr/bin/env python
# General libs
import re
import json
import os
import sys
# Tool libs
from utils import run, sanitize
import utils
import conf
from objects import GameMob
utils.title('MOS')
if conf.SAVE:
sys.path.append('../../minecraftcodex')
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
#from database.models import Achievement
###
# GLOBALS
###
ITEMS = []
ITEMS_STR = []
###
# LOOK FOR CORRECT JAVA FILES
###
utils.sub("Looking for java files...")
#utils.sub("Keywords: %s" % ', '.join(conf.ACHIEVEMENTS_JAVA_KEYWORDS))
for keyword in conf.MOBS_JAVA_KEYWORDS:
cmd = run("grep '%s' ./classes/*" % keyword)
for result in cmd:
for line in result.split('\n'):
if line and result is not '':
java_file = os.path.basename(line.strip().split()[0][:-1])
if java_file not in conf.MOBS_FILES:
utils.echo("%s " % java_file, end='')
conf.MOBS_FILES.append(java_file)
utils.echo('\r')
###
# GET ITEMS INFO FROM CLASSFILE
###
utils.sub('Looking for dataz', end='\n')
# TODO OLD Data
for java_file in conf.MOBS_FILES:
print(java_file)
file_handler = open('./classes/%s' % java_file)
data = file_handler.read().split("\n")
item_regex = re.compile(conf.MOBS_PATTERN)
class_error_regex = re.compile('name \'(?P<name>\w+)\' is not defined')
for line in data:
if '"' in line:
t = item_regex.search(line)
if t:
item = t.groupdict()
if conf.DEBUG:
print("Line: " + item['name'])
if item['name'] not in ITEMS_STR:
obj = GameMob(item['name'], item['full'])
ITEMS.append(obj)
ITEMS_STR.append(item['name'])
for x in ITEMS:
print(x)

View File

@ -100,3 +100,24 @@ class GameAchievement(object):
self.id,
self.name
)
###
# MOBS
###
class GameMob(object):
def __init__(self, name, full, *args):
self.name = name
self.full = full
def method(self, *args):
return self
def __getattr__(self, *args):
return self.method
def __str__(self):
return "<Mob (%s: '%s')>" % (
self.name,
self.full
)