From 41e6549742f6f021515800b8617cf803ba93065f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Mon, 3 Jun 2013 17:42:45 +0200 Subject: [PATCH] [utils.miner] Added -sort of- mob miner --- utils/miner/conf.py | 7 ++- utils/miner/mobs.py | 103 +++++++++++++++++++++++++++++++++++++++++ utils/miner/objects.py | 21 +++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 utils/miner/mobs.py diff --git a/utils/miner/conf.py b/utils/miner/conf.py index 7ff82ff..4d1bbdb 100644 --- a/utils/miner/conf.py +++ b/utils/miner/conf.py @@ -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[a-z]{1,2}\((?P[1-9]{1,3})\, \"(?P\w+)\".*\))" +### +# MOBS +### +MOBS_FILES = [] +MOBS_JAVA_KEYWORDS = ['mob/'] +MOBS_PATTERN = '(?P\"mob/(?P[a-zA-Z0-9]+)\.png\")' ### # BLACKLIST diff --git a/utils/miner/mobs.py b/utils/miner/mobs.py new file mode 100644 index 0000000..fd1a6bb --- /dev/null +++ b/utils/miner/mobs.py @@ -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\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) + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/miner/objects.py b/utils/miner/objects.py index ea1bf7d..a0d1330 100644 --- a/utils/miner/objects.py +++ b/utils/miner/objects.py @@ -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 "" % ( + self.name, + self.full + )