Load language MF files

This commit is contained in:
Daniel 2015-03-13 19:57:49 +02:00
parent 0e5f7116bb
commit 780de39b8e
2 changed files with 10 additions and 10 deletions

View file

@ -101,6 +101,10 @@ __builtin__.contentPacksMgr = ContentPacksManager(
filepath=contentPacksFilepath, sortFilename=contentPacksSortFilename) filepath=contentPacksFilepath, sortFilename=contentPacksSortFilename)
contentPacksMgr.applyAll() contentPacksMgr.applyAll()
languagePack = settings['language'].lower() + '.mf'
if contentPacksMgr.isApplicable(languagePack):
contentPacksMgr.applyMultifile(languagePack)
import time import time
import sys import sys

View file

@ -1,19 +1,15 @@
from direct.directnotify.DirectNotifyGlobal import directNotify from direct.directnotify.DirectNotifyGlobal import directNotify
import fnmatch import fnmatch
import os import os
from panda3d.core import Multifile, Filename, VirtualFileSystem
import yaml import yaml
from panda3d.core import Multifile, Filename, VirtualFileSystem
APPLICABLE_FILE_PATTERNS = ('*.mf', 'ambience.yaml') APPLICABLE_FILE_PATTERNS = ('*.mf', 'ambience.yaml')
CONTENT_EXT_WHITELIST = ('.jpg', '.jpeg', '.rgb', '.png', '.ogg', '.ttf') CONTENT_EXT_WHITELIST = ('.jpg', '.jpeg', '.rgb', '.png', '.ogg', '.ttf')
class ContentPackError(Exception): class ContentPackError(Exception):
pass pass
class ContentPacksManager: class ContentPacksManager:
notify = directNotify.newCategory('ContentPacksManager') notify = directNotify.newCategory('ContentPacksManager')
notify.setInfo(True) notify.setInfo(True)
@ -37,7 +33,7 @@ class ContentPacksManager:
Returns whether or not the specified file is applicable. Returns whether or not the specified file is applicable.
""" """
# Does this file exist? # Does this file exist?
if not os.path.exists(os.path.join(self.filepath, filename)): if not os.path.exists(filename):
return False return False
# Does this file match one of the applicable file patterns? # Does this file match one of the applicable file patterns?
@ -53,7 +49,7 @@ class ContentPacksManager:
Apply the specified multifile. Apply the specified multifile.
""" """
mf = Multifile() mf = Multifile()
mf.openReadWrite(Filename(os.path.join(self.filepath, filename))) mf.openReadWrite(Filename(filename))
# Discard content with non-whitelisted extensions: # Discard content with non-whitelisted extensions:
for subfileName in mf.getSubfileNames(): for subfileName in mf.getSubfileNames():
@ -77,7 +73,7 @@ class ContentPacksManager:
self.notify.info('Applying %s...' % filename) self.notify.info('Applying %s...' % filename)
basename = os.path.basename(filename) basename = os.path.basename(filename)
if basename.endswith('.mf'): if basename.endswith('.mf'):
self.applyMultifile(filename) self.applyMultifile(os.path.join(self.filepath, filename))
elif basename == 'ambience.yaml': elif basename == 'ambience.yaml':
self.applyAmbience(filename) self.applyAmbience(filename)
@ -91,7 +87,7 @@ class ContentPacksManager:
# Next, apply the sorted files: # Next, apply the sorted files:
for filename in self.sort[:]: for filename in self.sort[:]:
if self.isApplicable(filename): if self.isApplicable(os.path.join(self.filepath, filename)):
self.apply(filename) self.apply(filename)
else: else:
self.notify.warning('Invalidating %s...' % filename) self.notify.warning('Invalidating %s...' % filename)
@ -108,7 +104,7 @@ class ContentPacksManager:
continue continue
# Ensure this file is applicable: # Ensure this file is applicable:
if not self.isApplicable(filename): if not self.isApplicable(os.path.join(self.filepath, filename)):
continue continue
# Apply this file, and add it to the sort configuration: # Apply this file, and add it to the sort configuration: