Move getResourceLoaderForFilename to minecraftinstall.py

This commit is contained in:
David Vierra 2015-08-30 05:34:24 -10:00
parent 801c122f33
commit 3c3e0292cc
3 changed files with 28 additions and 27 deletions

View File

@ -647,31 +647,6 @@ class MCEditApp(QtGui.QApplication):
tab = self.currentTab()
return getattr(tab, 'editorSession', None)
def getResourceLoaderForFilename(self, filename):
# Is this world inside a MultiMC instance?
filename = os.path.normpath(filename)
installs = minecraftinstall.GetInstalls()
for instance in installs.instances:
savesFolder = os.path.normpath(instance.saveFileDir)
if filename.startswith(savesFolder):
return instance.getResourceLoader()
# Nope. Use the version and respack chosen in the world list.
# ... should search for installs matching this one, but vanilla installs are still multi-version...
return self.getSelectedResourceLoader()
def getSelectedResourceLoader(self):
i = minecraftinstall.currentInstallOption.value()
if i == -1:
return minecraftinstall.GetInstalls().getDefaultResourceLoader()
install = minecraftinstall.GetInstalls().getInstall(i)
v = minecraftinstall.currentVersionOption.value()
if not v:
v = list(install.versions)[0]
p = minecraftinstall.currentResourcePackOption.value() or None
return install.getResourceLoader(v, p)
def loadFile(self, filename, readonly=False):
self.hideWorldList()
fileLoadingDialog = QtGui.QProgressDialog(self.tr("Loading world..."),
@ -692,7 +667,7 @@ class MCEditApp(QtGui.QApplication):
fileLoadingDialog.setLabelText(status)
try:
resourceLoader = self.getResourceLoaderForFilename(filename)
resourceLoader = minecraftinstall.getResourceLoaderForFilename(filename)
configuredBlocks = self.configureBlocksDialog.getConfiguredBlocks()
session = EditorSession(filename, resourceLoader, configuredBlocks, readonly=readonly, progressCallback=callback)
self.undoGroup.addStack(session.undoStack)

View File

@ -27,6 +27,32 @@ currentMMCInstanceOption = settings.Settings().getOption("minecraft_installs/cur
_installs = None
def getResourceLoaderForFilename(filename):
# Is this world inside a MultiMC instance?
filename = os.path.normpath(filename)
installs = GetInstalls()
for instance in installs.instances:
savesFolder = os.path.normpath(instance.saveFileDir)
if filename.startswith(savesFolder):
return instance.getResourceLoader()
# Nope. Use the version and respack chosen in the world list.
# ... should search for installs matching this one, but vanilla installs are still multi-version...
return getSelectedResourceLoader()
def getSelectedResourceLoader():
i = currentInstallOption.value()
if i == -1:
return GetInstalls().getDefaultResourceLoader()
install = GetInstalls().getInstall(i)
v = currentVersionOption.value()
if not v:
v = list(install.versions)[0]
p = currentResourcePackOption.value() or None
return install.getResourceLoader(v, p)
def GetInstalls():
global _installs
if _installs is None:

View File

@ -367,7 +367,7 @@ class WorldListWidget(QtGui.QDialog):
try:
worldEditor = worldeditor.WorldEditor(filename, readonly=True)
resLoader = QtGui.qApp.getResourceLoaderForFilename(filename)
resLoader = minecraftinstall.getResourceLoaderForFilename(filename)
blockModels = BlockModels(worldEditor.blocktypes, resLoader)
textureAtlas = TextureAtlas(worldEditor, resLoader, blockModels)