Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Khroki/MCEdit-Unified
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubisk committed Aug 7, 2015
2 parents 5d6aedd + 22ac942 commit 7498b25
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 70 deletions.
36 changes: 0 additions & 36 deletions documentation/filters/box.md

This file was deleted.

15 changes: 0 additions & 15 deletions documentation/filters/level.md

This file was deleted.

73 changes: 66 additions & 7 deletions resource_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@


def step(slot):
'''
Utility method for multiplying the slot by 16
:param slot: Texture slot
:type slot: int
'''
texSlot = slot*16
return texSlot
'''
Expand Down Expand Up @@ -525,6 +531,9 @@ def step(slot):


class IResourcePack:
'''
Sets all base variables for a Resource Pack
'''

def __init__(self):
self.__stop = False
Expand All @@ -534,12 +543,6 @@ def __init__(self):
self._too_big = False
self.big_textures_counted = 0
self.big_textures_max = 10
'''
try:
os.makedirs(self.texture_path)
except OSError:
pass
'''
self.block_image = {}
self.propogated_textures = []
self.all_texture_slots = []
Expand All @@ -552,24 +555,42 @@ def __init__(self):

@property
def pack_name(self):
'''
The name of the Resource Pack
'''
return self._pack_name

@property
def terrain_name(self):
'''
Name of the parsed texture PNG file
'''
return self._terrain_name

def terrain_path(self):
'''
Path to the parsed PNG file
'''
return self._terrain_path

@property
def isEmpty(self):
'''
Returns true if the Resource Pack doesn't replace the minimum amount of textures
'''
return self._isEmpty

@property
def tooBig(self):
'''
Returns true if the Resource Pack has a greater resolution than 32x32
'''
return self._too_big

def parse_terrain_png(self):
'''
Parses each block texture into a usable PNG file like terrain.png
'''
new_terrain = Image.new("RGBA", (512, 512), None)
for tex in self.block_image.keys():
if not self.__stop and tex in textureSlots.keys():
Expand Down Expand Up @@ -613,6 +634,9 @@ def parse_terrain_png(self):
del self.block_image

def handle_too_big_packs(self):
'''
Removes the parsed PNG file
'''
self._too_big = True
#print u"{} seems to be a higher resolution than supported".format(self._pack_name)
try:
Expand All @@ -624,7 +648,7 @@ def handle_too_big_packs(self):

class ZipResourcePack(IResourcePack):
'''
Represents a single Resource Pack
Represents a single Resource Pack that is in a zip file
'''

def __init__(self, zipfileFile, noEncConvert=False):
Expand All @@ -640,6 +664,9 @@ def __init__(self, zipfileFile, noEncConvert=False):
print "Error while trying to load one of the resource packs: {}".format(e)

def open_pack(self):
'''
Opens the zip file and puts texture data into a dictionary, where the key is the texture file name, and the value is a PIL.Image instance
'''
zfile = zipfile.ZipFile(self.zipfile)
for name in zfile.infolist():
if name.filename.endswith(".png") and not name.filename.split(os.path.sep)[-1].startswith("._"):
Expand Down Expand Up @@ -705,6 +732,9 @@ def __init__(self, folder, noEncConvert=False):
self.add_textures()

def add_textures(self):
'''
Scraps the block textures folder and puts texture data into a dictionary with exactly identical structure as ZipResourcePack
'''
base_path = os.path.join(self._full_path, "assets", "minecraft", "textures", "blocks")
if os.path.exists(base_path):
files = os.listdir(base_path)
Expand Down Expand Up @@ -755,6 +785,9 @@ def add_textures(self):


class DefaultResourcePack(IResourcePack):
'''
Represents the default Resource Pack that is always present
'''

def __init__(self):
self._isEmpty = False
Expand All @@ -775,6 +808,9 @@ def tooBig(self):


def setup_resource_packs():
'''
Handles parsing of Resource Packs and removing ones that are either have to0 high of a resolution, or don't replace any textures
'''
terrains = {}
try:
os.mkdir("terrain-textures")
Expand Down Expand Up @@ -809,6 +845,9 @@ def setup_resource_packs():


class ResourcePackHandler:
'''
A single point to manage which Resource Pack is being used and to provide the paths to each parsed PNG
'''

def __init__(self):
try:
Expand All @@ -822,22 +861,42 @@ def __init__(self):

@property
def resource_packs(self):
'''
A dictionary of Resource Packs, where the key is the pack's file/folder name, and the value is the path to the parsed PNG
'''
return self._resource_packs

def get_available_resource_packs(self):
'''
Returns the names of all the Resource Packs that can be used
'''
return self._resource_packs.keys()

def reload_resource_packs(self):
'''
Reparses all Resource Packs
'''
self._resource_packs = setup_resource_packs()

def get_selected_resource_pack_name(self):
'''
Returns the currently selected Resource Pack's name
'''
return self._selected_resource_pack

def set_selected_resource_pack_name(self, name):
'''
Sets the currently selected Resource Pack
:param name: Name of the Resource Pack
'''
config.settings.resourcePack.set(name)
self._selected_resource_pack = name

def get_selected_resource_pack(self):
'''
Returns the selected Resource Pack instance. Can be an instance of either DefaultResourcePack, ZipResourcePack or FolderResourcePack
'''
return self._resource_packs[self._selected_resource_pack]

packs = ResourcePackHandler()
38 changes: 26 additions & 12 deletions version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import threading
import traceback
import logging
from uuid import UUID

logger = logging.getLogger()

Expand All @@ -20,17 +21,22 @@ def new_func(*args, **kwargs):
#logger.warn("Function \""+str(func.__name__)+"\" is deprecated and should not be used")
return func(*args, **kwargs)
new_func.__name__ = func.__name__
new_func.__doc__ = '''*Deprecated*\n%s'''%func.__doc__
if func.__doc__ is not None:
new_func.__doc__ = '''*Deprecated*\n%s'''%func.__doc__
else:
new_func.__doc__ = '''*Deprecated*'''
new_func.__dict__.update(func.__dict__)
return new_func

class __PlayerCache:
class PlayerCache:
'''
Used to cache Player names and UUID's, provides an small API to interface with it
'''

SUCCESS = 0
FAILED = 1

_playerCacheList = []

def __convert(self):
jsonFile = None
Expand Down Expand Up @@ -60,9 +66,7 @@ def fixAllOfPodshotsBugs(self):
del player["Timstamp"]
self._save()


def __init__(self):
self._playerCacheList = []
def load(self):
if not os.path.exists(userCachePath):
out = open(userCachePath, 'w')
json.dump(self._playerCacheList, out)
Expand All @@ -85,9 +89,7 @@ def __init__(self):
self.refresh_lock = threading.Lock()
self.player_refreshing = threading.Thread(target=self._refreshAll)
self.player_refreshing.daemon = True
self.player_refreshing.start()
#self._refreshAll()

self.player_refreshing.start()

def _save(self):
out = open(userCachePath, "w")
Expand Down Expand Up @@ -254,6 +256,7 @@ def getAllPlayersKnown(self, returnType=0, include_failed_lookups=False):
def getFromCacheUUID(self, uuid, seperator=True):
'''
Checks if the UUID is already in the cache
:param uuid: The UUID that might be in the cache
:type uuid: str
:param seperator: Whether the UUID is seperated by -'s
Expand All @@ -268,6 +271,7 @@ def getFromCacheUUID(self, uuid, seperator=True):
def getFromCacheName(self, name):
'''
Checks if the Player name is already in the cache
:param name: The name of the Player that might be in the cache
'''
for player in self._playerCacheList:
Expand All @@ -277,16 +281,18 @@ def getFromCacheName(self, name):
def getPlayerInfo(self, arg, force=False):
'''
Recommended method to call to get Player data. Roughly determines whether a UUID or Player name was passed 'arg'
:param arg: Either a UUID or Player name to retrieve from the cache/Mojang
:type arg: str
:param force: True if the Player name should be forcefully fetched from Mojang
'''
if arg.count('-') == 4:
try:
UUID(arg, version=4)
if self.uuidInCache(arg) and not force:
return self.getFromCacheUUID(arg)
else:
return self._getPlayerInfoUUID(arg)
else:
except ValueError:
if self.nameInCache(arg) and not force:
return self.getFromCacheName(arg)
else:
Expand Down Expand Up @@ -365,15 +371,23 @@ def cleanup(self):
for toRemove in remove:
self._playerCacheList.remove(toRemove)
self._save()

playercache = __PlayerCache()

_playercache = PlayerCache()
_playercache.load()
playercache = _playercache

@deprecated
def getUUIDFromPlayerName(player, seperator=True, forceNetwork=False):
'''
Old compatibility function for the PlayerCache method. It is recommended to use playercache.getPlayerInfo()
'''
return playercache.getPlayerFromPlayername(player, forceNetwork, seperator)

@deprecated
def getPlayerNameFromUUID(uuid,forceNetwork=False):
'''
Old compatibility function for the PlayerCache method. It is recommended to use playercache.getPlayerInfo()
'''
return playercache.getPlayerFromUUID(uuid, forceNetwork)

def getPlayerSkin(uuid, force=False, trying_again=False, instance=None):
Expand Down

0 comments on commit 7498b25

Please sign in to comment.