diff --git a/.gitignore b/.gitignore index 4f53c85..5a84001 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.o -einstein +__pycache__ diff --git a/einstein b/einstein new file mode 100755 index 0000000..b274343 --- /dev/null +++ b/einstein @@ -0,0 +1,7 @@ +#! /usr/bin/env python3 + +import sys + +from einsteingame.main import main + +main(*sys.argv) diff --git a/einsteingame/i18n.py b/einsteingame/i18n.py index 833853b..aa88ba7 100644 --- a/einsteingame/i18n.py +++ b/einsteingame/i18n.py @@ -1,10 +1,12 @@ +from locale import setlocale, LC_ALL, LC_NUMERIC + class Locale(object): def __init__(self): self.parseLocale(setlocale(LC_ALL, "")) # hack because of numbers in Lua setlocale(LC_NUMERIC, "C") - def parseLocale(name): + def parseLocale(self, name): pos = name.find('.') langAndCountry = None @@ -80,15 +82,17 @@ def splitFileName(fileName): return name, ext, lang, country def getScore(lang, country, locale): - if len(country) == 0 and len(locale) == 0: + if len(country) == 0 and len(lang) == 0: return 1 score = 0 - if (locale.getCountry().length() && (locale.getCountry() == country)) - score += 2; - if (locale.getLanguage().length() && (locale.getLanguage() == lang)) - score += 4; + if locale.getCountry() == country: + score += 2 - return score; -} + if locale.getLanguage() == lang: + score += 4 + + return score + +locale = Locale() diff --git a/einsteingame/resources.py b/einsteingame/resources.py index 742da6e..c5b5f2d 100644 --- a/einsteingame/resources.py +++ b/einsteingame/resources.py @@ -3,7 +3,7 @@ import struct import io from .buffer import Buffer -from .i18n import splitFileName, getScore +from .i18n import splitFileName, getScore, locale class ResourceError(Exception): def __init__(self, code=None): @@ -88,6 +88,7 @@ class ResourcesCollection: def __init__(self, directories): self.__files = [] self.__buffer = None + self.__resources = {} self.loadResourceFiles(directories) self.processFiles() @@ -112,10 +113,11 @@ class ResourcesCollection: if score > 0: resName = name + '.' + ext - res = resources[resName]; + res = self.__resources.get(resName, None) + if not res: res = Resource(res_file, score, de, resName) - resources[resName] = res; + self.__resources[resName] = res if len(de.group) > 0: groups[de.group].append(res)